akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

//********************************template END****************************************//

void solve(void){

	string S;
	cin >> S;
	int ans = 0;
	rep(4, i)
	{
		if (S[i] == '+')
		{
			ans++;
		}
		else
		{
			ans--;
		}
	}

	cout << ans << endl;
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>

using namespace std;



int main() {
	int n,a,b;
	cin >> n;
	cout << 3 * n * n  << endl;

}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef vector<ll> vel;
typedef vector<str> ves;
#define REP(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, b) REP(i, 0, b)
const ll mod = 1000000007;
const double pi = 3.14159265358979;

int main() {
    str s;
    cin >> s;
    if(s == "ABC") {
        cout << "ARC" << endl;
    }
    else {
        cout << "ABC" << endl;
    }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}
ll n;
ll p[101];
ll a[101];
ll dp[100001][101];
ll getans(ll i,ll s)
{
	if(i>=n)
	{
		return 0;
	}
	if(s==0)
	{
		return 0;
	}
	if(dp[s][i]!=-1)
	{
		return dp[s][i];
	}
	if(p[i]>s)
	{
		return dp[s][i]=getans(i+1,s);
	}
	else
	{
	return dp[s][i]=max(getans(i+1,s),a[i]+getans(i+1,s-p[i]));	
	}
}
int main()
{
   ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
ll s;
cin>>n>>s;
for(ll i=0;i<n;i++)
{
	cin>>p[i]>>a[i];
}

for(ll i=0;i<=s;i++)
{
	for(ll j=0;j<n;j++)
{
	
	dp[i][j]=-1;
}
}
cout<<getans(0,s)<<endl;
}
 


Measured memory_bytes: 82440
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
tmp = 1
First = [True]*N
First[tmp-1] = False
i = 0
mem = 0
while i < K:
    i += 1
    tmp = A[tmp-1]
    if not First[tmp-1]:
        mem = tmp
        break
    First[tmp-1] = False
count = 0
while i < K:
    i += 1
    count += 1
    tmp = A[tmp-1]
    if tmp == mem:
        break
K -= i
if K > 0:
    K %= count
for i in range(K):
    tmp = A[tmp-1]
print(tmp)

Measured memory_bytes: 32372
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;

    int D;
    cin >> D;

    //D*2+1見れるからi=N/(D*2+1)と、if(N%(D*2+1)==0){i+=}

    int i = N/(D*2+1);

    if(N%(D*2+1)!=0){
        i++;
    }

    cout << i << endl;
}

Measured memory_bytes: 256
def makeLunLun(num):
  lunlunNums = []
  m = num % 10 -1
  z = m + 1
  p = m + 2
  if m >= 0:
    lunlunNums.append(num * 10 + m)
  lunlunNums.append(num * 10 + z)
  if p <= 9:
    lunlunNums.append(num * 10 + p)
  return lunlunNums

K=int(input())

queue = [1,2,3,4,5,6,7,8,9]
i=0
while K > len(queue):
  lunluns = makeLunLun(queue[i])
  queue += lunluns
  i += 1
print(queue[K-1])

Measured memory_bytes: 7320
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/
ll n,x;
using data=tuple<ll,ll,ll>;
ll v(data d){
	ll b,l,u;
	tie(b,l,u)=d;
	return l*b+u*(x-b); //lがB個、uがx-b個
}

ll getval(data d, ll h){
	ll b,l,u;
	tie(b,l,u)=d;
	return l*min(b,h)+u*max(h-b,0);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>n>>x;
	vector<data> a;
	rep(i,n){
		ll q,w,e;
		cin>>q>>w>>e;
		a.emplace_back(q,w,e);
	}
	sort(all(a),[](data p,data q){return v(p)>v(q);}); // 寄与量降順

	ll init=0;
	rep(i,n){
		ll b,l,u;
		tie(b,l,u)=a[i];
		init-=l*(b);
	}


	ll ok=n*x,ng=-1;
	while(abs(ok-ng)>1){
		ll mid=(ok+ng)/2;
		ll val=init,cur=mid;
		ll q=cur/x,r=cur%x;
		
		rep(i,q){
			val+=getval(a[i],x);
		}

		ll ans=val;
		if(r){
			rep(i,n){
				ll res=val;
				res+=getval(a[i],r);
				if(i<q){
					res+=getval(a[q],x);
					res-=getval(a[i],x);
				}
				chmax(ans,res);
			}
		}
		if(ans>=0)ok=mid;
		else ng=mid;
	}
	puta(ok);
	return 0;
}


Measured memory_bytes: 4596
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); ++i)
#define REP(i,start,end) for(int i=(start);i<=(end);++i)
#define all(n) begin(n),end(n)

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int a,b,c,d;
	cin >> a >> b >> c >> d;

	int left = a + b;
	int right = c + d;

	if(left > right) cout << "Left\n";
	else if(left == right) cout << "Balanced\n";
	else cout << "Right\n";
	return 0;
}

Measured memory_bytes: 256
n = input()
k = int(input())
n_len = len(n)

dp = [[[0]*(k+2) for _ in range(2)] for _ in range(n_len+1)]
dp[0][False][0] = 1

for i in range(n_len):
    for j in range(k+1):
        # iでTrue、i+1でTrueのとき（i桁目が０でないとき、ｋは減る）
        # かける９の意味は０以外のなんでもいい数ということ
        dp[i+1][True][j+1] += dp[i][True][j]*9
        # iでTrue、i+1でTrueのとき（i桁目が０のとき、ｋは減らない）
        # ０一択なので＊１
        dp[i+1][True][j] += dp[i][True][j]*1

        # i桁目まで等しい状態からi+1桁目で小さくなるとき
        # i⁺1桁目が０だったら小さくなりようがないので考えない
        # i+1桁目が０のときはもう一つ下の場合分けに入っている
        if int(n[i]) != 0:
            dp[i+1][True][j+1] += dp[i][False][j]*(int(n[i])-1)
            dp[i+1][True][j] += dp[i][False][j]
            

        # i桁目まで等しい状態からi+1桁目も等しい状態のとき
        if int(n[i]) != 0:
            dp[i+1][False][j+1] = dp[i][False][j]
        else:
            dp[i+1][False][j] = dp[i][False][j]

print(dp[-1][False][k] + dp[-1][True][k])

Measured memory_bytes: 38384
#include"bits/stdc++.h"
using namespace std;

#define ll long long int
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define sz(a) int((a).size())
#define mod 1000000007
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
template <typename T>
inline T gcd(T a, T b)
{
    while (b != 0) swap(b, a %= b);
    return a;
}

template <typename T>
inline void seethis(vector<T>vect)
{
    for(T x : vect)
        cout << x << " ";
    cout << "\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
//LCM
int lcm(int a, int b)
{
    return a * (b / gcd(a, b));
}

//For sort by second
bool cmp(const pair<int, int> &a)
{
    return a.first < a.second;
}

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a, ll b, ll c)
{
    ll res = 1;
    while(b)
    {
        if(b & 1LL)
            res = (res * a) % c;
        a = (a * a) % c;
        b >>= 1;
    }
    return res;
}

int main()
{
    FASTIO;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin >> n;

    vector<ll>vect(n + 1);
    vector<ll>cum_sum(n+1,0);
    f(i, 1, n + 1)
    {
        cin >> vect[i];
        cum_sum[i]= vect[i]+cum_sum[i-1];
    }

    ll dp[n + 1][n + 1];
    memset(dp, 0, sizeof dp);


    for(int i = 2; i <= n; i++)
    {
      int start=1;
      int end=i;

      while(end<=n)
      {
        ll res=inf;

        for(int pivot=start;pivot<end;pivot++)
        {
          res=min(res,dp[start][pivot] + dp[pivot+1][end] + cum_sum[pivot]-cum_sum[start-1] + cum_sum[end]-cum_sum[pivot]);
        }
        dp[start][end]=res;

        start++;
        end++;
      }
    }


    // for(int i=1;i<=n;i++)
    // {
    //   for(int j=1;j<=n;j++)
    //     cout<<dp[i][j]<<" ";
    //   cout<<"\n";
    // }


    cout<<dp[1][n]<<"\n";

    return 0;
}

Measured memory_bytes: 4820
#include<stdio.h>
int main()
{
	int a[2], k;
	int t;
	scanf("%d%d%d", &a[0], &a[1], &k);
	for (int i = 0; i < k; i++)
	{
		a[i % 2] /= 2;
		a[(i + 1) % 2] += a[i % 2];
	}
	printf("%d %d", a[0], a[1]);
	return 0;
}

Measured memory_bytes: 128
/*     *******************Bismillahir Rahmanir Rahim************************
                          MD. ASFAKUL GHANI!
                          *ProMAGFAT*!
 SECRET_warning :)->FAT   CSE-25!
                          JAHANGIRNAGAR UNIVERSITY!
                          Dhaka,Bangladesh!
*/

#include <bits/stdc++.h>
#include <set>
using namespace std;

#define           fasterIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#define           Im int main()
#define           ll long long
#define           sc scanf
#define           pf printf
#define           rn0 return 0
#define           rn return
#define           f0(i,n) for(ll i=0;i<n;i++)
#define           f1(i,n) for(ll i=1;i<=n;i++)
#define           f2(i,n) for(ll i=n-1;i>=0;i--)
#define           pi 2*acos(0.0)
#define           modulo 1000003
#define           dd double
#define           PI 3.14159265358979
#define           pi 2*acos(0.0)
#define           p_b push_back
#define           ps push

/*
ll for_binarySearch(ll a,ll b,ll aa[],ll x){while(a<=b){ll mid=(a+b)/2;if(aa[mid]==x) return 1;else if(aa[mid] > x) b=mid-1;else a=mid+1;}return -1;}
ll for_gcd(ll a,ll b){if(a==0) return b;else return for_gcd(b%a,a);}
ll for_prime(ll x){for (ll i=2;i*i<=x;i++){if(x%i==0) return 0;}return 1;}
void for_swap(char *x,char *y){char temp;temp=*x;*x=*y;*y=temp;}
ll for_big_mod(ll b,ll p,ll m){if(p==0) return 1;else if(p%2==0){ll k=for_big_mod(b,p/2,m);return (k*k)%m;}else return ((b%m)*(for_big_mod(b,p-1,m)))%m;}
ll for_josephus(ll n,ll k){if(n==1) return 1;return (for_josephus(n-1,k)+k-1)%n+1;}
ll for_gcdExtended(ll a,ll b,ll *x,ll *y){if(a==0){*x=0;*y=1;return b;}ll x1,y1;ll gcd=for_gcdExtended(b%a,a,&x1,&y1);*x=y1-(b/a)*x1;*y=x1;return gcd;}
*/

void debug1()
{
    cout << "***" << endl;
}

void debug11(ll n)
{
    cout << n << endl;
}

#define ipair pair <ll,ll>
#define inf 12345678912345
ll n,m,p;
vector <ipair> v1[101010];
vector <ll> dis;

void FAT_dj(ll src)
{
    priority_queue <ipair, vector<ipair>, greater<ipair> > pq;
    pq.ps(make_pair(0,src));
    dis[src] = 0;
    while (!pq.empty()){
        ll u = pq.top().second;
        pq.pop();

        vector <ipair> ::iterator it;
        for (it = v1[u].begin(); it != v1[u].end(); it += 1){
            ll v = (*it).first;
            ll w = (*it).second;
            if (dis[v] > dis[u] + w){
                dis[v] = dis[u] + w;
                pq.ps(make_pair(dis[v],v));
            }
        }
    }
}

Im
{
    /*#ifdef FAT
       freopen("input.txt","w",stdin);
    #endif // FAT*/

    //fasterIO;

    cin>>n>>m>>p;

    for (ll i = 0; i < m; i += 1){
        ll u,v,w;
        cin>>u>>v>>w;
        v1[u].p_b(make_pair(v,w));
        //v1[v].p_b(make_pair(u,w));
    }

    for (ll i = 0; i <= n; i += 1) dis.p_b(inf);

    FAT_dj(p);

    for (ll i = 0; i < n; i += 1){
        if (dis[i] == inf) cout << "INF" << endl;
        else cout << dis[i] << endl;
    }

    for (ll i = 0; i < n; i += 1) v1[i].clear();

   // main();

    rn0;
}

Measured memory_bytes: 19488
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string str;
    int n,t,i,j;
    cin>>str;
    bool flag=true;
    for(i=0,j=str.size()-1; i<j; i++,j--)
    {
        if(str[i]!=str[j])
        {
            flag=false;
            break;
        }
    }
    if(flag)
    {
        int l=str.size();
        flag=true;
        for(i=0,j=(l-1)/2-1; i<j; i++,j--)
        {
            if(str[i]!=str[j])
            {
                flag=false;
                break;
            }
        }
        if(flag)
        {
            flag=true;
            for(i=(l+3)/2-1,j=l-1; i<j; i++,j--)
            {
                if(str[i]!=str[j])
                {
                    flag=false;
                    break;
                }
            }
            if(flag)
            {
                cout<<"Yes"<<endl;
            }
            else
            {
                cout<<"No"<<endl;
            }
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
N = int(input())
keta = len(str(N))
cnt = 0

if (keta % 2 == 0):
    cnt += 9
    keta -= 1
    
    while (keta > 1):
        cnt += 9 * 10 ** (keta - 1)
        keta -= 2

else:
    cnt += N - 10 ** (keta - 1) + 1
    keta -= 2
    
    while (keta > 0):
        cnt += 9 * 10 ** (keta - 1)
        keta -= 2

print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<cctype>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cctype>
#include<cstring>
#include<utility>
#include<cmath>
#include <string>
using namespace std;


int main() {
    string S, T;
    bool flag = false;
    cin >> S >> T;

    if (S.length() >= T.length()) {
        for (int i = S.length() - T.length(); i >= 0; i--) {
            string tmp = S.substr(i, T.length());
            int tmp_flag = 0;
            for (int j = 0; j < T.length(); j++) {
                if (tmp[j] == T[j]) {
                    tmp_flag++;
                }
                else if (tmp[j] == '?') {
                    tmp_flag++;
                }
            }
            if (tmp_flag == T.length()) {
                flag = true;
                S.replace(i, T.length(), T);
                break;
            }
        }
    }

    for (int i = 0; i < S.length(); i++) {
        if (S[i] == '?') S[i] = 'a';
    }

    if (flag) cout << S << endl;
    else cout << "UNRESTORABLE" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;++i)

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

vector<vector<int>> node;
vector<bool> searched;
vector<int> cost;

void solve(int index){
    cost[index]=0;
    queue<int> que; que.push(index);
    REP(i,(int)node[index].size())
    while(!que.empty()){
        int order = que.front(); que.pop();
        REP(i,(int)node[order].size()){
            if(cost[node[order][i]]==-1){
                cost[node[order][i]]=cost[order]+1;
                que.push(node[order][i]);
            }
        }
    }
}

int main(){
   int n; cin>>n;
   node.resize(n);
   cost.resize(n,-1);
   REP(i,n){
    int index,size; cin >> index >> size; index--;
    node[index].resize(size);
     REP(j,size){cin >> node[index][j];node[index][j]--;}
    sort(node[index].begin(),node[index].end());
   }
   solve(0);
   REP(i,n)
    cout<<i+1<<" "<<cost[i]<<endl;
}


Measured memory_bytes: 3084
#include "bits/stdc++.h"

using namespace std;

long long dfs(string prev, long long accum, int curr, const string& S) {
    if (curr == S.size()) {
        if (prev == "") {
            return accum;
        }
        else {
            return accum + atoll(prev.c_str());
        }
    }

    long long ret = 0LL;
    if (prev == "") {
        ret += dfs(S.substr(curr, 1), accum, curr + 1, S);
    }
    else {
        ret += dfs(S.substr(curr, 1), accum + atoll(prev.c_str()), curr + 1, S);
        ret += dfs(prev + S.substr(curr, 1), accum, curr + 1, S);
    }
    return ret;
}

void Main() {
    string S;
    cin >> S;

    long long ans = dfs("", 0LL, 0, S);
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
using namespace std;

#define INF 1e9+7
#define mp make_pair
#define pii pair<int,int>
#define st first
#define nd second
#define pb push_back

typedef long long int lint;
typedef unsigned long long int ulint;


int main()
{
    int n;
    cin >> n;

    int arr[n+10];
    int dp[n+10];

    for (int i=1; i<n+1; i++)
        cin >> arr[i];

    dp[1] = 0;
    dp[2] = abs(arr[2] - arr[1]);

    for (int i=3; i<n+1; i++)
    {
        dp[i] = min(dp[i-1] + abs(arr[i] - arr[i-1]), dp[i-2] + abs(arr[i] - arr[i-2]));
    }

    cout << dp[n];

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<math.h>

using namespace std;

const int sz = 1e5 + 13;
const int logsz = 17;

int n;

int p[sz][logsz];
int t[sz], level[sz];

vector<vector<int> > g (sz);

void dfs(int u, int parent){
    for(auto v: g[u]){
        if(v != parent){
            level[v] = level[u] + 1;
            t[v] = u;
            dfs(v, u);
        }
    }
}

void preprocess(){
    dfs(0, -1);
    for(int i = 0; i < n; ++i)
        for(int j = 0; (1<<j) < n; ++j)
            p[i][j] = -1;
    for(int i = 0; i < n; ++i)
        p[i][0] = t[i];
    for(int j = 1; (1<<j) < n; ++j)
        for(int i = 0; i < n; ++i) if(p[i][j-1] != -1)
            p[i][j] = p[p[i][j-1]][j-1];
}

int lca(int u, int v){
    if(level[u] < level[v]){u ^= v; v ^= u; u ^= v;}
    int log;
    for(log = 1; (1<<log) < level[u]; ++log);
    log--;
    for(int i = log; i >= 0; --i)
        if(level[u]  - (1<< i) >= level[v])
            u = p[u][i];
    if(u == v)
        return u;
    for(int i = log; i>= 0; --i)
        if(p[u][i] != -1 && p[u][i] != p[v][i]){
            u = p[u][i]; v = p[v][i];
        }
    return t[u];
}


int main(){
    cin>>n;
    for(int i = 0; i < n; ++i){
        int k;
        cin>>k;
        for(int j = 0; j < k; ++j){
            int x;
            cin>>x;
            g[i].push_back(x);
            g[x].push_back(i);
        }
    }
    preprocess();
    int q;
    cin>>q;
    for(int i = 0; i < q; ++i){
        int u,v;
        cin>>u>>v;
        cout<<lca(u,v)<<"\n";
    }
}

Measured memory_bytes: 20480
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
#include <numeric>
#include <sstream>
#include <queue>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl
#define printV(v) for(int zxc=0;zxc<v.size()-1;zxc++){cout << v[zxc] << " ";} cout << v.back() << endl;


int main () {
    int k, t;
    cin >> k >> t;
    vector<int> a;
    PUSH(t,a);
    
    sort(ALL(a));
    
    int ma = a.back();
    
    REP(i,a.size()-1) {
        ma -= a[i];
    }
    
    cout << max(ma - 1, 0) << endl;
}
/*

int main() {
    int MOD = 1e9 + 7;
    int n;
    cin >> n;
    vector<int> T, A;
    int z;
    REP(i,n) {
        cin >> z;
        T.push_back(z);
    }
    REP(i,n) {
        cin >> z;
        A.push_back(z);
    }
    
    bool aa = false;
    if (T.back() != A.front()) aa = true;
    
    REP(i,n/2) {
        if (T[i] > A[i]) aa = true;
        if (A[n-1-i] > T[n-1-i]) aa = true;
    }
    if (aa) {
        cout << 0 << endl;
        return 0;
    }
    
    
    long ans = 1;
    vector<int> S = vector<int>(n,1);
    vector<int> W = vector<int>(n,1);
    
    vector<int> FIX = vector<int>(n,-1);
    
    FOR(i,1,n) {
        if (T[i] > T[i-1]) {
            
        }else {
            S[i] = T[i];
        }
        
        if (A[n-i] < A[n-i-1]) {
            
        }else {
            W[n-i-1] = A[n-i-1];
        }
    }
    
    REP(i,n) {
        if (S[i] == 1) {
            FIX[i] = T[i];
        }
    }
    REP(i,n) {
        if (W[i] == 1) {
            if (FIX[i] != -1 && A[i] != FIX[i]) {
                aa = true;
            }else {
                FIX[i] = A[i];
            }
        }
    }
    
    REP(i,n) {
        if (FIX[i] != -1) {
            if (A[i] < FIX[i] || T[i] < FIX[i]) aa = true;
        }
    }
    
    if (aa) {
        cout << 0 << endl;
        return 0;
    }
    
    
    
    REP(i,n) {
        ans *= (long)(min(S[i], W[i]));
        ans %= MOD;
    }
    cout << ans << endl;
    

    
    return 0;
}*/


Measured memory_bytes: 256
#include <iostream>
using namespace std;

int main(void) {
    int n, q;
    char name[100000][10];
    long int time[100000];
    int address[100000][2];
    int back = 0;
    int front = 1;
    int index;
    int check;
    long int time_sum;
    
    cin >> n >> q;
    for(int i = 0; i < n; ++i) {
        cin >> name[i] >> time[i];
        address[i][back] = i - 1;
        address[i][front] = i + 1;
    }
    address[0][back] = n - 1;
    address[n - 1][front] = 0;
    
    time_sum = 0;
    check = 0;
    index = 0;
    while(check != n) {
        if(time[index] - q <= 0) {
            time_sum += time[index];
            cout << name[index] << ' ' << time_sum << endl;
            address[address[index][back]][front] = address[index][front];
            address[address[index][front]][back] = address[index][back];
            index = address[index][front];
            ++check;
        } else {
            time[index] -= q;
            time_sum += q;
            index = address[index][front];
        }
    }
    return 0;
}




Measured memory_bytes: 4364
sx,sy,tx,ty=map(int,input().split())

x=tx-sx
y=ty-sy

r="R"
d="D"
u="U"
l="L"


ans=""

ans+=(r*abs(x))
ans+=(u*abs(y))
ans+=(l*abs(x))
ans+=(d*abs(y))
ans+=(d)
ans+=(r*abs(x+1))
ans+=(u*abs(y+1))
ans+=(l)
ans+=(u)
ans+=(l*abs(x+1))
ans+=(d*abs(y+1))
ans+=(r)


print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
	int n, m;
	cin >> n >> m;
	vector<vector<int>> sw(n);
	rep(i, m) {
		int k;
		cin >> k;
		rep(j, k) {
			int s;
			cin >> s;
			sw[s - 1].push_back(i);
		}
	}
	vector<int> p(m);
	rep(i, m) cin >> p[i];
	int ans = 0;
	rep(bit, 1 << n) {
		vector<int> cnt(m);
		rep(i, n) {
			if (bit & (1 << i)) {
				for (auto a : sw[i]) cnt[a]++;
			}
		}
		bool ok = true;
		rep(i, m) if (cnt[i] % 2 != p[i]) ok = false;
		if (ok) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<string>
using namespace std;

int main()
{
  string s, t;  cin >> s >> t;
  int s_len = s.length();
  int t_len = t.length();
  int ans = t_len;

  for(int i=0; i<=s_len - t_len; ++i)
  {
    int cnt = 0;
    for(int j=0; j<t_len; ++j)
    {
      if(s[i+j] == t[j])
      {
        ++cnt;
      }
    }
    ans = min(ans, t_len-cnt);
  }

  cout << ans << endl;
}


Measured memory_bytes: 3620
FAST_IO = 0
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())

####

def solve(X):
    # A**5 - B**5 = X
    # (A-B)(A**4 + ... )
    for bb in xrange(1000):
        for b in (-bb, bb):
            target = X + b ** 5
            sign = 1 if target >= 0 else -1
            target = abs(target)
            a = int(target**0.2)
            if a ** 5 == target:
                return a * sign, b
            if (a+1)**5 == target:
                return a * sign, b
    
print "{} {}".format(*solve(rri()))


Measured memory_bytes: 65028
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	public static void main(String[] args) {
		int N=sc.nextInt();
		
		int v[]=new int[100001];
		
		for(int i=0;i<N;i++) {
			int a=sc.nextInt();
			v[a]++;
			v[a+1]++;
			if(a!=0)v[a-1]++;
		}
	int ans=0;
	
	for(int i:v) {
		ans=Math.max(ans, i);
	}
		p(ans);
		
		
		
	}
	
	
	
	
	/*static boolean v(int i,long sum1,long sum2) {
		if(i==N) {
			long b=Math.abs(sum1-sum2);
			if(b==0) {
				if(sum1<=K) {
					return true;
				}else return false;
			}else if(b%D==0) {
				if(Math.max(sum1, sum2)<=K)return true;
				else return false;
			}
			else return false;
		}
		
		if(v(i+1,sum1,sum2+v[i]%D))return true;
		
		if(v(i+1,sum1+D-v[i]%D,sum2))return true;
		return false;
		
	}*/
	
	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 49016
//bismillahir rahmanir rahim            //Author:Fayed Anik
 
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
//using namespace __gnu_pbds;
 
//#define         ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define         ll                          long  long
#define         lf                          double
#define         pb(x)                       push_back(x)
#define         ull                         unsigned long long
#define         sfl(a)                      scanf("%lld",&a)
#define         sf(a)                       scanf("%d",&a)
#define         pf(a)                       printf("%d\n",a)
#define         pfl(a)                      printf("%lld\n",a)
#define         FOR(x,n)                    for(ll x=1;x<=n;++x)
#define         pii                         pair< ll , ll >
#define         mp(a,b)                     make_pair(a,b)
#define         UNIQUE(v)                   v.resize(distance(v.begin(),unique(v.begin(),v.end())))
#define         mod                         1000000007
#define         INF                         2e18
#define         EPS                         1e-15
#define         f1                          first
#define         f2                          second
#define         all(v)                      v.begin(),v.end()
#define         PI                          acos(-1)
#define         printminusone               printf("-1\n")
#define         bug                         printf("bug")
#define         FILEIN                      freopen("in.txt","r",stdin)
#define         FILEOUT                     freopen("out.txt","w",stdout)
 
//ll SET(ll mask,ll pos){ return mask = (mask | (1ll<<pos)); }
//ll RESET(ll mask,ll pos){ return mask = mask & ~(1ll<<pos); }
//bool CHECK(ll mask,ll pos) { return (bool) (mask & (1ll<<pos)); }
//priority_queue <ll, vector<ll>, greater<ll> > pq;
//int dx[]={0,0,1,-1,1,1,-1,-1};
//int dy[]={1,-1,0,0,1,-1,1,-1};

#define lim 10005

ll a[lim];
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,k;
    sfl(n),sfl(k);
    for(ll i=1;i<=n;i++){
        sfl(a[i]);
    }
    sort(a+1,a+n+1);
    ll sum=0;
    for(ll i=1;i<=k;i++){
        sum += a[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define modulo 1000000007
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int n;
int a[21][21];
ll dp[1<<21];
ll find(int mask){
	int idx=__builtin_popcount(mask);
	if(idx==n)
		return 1;
	if(dp[mask]!=-1)
		return dp[mask];
	ll ans=0;
	for (int i = 0; i < n; ++i){
		if(a[idx][i] && (!(mask & (1<<i))))
			ans=(ans+find(mask|(1<<i)))%modulo;
	}
	dp[mask]=ans;
	return ans;
}
int main(){
	fast_io;
	cin>>n;
	for (int i = 0; i < n; ++i){
		for (int j = 0; j < n; ++j){
			cin>>a[i][j];
		}
	}
	memset(dp,-1,sizeof(dp));
	cout<<find(0)<<"\n";
	return 0;
}

Measured memory_bytes: 20020
#include <bits/stdc++.h>
#include <stdio.h>

#define ll long long
#define int ll
#define pii pair<int, int>
#define pb push_back
#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define FORD(i, a, b) for (int i=a; i>=b; i--)
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

using namespace std;

void solve() {
    int N, K, Q;
    cin >> N >> K >> Q;

    vector<int> M(N);
    REP(i, N) M.at(i) = K-Q;

    vector<int> A(Q);

    REP(i, Q) cin >> A.at(i);

    REP(i, Q) {
        M[A.at(i)-1] += 1;
    }

    REP(i, N) {
        if (M.at(i) <= 0) print("No");
        else print("Yes");
    }

}

signed main() {
    solve();
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    string S,T;
    cin >> S >> T;
    int A,B;
    cin >> A >> B;
    string U;
    cin >> U;
    if (S == U) cout << A - 1 << " " << B << endl;
    else cout << A << " " << B - 1 << endl;
}



Measured memory_bytes: 3576
n,m = gets.split.map(&:to_i)
ks = []
ss = []

m.times do |i|
  ks << gets.split.map(&:to_i) 
  ks[i].shift
  ss += ks[i]
end
ss.sort!.uniq!
p = gets.split.map(&:to_i) 

f = ['on', 'off']
ans = 0
f.repeated_permutation(n).to_a.each do |i|
  flag = true
  ks.each_with_index do |v,l|
    kkk = 0
    v.each do |b|
      if i[b-1] == 'on'
        kkk += 1
      end
    end
    if p[l] != kkk%2
      flag = false
      break
    end
  end

  if flag
    ans += 1
  end
end

puts ans


Measured memory_bytes: 2172
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    string s, t;
    scan(s);
    scan(t);
    auto n = s.length;

    bool ok;

    foreach (i ; 0 .. n) {
        auto sr = s[i .. $] ~ s[0 .. i];
        if (sr == t) ok = true;
    }

    writeln(ok ? "Yes" : "No");
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

struct UnionFind{
	vi data;
	UnionFind(int n):data(n,-1){}
	int Find(int i){
		return data[i]<0?i:(data[i]=Find(data[i]));
	}
	bool Unite(int a,int b){
		a=Find(a),b=Find(b);
		if(a==b) return false;
		if(-data[a]<-data[b]) swap(a,b);
		data[a]+=data[b];
		data[b]=a;
		return true;
	}
	int Size(int i){
		return -data[Find(i)];
	}
};

struct Edge{
	int src,dst,weight;
	Edge(){}
	Edge(int s,int d,int w):src(s),dst(d),weight(w){}
};
typedef vector<vector<Edge>> Graph;
bool operator<(const Edge& a,const Edge& b){return a.weight<b.weight;}
bool operator>(const Edge& a,const Edge& b){return a.weight>b.weight;}

int Kruskal(const Graph& g,vector<Edge>& forest)
{
	int n=g.size();
	vector<Edge> es;
	rep(i,n) es.insert(end(es),all(g[i]));
	sort(all(es));
	
	UnionFind uf(n);
	int res=0;
	for(auto e:es)
		if(uf.Unite(e.src,e.dst)){
			res+=e.weight;
			forest.push_back(e);
		}
	return res;
}

int main()
{
	for(int n,m;cin>>n>>m && n|m;){
		Graph g(n);
		rep(i,m){
			int u,v,w; cin>>u>>v>>w;
			g[u].emplace_back(u,v,w);
			g[v].emplace_back(v,u,w);
		}
		vector<Edge> forest;
		cout<<Kruskal(g,forest)<<endl;
	}
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;

long long lcm(long long a, long long b){
  if(a<b) swap(a,b);
  long long ab = a*b;
  long long r = a%b;
  while(r!=0){
    a = b;
    b = r;
    r = a%b;
  }
  return ab/b;
}

long long x2(long long x){
  long long res=0;
  while(x%2==0){
    res++;
    x /= 2;
  }
  return res;
}

int main() {
  long long N,M;
  cin >> N >> M;
  vector<long long> A(N);
  for(int i=0;i<N;i++) cin >> A[i];
  
  long long L=1;
  long long X = x2(A[0]);
  for(int i=0;i<N;i++){
    if(A[i]%2==1 || x2(A[i])!=X){
      cout << 0 << endl;
      return 0;
    }
    A[i] /= 2;
    L = lcm(A[i],L);
  }
  
  cout << ((M/L)+1)/2 << endl;
  return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int> > a(n);
    for(int i=0; i<n; ++i){
        cin >> a[i].first;
        a[i].second = -i;
    }
    sort(a.rbegin(), a.rend());

    int prev = a[0].first;
    int front = -a[0].second;
    vector<long long> ans(n, 0);
    for(int i=1; i<n; ++i){
        int curr = a[i].first;
        ans[front] += (prev - curr) * (long long)i;
        prev = curr;
        front = min(front, -a[i].second);
    }
    ans[front] += prev * (long long)n;

    for(int i=0; i<n; ++i)
        cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <cstdlib>
#include <fstream>
#include <set>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long ll;

#define forn(i, n) for(int i = 0; i < (int)(n);++i)
#define fore(i, a, b) for(int i = (int)(a); i <= (int)(b); ++i)
#define fi first
#define se second
#define pb push_back
#define pll pair<ll,ll>
#define vi vector<int>
#define vb vector<bool>
#define vvi vector<vi>
#define vpll vector<pll>
#define vll vector<ll>
#define vvll vector<vll>
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()


void fastik() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
}

//ifstream &cin
void solve(){

}

bool cmp(pair<pair<string,ll>,ll> a, pair<pair<string,ll>,ll> b){
    if(a.fi.fi == b.fi.fi){
        return a.fi.se > b.fi.se;
    }
    return a.fi.fi < b.fi.fi;
}

int main() {
    fastik();
    //ifstream cin("input.txt");
    /*ll t = 1;
    cin >> t;
    while(t--){
       solve();
    }*/
    ll n; cin>>n;
    vector<pair<pair<string,ll>,ll>>  s(n);
    forn(i,n){
        cin >> s[i].fi.fi >> s[i].fi.se;
        s[i].se = i+1;
    }
    sort(all(s),cmp);
    for(auto i: s){
        cout << i.se << "\n";
    }
}

Measured memory_bytes: 256
from collections import deque
h, w = map(int, input().split())
s = []
for i in range(h):
	t = input()
	s.append(t)

res = 0
dx = [1,0,-1,0]
dy = [0,1,0,-1]
for i in range(h):
	for j in range(w):
		if s[i][j] == "#":
			continue
		queue = deque([[i,j]])
		visited = [[-1 for ii in range(w)] for jj in range(h)]
		visited[i][j] = 0
		while queue:
			l,m = queue.popleft()
			for k in range(4):
				x = l + dx[k]
				y = m + dy[k]
				if x < 0 or y < 0 or x >= h or y >= w or visited[x][y] != -1 or s[x][y] == "#":
					continue
				visited[x][y] = visited[l][m] + 1
				queue.append([x,y])
		for ii in range(h):
			for jj in range(w):
				res = max(res,visited[ii][jj])
print (res)

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.nextLine();
		if(s.length() < 3 || s.length() > 100)
			return;
		String[] out_s = s.split("");
		System.out.print(out_s[0] + (out_s.length - 2) + out_s[out_s.length-1]);
		

		System.out.println("");

	}

}

Measured memory_bytes: 21844
import math
def comb(n,r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N,M = map(int,input().split())
count = 0
if N <= 1:
    a = 0
else:
    a = comb(N,2)

if M <= 1:
    b = 0
else:
    b = comb(M,2)
print(a+b)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
const int MOD = ((int)1e9)+7;
const int INF = (int)(1e9)+(int)(1e7);
const ll INFL = (ll)(1e18)+INF;
const double EPS = 1e-8;
using namespace std;
int main()
{
    int N,R;
    cin >> N >> R;
    if(N>=10){
        cout << R << endl;
    }
    else{
        cout << R+100*(10-N) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
class Node
  attr_accessor :key, :left, :right
  def initialize key
    @key = key
  end
 
  def inorder
    left.inorder if left
    print " ", key
    right.inorder if right
  end
 
  def preorder
    print " ", key
    left.preorder if left
    right.preorder if right
  end
end
 
def insert
  z = Node.new $key.to_i
  x = $root
  while x
    y = x
    x = z.key < x.key ? x.left : x.right
  end
 
  unless y
    $root  = z
  else
    z.key < y.key ? y.left = z : y.right = z
  end
end
 
n = gets.to_i
n.times do
  command, $key = gets.split
  if command == "insert"
    insert
  else
    $root.inorder
    puts
    $root.preorder
    puts
  end
end

Measured memory_bytes: 47868
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    s = input()
    if s == "ABC":
        print("ARC")
    else:
        print("ABC")


if __name__ == '__main__':
    main()


Measured memory_bytes: 8976
#include <iostream>
#include <string>
using namespace std;
 
main() {
  string S,Ans;
  cin >> S;
  Ans ="AC";
  if (S[0] != 'A')
    Ans ="WA";
    int cnt=0;
  for(int i=1; i<S.size(); i++){
    if(isupper(S[i])){
      if( i==1 || S[i] != 'C' || i==S.size()-1 )
        Ans ="WA";
      if( S[i] =='C' && i != 1 && i != S.size()-1 )
        cnt++;
    }
  }
  if( cnt != 1)
    Ans= "WA";
  cout << Ans ;
  return 0; 
}       

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

#define range(i, f, t) for (int i = (f); i < (t); ++i)
#define rep(i, n) range(i, 0, n)

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v)
{
  out << "vector(" << v.size() << ") [";
  if (v.size() > 0)
  {
    rep(i, v.size()) out << v[i] << ", ";
    out << "\b\b]";
  }
  else
  {
    out << "]";
  }
  return out;
}

template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
  out << '(' << p.first << ", " << p.second << ")";
  return out;
}

const double RATIO = 380000.0;

void solve()
{
  int N;
  cin >> N;
  double answer = 0.0;
  rep(i, N)
  {
    string value, type;
    cin >> value >> type;
    if (type[0] == 'J')
    {
      answer += stoi(value);
    }
    else
    {
      answer += stod(value) * RATIO;
    }
  }

  cout << answer << endl;
}

int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  solve();

  return 0;
}


Measured memory_bytes: 256
A11, A12, A13 = map(int, input().split())
A21, A22, A23 = map(int, input().split())
A31, A32, A33 = map(int, input().split())
N = int(input())
bj = [int(input()) for i in range(N)]

result = []
result.append([A11, A12, A13])
result.append([A13, A23, A33])
result.append([A33, A32, A31])
result.append([A31, A21, A11])
result.append([A12, A22, A32])
result.append([A21, A22, A23])
result.append([A11, A22, A33])
result.append([A31, A22, A13])

flg = 'No'
for cmb in result:
	count = 0
	for i in bj:
		if i in cmb:
			count += 1
	if count == 3:
		flg = 'Yes'
print(flg)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    int n,m;
    cin >> n >> m;
    ll ans=0,cnt = n;
    map<ll,ll> mp;
    for(int i = 0;i < n;i ++){
        ll a;
        cin >> a;
        mp[a] ++;
    }
    for(int i = 0;i < m;i ++){
        ll b,c;
        cin >> b >> c;
        mp[c] += b;
    }
    for(auto ite = mp.rbegin();ite != mp.rend();++ite){
        ans += ite->first * min(ite->second,cnt);
        cnt -= ite->second;
        if(cnt<=0) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12800
ngs4 = ["ATGC", "AGTC","ACGC", "AGCC","AGGC", "AGGC"]
ngs3 = ["AGC", "ACG", "GAC"]
def is_valid(b):
    s = b[-4:]
    if s in ngs4:
        return False
    s = s[-3:]
    if s in ngs3:
        return False
    return True

N = int(input())
memo = [{} for i in range(N+1)]
acgt = ["A", "C", "G", "T"]
MOD = 10**9 + 7
def dp(i, last3):
    if last3 in memo[i]:
        return memo[i][last3]

    if i == N:
        return 1
    
    ret = 0
    for c in acgt:
        candi = last3 + c
        if is_valid(candi):
            ret = (ret + dp(i+1, last3[1:] +c)) % MOD
    memo[i][last3] = ret
    return ret

def sub():
    print(dp(0, "TTT"))

sub()


Measured memory_bytes: 3808