Source Code
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define F first
#define S second
#define all(a) a.begin(),a.end()

using namespace std;

const ll Mod=1e9+7 ;

ll poww(ll a,ll b,ll mod){
    ll res=1;if(b<0)b=(b%(mod-1)+mod-1)%(mod-1);
    for(;b;b>>=1,a=1ll*a*a%mod)
      if(b&1)res=1ll*res*a%mod;
    return res;
}

void Max(ll& x,ll y){
x=max(x,y);
}
void Min(ll& x,ll y){
x=min(x,y);
}
void OK(bool yes){
    cout<<(yes?"Yes\n":"No\n");
}

const ll N=200500,M=2010,LN=(1<<24),K=17,Mx=4e6+50,inf=3e18,Mod1=1e9+7,Mod2=999997457;
const ld pi=acos(-1),eps=1e-12;

ll Fact[N];
void init(){
Fact[0]=1ll;
for(int i=1;i<N;i++)Fact[i]=(1ll*Fact[i-1]*i)%Mod;
}
int Cnk(ll x,ll y){
if(y > x)return 0;
return (  ((Fact[x]*poww(Fact[y],-1,Mod))%Mod)  *poww(Fact[x-y],-1,Mod))%Mod;
}


void Add(ll& x,ll y,int j=0){
ll mod=Mod;
if(j==1)mod=Mod1;
if(j==2)mod=Mod2;
x%=mod;
y%=mod;
if(x<0)x+=mod;
if(y<0)y+=mod;
x=(x+y>=mod?x+y-mod:x+y);
}
/*
void init(){
Fact[0]=iFact[0]=1ll;
for(int i=1;i<N;i++)Fact[i]=(Fact[i-1]*i)%Mod;
for(int i=1;i<N;i++)iFact[i]=(iFact[i-1]*poww(i,-1,Mod))%Mod;
}
*/

ll a[N];

int main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);
    //cout.tie(0);

    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

    //freopen("heinto.in","r",stdin);


    int T=1;
    int Case=1;
    //init();
    //cin>>T;
    while(T--){
        ll n,k;
        cin>>n;
        vector<ll> v;
        for(int i=1;n>0;i++){
            if(n<i){
                n+=i-1;
                v.pop_back();
                v.pb(n);
                break;
            }
            n-=i;
            v.pb(i);
        }
        cout<<v.size()<<'\n';
        //reverse(all(v));
        for(auto p:v){
            cout<<p<<' ';
        }
        //OK(ok);
    }

    return 0;
}
/*
6
2 1 4 2 2 4
6
4 1 1 2 1 2
8
3 1 1 2 1 2 1 2
*/

Copy
Want More! Wise-ard
GNU G++17
185 ms
22.4 MB
Accepted