akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

int gcd(int a,int b){
  if(a%b==0){
    return b;
  }else{
    return(gcd(b,a%b));
  }
}
int main(){
  int n;
  string s;
  string alp="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  cin>>n>>s;
  REP(i,s.length()){
    REP(j,26){
      if(s[i]==alp[j]){
        s[i]=alp[j+n];
        break;
      }
    }
  }
  cout<<s<<endl;
}

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

const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


int main(void) {
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin >> n;
    cout << a[n-1] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,s;
	for(a=1;a<=9;a++){
		s=1*a;
		printf("1x%d=%d\n",a,s);
	}
	for(a=1;a<=9;a++){
		s=2*a;
		printf("2x%d=%d\n",a,s);
	}
	for(a=1;a<=9;a++){
		s=3*a;
		printf("3x%d=%d\n",a,s);
	}
	for(a=1;a<=9;a++){
		s=4*a;
		printf("4x%d=%d\n",a,s);
	}
	for(a=1;a<=9;a++){
		s=5*a;
		printf("5x%d=%d\n",a,s);
	}
	for(a=1;a<=9;a++){
		s=6*a;
		printf("6x%d=%d\n",a,s);
	}
	for(a=1;a<=9;a++){
		s=7*a;
		printf("7x%d=%d\n",a,s);
	}
	for(a=1;a<=9;a++){
		s=8*a;
		printf("8x%d=%d\n",a,s);
	}
	for(a=1;a<=9;a++){
		s=9*a;
		printf("9x%d=%d\n",a,s);
	}
	return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<string>
#include<algorithm>

int main(){

    size_t n;
    std::string s, t;
    std::cin >> n >> s >> t;

    if(s == t){
        std::cout << n << std::endl;
    }else if(s.back() == t.front()){
        size_t cnt1 = 0;
        for(size_t i = 0; i < n; i++){
            if(s.at(n - i - 1) == s.back()){
                cnt1++;
            }else{
                break;
            }
        }

        size_t cnt2 = 0;
        for(size_t i = 0; i < n; i++){
            if(t.at(i) == t.front()){
                cnt2++;
            }else{
                break;
            }
        }

        std::cout << 2 * n - std::min(cnt1, cnt2) << std::endl;
    }else{
        size_t min = std::numeric_limits<size_t>::max();
        for(size_t i = 0; i < n; i++){
            auto str = s.substr(0, n - i) + t.substr(i, n);
            if((str.find(s) != std::string::npos) && (str.find(t) != std::string::npos)){
                min = std::min(min, str.size());
            }
        }

        std::cout << min << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
//Bismillahir Rahmanir Rahim
//In the name of Allah the Most Merciful
//Astagfirullahil laji Rabbi Minkulli Jamio
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
int i,j,k;
 main()
 {
     int n,k,x,y;
     cin>>n>>k>>x>>y;
     if(n<k) cout<<n*x<<endl;
     else cout<<k*x+(n-k)*y<<endl;
 }


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

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

const int INF = 1e9;
const int MOD =1e9+7;
const ll LINF = 1e18;

int main(){
    int N;

    cin >> N;

    int sum = 0;
    int Ntmp = N;
    while(N > 0){
        sum += N % 10;
        N /= 10;    
    }

    if(Ntmp % sum){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
S=input()
s=len(S)
a=''
b=''
for i in range(0,(s-1)//2):
    a+=S[i]
for n in range((s+3)//2-1,s):
    b+=S[n]
if a==b:
    A=a[::-1]
    B=b[::-1]
    if A==a and B==b:
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 9060
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<string> vc( N * M );
    for( auto &x : vc )
    {
        cin >> x;
    }
    REP( i, N * M )
    {
        if( vc[ i ] == "snuke" )
        {
            cout << static_cast<char>( i % M + 'A' ) << i / M + 1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
int main(void)
{
	int i,j,k,h,w,cnt1,cnt2;
	char a[101][101];
	cnt1=0;
	cnt2=0;
	cin>>h>>w;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cin>>a[i][j];
		}
	}
	
	for(i=0;i<h;i++){
//		cout<<"-----------"<<endl;
		for(j=0;j<w;j++){
			if(a[i][j]=='.'){
				cnt1=cnt1+1;
//				cout<<cnt1<<' '<<a[i][j]<<endl;
			}
		}
		if(cnt1==w){
			if(i==h){
				h=h-1;
			}
			else{
				for(j=i;j<h;j++){
					for(k=0;k<w;k++){
						swap(a[j][k],a[j+1][k]);
					}
				}
				h=h-1;
//				cout<<cnt1<<' '<<h<<endl;
			}
			i=i-1;
		}
		cnt1=0;
		
	/*	for(j=0;j<h;j++){
			for(k=0;k<w;k++){
				cout<<a[j][k];
			}
			cout<<endl;
		}*/
//		cout<<"-----------"<<endl;
	}
	
//	cout<<"+++++++++++++++++++++++"<<endl;
	
	for(i=0;i<w;i++){
//		cout<<"-----------"<<endl;
		for(j=0;j<h;j++){
			if(a[j][i]=='.'){
				cnt2=cnt2+1;
//				cout<<i<<j<<cnt2<<' '<<a[j][i]<<endl;
			}
		}
		if(cnt2==h){
			if(i==w){
				w=w-1;
			}
			else{
				for(j=i;j<w;j++){
					for(k=0;k<h;k++){
						swap(a[k][j],a[k][j+1]);
					}
				}
				w=w-1;
//				cout<<cnt2<<' '<<w<<endl;
			}
			i=i-1;
		}
		cnt2=0;
		
	/*	for(j=0;j<h;j++){
			for(k=0;k<w;k++){
				cout<<a[j][k];
			}
			cout<<endl;
		}*/
//		cout<<"-----------"<<endl;
	}
	
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cout<<a[i][j];
		}
		cout<<endl;
	}
	
	return 0;
}


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

int main() {
	string s;
	cin >> s;
	int left = 0, right = s.size();
	while (left < right) {
		int mid = (left + right) >> 1;
		bool flag = false;
		for (int base = 0; !flag && base < 2; base++) {
			int low = base;
			int high = mid;
			if ((high ^ low) & 1) {
				high--;
			}
			bool ok = high >= low;
			for (int i = 0; ok && i < s.size(); i++) {
				if (s[i] == '1' || low < 1) {
					low++;
				}
				else {
					low--;
				}
				if (s[i] == '0' || high > mid - 1) {
					high--;
				}
				else {
					high++;
				}
				ok = high >= low;
			}
			flag = ok;
		}
		if (flag) {
			right = mid;
		}
		else {
			left = mid + 1;
		}
	}
	cout << left << endl;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e2 + 5;

int v[MAXN][MAXN];

int cnt[MAXN * MAXN];

void solve(){
	int h, w, n;
	scanf("%d%d%d", &h, &w, &n);
	REPN(i, 1, n){
		scanf("%d", &cnt[i]);
	}
	for(int i = 0, j = 0, ind = 1; ind <= n; ind++){
		for(; cnt[ind] > 0; cnt[ind]--){
			v[i][j] = ind;
			if (i % 2 == 0){
				j++;
				if (j == w){
					j = w - 1;
					i++;
				}
			} else {
				j--;
				if (j == -1){
					j = 0;
					i++;
				}
			}
		}
	}
	REP(i, 0, h){
		REP(j, 0, w){
			printf("%d ", v[i][j]);
		}
		putchar('\n');
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner stdIn=new Scanner(System.in);
		String S=stdIn.next();
		String T=stdIn.next();
		char s[]=new char[S.length()];
		char t[]=new char[T.length()];
		char u[]=new char[S.length()];
		int slen=S.length(),tlen=T.length();
		int z=slen,y=0,x=0,v=slen-1,fin=0;
		while(z>0){
			s[y]=S.charAt(z-1);
			y++;
			z--;
		}z=tlen;y=0;
		while(z>0){
			t[y]=T.charAt(z-1);
			y++;
			z--;
		}z=0;y=0;
		while(z<(slen-tlen)+1){
			while(y<tlen){
				if(s[z+y]!='?'&&s[z+y]!=t[y]){
					fin=1;
					break;
				}
				else
					y++;
			}
			if(fin==0){
				fin=2;
				break;
			}
			fin=0;
			y=0;
			z++;
		}y=0;
		if(fin==2){
			while(x<slen){
				if(x==z)
					while(y<tlen){
						u[v]=t[y];
						y++;v--;x++;
					}
				else{
					if(s[x]=='?')
						u[v]='a';
					else
						u[v]=s[x];
					x++;v--;
				}
			}z=0;
			while(z<slen){
				System.out.print(u[z]);
				z++;
			}
		}
		else
			System.out.println("UNRESTORABLE");
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pii pair <int,int>
#define pll pair <ll,ll>
#define testcase() int t; cin>>t; while(t--)
#define forn(i,n) for(int i=0;i<n;i++)
#define forn1(i,n) for(int i=1;i<=n;i++)
#define vll vector <ll>
#define vi vector <int>
#define all(v) v.begin(),v.end()

ll M = 1e9 + 7;
double pi = acos(-1.0);
ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }
ll gcd(ll a,ll b){if(b>a)return gcd(b,a); if(b==0)return a; return gcd(b,a%b);}

int main() {
	
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int n; cin>>n;
	vll v(n);
	forn(i,n) cin>>v[i];
	sort(all(v));
	reverse(all(v));
	ll sm = v[0]; int id = 1;
	for(int i=2;i<=n-1;i++)
	{
		sm += v[id];
		if(i&1) id++;
	}
	cout<<sm;

	return 0;
}


Measured memory_bytes: 4788
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
/*迷路移動*/const int dx[4]={1,0,-1,0};const int dy[4]={0,1,0,-1};
llfor;//ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n;
 cin>>n;
  
 vector<ll>a;
 ll b;
 rep(i,0,n){
  cin>>b;
  push(a,b);
 }
 sort(all(a));
  
 vector<ll>al1;//初めに大きいほうを持ってくる
 rep(i,0,n){
  if(i==0){
   push(al1,1);
   continue;
  }
  if(i%2==0){
   if(i!=n-1)push(al1,2);
   else push(al1,1);
  }
  else {
   if(i!=n-1)push(al1,-2);
   else push(al1,-1);
  }
 }
 sort(all(al1));
 ll t1=0;
 rep(i,0,n){
  t1+=al1[i]*a[i];
 }
  
 vector<ll>al2;//初めに小さいほうを持ってくる
 rep(i,0,n){
  if(i==0){
   push(al2,-1);
   continue;
  }
  if(i%2==1){
   if(i!=n-1)push(al2,2);
   else push(al2,1);
  }
  else {
   if(i!=n-1)push(al2,-2);
   else push(al2,-1);
  }
 }
 sort(all(al2));
 ll t2=0;
 rep(i,0,n){
  t2+=al2[i]*a[i];
 }  
 ll ans=max(t1,t2);
 pr(ans);
 return 0;}

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

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }
const ll LINF = 1LL << 60;
struct Edge{
  int from, to, fair;
  ll minute;
};

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef pair<ll, pair<int, int> > State ; 

const int CMAX = 50 * 50;
int main() {
  int N, M, S; cin>>N>>M>>S;
  Graph G = vector<Edges>(N);
  REP(i,M) {
    int u, v, a; ll b;  cin>>u>>v>>a>>b;
    u--; v--;
    G[u].push_back((Edge){u, v, a, b});
    G[v].push_back((Edge){v, u, a, b});
  }
  vector<ll> ans(N, LINF), C(N), D(N);
  REP(i,N) cin>>C[i]>>D[i];
  chmin(S, CMAX);
  vector<vector<ll> > closed(N, vector<ll>(CMAX+1, LINF));
  closed[0][S] = 0;
  priority_queue<State, vector<State>, greater<State> > q;
  q.push(make_pair(0, make_pair(0, S)));
  int cnt = 0;
  while(!q.empty()) {
    State s = q.top(); q.pop();
    ll cmin = s.first;
    int cpos = s.second.first;
    ll ccur = s.second.second;
    if(cmin < ans[cpos]) {
      ans[cpos] = cmin;
      cnt++;
      if(cnt >= N) break;
    }
    chmin(ans[cpos], cmin);
    //    cout << cpos << " " << cmin << " " << ccur << endl;
    //    if(ans[cpos] < LINF) continue;
    for(ll c = 1; ; c++) {
      const int npos = cpos;
      ll work = ccur + C[cpos] * c;
      ll nmin = cmin + D[cpos] * c;
      ll ncur = min((ll)CMAX, work);
      if(nmin < closed[npos][ncur]) {
	closed[npos][ncur] = nmin;
	q.push(make_pair(nmin, make_pair(npos, ncur)));
      }
      if(work > CMAX) break;
    }
    REP(i, G[cpos].size()) {
      const int npos = G[cpos][i].to;
      ll nmin = cmin + (ll)G[cpos][i].minute;
      ll work = ccur - (ll)G[cpos][i].fair;
      ll ncur = min((ll)CMAX, work);
      if(ncur >= 0 && nmin < closed[npos][ncur]) {
	  closed[npos][ncur] = nmin;
	  q.push(make_pair(nmin, make_pair(npos, ncur)));
      }
    }
  }
  for(int i = 1; i < N; i++) cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 20212
#include <bits/stdc++.h>
#define mp make_pair
#define sqr(x) (x)*(x)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int maxn=100007;
const ll inf=1<<29;
int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int gcd(int a,int b){
    return b==0?a:gcd(b,a%b);
}
int g[207][207];
int main(){
    int n=read();
    for(int i=1;i<=n;i++)
    for(int k=1;k<=n;k++)
    g[i][k]=gcd(i,k);
    ll sum=0;
    for(int i=1;i<=n;i++)
    for(int k=1;k<=n;k++)
    for(int z=1;z<=n;z++)
    sum+=g[g[i][k]][z];
    cout<<sum;
    return 0;
}

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

void dfs(int n, int &t, vector<vector<int>>& g, vector<int>& d, vector<int>& f, vector<bool>& seen)
{
    t++;
    if (d[n] == 0) d[n] = t;
    seen[n] = true;
    for (int i = 0; i < g[n].size(); i++)
    {
        if (seen[g[n][i]]) continue;
        dfs(g[n][i], t, g, d, f, seen);
    }
    t++;
    f[n] = t;
}

int main()
{
    int n; cin >> n;
    vector<vector<int>> g(n, vector<int>());
    for (int i = 0; i < n; i++)
    {
        int u, k; cin >> u >> k; u--;
        for (int j = 0; j < k; j++)
        {
            int v; cin >> v; v--;
            g[u].push_back(v);
        }
    } 
    vector<int> d(n, 0);
    vector<int> f(n, 0);
    vector<bool> seen(n, false);
    int t = 0;
    for (int i = 0; i < n; i++)
        if (seen[i] == false)
            dfs(i, t, g, d, f, seen);
    for (int i = 0; i < n; i++)
    {
        cout << i + 1 << " " <<  d[i] << " " << f[i] << endl;
    }
}


Measured memory_bytes: 3164
import java.util.*;

// ARC 93-D
// https://beta.atcoder.jp/contests/arc093/tasks/arc093_b

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		String s = in.next();
		
		if (s.equals("zyxwvutsrqponmlkjihgfedcba")) {
			System.out.println(-1);
		} else {
			int[] count = new int[26];
			for (int i = 0; i < s.length(); i++) {
				count[s.charAt(i) - 'a'] += 1;
			}
			
			int index = -1;
			for (int i = 0; i < count.length; i++) {
				if (count[i] == 0) {
					index = i;
					break;
				}
			}
			
			if (index >= 0) {
				System.out.printf("%s%c\n", s, index + 'a');
			} else {
				count = new int[26];
				int stringTill = 0;
				char tailingCharacter = ' ';
				boolean answerFound = false;

				for (int i = s.length() - 1; i >= 0 && !answerFound; i--) {
					int cindex = s.charAt(i) - 'a';
					for (int j = cindex + 1; j < 26; j++) {
						if (count[j] > 0) {
							tailingCharacter = (char) (j + 'a');
							stringTill = i;
							answerFound = true;
							break;
						}
					}
					count[cindex] += 1;
				}
				
				for (int i = 0; i < stringTill; i++) {
					System.out.printf("%c", s.charAt(i));
				}
				System.out.printf("%c\n", tailingCharacter);
				
//				char lastHeadChar = s.charAt(s.length() - 1);
//				boolean answerFound = false;
//				for (int i = s.length() - 2; i >= 0 && !answerFound; i--) {
//					if (s.charAt(i) < lastHeadChar) {
//						answerFound = true;
//						index = i;
//					}
//				}
//				
//				if (answerFound) {
//					for (int i = 0; i < index; i++) {
//						System.out.printf("%c", s.charAt(i));
//					}
//					System.out.printf("%c\n", lastHeadChar);
//				} else {
//					System.out.printf("%c\n", 1 + s.charAt(0));
//				}
			}
		}
	}
}

Measured memory_bytes: 24020
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
n, m = map(int, input().split())

uf = UnionFind(n)

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    uf.union(a,b)

print(uf.group_count() -1 )

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//桁数
ll GetDigit(ll num)
{
  return log10(num) + 1;
}

//約数全列挙
vector<ll> enum_div(ll n)
{
  vector<ll> ret;
  for (ll i = 1; i * i <= n; ++i)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
      {
        ret.push_back(n / i);
      }
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}

//累乗(xのn乗%mod)
ll modpow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//階乗
ll factorial(ll n)
{
  if (n > 0)
    return n * factorial(n - 1);
  else
    return 1;
}

ll modinv(ll a, ll mod)
{
  ll b = mod, u = 1, v = 0;
  while (b)
  {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

void Main()
{
  ll n, q; cin >> n >> q;
  str s; cin >> s;
  vll AC(n);
  for(ll i = 1;i < n;i++)
  {
    if(s[i - 1] == 'A' && s[i] == 'C') AC[i] += 1;
    AC[i + 1] += AC[i];
  }
  rep(Q, q)
  {
    ll l, r; cin >> l >> r;
    ll ans = AC[r - 1] - AC[l - 1];

    cout << ans << endl;
  }
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}

Measured memory_bytes: 1872
n = int(input())
a = list(map(int, input().split()))

flag = [0]*n
t = 1
for i in range(n-1):
  if t == 1:
    if a[i] >= a[i+1]: continue
    else:
      flag[i] = 1
      t = 2
  elif t == 2:
    if a[i] <= a[i+1]: continue
    else:
      flag[i] = 2
      t = 1

if t == 2:
  for i in range(n-1, -1, -1):
    if flag[i] == 1:
      flag[i] = 0
      break
    if a[i] < a[i-1]: continue
    flag[i] = 2
    break

ans = 1000
s = 0
for i in range(n):
  if flag[i] == 1:
    t = ans//a[i]
    ans%=a[i]
  if flag[i] == 2:
    ans += t*a[i]
    t = 0
print(ans)

Measured memory_bytes: 9248
#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 rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out <<  "(" << a.F << ", " << a.S << ")";
}
 
template<class A> ostream& operator << (ostream& out, const vector<A> &a) {
	out << "[";
	for (auto it = a.begin(); it != a.end(); ++it) {
		if (it != a.begin())
			out << ", ";
		out << *it;
	}
	return out << "]";
}
int main()
{
    boost;
    ll n,i,j,x,t,y,q,f;
    char c;
    string s;
    cin>>s;
    list<char>l;
    for(auto p:s) l.pb(p);
    x=0;
    cin>>q;
    while(q--){
        cin>>t;
        if(t==1){
            x=1-x;
        }
        else{
            cin>>f>>c;
            if(x==0){
                if(f==1) l.push_front(c);
                else l.pb(c);
            }
            else{
                if(f==2) l.push_front(c);
                else l.pb(c);
            }
        }
    }
    string ans="";
    for(auto p:l) ans+=p;
    if(x==1) reverse(all(ans));
    cout<<ans;
}

Measured memory_bytes: 10452
import java.util.Scanner;

public class Main {
	private Scanner sc;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);

		int lim = Integer.parseInt(sc.next());
		for (int i = 0; i < lim; i++) {
			double[] point = new double[6];
			for (int j = 0; j < 6; j++) {
				point[j] = Double.parseDouble(sc.next());
			}
			
			double[] m = new double[4];
			m[0] = (point[0] + point[2]) / 2;
			m[1] = (point[1] + point[3]) / 2;
			m[2] = (point[2] + point[4]) / 2;
			m[3] = (point[3] + point[5]) / 2;
			
			double a = m[0] - point[0];
			double b = m[1] - point[1];
			double c = m[2] - point[2];
			double d = m[3] - point[3];

			double p = a * m[0] + b * m[1];
			double q = c * m[2] + d * m[3];
			
			double det = a * d - b * c;

			double x = (p * d + q * (-b)) / det;
			double y = (p * (-c) + q * a) / det;

			if (a == 0.0) y = m[1];
			if (b == 0.0) x = m[0];
			if (c == 0.0) y = m[3];
			if (d == 0.0) x = m[2];
			
			double r = Math.sqrt((x - point[0]) * (x - point[0]) + (y - point[1]) * (y - point[1]));
			
			System.out.printf("%.3f %.3f %.3f\n", x, y, r);
		}
	}
}

Measured memory_bytes: 26600
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t N;
    intmax_t ans = 0;

    scanf("%jd", &N);

    for (size_t i = 1; i <= N; i++) {
        if ((i % 3 != 0) && (i % 5 != 0)) {
            ans += i;
        }
    }

    printf("%jd\n", ans);

    return 0;
}


Measured memory_bytes: 2168
#include <cmath>
#include <iostream>
#include <vector>
#include <tuple>

using lli=long long int;

lli sgd(lli a, lli b){
  if(b == 0) return a;
  return sgd(b, a%b);
}

std::vector<std::tuple<lli, lli>> factorize(lli x){
  std::vector<std::tuple<lli, lli>> ans;
  lli nmax = static_cast<lli>(std::sqrt(x))+1;
  for(int i = 2; i < nmax; i++){
    if(x%i == 0){
      lli ni = 0;
      while(x%i == 0){
        ni++;
        x /= i;
      }
      ans.push_back(std::make_tuple(i, ni));
    }
    //if(x == 1) break;
  }
  if(x > 1) ans.push_back(std::make_tuple(x, 1));
  return ans;
}

int main(){
  lli A,B;
  std::cin >> A >> B;

  auto f = factorize(sgd(A,B));
  std::cout << f.size()+1 << std::endl;

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int a = 0;
    int b = 0;
    int c = 0;
    scanf("%d %d %d\n", &a, &b, &c);
    if (a ==b && a != c)
    {
        printf("Yes");
    }
    else if (c ==b && a != c)
    {
        printf("Yes");
    }
    else if (c ==a && a != b)
    {
        printf("Yes");
    }
    else {
         printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
N,M = map(int,input().split())
KS = [list(map(int,input().split())) for _ in range(M)]
P = list(map(int,input().split()))
ans = 0
tmp = 0
for i in range(2**N):
    Judge = True
    for j in range(0,M):
        tmp = 0
        for k in range(1,KS[j][0]+1):
            if i >> (KS[j][k]-1) & 1 == 1:
                tmp += 1
        if tmp%2 != P[j]:
            Judge = False
    if Judge:
        ans += 1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int n,m; cin >> n >> m;
    vector<int> a(n);
    REP(i,n) cin >> a[i];

    sort(a.begin(), a.end(), greater<int>());

    int total = accumulate(a.begin(), a.end(), 0);
    int ans;
    REP(i,n){
        if(double(a[i]) < double(total)/(4.0*double(m))){
            ans = i;
            if(ans>=m) cout << "Yes" << endl;
            else cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
T=0..59
puts 9394,a=?+,0,1,c=8,?<,2,8,3,[0,1].map{|x|[a,3,x,x]+T.map{[a,v=x+4,v,v,a,3,v,6,[a,6,6,6]*(59-_1),?<,6,x,c+=1,a,v,c,v]}},T.map{|t|[a,2,2,2]+(1..t).map{[a,39+t-_1,98+_1,5,?<,3,5,5,a,2,5,2]}}

Measured memory_bytes: 14840
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set; 

int main(){
    fastio
    int n , d ; 
    cin >> n >> d ; 
    d = d * 2 + 1 ;
    int ans = (n+d-1) / d ; 
    cout << ans << endl;
    return 0 ;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

    public class PictureMatching
    {
        private static int[] item;

        public static void Main(string[] args)
        {
            Input();
            Method();
            System.Console.ReadLine();
        }

        private static void Input()
        {
            var num = int.Parse(System.Console.ReadLine());
            item = new int[num];
            for (int i = 0; i < num; i++)
            {
                item[i] = int.Parse(System.Console.ReadLine());
            }
        }

        private static void Method()
        {
            var i = item.Where(IsPrime);
            System.Console.WriteLine(i.Count());
        }

        private static bool IsPrime(int x)
        {
            if (x == 1 || x == 0) return false;
            if (x == 2) return true;

            var boundary = (int)Math.Floor(Math.Sqrt(x));

            for (int i = 2; i <= boundary; i++)
            {
                if (x % i == 0) return false;
            }

            return true;
        }
}

Measured memory_bytes: 9728
#include <iostream>

using namespace std;

int main(){
    int n;
    while (cin >> n && n){
        int sum = 0;
        for (int i = 0; i < (n - 1) * n / 2; i++){
            int x; cin >> x;
            sum += x;
        }
        cout << sum / (n-1) << endl;
    }
}

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

long long n, m;

int main(){
	
	cin >> n >> m; 
	
	if( n > m ) swap( n, m);

	if( n == 1 ){
		if( m == 1 ) cout << 1 << endl;
		if( m != 1 ) cout << m - 2 << endl; 
	}
	
	
	if( n > 1 ){
		cout << ( n - 2 ) * ( m - 2 ) << endl; 
	}
	
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main(){
    int n;
    cin>>n;
    int x[110];
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    int vmin=100000000;
    for(int p=1;p<=100;p++){
        int sum=0;
        for(int i=0;i<n;i++){
            sum+=pow(x[i]-p,2);
        }
        vmin=min(vmin,sum);
    }
    cout<<vmin<<"\n";
    return(0);
}

Measured memory_bytes: 3600
#include <iostream>
#include <fstream>
#include <map>

using namespace std;

int main()
{
		//freopen("in.txt","r",stdin);
		map<string,int>ans;
		ans["AC"]=0;
		ans["WA"]=0;
		ans["TLE"]=0;
		ans["RE"]=0;

		int n;
		cin>>n;
		for(int i=0;i<n;i++)
		{
			string ss;
			int value;
			cin>>ss;
			ans[ss]++;
		}

		cout<<"AC x "<<ans["AC"]<<endl;
		cout<<"WA x "<<ans["WA"]<<endl;
		cout<<"TLE x "<<ans["TLE"]<<endl;
		cout<<"RE x "<<ans["RE"]<<endl;

		

	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

#define MAX_N 500
int n;
int p[MAX_N * MAX_N];
int dist[MAX_N][MAX_N];
bool isVacant[MAX_N][MAX_N];
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const int dx2[] = {-1, 1, -1, 1};
const int dy2[] = {-1, -1, 1, 1};

void update(int x, int y) {
    rep(i, 4) {
        int nx = x + dx[i], ny = y + dy[i];
        if (nx >= 0 && ny >= 0 && nx < n && ny < n) {
            if (isVacant[y][x] && dist[ny][nx] > dist[y][x]) {
                dist[ny][nx] = dist[y][x];
                update(nx, ny);
            }
            if (!isVacant[y][x] && dist[ny][nx] > dist[y][x] + 1) {
                dist[ny][nx] = dist[y][x] + 1;
                update(nx, ny);
            }
        }
    }
}

int main() {
    cin >> n;
    rep(i, n * n) {
        cin >> p[i];
        p[i]--;
    }
    rep(i, n * n) {
        int x = i % n;
        int y = i / n;
        dist[y][x] = min({x, y, n - 1 - x, n - 1 - y});
    }
    ll ans = 0;
    rep(i, n * n) {
        int x = p[i] % n;
        int y = p[i] / n;
        ans += dist[y][x];
        isVacant[y][x] = true;
        rep(i, 4) {
            int nx = x + dx[i], ny = y + dy[i];
            if (nx >= 0 && ny >= 0 && nx < n && ny < n) {
                if (dist[ny][nx] > dist[y][x]) {
                    dist[ny][nx] = dist[y][x];
                    update(nx, ny);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 36808
#include<iostream>
#include<algorithm>

using namespace std;
#define MAXN	110

int N;
struct P {
    int x, y, h;
};
P ps[MAXN];

int h[MAXN][MAXN];

inline int calcH(int cx, int cy, int ch, int x, int y) {
	return max(ch-abs(x-cx)-abs(y-cy), 0);
}

int isok(int cx, int cy, int ch) {
    for(int i=0; i<N; i++) {
        if(calcH(cx, cy, ch, ps[i].x, ps[i].y) != ps[i].h) {
            return 0;
        }
    }
    return 1;
}
int main() {
  scanf("%d", &N);
  int a, b, c;
  int mx, my, t;
  mx = my = 0;
  for(int i=0; i<N; i++) {
    scanf("%d%d%d", &a, &b, &c);
    mx = max(mx, a);
    my = max(my, b);
    if(c) t = i;
    ps[i].x = a; ps[i].y= b; ps[i].h = c;
  }
    for(int x=0; x<=mx; x++) {
        for(int y=0; y<=my; y++) {
            int h = ps[t].h + abs(ps[t].x-x)+abs(ps[t].y-y);
            if(isok(x, y, h)) {
                printf("%d %d %d\n", x, y, h);
                exit(0);
            }
        }
  }
  return 0;
}

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

using namespace std;

using ll = long long;

int main(){
    ll n; cin >> n;
    ll arr[n];
    for(ll i = 0; i < n; ++i){
        cin >> arr[i];
    }
    ll ans = 0;
    for(ll i = 0; i < n; ++i){
        if(arr[i] == i + 1){
            swap(arr[i], arr[i + 1]);
            ans++;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1152
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int S = sc.nextInt();
		int res = 0;
		for (int x=0; x<=K; x++) {
			for (int y=0; y<=K; y++) {
				int z = S-x-y;
				if ( z>=0 && z<=K ) res++;
			}			
		}
		System.out.println(res);
	}
}


Measured memory_bytes: 23636
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(vec, s) vec.find(s) != vec.end()
#define Set_union(A, B, res) set_union(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_intersection(A, B, res) set_intersection(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_difference(A, B, res) set_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));
#define Set_symmetric_difference(A, B, res) set_symmetric_difference(A.begin(), A.end(), B.begin(), B.end(), inserter(res, res.end()));

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	Rep(i, N) cin >> A[i];
	ll ans = 0;
	for (int i = 1; i < N; i++) {
		if (A[i] < A[i - 1]) {
			ans += A[i - 1] - A[i];
			A[i] = A[i - 1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4040
from sys import stdin
input = stdin.readline


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


N, Q = map(int, input().split())
c = list(map(int, input().split()))

lr = []
for i in range(Q):
    l, r = map(int, input().split())
    lr.append([l, r, i])

lr.sort(key=lambda x: x[1])
# print("lr", lr)
rightest = [-1] * (N + 1)
current_q = 0
bit = Bit(N)
ans = [0] * Q

for i in range(N):
    if rightest[c[i]] != -1:
        bit.add(rightest[c[i]] + 1, -1)
    rightest[c[i]] = i
    bit.add(i + 1, 1)
    # print(bit.tree)

    while current_q < Q and lr[current_q][1] == i + 1:
        ans[lr[current_q][2]] = bit.sum(lr[current_q][1]) - bit.sum(lr[current_q][0] - 1)
        current_q += 1

for i in range(Q):
    print(ans[i])


Measured memory_bytes: 226532
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;cin>>s;
    if((s[0]=='A' || s[1]=='A' || s[2]=='A') &&(s[0]=='B' || s[1]=='B' || s[2]=='B'))cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
//?¶????????????????????????????????????§??????????????????????¢????????????????
constexpr int INF = 2000000000;
const double PI = acos(-1);

#define v2d Vector2D

struct Vector2D {
	double x, y;
};

Vector2D sub_vector2D(const Vector2D& a, const Vector2D& b) {
	Vector2D ret;
	ret.x = a.x - b.x; ret.y = a.y - b.y;
	return ret;
}

double out_mul(Vector2D a, Vector2D b) {
	return a.x*b.y - a.y*b.x;
}

bool point_in_triangle_2D(v2d a, v2d b, v2d c, v2d p) {
	v2d ab = sub_vector2D(b, a);
	v2d bp = sub_vector2D(p, b);

	v2d bc = sub_vector2D(c, b);
	v2d cp = sub_vector2D(p, c);

	v2d ca = sub_vector2D(a, c);
	v2d ap = sub_vector2D(p, a);

	double c1 = out_mul(ab, bp), c2 = out_mul(bc, cp), c3 = out_mul(ca, ap);

	if ((c1>0 && c2>0 && c3>0) || (c1<0 && c2<0 && c3<0)) return true;
	return false;
}

int main() {
	v2d a, b, c, p;

	while (cin >> a.x >> a.y >> b.x >> b.y >> c.x >> c.y >> p.x >> p.y) {
		if (point_in_triangle_2D(a, b, c, p)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

Measured memory_bytes: 3052
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<string.h>
#include<math.h>
#include<utility>
#include<algorithm>
#include<functional>
using namespace std;
 
int n,q;
int k=0;
int a[20];
int m[200];

bool dfs(int i,int s)
{
	if(i==n) return s==k;
	if(dfs(i+1,s))return true;
	if(dfs(i+1,s+a[i]))return true;
   return false;
}
 
int main()
{
	cin>>n;
	for(int i=0;i<n;i++){
	cin>>a[i];
	}

	cin>>q;
	for(int i=0;i<q;i++){
	cin>>m[i];
	}

	for(int i=0;i<q;i++){
		k=m[i];
	if(dfs(0,0)==true)cout<<"yes"<<endl;
	else cout<<"no"<<endl;
	}
	
	
    return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
int main(void){
int a,b,c,d;cin>>a>>b>>c>>d;
while(true){
    c-=b;
    if(c<=0&&a>0)
        {cout<<"Yes"<<endl;break;}
    a-=d;
    if(a<=0&&c>0)
        {cout<<"No"<<endl;break;}
}
return 0;}


Measured memory_bytes: 3608
def warshall_floyd(d, V): #d[i][j]は2頂点間i, j間の移動コストを格納, Vは頂点数
    for k in range(V):
        for i in range(V):
            for j in range(V):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
                
    return d
                
H, W = map(int, input().split())                
L = [list(map(int, input().split())) for _ in range(10)]
a = [list(map(int, input().split())) for _ in range(H)]

cost = warshall_floyd(L, 10)

res = 0
for i in range(H):
    for j in range(W):
        if a[i][j] != -1:
            res += cost[a[i][j]][1]
        
print(res)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
 
 
int main(){
  int H, W;
  cin >> H >> W;
  for(int row=0; row<H; row++){
    for(int col=0; col<W; col++){
      string s;
      cin >> s;
      if(s=="snuke"){
        cout << char(col + 'A') << row + 1 << endl;
        return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    int N; cin >> N;
    vector<long long> a(N), b(N);
    for (int i = 0; i < N; ++i) cin >> a[i];
    for (int i = 0; i < N; ++i) cin >> b[i];
    long long biggerA = 0, biggerB = 0;
    for (int i = 0; i < N; ++i) {
        if (a[i] > b[i]) biggerA += a[i] - b[i];
        if (b[i] > a[i]) biggerB += (b[i] - a[i])/2;
    }
    if (biggerB >= biggerA) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 384
n = int(input())
S = input()
p = 10**9 + 7
DP = [[0 for j in range(n + 1)] for i in range(n + 1)]
for j in range(n):
    DP[1][j] = 1
for i in range(2, n + 1):
    A = [0]
    for j in range(n):
        A.append(A[-1] + DP[i - 1][j])
    for j in range(n - i + 1):
        if S[i - 2] == '<':
            DP[i][j] = (A[n - i + 1 + 1] - A[j + 1]) % p
        else:
            DP[i][j] = A[j + 1] % p
print(DP[n][0])


Measured memory_bytes: 119388
from itertools import combinations as c
n=int(input())
s=[input() for _ in range(n)]
march=[0]*5
for i in range(n):
    if s[i][0]=='M':march[0]+=1
    elif s[i][0]=='A':march[1]+=1
    elif s[i][0]=='R':march[2]+=1
    elif s[i][0]=='C':march[3]+=1
    elif s[i][0]=='H':march[4]+=1
print(sum(i*j*k for i, j, k in c(march, 3)))

Measured memory_bytes: 9776
#include<bits/stdc++.h>
#define NMAX 3001

using namespace std;

string s, t, ans;
int cost[NMAX][NMAX];

int main()
{
    cin>>s>>t;
    int sLen = s.length(), tLen = t.length();

    for(int i = 0 ; i < sLen ; i++){
        for(int j = 0 ; j < tLen ; j++){
            if(s[i] == t[j]){
                cost[i + 1][j + 1] = max(cost[i + 1][j + 1], cost[i][j] + 1);
            }
            else{
                cost[i + 1][j + 1] = max(cost[i + 1][j + 1], cost[i][j + 1]);
                cost[i + 1][j + 1] = max(cost[i + 1][j + 1], cost[i + 1][j]);
            }
        }
    }

    int i = sLen, j = tLen;

    while(i > 0 && j > 0){
         if(cost[i][j] == cost[i - 1][j])
            i --;
          else if( cost[i][j] == cost[i][j - 1] )
            j --;
          else{
            ans = s[i - 1] + ans;
            i --;
            j --;
          }
    }

    cout<<ans;
    return 0;
}


Measured memory_bytes: 35456
#include<iostream>
#include<string>
#include<cmath>

int main(){
    using namespace std;
    cin.tie(0);
    ios::sync_with_stdio(false);

    long long int n;
    cin >> n;
    int ans = 114514;
    for(int a=1; a<=sqrt(n); a++){
        int f_a = 114514;
        int f_b = 114514;
        if(n % a == 0){
            long long int b = n / a;
            f_a = to_string(a).length();
            f_b = to_string(b).length();
        }
        ans = min(ans, max(f_a, f_b));
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
    FAST
    ll x;
    cin>>x;
    ll y=ceil(x/11.0);
    if((5*(y-1) + 6*y)>=x)
     cout<<(y*2)-1;
     else 
     cout<<y*2;
}

Measured memory_bytes: 256