akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	String str=input.readLine();
	int m=0,n=str.length()-1;
	char ch[]=str.toCharArray();
	String str1;
	while(true)
	    {
		
		if((m==n) || (m>n))
		    {
			str1=String.valueOf(ch);
			break;
		    }
		
		
		char tmp=ch[m];
		ch[m]=ch[n];
		ch[n]=tmp;
		m++;
		n--;

	    }
	
		System.out.println(str1);
	    
    }
}

Measured memory_bytes: 16856
#include<stdio.h>
typedef struct{
  int TID;
  int TT;
  int Time;
}T;

T team[51],tmp;

int main()
{
  int i,j,T,P,R,ID,PID,Ti;
  int PP[51][11];
  char S[10];
  while(1){
    scanf("%d%d%d",&T,&P,&R);
    if(T==0&&P==0&&R==0)break;
    for(i=1;i<T+1;i++){
      team[i].TID=i;
      team[i].TT=0;
      team[i].Time=0;
      for(j=0;j<11;j++)PP[i][j]=0;
    }
    for(i=0;i<R;i++){
      scanf("%d%d%d%s",&ID,&PID,&Ti,S);
      if(S[0]=='W')PP[ID][PID]++;
      else if(S[0]=='C'){
        team[ID].TT++;
	team[ID].Time+=(PP[ID][PID]*1200+Ti);
      }
    }
    for(i=1;i<T+1;i++){
      for(j=T;j>i;j--){
	if(team[j].TT>team[j-1].TT){
	  tmp=team[j];
	  team[j]=team[j-1];
	  team[j-1]=tmp;
	}
	else if(team[j].TT==team[j-1].TT && team[j].Time<team[j-1].Time){
	  tmp=team[j];
	  team[j]=team[j-1];
	  team[j-1]=tmp;
	}
      }
    }
    for(i=1;i<T+1;i++){
      printf("%d %d %d\n",team[i].TID,team[i].TT,team[i].Time);
    }
  }
  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

int p[100010],pr[20100],t;
ll ad[101000],mi[101000],num[555][555];
ll mx;
vector<pair<int,PII>> pp;
int main() {
	rep(i,2,20000) if (p[i]==0) {
		pr[t++]=i;
		for (int j=i;j<=20000;j+=i) p[j]=1;
	}
//	printf("%d\n",t);
	for (int c=0;c<=998;c++) if (c%2==0) {
		pp.pb(mp(abs(c-499),mp(c,0)));
	}

	for (int c=-499;c<=499;c++) if (c%2==0) {
		pp.pb(mp(abs(c),mp(c,1)));
	}
	sort(all(pp));
	rep(i,0,SZ(pp)) {
		if (pp[i].se.se==0) ad[pp[i].se.fi]=pr[i];
		else mi[pp[i].se.fi+1000]=pr[i];
	}
	set<ll> ss;
	rep(i,0,500) rep(j,0,500) {
		if ((i+j)%2==0) {
			ll p1=ad[i+j];
			ll p2=mi[i-j+1000];
			num[i][j]=p1*p2;
			ss.insert(num[i][j]);
		}
	}
	ll mx=0;
	rep(i,0,500) rep(j,0,500) {
		if ((i+j)%2==1) {
			num[i][j]=1;
			rep(k,0,4) {
				int nx=i+dx[k],ny=j+dy[k];
				if (nx>=0&&nx<500&&ny>=0&&ny<500) {
					num[i][j]=num[i][j]/gcd(num[i][j],num[nx][ny])*num[nx][ny];
				}
			}
			ll x=num[i][j]+1;
			while (ss.count(x)) x+=num[i][j];
			num[i][j]=x;
			ss.insert(x);
			mx=max(mx,num[i][j]);
		}
	}
	ss.clear();
	rep(i,0,500) rep(j,0,500) {
		rep(k,0,4) {
			int nx=i+dx[k],ny=j+dy[k];
			if (nx>=0&&nx<500&&ny>=0&&ny<500) {
				ll c1=max(num[i][j],num[nx][ny]);
				ll c2=min(num[i][j],num[nx][ny]);
				assert(c1%c2==1);
			}
		}
		ss.insert(num[i][j]);
		assert(num[i][j]>=1&&num[i][j]<=1000000000000000ll);
	}
	assert(SZ(ss)==250000);
	int x=0;
	scanf("%d",&x);
	rep(i,0,x) {
		rep(j,0,x) printf("%lld%c",num[i][j]," \n"[j==x-1]);
	}
}


Measured memory_bytes: 18816
//	created : 15/12/30
// 	autor   : Rp7rf
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>

using namespace std;
#define rep(i,a) for(long long i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(long longs i = a ; i < b ; i ++)
#define mp make_pair
#define pb push_back
#define f first
#define s second
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
int main(void){
	ll n,in;
	while(cin>>n,n){
		cin>>in;
		vector<pii> v;
		v.pb(mp(in,1));
		ll input = n;
		while(--input){
			cin>>in;
			if(v[v.size()-1].first == in){
				v[v.size()-1].s ++;
			}else{
				v.pb(mp(in,1));
			}
		}
		ll ret = n;
		rep(i,v.size()){
				ll now = n;
				ll l = i - 1 , r = i + 1;
				while(0 <= l && r < v.size()){
					if(v[l].s + v[r].s >= 4 && v[l].f == v[r].f){
						now = now - (v[l].s + v[r].s);
					}else{
						break;
					}
					l --; r ++;
				}
				if(now != n)now -=v[i].s;
				ret = min(ret,now);
			
			//cout<<v[i].f<<" "<<v[i].s<<endl;
		}
		cout<<ret<<endl;
	}
}

Measured memory_bytes: 1308
/**
class cfmaster {
 public:
  struct code {
  	see the details down there !
  };
};
**/
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  if (n == 1) {
    cout << "Hello World" << '\n';
    return 0;
  }
  int a, b;
  cin >> a >> b;
  cout << a + b << '\n';
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using console=System.Console;
namespace AtCoderTemplate
{
    public class App
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("{3}",
            args=new string[3],
            args[0] = console.ReadLine(),
            args[1] = args[0].Count()==26?((char)(25 - args[0].Skip(1).Zip(args[0],(a,b)=>a-b).Reverse().TakeWhile(i=>i<0).Count())).ToString():"",
            args[0].Count()==26?((args[1][0]==0)?"-1":(string.Join("",args[0].Take(args[1][0]).Select((v,i)=>i==args[1][0]-1?args[0].Last(c=>c>args[0][args[1][0]-1]):v)))):(args[0] +(char)('a'+ args[0].OrderBy(c=>c).Where((c,i)=>c-i=='a').Count())));
        }
    }
}

Measured memory_bytes: 13396
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
#include <sstream>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
using namespace std;
#define inf 1000000007
#define int long long
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
struct edge{int from,to,cost;};
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
signed main(){
    int n;cin>>n;
    if(n<=15000){
        if((n-2)%3==0){
             cout<<3<<" "<<9<<" ";
        rep(i,1,n-1){
            cout<<2*i<<" ";
        }cout<<endl;
        return 0;
        }
        else if((n-2)%3==1){
            if(n==3){
                cout<<2<<" "<<5<<" "<<63<<endl;return 0;
            }
            cout<<3<<" "<<9<<" "<<30000<<" ";
            rep(i,1,n-2){
                cout<<2*i<<" ";
            }cout<<endl;
            return 0;
        }else{
            cout<<3<<" "<<9<<" ";
            rep(i,1,n-1){
                cout<<2*i<<" ";
            }cout<<endl;
            return 0;
        }
       
    }else {
        int count=0;
        if(n%2){
            rep(i,1,15000){
            cout<<2*i<<" ";
            count++;
        }
        for(int i=1;i+15000<=n+1;i++){
            cout<<6*i-3<<" ";
            count++;
        }cout<<endl;
        return 0;
        }else {
            rep(i,1,15001){
                cout<<2*i<<" ";
                count++;
            }
            for(int i=1;i+15000<=n;i++){
                cout<<6*i-3<<" ";
                count++;
            }cout<<endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define revv(V) reverse(allv(V))
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 100005;

int A[MAXN], B[MAXN];
pii C[MAXN];

int Ans[MAXN];

int N, L, T, X, F;

int main() {
	ios::sync_with_stdio(false);

	cin >> N >> L >> T;
	for(int i = 1; i <= N; i++) {
		cin >> A[i] >> B[i];
	}

	X = A[1];
	for(int i = 1; i <= N; i++)
		A[i] = ((A[i] - X) % L + L) % L;

	if(2 == B[1]) {
		F = 1;
		for(int i = 1; i <= N; i++) {
			B[i] = 3-B[i];
			A[i] = (L-A[i]) % L;
		}
	}

	for(int i = 1; i <= N; i++) {
		if(1 == B[i]) {
			ll x = ll(A[i]) + T;
			x %= L;
			if(x) C[i] = pii(x, 1);
			else C[i] = pii(L, 1);
		} else {
			ll x = ll(A[i]) - T;
			x %= L;
			x = (x + L) % L;
			C[i] = pii(x, 2);
		}
	}
	sort(C+1, C+N+1);

	//for(int i = 1; i <= N; i++)
    //  printf("%d : %d %d : %d %d\n", i, A[i], B[i], C[i].first, C[i].second);

	{
		ll sum = 0;
		for(int i = 2; i <= N; i++) {
			if(1 == B[i] || 2*T <= A[i]) continue;
			sum += (2*T - A[i] - 1) / L + 1;
		}
		sum %= N;

		int idx = (1+sum) % N;
		if(!idx) idx = N;

		if(F && 1 != idx) {
            idx = N+2-idx;
		}

		//printf("sum=%lld, idx=%d\n", sum, idx);

		pii p = pii((A[1]+T)%L, 1);
		if(!p.first) p.first = L;
		int i = 1;
		for(; C[i] != p; i++);

		for(int j = 0; j < N; j++) {
			int x = (!F) ? ((idx+j) % N) : ((idx-j+N) % N);
			if(!x) x = N;

			int y = (i+j) % N;
			if(!y) y = N;

			//printf("x=%d, y=%d\n", x, y);

			Ans[x] = C[y].first;
		}
	}

	if(F) {
		for(int i = 1; i <= N; i++)
			Ans[i] = (L-Ans[i]) % L;
	}
	for(int i = 1; i <= N; i++)
		Ans[i] = (Ans[i] + X) % L;

	for(int i = 1; i <= N; i++)
		printf("%d\n", Ans[i] % L);
	return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int A,B; cin >> A >> B; // Aが白

    bool changed = false;
    if (A>B){
        swap(A,B);
        changed = true;
    }

    vector<vector<int>> T(100,vector<int>(100,0));

    
    int b = 1;
    while(b<=B){
        int yoko = (b-1)%25;
        yoko *= 4;
        int tate = (b-1)/25;
        tate *= 4;

        T[tate][yoko] = 1;
        T[tate][yoko+1] = 1;
        T[tate][yoko+2] = 1;
        T[tate+1][yoko] = 1;
        T[tate+1][yoko+1] = 1;
        T[tate+1][yoko+2] = 1;
        T[tate+2][yoko] = 1;
        T[tate+2][yoko+1] = 1;
        T[tate+2][yoko+2] = 1;    

        b++;
    }

    int a = 1;
    while(a<=A-1){
        int yoko = (a-1)%25;
        yoko *= 4;
        int tate = (a-1)/25;
        tate *= 4;

        
        T[tate+1][yoko+1] = 0;   

        a++;
    }

    cout << 100 << " " << 100 << endl;
    REP(i,100){
        REP(j,100){
            if(!changed){
                if(T[i][j]==0)cout << ".";
                else cout << "#";
            }else{
                if(T[i][j]==0)cout << "#";
                else cout << ".";
            }
            
        }
        cout << endl;
    }

    


    return 0;
}

Measured memory_bytes: 3580
MOD = 10 ** 9 + 7

def solve():
    N, K = map(int, input().split())
    A = list((map(int, input().split())))
    
    ans = 0
    for i, ai in enumerate(A):
        left = 0
        right = 0
        for j in range(i):
            if ai > A[j]:
                left += 1
        for j in range(i+1, N):
            if ai > A[j]:
                right += 1
        
        ans += (K*(K+1)*right//2) + (K*(K-1)*left//2)
        
    return ans % MOD
    
print(solve())

Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#define REP(i, a, b) for ( int i = (a); i < (b); i++ )
#define REVREP(i, a, b) for ( int i = (a); i >= (b); i--)
#define DEBUG_INT(var) printf("the value of "#var" is %d\n", var)
#define PRINT_ARRAY(name, i) printf("the value of "#name"[%d] is %d\n", (i), name[(i)])
#define DEBUG_ARRAY(name, begin, end) REP(i, begin, end) PRINT_ARRAY(name, i)

using namespace std;

int n[3];
int ans;


int main(void) {
    scanf("%d %d %d", &n[0], &n[1], &n[2]);
    sort(n,n+3);
    
    int odd = 0;
    REP(i, 0, 3) if (n[i] % 2 == 1) odd++;
    if (odd == 1) {
      REP(i, 0, 3) if (n[i] % 2 == 0) n[i]++;
      ans++;   
    } else if (odd == 2) {
       REP(i, 0, 3) if (n[i] % 2 == 1) n[i]++;
       ans++;
    
    }
    
    
    ans += (n[2] - n[0] + n[2] - n[1]) / 2;
    
    printf("%d\n", ans);
    

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<tuple>
#include<string.h>
#include <numeric> 
#include<unordered_map>
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 pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define pp1(...) "\033[1;47;35m" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "]\033[0m"
#define dg(x) debug() << pp1(x)
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define int long long
#define all(x) x.begin() , x.end()
#define clr(x) memset(x , 0 , sizeof x);
#define sz(x) (int)x.size()
template<typename T> void db(T x ){ debug() <<">>> " <<  x; }
template<typename T> void db(T x , T y){ debug() <<">>> " <<  x <<" , "<< y; }
template<typename T> void db(T x , T y , T z){ debug() <<">>> "<< x <<" , "<< y <<" , "<< z; }
template<typename T> void db(T x , T y , T z , T a){ debug() <<">>> "<< x <<" , " << y <<" , "<< z <<" , "<< a; }
const int xx = 2e5;
const int Mod = 1e9 + 7;
const int inf = 1e18;
const int Maxn = 20010;

signed main(){
  ios::sync_with_stdio(false);cin.tie(0);

  string S , T;
  cin >> S >> T;
  int N = sz(S) , M = sz(T);
  vector<string> vs;
  string ans = "";
  bool ok = false;
  for(int i = 0;i  <= N - M; i++) {
    string x = "";
    for(int j = 0; j < M; j++) {
      if(S[i + j] == '?'){
        x += T[j];
      } else {
        x += S[i + j];
      }
    }
    dg2(i , x);
    if(x == T) {
      ok = true;
      for(int j = i - 1; j >= 0; j--){
        if(S[j] != '?') x = S[j] + x;
        else x = 'a' + x;
      }
      for(int j = sz(x); j < N ; j++) {
        if(S[j] != '?') x += S[j];
        else x += 'a';
      }

      vs.push_back(x);
    }
  }
  if(!ok) {
    cout << "UNRESTORABLE" << '\n';
    return 0;
  }
  sort(vs.begin() , vs.end());
  cout << vs[0] << '\n';
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
typedef long long ll;

using namespace std;

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define MAX                 10000007
#define MIN                 -10000007



              
int main()
{
  ios::sync_with_stdio(0);
    cin.tie(0);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
      
    int t;
    t=1;
     //  cin>>t;
    while(t--){
        	ll a[5];
        	REP(i,0,4){cin>>a[i];}

        	REP(i,0,4){
        		if(a[i]==0){
        			cout<<i+1;
        			return 0;
        		}
        	}
       


             }
             cerr<<"Time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}


Measured memory_bytes: 3636
import sys
import heapq
import bisect
 
mod = 10**9+7
 
def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(list(sys.stdin.readline())[:-1])
 
def main():
    N = I()
    A = LI()
    ans = 0
    count = [0]*62

    for i in range(62):
        mask = 1<<i
        for a in A:
            if a&mask:
                count[i]+=1

    for i in range(62):
        ans += (count[i] * (N-count[i]))*(1<<i)%mod
        ans %= mod


    return(ans)
 
if __name__ == "__main__":
    print(main())


Measured memory_bytes: 123132
import java.util.*;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0 ; i< n - 1; i++) {
            arr[sc.nextInt() - 1]++;
        }

        for (int i = 0; i < n;i++) {
            System.out.println(arr[i]);
        }


    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 54268
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define bitcount(x)  __builtin_popcount(x)
#define bitcountll(x)  __builtin_popcountll(x)
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 100005  //check the limits, man
int main()
{
    int a,b;
    set<int> st;
    st.insert(1);
    st.insert(2);
    st.insert(3);
    in2(a,b);
    st.erase(a);
    st.erase(b);
    set<int> :: iterator itr;
    itr=st.begin();
    a=(*itr);
    out(a);
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,x,s=0,t,i;
    cin>>a>>t;
   for(i=0;i<t;i++)
    {
      cin>>x;
      s+=x;
        }
        if((a-s)<0) cout<<"-1"<<endl;
        else cout<<a-s<<endl;
}


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

int main() {
  int h, n;
  cin >> h >> n;
  vector<int> a(n), b(n);
  for(int i=0; i < n; i++) cin >> a[i] >> b[i];
  long long cost[10010];
  for(int i=0; i < 10010; i++) cost[i] = 10e9;
  cost[0] = 0;
  for(int i=0; i < h; i++) {
    for(int j=0; j < n; j++) {
      int m = min(i+a[j], h);
      cost[m] = min(cost[m], cost[i] + b[j]);
    }
  }
  cout << cost[h] << endl;
}


Measured memory_bytes: 384
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let w: f64 = sc.read();
    let h: f64 = sc.read();
    let x: f64 = sc.read();
    let y: f64 = sc.read();
    let ans = (w * h) / 2.0;
    let num = (((x * 2.0) == w) && ((y * 2.0) == h)) as u8;
    println!("{:.6} {}", ans, num);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h> 
#define rep(i,n) for(int i=0; i<(n); ++i)
#define cout(x) cout<<x<<endl
#define all(v) v.begin(), v.end()
using namespace std;
//型エイリアス
using vi = vector<int>;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
const ll inf = 1e18;
const int N = 2e5 + 10;


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

    if(x==1){
        cout(1);
        return 0;
    }
    int min_dif = 1e9;
    int ans = 0;
    for(int b=2; b<sqrt(1e3); ++b){
        for(int p=2; p<=9; ++p){
            int y = pow(b,p);
            int dif = x - y;
            if(dif>=0 && min_dif>dif){
                min_dif = dif;
                ans = y;
            }
        }
    }
    cout(ans);
    return 0;
}

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int p[n];
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	sort(p, p + n);
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		ans += p[i];
	}
	ans += p[n - 1] / 2;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
int x,a,b;

int main(int argc, char const *argv[])
{
    cin>>x>>a>>b;
    if(abs(x-a)<abs(x-b)){
        cout<<'A'<<endl;
    }else{
        cout<<'B'<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n, a, cnt = 0;
	
	scanf("%d", &n);
	
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		while (a % 2 == 0) {
			cnt++;
			a = a / 2;
		}
	}
	
	printf("%d\n", cnt);
	
	return 0;
}

Measured memory_bytes: 128
n, m = map(int, input().split())

if n % 2: # odd
    for i in range(m):
        print(i + 1, n - i)
else: # even
    for i in range(m):
        if 1 + 2 * i >= n - 1 - 2 * i:
            l1 = i
            break
        m -= 1
        print(i + 1, n - i)

    for i in range(m):
        if i + 1 + l1 >= n - i - l1 - 1:
            raise Exception()
        print(i + 1 + l1, n - i - l1 - 1)


Measured memory_bytes: 9192
local n = io.read("n")
local c = io.read("n")
local b = io.read("n")
local a = io.read("n")
function pay(x,y,z)
    return math.abs(x-a)+math.abs(y-b)+math.abs(z-c)
end
local bamboos = {}
function dfs(cur,a,b,c)
    if cur == #bamboos+1 then
        return math.min(a,b,c) > 0 and pay(a,b,c) - 30 or math.huge
    end
    local vcur = bamboos[cur]
    local toa = 10 + dfs(cur+1, a+vcur, b, c)
    local tob = 10 + dfs(cur+1, a, b+vcur, c)
    local toc = 10 + dfs(cur+1, a, b, c+vcur)
    local skip = dfs(cur+1, a, b, c)
    return math.min(toa, tob, toc, skip)
end

for i=1,n do
    bamboos[i] = io.read("n")
end
print(dfs(1,0,0,0))

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

using namespace std;
vector<int> lista[100001];
bool vis[100001];
int memo[100001];
int dist(int node){
    if(vis[node])
        return memo[node];
    vis[node]=true;
    int maxi=0;
    for(auto x:lista[node])
        maxi=max(maxi, dist(x)+1);
    memo[node]=maxi;
    return maxi;
}
int main(){
    int n, m;
    cin>>n>>m;
    for(int i=0; i<m; i++){
        int x, y;
        cin>>x>>y;
        lista[x].push_back(y);
    }
    int ans=0;
    for(int i=1; i<=n; i++){
        if(!vis[i])
            dist(i);
        ans=max(memo[i], ans);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 8192
#include <cstdio>
#include <cstring>

using namespace std;

const int mod = 1000000007;
char s[10001];
int dp[10001][100][2];

int main() {
    int n, d, i, j, k, l;
    long long ans;
    
    scanf("%s", s);
    scanf("%d", &d);
    
    n = strlen(s);
    
    dp[0][0][0] = 1;
    
    for (i = 0; i < n; i++) {
        for (j = 0; j < d; j++) {
            for (k = 0; k < 2; k++) {
                if (dp[i][j][k] == 0) continue;
                
                for (l = 0; l < 10; l++) {
                    if (k == 0 && l > s[i] - '0') break;
                    
                    if (k == 1 || l < s[i] - '0') {
                        dp[i + 1][(j + l) % d][1] += dp[i][j][k];
                        if (dp[i + 1][(j + l) % d][1] >= mod) dp[i + 1][(j + l) % d][1] -= mod;
                    } else {
                        dp[i + 1][(j + l) % d][0] += dp[i][j][k];
                        if (dp[i + 1][(j + l) % d][0] >= mod) dp[i + 1][(j + l) % d][0] -= mod;
                    }
                }
            }
        }
    }
    
    ans = dp[n][0][0] + dp[n][0][1] - 1;
    while (ans < 0) ans += mod;
    while (ans >= mod) ans -= mod;
    
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 7936
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    ll x;
    ll i = 1;
    cin >> x;
    for(; (i * (i + 1)) / 2 < x; i++){
        ;
    }
    cout << i <<  endl;
}


Measured memory_bytes: 3596
#include <stdio.h>
#include <string.h>
#include <ctype.h>


int main(void)
{
	int i,j,k;
	int a,b,x,y,rem;


	scanf("%d %d", &a, &b);
	
	if (a < b)
	{
		x = a;
		y = b;
	}else
	{
		x = b;
		y = a;
	}

	while(1)
	{
		rem = y % x;

		if (rem == 0)
		{
			printf("%d\n", x);
			break;
		}
		y = x;
		x = rem;

	}



	return 0;
}

Measured memory_bytes: 592
#include<iostream>
using namespace std;
typedef long long li;
#define yn(i) print((i)?"YES":"NO")
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  string s; cin >>s;
  string t="AKIHABARA";
  int n=s.size();
  if(n>9){
    yn(0);
    return 0;
  }
  int j=0;
  rep(i,n){
    if(df)print(s[i],t[j]);
    while(t[j]!=s[i]){
      if(t[j]!='A'){
        yn(0);
        return 0;
      }
      j++;
      if(j>=9){
        yn(0);
        return 0;
      }
      if(df)print(s[i],t[j]);
    }
    j++;
  }
  if(j==t.size()){
    yn(1); return 0;
  }
  if(t[j]=='A'){
    j++;
  }
  yn(j==t.size());
}


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

#define int long long
#define forn(i,a,n) for (int i=a; i<n; i++)

signed main(){
	ios::sync_with_stdio(false);
   	cin.tie(0);

	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);

	int n,x,t;
	cin>>n>>x>>t;
	int res=n/x*t;
	int mod=n%x;
	if (mod!=0) res+=t;
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
#include <cassert>
using namespace std;

typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)x)<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define EREP(i,a,b) for(int i=a;i<=b;i++)
#define erep(i,n) EREP(i,0,n)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

int main(void){
  int a,b,c,d,e,f;

  while(cin>>a>>b>>c>>d>>e>>f,a||b||c||d||e||f){
    int A = a + d;
    int B = b + e;
    int C = c + f;
    int res = 0;

    res = max(res,A/3 + B/3 + C/3);
    if(A > 0 && B > 0 && C > 0) res = max(res,(A-1)/3+(B-1)/3+(C-1)/3+1);
    if(A > 1 && B > 1 && C > 1) res = max(res,(A-2)/3+(B-2)/3+(C-2)/3+2);

    cout<<res<<endl;
  }
}

Measured memory_bytes: 872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
ll keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
ll keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
ll ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}

int main(){
  ll N,M; cin>>N>>M;
  ll p[M];
  ll y[M];
  vector<ll> v[N+1];
  REP(i,M){
    cin >> p[i] >> y[i];
    v[ p[i] ].push_back(y[i]);
  }
  REP(i,N+1){
    sort(ALL(v[i]));
  }
  REP(i,M){
    cout << setfill('0') << right << setw(6) << p[i]; 
    cout << setfill('0') << right << setw(6) << lower_bound(ALL(v[p[i]]),y[i])-v[p[i]].begin()+1;
    cout << "\n";
  }
}

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

int main() {
    int n;cin>>n;
    int p[n],q[n],ans=0;
    for(int i=0;i<n;++i){
        cin>>p[i];
        q[i]=p[i];
    }
    sort(q,q+n);
    for(int i=0;i<n;++i){
        if(q[i]!=p[i])ans++;
    }
    if(ans>2)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;

	return 0;
}

Measured memory_bytes: 256
require 'bigdecimal'
input = STDIN.read.split("\n")
Array.new(input.shift.to_i) do
  x1, y1, x2, y2, x3, y3, x4, y4 = input.shift.chomp.split.map { |e| BigDecimal.new(e) }
  if y1 == y2 && y3 == y4
    puts 'YES'
  elsif (y2 - y1) / (x2 - x1) == (y4 - y3) / (x4 - x3)
    puts 'YES'
  else
    puts 'NO'
  end
end

Measured memory_bytes: 8820
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
constexpr long long LINF = 1000100010001000100LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }


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

    ll T, A;
    rep(i, n){
        ll t, a; cin >> t >> a; 
        if(i==0 or t>=T and a>=A) T = t, A = a;
        else if(t < a) {
            ll num = (T+t-1)/t;
            if(num*a>= A) T = num*t, A = num*a;
            else{
                num = (A+a-1)/a;
                T = num*t, A = num*a;
            }
        }else if(t > a){
            ll num = (A+a-1)/a;
            if(num*t >= T) T = num*t, A = num*a;
            else{
                num = (T+t-1)/t;
                T = num*t, A = num*a;
            }
        }else{
            if(T > A) A = T;
            else T = A;
        }
        //cout << "T:" << T << " A:" << A << ln;
    }

    cout << T + A << ln;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
#include<numeric>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
constexpr ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);

void chmin(ll &a, ll b) {
	a = min(a, b);
}
void chmax(ll &a, ll b) {
	a = max(a, b);
}
ll mod_pow(ll a, ll n, ll m = mod) {
	a %= m;
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }
const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };

int trans(int x, int y) {
	return x * 60 + y;
}

void solve() {
	string s; cin >> s;
	rep(i, s.size())if (s[i] == '?')s[i] = 'D';
	cout << s << "\n";
}


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init_f();
	//init();
	//int t; cin >> t; rep(i, t)solve();
	solve();
	stop
		return 0;
}


Measured memory_bytes: 7872
#include<iostream>
#include<string>
using namespace std;
int main() {
	string n, m;
	while (cin >> n >> m&&n != "0"&&m != "0") {
		int h = 0, b = 0;
		bool w[4];
		fill(w, w + 4, false);
		for (int i = 0; i < 4; i++) {
			if (n[i] == m[i]) {
				h++;
				w[i] = true;
			}
		}
		for (int i = 0; i < 4; i++) {
			if (!w[i]) {
				for (int j = 0; j < 4; j++) {
					if (!w[i] && n[i] == m[j])
						b++;
				}
			}
		}
		cout << h << " " << b << endl;
	}
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout <<(#x)<<" is "<<(x)<<endl
#define debug cout <<"hi"<<endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int MOD=1e9+7;
const int INF32=1<<30;
const ll INF64=1LL<<60;

void solve(){
  int x; cin >>x;
  if(x>=30) cout <<"Yes";
  else cout <<"No";
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  solve();
return 0;}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(20);

    int n,m;
    cin>>n>>m;

    cout<<n*(n-1)/2+m*(m-1)/2<<endl;


}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
char s[100],ss[10];
  scanf("%s %s",s,ss);
  if(s[0]==ss[0]){printf("=");}
  else if(s[0]<ss[0]){printf("<");}
                    else if(s[0]>ss[0]){printf(">");}
}

Measured memory_bytes: 128
import numpy as np
import sys

A = []
for i in range(3):
    array = list(map(int, input().split()))
    A.append(array)
N = int(input())
b = []
for i in range(N):
    k = int(input())
    b.append(k)

for k in range(len(b)):
    for i in range(len(A)):
        for j in range(len(A[i])):
            if b[k] == A[i][j]:
                A[i][j] = 0


s_row = np.sum(A, axis=1)
for i in range(3):
    if s_row[i] == 0:
        print('Yes')
        sys.exit()


s_col = np.sum(A, axis=0)
for i in range(3):
    if s_col[i] == 0:
        print('Yes')
        sys.exit()

c = 0
for i in range(3):
    c += A[i][i]
if c == 0:
    print('Yes')
    sys.exit()

c = 0
for i in range(3):
    c += A[3-i-1][i]
if c == 0:
    print('Yes')
    sys.exit()

print('No')

Measured memory_bytes: 12484
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int main(){
    int  n;
    while(cin >> n, n){
        int i = 0, s[15], ap[1024] = {0};
        rep(j,n){
            cin >> s[j];
            ap[s[j]]++;
        }
        int sub[15], ans = 0;;
        while(true){
            rep(j,n){
                sub[j] = ap[s[j]];
            }
            bool c = true;
            rep(j,1024) ap[j] = 0;
            rep(j,n){
                if(s[j] != sub[j]) c = false;
                s[j] = sub[j];
                ap[s[j]]++;
            }
            if(c) break;
            ans++;
        }
        cout << ans << endl;
        rep(j,n){
            if(j) cout << ' ';
            cout << s[j];
        }cout << endl;
    }
    
}

Measured memory_bytes: 1160
<?php
$numbers = fgets(STDIN);
$n = intval($numbers);

for ($j=0; $j < $n; $j++) { 
    # code...
    $numbers = str_split(rtrim(fgets(STDIN)));
    
    sort($numbers);
    $min = '';
    for ($i=0; $i < count($numbers); $i++) { 
        $min .= $numbers[$i];
    }
    
    rsort($numbers);
    $max = '';
    for ($i=0; $i < count($numbers); $i++) { 
        $max .= $numbers[$i];
    }
    print $max - $min;
    print PHP_EOL;
}


Measured memory_bytes: 9232
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

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

	vector<int> v(N), w(N);
	for(int i = 0; i < N; ++i) {
		v[i] = s[i] == 'o' ? 0: 1;
	}

	for(int i = 0; i < 2; ++i) for(int j = 0; j < 2; ++j) {
		w[0] = i;
		w[1] = j;
		for(int k = 1; k < N-1; ++k) {
			if((v[k] + w[k]) % 2 == 0) {
				w[k + 1] = w[k-1];
			} else {
				w[k + 1] = 1 - w[k-1];
			}
		}
		if ((w[0] ^ v[0]) == (w[N-1] ^ w[1])
				&& (w[N-1] ^ v[N-1]) == (w[N-2] ^ w[0])) {
			for(int k = 0; k < N; ++k) {
				cout << (w[k] == 0 ? "S": "W");
			}
			cout << endl;
			return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;

struct Node{
  Node *r,*l,*p;
  int key;
};

Node *root, *NIL;

Node * find(Node *u,int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key)
      u=u->l;
    else u=u->r;
  }
  return u;
}


void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;
  z =(Node *)malloc(sizeof(Node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;
  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->l;
    }
    else{
      x=x->r;
    }
  }
    z->p=y;
  if(y==NIL){
    root=z;
  }
  else{
    if(z->key < y->key){
      y->l=z;
    }
    else{
      y->r=z;
    }
  }
}


void inorder(Node *u){
  if(u==NIL)
    return;
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
}
void preorder(Node *u){
  if(u==NIL)
    return;
  printf(" %d",u->key);
  preorder(u->l);
  preorder(u->r);

}


int main(){
  int n, i, x;
  string com;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    cin>>com;
    if(com[0]=='f'){
      scanf("%d",&x);
      Node *t=find(root,x);
      if(t!=NIL)
	printf("yes\n");
      else
	printf("no\n");
    }
    else if ( com == "insert" ){
      scanf("%d", &x);
      insert(x);
    } else if ( com== "print" ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }
  return 0;
}



Measured memory_bytes: 22028
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 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!=1&&i*i!=n) ret.push_back(n/i);
    }
  }
  return ret;
}

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> V = enum_div(M);
  V.push_back(M);
  sort(V.begin(), V.end());
  reverse(V.begin(), V.end());
  for (int i=0; i<(int)V.size(); i++) {
    if (V[i]*N<=M) {
      cout << V[i] << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3620
#pragma gcc optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i=(ll)(r);i<(ll)(n);++i)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define pb(n) push_back(n)
#define endl '\n'
#define P(x)  cout << #x << " = " << (x) << endl
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = numeric_limits<ll>::max();
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
ll n, m, k, ans, sum, cnt = 0; string s; char c; bool flg;

int main(){
  cin.tie(0);ios::sync_with_stdio(false);
  IN(n);
  vi d(n);
  VIN(d);
  sort(ALL(d));

  FOR(i,0,n-1) {
    if (d[i] == d[i+1]) cnt++;
  }
  OUT(n-cnt);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cassert>
#include <cstring>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

int p[100001];

int main(void) {
    int i, n;
    scanf("%d",&n);
    REP (i,n) scanf("%d",&p[i]);

    int ans = 0;
    REP (i,n) if (p[i] == i + 1) {
        swap(p[i],p[i+1]);
        ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int N, Y;
    cin >> N >> Y;
    Y /= 1000;
    if(10 * N < Y) {
        cout << -1 << " " << -1 << " " << -1 << "\n";
        return 0;
    }
    if(10 * N == Y) {
        cout << N << " " << 0 << " " << 0 << "\n";
        return 0;
    }
    int target = 10 * N - Y;
    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= N; j++) {
            if(i + j > N) continue;
            if(target == 5 * i + 9 * j) {
                cout << N - i - j << " " << i << " " << j << "\n";
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << "\n";
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	int n,x,y;
	cin>>n>>x>>y;
	x--;y--;
	vvi a(n,vi(n));
	rep(i,n){
		rep(j,n){
			if(i<j){
			a[i][j]=abs(i-j);
			if((i>=x&&i<=y)&&(j>=x&&j<=y)){
				a[i][j]=min(a[i][j],(i-x)+1+(y-j));
			}
			if(x>=i&&(j>=x&&j<=y)){
				a[i][j]=min(a[i][j],(x-i)+1+(y-j));
			}
			if(j>=y&&(i>=x&&i<=y)){
				a[i][j]=min(a[i][j],(j-y)+1+(i-x));
			}
			if(i<=x&&y<=j){
				a[i][j]=min(a[i][j],(x-i)+1+(j-y));
			}
			}
			else a[i][j]=100000000;
		}
	}
	map<int,int>d;
	rep(i,n){
		rep(j,n){
			d[a[i][j]]++;
		}
	}
	for(int i=1;i<n;++i){
		cout<<d[i]<<endl;
	}
}


Measured memory_bytes: 16000
//飛ばし

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

#define MAX 10000

int A[2000000];
int C[MAX+1];

void CountingSort(int A[], int n){
  // Count
  for(int i=0; i<n; i++){
    C[A[i]]++;
  }

  // Sort
  int idx=0;
  for(int i=0; i<MAX+1; i++){
    for(int j=0; j<C[i]; j++){
      A[idx++] = i;
    }
  }
}

int main(){

  int n;
  scanf("%d", &n);
  for(int i=0; i<n; i++){
    scanf("%d", &A[i]);
  }

  CountingSort(A, n);

  for(int i=0; i<n; i++){
    printf("%d", A[i]);

    if(i != n-1){
      printf(" ");
    }
    else{
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 11084