akhauriyash/Code-Regression huggingface dataset:
import sys
import math
import string

ALPHABET = string.ascii_lowercase
result = []

def alphabet_decimal(v):
    quotient = math.floor(v / len(ALPHABET))
    surplus = v % len(ALPHABET)
    quotient -= 1 if surplus == 0 else 0
    surplus = len(ALPHABET) if surplus == 0 else surplus
    result.append(surplus)
    if len(ALPHABET) < quotient:
        alphabet_decimal(quotient)
    elif len(ALPHABET) < v:
        result.append(quotient)
    return "".join([ALPHABET[i - 1] for i in reversed(result)])

print(alphabet_decimal(int(input())))

Measured memory_bytes: 9992
n=int(input())
a=list(map(int,input().split()))
f=a[0:n]
l=a[2*n:3*n]
for i in range(n):
    l[i]*=-1


mx=[0]*(n+1)
mn=[0]*(n+1)

import heapq

heapq.heapify(f)
heapq.heapify(l)

mx[0]=sum(f)
for i in range(n):
    x=f[0]
    if x<a[n+i]:
        mx[i+1]=mx[i]-x+a[n+i]
        heapq.heappop(f)
        heapq.heappush(f,a[n+i])
    else:
        mx[i+1]=mx[i]
mn[n]=sum(l)*-1

for i in range(n-1,-1,-1):
    x=l[0]
    if x<a[n+i]*-1:
        mn[i]=mn[i+1]+x+a[n+i]
        heapq.heappop(l)
        heapq.heappush(l,a[n+i]*-1)
    else:
        mn[i]=mn[i+1]
#print(mx,mn)
buf=float('inf')
buf*=-1
for i in range(n+1):
    buf=max(buf,mx[i]-mn[i])
    
print(buf)

Measured memory_bytes: 119848
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)

using lli = long long int;
using namespace std;
struct dijkstra {
    using lli = long long int;
    vector<vector<pair<lli, lli>>> e;
    int n;
    lli inf = 1e18;
    dijkstra(int n) : n(n)
    {
        e.resize(n);
    }
    void add(int a, int b, lli c)
    {
        e[a].push_back(make_pair(b, c));
    }
    void biadd(int a, int b, lli c)
    {
        add(a, b, c);
        add(b, a, c);
    }
    vector<lli> get(int s)
    {
        vector<lli> dist(n, inf);
        dist[s] = 0;
        using p = pair<lli, lli>;
        priority_queue<p, vector<p>, greater<p>> que;
        que.push(make_pair(0, s));
        while (!que.empty()) {
            lli d = que.top().first;
            lli cur = que.top().second;
            que.pop();
            if (dist[cur] < d)
                continue;
            dist[cur] = d;
            for (auto s : e[cur]) {
                lli wei = s.second;
                lli to = s.first;
                if (dist[to] > dist[cur] + wei) {
                    dist[to] = dist[cur] + wei;
                    que.push(make_pair(dist[cur] + wei, to));
                }
            }
        }
        return dist;
    }
};

int h, w;
int get(int x, int y)
{
    return x * w + y;
}
char f[101][101];
bool range(int x, int y)
{
    return 0 <= x and x < h and 0 <= y and y < w;
}
int main()
{
    cin >> h >> w;
    rep(i, h) rep(j, w)
    {
        cin >> f[i][j];
    }
    dijkstra dij(h * w + 10);
    rep(i, h) rep(j, w)
    {
        if (f[i][j] == '.') {
            if (range(i + 1, j) and f[i + 1][j] == '.') {
                dij.biadd(get(i, j), get(i + 1, j), 1);
            }
            if (range(i, j + 1) and f[i][j + 1] == '.') {
                dij.biadd(get(i, j), get(i, j + 1), 1);
            }
        }
    }
    auto res = dij.get(0);
    lli sum = 0;
    rep(i, h) rep(j, w)
    {
        if (f[i][j] == '#')
            sum++;
    }
    cout << (res[get(h - 1, w - 1)] != dij.inf ? h * w - sum - res[get(h - 1, w - 1)] - 1 : -1) << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[n - k] % MOD) % MOD;
}

typedef long long ll;

int main(int argc, char const *argv[])
{
  ll n, k;
  cin >> n >> k;
  vector<vector<ll>> e(n, vector<ll>());
  queue<ll> q;
  queue<ll> bro;
  vector<bool> visit(n, false);
  ll a, b;
  REP(i, n - 1)
  {
    cin >> a >> b;
    e[a - 1].push_back(b - 1);
    e[b - 1].push_back(a - 1);
  }
  COMinit();
  ll res = k;
  bro.push(e[0].size());
  for (auto child : e[0])
  {
    q.push(child);
  }
  q.push(-1);
  bool flag = true;
  bool flag2 = false;
  visit[0] = true;
  while (!q.empty())
  {
    ll node = q.front();
    q.pop();
    if (node == -1)
    {
      flag = false;
      flag2 = false;
      continue;
    }
    visit[node] = true;
    // 自分を更新
    //兄弟の数
    if (!flag2)
    {
      if (flag)
      {
        res *= COM(k - 1, bro.front()) % MOD;
      }
      else
      {
        res *= COM(k - 2, bro.front()) % MOD;
      }
      bro.pop();
    }
    flag2 = true;
    res = res % MOD;
    // 子供をキューへ
    ll tmp = 0;
    for (auto child : e[node])
    {
      if (!visit[child])
      {
        q.push(child);
        tmp++;
      }
    }
    q.push(-1);
    if (tmp != 0)
    {
      bro.push(tmp);
    }
  }
  cout << res % MOD << endl;
  return 0;
}


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

int main(){
	int a[5];
	char c;
	while(cin>>a[0]>>c>>a[1]>>c>>a[2]>>c>>a[3]>>c>>a[4]){
		int b[14];
		for(int i=0;i<14;i++) b[i] = 0;
		for(int i=0;i<5;i++) b[a[i]]++;
		int d[5];
		for(int i=0;i<5;i++) d[i] = 0;
		for(int i=0;i<14;i++) d[b[i]]++;
		bool st = false;
		for(int i=1;i<11;i++){
			int z = 1;
			for(int j=i;j<i+5;j++) z *= b[(j-1)%13+1];
			if(z==1) st = true;
		}
		if(d[4]==1) cout << "four card";
		else if(d[3]*d[2]==1) cout << "full house";
		else if(st) cout << "straight";
		else if(d[3]==1) cout << "three card";
		else if(d[2]==2) cout << "two pair";
		else if(d[2]==1) cout << "one pair";
		else cout << "null";
		cout << endl;
	}
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define vi vector<int>
#define vpii vector<pii>
#define vp3i vector<p3i>
#define vpll vector<pll>
#define vp3l vector<p3l>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() ((rand() << 14)+rand())
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846

int n, m, psa[200][200], dp[2][200][200][200];
char ch;
int32_t main(){
  scanf("%i%i", &n, &m);
  fox1(l, n){
    fox1(l2, m){
      scanf(" %c", &ch);
      psa[l][l2] = (ch=='#')+psa[l][l2-1];
     // cout << psa[l][l2] << ' ';
      //psa2[l][l2] = (ch=='#')+psa[l-1][l2];
    }
    //cout << endl;
  }
  flood(dp);
  fox1(l, n){
    fox1(l2, m){
      for(int l3 = l2; l3 <= m; ++l3){
        if (psa[l][l3] - psa[l][l2-1] == 0 || psa[l][l3] - psa[l][l2-1] == l3-l2+1){
          if (psa[l][l3] - psa[l][l3-1] != psa[l-1][l3] - psa[l-1][l3-1] || l == 1){
            dp[0][l][l2][l3] = l;
          } else {
            dp[0][l][l2][l3] = dp[0][l-1][l2][l3];
          }
        } else {
          dp[0][l][l2][l3] = l+1;
        }
      }
    }
  }
  fox(t, 19){
    flood(dp[(t+1)%2]);
    /*cout << t << endl;
    fox1(l, n){
      fox1(l2, m){
        fox1(l3, m){
          printf("%i %i %i\n", l2, l3, dp[t%2][l][l2][l3]);
        }
      }
      printf("\n");
    }*/
    if (dp[t%2][n][1][m] <= 1){
      cout << t;
      return 0;
    }
    fox1(l, n){
      fox1(l2, m){
        int p = 1;
        for (int l3 = m; l3 >= l2; --l3){
          while(p <l2 && dp[t%2][l][p][l2-1] > dp[t%2][l][l2][l3]) ++p;
          dp[(t+1)%2][l][p][l3] = min(dp[(t+1)%2][l][p][l3], dp[t%2][l][l2][l3]);
        }
      }
      fox1(l2, m){
        int p = m;
        for (int l3 = 1; l3 <= l2; ++l3){
          while(p > l2 && dp[t%2][l][l2+1][p] > dp[t%2][l][l3][l2]) --p;
          dp[(t+1)%2][l][l3][p] = min(dp[(t+1)%2][l][l3][p], dp[t%2][l][l3][l2]);
        }
      }
      fox1(l2, m){
        for (int l3 = l2; l3 <= m; ++l3){
          if (dp[t%2][l][l2][l3] == 1) dp[(t+1)%2][l][l2][l3] = 1;
          else dp[(t+1)%2][l][l2][l3] = min(dp[(t+1)%2][l][l2][l3], dp[t%2][dp[t%2][l][l2][l3]-1][l2][l3]);
        }
      }
    }
  }
  return 1;
}


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

const int mod = 1e9 + 7;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define int long long
#define ll long long
#define vi vector < int >
#define vll vector < ll >
#define pii pair < int , int >
#define ff first
#define tc \
    int ttt; cin >> ttt;\
    while(ttt --)
#define ss second
#define f(i,a,b) for(int i=a;i<b;i++)
#define rev(i,a,b) for(int i=a;i>=b;i--)
#define nl '\n'
#define all(x) x.begin() , x.end()
#define mne min_element
#define mxe max_element
ll gcd(ll x, ll y) {return y == 0 ? x : gcd(y, x % y);}
int logg(ll x , ll y) {if (x == 0) return -1; return logg(x / y, y) + 1;}
ll poww(ll a, ll b, ll m) {
	if (b == 0) return 1;
	ll ans = 1;
	ans = poww(a, b >> 1, m);
	ans = (ans * ans) % m;
	if (b & 1) ans = (ans * a) % m;
	return ans;
}
// Start of code
const int N = 1e5 + 5;
int dp[105][N];
int weight[105];
int val[105];
int n, w;

int solve() {

	memset(dp, 0, sizeof dp);
	dp[1][weight[1]] = val[1];
	int maxg = dp[1][weight[1]];
	f(i, 2, n + 1) {
		f(j, i, w + 1) {
			dp[i][j] = dp[i - 1][j];
			if (weight[i] > j) continue;
			dp[i][j] = max(dp[i][j], val[i] + dp[i - 1][j - weight[i]]);
			maxg = max(maxg, dp[i][j]);
		}
	}
	return maxg;
}

int32_t main() {


	fast;

	cin >> n >> w;

	f(i, 1, n + 1) cin >> weight[i] >> val[i];
	cout << solve() << nl;
}


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

int main() {
    int N, L;
    cin >> N >> L;
    int sum = (L+N) * (L+N-1) / 2 - L * (L-1) / 2;
    if(L < 0 && abs(L) < N){
        cout << sum << endl;
    }
    else if(L < 0){
        cout << sum - (L+N-1) << endl;
    }
    else{
        cout << sum - (L+1-1) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[] args){
        FastScanner sc = new FastScanner();
        int W = sc.nextInt();
        int H = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int r = sc.nextInt();

        if(a-r>=0 && a+r<=W && b-r>=0 && b+r<=H)System.out.println("Yes");
        else System.out.println("No");

    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}



Measured memory_bytes: 24368
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;



int main(void){
    int a,b;
    cin>>a>>b;
    int now = 1;
    int ans = 0;
    while(now<b){
        ans++;
        now = now-1+a;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<string>
#include<algorithm>

int main(void){
    int n;
    std::cin >> n;

    std::map<std::string, int> mp;
    for(int i = 0; i < n; i++){
        std::string s;
        std::cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }

    long long ans = 0;
    for(auto p : mp){
        int temp = p.second;
        ans += (long long) temp * (temp - 1) / 2;
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef vector<int>   vi;
typedef vector<double>   vd;
typedef vector<long long> vll;
typedef vector<pair<int,int> > vii;
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pq priority_queue
#define mii map<int,int>
#define sf1(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define log2(x) (31 - __builtin_clz(x))
#define lcm(x,y) (x*y) / __gcd(x,y)
int inf = (1e9) + 7;
int mod = 998244353;

int main(){
	
	int n;
	sf1(n);
	vi a;
	vi b;
	for (int i = 0; i < n; ++i)
	{
		int x;
		sf1(x);
		a.pb(x);
	}
	for (int i = 0; i < n; ++i)
	{
		int x;
		sf1(x);
		b.pb(x);
	}
	ll acc = 0;
	for (int i = 0; i < n; ++i){
		if(a[i] < b[i]){
			int x = (-a[i] + b[i]+1)/2;
			acc += x;
			a[i] += 2*x;
		}
	}

	ll dif = 0; 
	for (int i = 0; i < n; ++i){
		dif += a[i] - b[i];
	}

	if(dif > acc){
		printf("No\n");
	}
	else
		printf("Yes\n");

}	


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include <algorithm>
#include<vector>
using namespace std;

/* */

int main(){
    // 入力スタンダード
    int k,a,b;
    cin >> k >> a >> b;

    int c = a/k;
    if (c*k == a || (c+1) * k <= b){
        cout<< "OK";
    }else
    {
        cout<< "NG";
    }
    
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>

int main()
{
    int age;
    std::cin >> age;
    if (age == 1) {
        std::cout << "Hello World\n";
    } else if (age == 2) {
        int inp1, inp2;
        std::cin >> inp1;
        std::cin >> inp2;
        std::cout << inp1 + inp2 << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())

def conv_to_bit(clist):
  ret=0
  for c in clist:
    ret+=2**(c-1)
  return ret

alist=[]
cmat=[]
for i in range(M):
  a,b=map(int,input().split())
  alist.append(a)
  clist=list(map(int,input().split()))
  cmat.append(clist)
  
dp=[]
for i in range(M+1):
  dp.append([float("inf")]*(2**N))
dp[0][0]=0
  
for i in range(M):
  cbit=conv_to_bit(cmat[i])
  for j in range(2**N):
    dp[i+1][j]=dp[i][j]

  for j in range(2**N):
    bit_or=j|cbit
    dp[i+1][bit_or]=min(dp[i+1][bit_or],dp[i][j]+alist[i])
    
if dp[-1][-1]==float("inf"):
  print(-1)
else:
  print(dp[-1][-1])

Measured memory_bytes: 118360
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};
#define MAX 100000
int main(){
    int n,m,p;
    vector<int> x;
    while(cin >> n >> m >> p,n|m|p){
        x.resize(n);
        int sum = 0;
        m--;
        int tmp;
        rep(i,n) {
            cin >> x[i];
            sum += x[i];
            if(i == m) tmp = x[i];
        }
        if(tmp == 0) cout << 0 << endl;
        else cout << sum*(100-p)/tmp << endl;
    }
    return 0;
}



Measured memory_bytes: 3148
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 1000000000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    int n;cin>>n;
    V<ll>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    int q;cin>>q;
    while(q--){
        int k;cin>>k;
        cout<<lower_bound(all(a),k)-a.begin()<<" "<<upper_bound(all(a),k)-a.begin()<<endl;
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define pb push_back
#define size(v)  (int) v.size()
#define fast ios_base:: sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
ll power_mod(ll a,ll x){if(x==0) return 1;ll y=power_mod(a,x/2);ll ans=(y*y)%mod; if(x%2) ans=(ans*a)%mod;return ans;}
ll inv(ll a){return power_mod(a,mod-2);}    
ll power(ll a, ll x){ if(x==0) return 1; ll y= power(a,x/2); ll ans=(y*y); if(x%2) ans*=a; return ans;}

bool cmp(pair<ll,ll> a, pair<ll,ll> b){
    return (a.second<b.second);
}


int main(){

ll n;
cin>>n;
vector< pair<ll,ll> > v;
  
for(ll i=0;i<n;i++){
     ll a,b;
     cin>>a>>b;
     v.pb({a-b,a+b});
}
sort(all(v),cmp);
ll count = 1;
ll ed = v[0].second;
for(int i=1;i<n;i++){
   if(v[i].first<ed) continue;
   ed = v[i].second;
   count++;
}
  cout<<count<<endl;

}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n;
  vector<long long> t(n);
  for (int i= 0; i<n; i++) {
    cin >> t[i];
  }
  cin >> m;
  vector<int> p(m);
  vector<int> x(m);
  for (int k = 0; k<m; k++) {
    cin >> p[k] >> x[k];
  }
  long long count = 0;
  for (int i = 0; i<m; i++) {
    count = 0;
    for (int j = 0; j<n; j++) {
      count += t[j];
      if (j == n-1) {
        count += x.at(i) - t.at(p.at(i)-1);
        cout << count << endl;
      }
    }
  }
}

Measured memory_bytes: 3608
#include<iostream>
using namespace std;
int n,m,sum,xi,x[55][55],o[55],a,b,i,flag=1;
int main()
{
	cin>>n>>m;
	for(i=1;i<=m;i++)
	{
		cin>>a>>b;
		o[a]++;
		o[b]++;
		x[a][b]=x[b][a]=1;
	}
	while(1)
	{
		flag=1;
		for(i=1;i<=n;i++)
		{
			if(o[i]==1)
			{
				sum++;
				xi=i;
				flag=0;
				o[i]--;
				break;
			}
		}
		if(flag)break;
		for(i=1;i<=n;i++)
		{
			if(x[xi][i]==1)
			o[i]--;
		}
	}
	cout<<sum;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define range(x,l,r) (l<=x && x<r)
#define fs first
#define sc second
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,int> tri;

int w,h;
int g[10][10];
int rem[10][10];
vector<tri> carpet[10][10];
int depth;

void search(int d){
  if(d==depth)return;

  int y=-1, x=-1, mink = h*w;
  vector<tri> priority;
  rep(i,h)rep(j,w){
    if(rem[i][j] && mink > (int)carpet[i][j].size()){
      y = i; x = j;
    }
  }

  if(y<0){
    depth = d;
    return;
  }

  for(tri t : carpet[y][x]){
    int tmp[10][10];
    for(int i=t.fs.fs;i<t.fs.fs+t.sc;i++){
      for(int j=t.fs.sc;j<t.fs.sc+t.sc;j++){
	tmp[i][j] = rem[i][j];
      }
    }

    for(int i=t.fs.fs;i<t.fs.fs+t.sc;i++){
      for(int j=t.fs.sc;j<t.fs.sc+t.sc;j++){
	rem[i][j] = 0;
      }
    }
    
    search(d+1);

    for(int i=t.fs.fs;i<t.fs.fs+t.sc;i++){
      for(int j=t.fs.sc;j<t.fs.sc+t.sc;j++){
	rem[i][j] = tmp[i][j];
      }
    }
    if(depth == d+1)return;
  }
}

int main(){
  while(cin >> w >> h, w){
    memset(g,0,sizeof(g));
    rep(i,h)rep(j,w){
      cin >> g[i][j];
      rem[i][j] = g[i][j];
      carpet[i][j].clear();
    }

    vector<tri> c;
    rep(i,h)rep(j,w){
      int k = 0;
      while(true){
	if(!range(i+k,0,h) || !range(j+k,0,w))break;
	int f = 1;
	for(int y=i;y<=i+k;y++)f &= g[y][j+k];
	for(int x=j;x<=j+k;x++)f &= g[i+k][x];
	if(!f)break;
	k++;
      }
      if(k)c.push_back( tri(pii(i,j), k) );
    }
    
    rep(i,c.size()){
      bool f = false;
      rep(j,c.size()){
	if(i==j)continue;
	if( range(c[i].fs.fs, c[j].fs.fs, c[j].fs.fs + c[j].sc) &&
	    range(c[i].fs.fs + c[i].sc, c[j].fs.fs, c[j].fs.fs + c[j].sc+1) &&
	    range(c[i].fs.sc, c[j].fs.sc, c[j].fs.sc + c[j].sc) &&
	    range(c[i].fs.sc + c[i].sc, c[j].fs.sc, c[j].fs.sc + c[j].sc+1) ){
	  f = true;
	  break;
	}
      }

      if(f){
	c.erase(c.begin()+i);
	i--;
      }
    }

    rep(i,c.size()){
      for(int y=c[i].fs.fs;y<c[i].fs.fs+c[i].sc;y++){
	for(int x=c[i].fs.sc;x<c[i].fs.sc+c[i].sc;x++){
	  carpet[y][x].push_back(c[i]);
	}
      }
    }

    int ans = 0;
    while(true){
      bool f = false;
      rep(i,h)rep(j,w){
	if(rem[i][j] && carpet[i][j].size()==1){
	  f = true;
	  ans++;
	  tri t = carpet[i][j][0];
	  for(int y=t.fs.fs;y<t.fs.fs+t.sc;y++){
	    for(int x=t.fs.sc;x<t.fs.sc+t.sc;x++){
	      rem[y][x] = 0;
	    }
	  }
	}
      }
      if(!f)break;
    }

    depth = h*w;
    search(0);
    
    cout << ans + depth  << endl;
  }
}

Measured memory_bytes: 1220
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include<bits/stdc++.h>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>*/

#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define rep(a, b, c) for(int a = b; a <= c; ++a)
#define per(a, b, c) for(int a = b; a >= c; --a)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
//using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
/*typedef tree<pair<int, int>, 
null_type, less<pair<int, int>>, 
rb_tree_tag, tree_order_statistics_node_update>
ordered_set;*/
//find_by_order() order_of_key()

const double eps = 1e-7;
const int mod = 1e9+7, MXN = 5e5+17;
const int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};

template<typename T>inline bool updmin(T &a, const T &b) {return a > b ? a = b,1 : 0;}
template<typename T>inline bool updmax(T &a, const T &b) {return a < b ? a = b,1 : 0;}

int32_t main() { _
#ifdef DanQQQQQ
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	string s; cin >> s;
	int ans = 0, p = 0, g = 0;
	rep(i,0,sz(s)-1) {
		if (g>p) ++p, ans += (s[i] == 'g');
		else ++g, ans -= (s[i] == 'p');
	}
	cout << ans << endl;
	return 0;
}

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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(ll)(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) reps(i,0,((n)+1))
#define repst(i,s,n) reps(i,s,((n)+1))
#define reprt(i,n,t) for(ll (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ');}}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a[100], s, t;

signed main() {
	cin >> n;
	rep(i,n) cin >> a[i];
	sort(a, a+n);
	bool f = true;
	repr(i,n-1) {
		if (f) s += a[i];
		else t += a[i];
		f = 1-f;
	}
	cout << s-t << ln;
}

Measured memory_bytes: 256
S = gets.chomp.chars
LR = [0] * S.size

l_len = 0
S.size.times{|i|
  if S[i] == ?L
    l_len += 1
    LR[i] = -l_len
  else
    l_len = 0
  end
}

r_len = 0
S.size.times.reverse_each{|i|
  if S[i] == ?R
    r_len += 1
    LR[i] = r_len
  else
    r_len = 0
  end
}

ans = [0] * S.size
S.size.times{|i|
  sign = LR[i] > 0 ? 1 : -1
  idx = i + LR[i] - LR[i].abs % 2 * sign
  ans[idx] += 1
}
puts ans*" "

Measured memory_bytes: 12152
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
--import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Fixed
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
import System.IO
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete

toDomino [x,y] = (digitToInt x, digitToInt y)

f ds = length ds == 1 || all ((>0) . (degs!)) loops && (oddcount == 0 || oddcount == 2)
  where
    (es, loops) = fmap (map fst) $ partition (uncurry (/=)) ds
    degs = array (0,6) $ ([(x,0) | x <- [0..6]]++) $ map (fnTuple (head, length)) $ group $ sort $ concat [[x, y] | (x,y) <- es] :: Array Int Int
    oddcount = length $ filter odd $ elems degs

main = do
    eof <- isEOF
    unless eof $ do
        n <- getInt
        ds <- map toDomino . words <$> getLine
        putStrLn $ cond "Yes" "No" $ f ds
        main


Measured memory_bytes: 4048
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pll;

const int maxN = 1e5 + 5;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll gcd(ll a, ll b){return !b ? a : gcd(b, a % b);}
ll modP(ll a, ll b) {return (!b ? 1 : (modP(a, b / 2) * modP(a, b / 2) * (b % 2 ? a : 1)) % MOD);}

ll x, y, i, g;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> x >> y;
	if (x % y == 0){
		return cout << -1 << endl, 0;
	}
	g = gcd(x, y);
	x /= g;
	y /= g;
	for (i = 2; i < INF; i++){
		if ((x * i) % y != 0){
			return cout << i * x * g << endl, 0;
		}
	}
	cout << -1 << endl;
	return 0;
}



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

int main()
{
    int n ;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int min1=0 ,min2=0,min[n];
    min[0]=0;
    min[1]=abs(a[0]-a[1]);
    for(int i=2;i<n;i++)
    {
        min1=min[i-1]+abs(a[i]-a[i-1]);
        min2=min[i-2]+abs(a[i]-a[i-2]);

        if(min1>min2)
        { min[i]=min2;
        }
        else
        { min[i]=min1;
        }
    }

    cout<<min[n-1];

}


Measured memory_bytes: 1024
n = gets.to_i
a,b,c = [],[],[]

n.times do |i|
    ai,bi = gets.split.map &:to_i
    a[i] = ai
    b[i] = bi
    c[i] = ai,bi
end

sorted = c.sort{|x,y|y[0] + y[1] <=> x[0] + x[1]}

takahasi = 0
aoki = 0

n.times do |i|
    if i % 2 == 0
        takahasi += sorted[i][0]
    else
        aoki += sorted[i][1]
    end
end

puts takahasi - aoki

Measured memory_bytes: 12684
#include <bits/stdc++.h>
using namespace std;
int main(void){
    pair<string, int> t[1010];
    int i;
    for(i=0; cin >> t[i].first >> t[i].second; i++);
    sort(t, t+i);
    cout << t[0].first << "\n";
    cout << t[0].second;
    for(int j=1; j<i; j++){
        if(t[j-1].first==t[j].first){
            cout << " " << t[j].second;
        }
        else{
            cout << "\n";
            cout << t[j].first << "\n";
            cout << t[j].second;
        }
    }
    cout << "\n";
}



Measured memory_bytes: 3064
#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 << "No\n";
  else cout << "Yes\n";
}

Measured memory_bytes: 256
s=input()
u,l=int(s[:2]),int(s[2:])
if 1<=u<=12:
    if 1<=l<=12:
        print('AMBIGUOUS')
        exit()
    else:
        print('MMYY')
        exit()
if 1<=l<=12:
    print('YYMM')
    exit()
print('NA')


Measured memory_bytes: 2940
import java.io.*;
import java.util.*;
import java.util.stream.*;

class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
	static final int INF = 1_000_000_000; // 10^9 
	static int mod = 1000000007; 
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int k = saori.saori_hayami();
		long ans = 0;
		long num1 = 0;
		long num2 = 0;
		for(int i = 0;i < k; i++){
			num1= (num1 +i)%MOD;
		}
		for(int i = n;i > n-k; i--){
			num2= (num2 +i)%MOD;
		}
		for(int i = k;i <= n+1;i++){
			ans += (num2-num1+1)%MOD;
			num1 = (num1+i)%MOD;
			num2 = (num2+n-i)%MOD;
		}
		
		ans = ans%MOD;
		if(ans < 0){
			while(ans <= 0){
				ans += mod;
			}
		}
		System.out.println(ans%MOD);
		saori.close();
	}
	
}
class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 32536
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 150000;

int main() {
    int n, p;
    VI primes, d(N,1);
    FOR(i,2,N-1){
        if (!d[i]) continue;
        primes.push_back(i);
        int x = 2*i;
        while (x < N){
            d[x] = 0;
            x += i;
        }
    }
    while (cin >> n >> p && p >= 0){
        VI cand;
        int i = 0;
        while (primes[i] <= n) i++;
        FOR(j,i,i+p) FOR(k,i,j){
            cand.push_back(primes[j]+primes[k]);
        }
        sort(cand.begin(), cand.end());
        cout << cand[p-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 3424
#include <bits/stdc++.h>
using namespace std;
#define mem(x,val) memset(x,val,sizeof(x)) 
typedef long long ll;

int dp[4][100005];
int a[4][100005];

int n;
int cal(int prev,int i)
{
    if(i>n)return 0;

    if(dp[prev][i]!=-1)return dp[prev][i];
    int ans=0;
    for(int j=1;j<=3;j++){
        if(j!=prev){
            ans=max(ans,cal(j,i+1)+a[j][i]);
        }
    }
    return dp[prev][i]=ans;
   
}
int main()
{
    mem(dp,-1);
    cin >>n;
    for(int i=1;i<=n;i++){
        cin >>a[1][i]>>a[2][i]>>a[3][i];
    }
    cout << cal(0,1)<<endl;
    return 0;
    
    
}

Measured memory_bytes: 9216
/* 7.1 マージソート ALDS1_5_B: Merge Sort
n個の整数を含む数列Sを上の疑似コードに従ったマージソートで昇順に整列するプログラムを作成してください。また、mergeにおける比較回数の総数を報告してください。
コンパイル g++ -o alds1_5_b.exe alds1_5_b.cpp -Wall

入力 1行目にn、2行目にSを表すn個の整数が与えられます
出力 1行目に整列済の数列Sを出力してください。数列の隣り合う要素は1つの空白で区切ってください。2行目に比較回数を出力してください。
制約 n<=500,000 , 0<=Sの要素<=10^9

実行 alds1_5_b.exe
入力例
  10
  8 5 9 2 6 3 7 1 10 4
出力例
  1 2 3 4 5 6 7 8 9 10
  34
*/

#include <iostream>
/* C++のstdio.hみたいなもの、cin (scanf), cout (printf) のためにincludeします。 */
using namespace std;
/* 名前空間にstdを指定する。毎回、std::cin , std::cout と記述するのはうっとおしいので省略するため。*/

#define MAX 500000
#define SENTINEL 2000000000 // 番兵

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[],int left, int mid, int right) {
  int n1 = mid -left;
  int n2 = right - mid;
// C++forループ専用のint型を宣言できる
// ループの中のみ有効なので安全
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid + i];
  L[n1] = R[n2] = SENTINEL;
  int i=0, j=0;
  for(int k=left; k<right; k++) {
    cnt++;
    if(L[i]<=R[j]) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[],int left,int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,left,mid);
    mergeSort(A,mid, right);
    merge(A,left,mid,right);
  }
}

int main(void) {
  int A[MAX], n, i;
  cnt = 0;

	cin >> n; // scanf("%d",&n);
  for(i=0;i<n;i++) cin >> A[i];

  mergeSort(A, 0, n);
  for(i=0;i<n;i++) {
    if(i)cout << " ";
  	cout << A[i]; // printf("%d",A[i]);
  }
  cout << endl; // endlは改行

  cout << cnt << endl; // printf("\n");

  return 0;
}



Measured memory_bytes: 7004
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
template<u32 M = 1000000007>
struct modint{
    u32 val;
    modint(): val(0){}
    template<typename T>
    modint(T t){t %= (T)M; if(t < 0) t += (T)M; val = t;}

    modint pow(ll k) const {
        modint res(1), x(val);
        while(k){
            if(k&1) res *= x;
            x *= x;
            k >>= 1;
        }
        return res;
    }
    template<typename T>
    modint& operator=(T t){t %= (T)M; if(t < 0) t += (T)M; val = t; return *this;}
    modint inv() const {return pow(M-2);}
    modint& operator+=(modint a){val += a.val; if(val >= M) val -= M; return *this;}
    modint& operator-=(modint a){if(val < a.val) val += M-a.val; else val -= a.val; return *this;}
    modint& operator*=(modint a){val = (u64)val*a.val%M; return *this;}
    modint& operator/=(modint a){return (*this) *= a.inv();}
    modint operator+(modint a) const {return modint(val) +=a;}
    modint operator-(modint a) const {return modint(val) -=a;}
    modint operator*(modint a) const {return modint(val) *=a;}
    modint operator/(modint a) const {return modint(val) /=a;}
    modint operator-(){return modint(M-val);}
    bool operator==(const modint a) const {return val == a.val;}
    bool operator!=(const modint a) const {return val != a.val;}
    bool operator<(const modint a) const {return val < a.val;}
};
using mint = modint<MOD>;


class Factorial {
    using mint = modint<MOD>;
    vector<mint> facts, factinv;

public:
    explicit Factorial(int n) : facts(static_cast<u32>(n+1)), factinv(static_cast<u32>(n+1)) {
        facts[0] = 1;
        for (int i = 1; i < n+1; ++i) facts[i] = facts[i-1]*mint(i);
        factinv[n] = facts[n].inv();
        for (int i = n-1; i >= 0; --i) factinv[i] = factinv[i+1] * mint(i+1);
    }

    mint fact(int k) const {
        if(k >= 0) return facts[k]; else return factinv[-k];
    }

    mint operator[](const int &k) const {
        if(k >= 0) return facts[k]; else return factinv[-k];
    }

    mint C(int p, int q) const {
        if(q < 0 || p < q) return 0;
        return facts[p] * factinv[q] * factinv[p-q];
    }

    mint P(int p, int q) const {
        if(q < 0 || p < q) return 0;
        return facts[p] * factinv[p-q];
    }

    mint H(int p, int q) const {
        if(p < 0 || q < 0) return 0;
        return q == 0 ? 1 : C(p+q-1, q);
    }
};


using mint = modint<MOD>;
int main() {
    int n, k;
    cin >> n >> k;
    Factorial f(2*n);
    mint ans = 0;
    for (int i = max(1, n-k); i <= n; ++i) {
        ans += f.C(n-1, i-1)*f.C(n, i);
    }
    cout << ans.val << "\n";
    return 0;
}

Measured memory_bytes: 3328
#include <cstdio>

int main (int argc, char const* argv[])
{
	
	int coin[6]={500,100,50,10,5,1};
	
	int a,r=0,m;
	
	while(true){
	
	scanf("%d",&m);
	if(m==0) break;
	m=1000-m;
	r=0;
	for(int i=0;i<6;i++){
		a=m/coin[i];
		r+=a;
		m-=(a*coin[i]);
	}
	
	
	printf("%d\n",r);
	
	}
	return 0;
}

Measured memory_bytes: 1028
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::collections::*;

fn main() {
    input! {
        k:i64,
    }
    let ans = (0..k)
        .scan(0, |acc, x| {
            *acc = (*acc + 7 * modpow(10, x, k) % k) % k;
            Some(*acc)
        })
        .enumerate()
        .find(|(_, x)| x % k == 0);
    if let Some((n, _)) = ans {
        println!("{}", n + 1);
    } else {
        println!("{}", -1);
    }
}

fn modpow(a: i64, x: i64, m: i64) -> i64 {
    if x == 0 {
        1
    } else if x % 2 != 0 {
        a * modpow(a, x - 1, m) % m
    } else {
        let half = modpow(a, x / 2, m);
        half * half % m
    }
}

Measured memory_bytes: 2116
class UnionFind
  def initialize(size)
    @rank = Array.new(size, 0)
    @parent = Array.new(size, &:itself)
    $count = Array.new(size, 1)
  end

  def unite(id_x, id_y)
    x_parent = get_parent(id_x)
    y_parent = get_parent(id_y)
    return if x_parent == y_parent
    
    sumcount=$count[x_parent]+$count[y_parent]
    $count[x_parent]=sumcount
    $count[y_parent]=sumcount

    if @rank[x_parent] > @rank[y_parent]
      @parent[y_parent] = x_parent
    else
      @parent[x_parent] = y_parent
      @rank[y_parent] += 1 if @rank[x_parent] == @rank[y_parent]
    end
  end

  def get_parent(id_x)
    @parent[id_x] == id_x ? id_x : (@parent[id_x] = get_parent(@parent[id_x]))
  end

  def same_parent?(id_x, id_y)
    get_parent(id_x) == get_parent(id_y)
  end
  
  def self.sayparent
    puts @parent
  end
end

n,m=gets.split.map(&:to_i)
a, b = m.times.map{gets.split.map(&:to_i)}.transpose
union=UnionFind.new(n)
a=a.reverse
b=b.reverse
max=n*(n-1)/2
answer=0
answerArray=[]

m.times{|i|
    if union.same_parent?(a[i]-1,b[i]-1)
        answerArray<<answer
    else
         answer+=$count[union.get_parent(a[i]-1)]*$count[union.get_parent(b[i]-1)]
         union.unite(a[i]-1,b[i]-1)
         answerArray<<answer
    end
}


answerArray=answerArray.reverse

ll=answerArray.length
i=1

(ll-1).times{
    puts max-answerArray[i]
    i+=1
}

puts max

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

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)

const int S_MAX = 100000;
const int Q_MAX = 100000;

char S[S_MAX + 1];
char T[S_MAX + 1];
int q;

int N, M;
int sa[S_MAX + 1];
int sb[S_MAX + 1];
int ta[S_MAX + 1];
int tb[S_MAX + 1];

void solve() {
  N = strlen(S);
  M = strlen(T);
  REP(i, N) {
    sa[i + 1] = sa[i] + (S[i] == 'A' ? 1 : 0);
    sb[i + 1] = sb[i] + (S[i] == 'B' ? 1 : 0);
  }
  REP(i, M) {
    ta[i + 1] = ta[i] + (T[i] == 'A' ? 1 : 0);
    tb[i + 1] = tb[i] + (T[i] == 'B' ? 1 : 0);
  }
  int a, b, c, d;
  REP(i, q) {
    scanf("%d%d%d%d", &a, &b, &c, &d);
    int sac = sa[b] - sa[a - 1];
    int sbc = sb[b] - sb[a - 1];
    int tac = ta[d] - ta[c - 1];
    int tbc = tb[d] - tb[c - 1];
    bool ans = ((sac * 2 + sbc) % 3 == (tac * 2 + tbc) % 3);
    printf("%s\n", ans ? "YES" : "NO");
  }
}

void input() {
  scanf("%s", S);
  scanf("%s", T);
  scanf("%d", &q);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 2304
#include<stdio.h>

int main(){
  int i,j,C=0,n,q,left  ,right,mid;
  int S[100000],T[50000];

  scanf("%d",&n);
  for(i = 0; i < n; i++) scanf("%d",&S[i]);
  scanf("%d",&q);
  for(i = 0; i < q; i++) scanf("%d",&T[i]);

 
  for( i = 0; i < q;i++){
    right = n; left = 0;
    while(left < right ){
      mid = (left + right)/2;
    if(S[mid] == T[i]){
      C++;
      break;
    }
    else if(T[i] < S[mid]) right = mid;
    else left = mid + 1;
      }
  }
  printf("%d\n",C);
  return 0;
}



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

using namespace std;

#define ll long long
#define mod 1000000007

void solve(){
	string s;
	cin>>s;
	int sum = 0;
	for(int i = 0;i<s.size();i++){
		sum += (s[i] - '0');
	}
	if(sum % 9 == 0){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
}

int main(){
	int t = 1;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 3748
#include <iostream>
using namespace std;
main() {
	int n, a[10000];
	cin >> n;
	for (int i=0; i<n; i++) cin >> a[i];
	int mi = a[0], ma = a[0];
	long int sum = 0;
	for (int i=0; i<n; i++) {
		mi = min(mi, a[i]);
		ma = max(ma, a[i]);
		sum += a[i];
	}
	cout << mi << " " << ma << " " << sum << endl;
}

Measured memory_bytes: 3116
#include <iostream>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
    string s;
    cin >> s;
    ll n[26] = {};
    for(int i=0;i<s.size();i++) {
        n[s[i]-'a']++;
    }

    vector<ll> v;
    for(ll i=0;i<26;i++) {
        if(n[i] != 0)
            v.push_back(n[i]);
    }
    ll ans = 0;
    if(v.size() <= 1) {
        ans = 1;
    } else {
        for(int i=0;i<v.size()-1;i++) {
            for(int j=i+1;j<v.size();j++) {
                ans += v[i] * v[j];
            }
        }
        ans++;
    }
    cout << ans << endl;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  // For float output.
  cout << fixed << setprecision(10);

  int n, l;
  cin >> n >> l;
  vector<int> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }
  double x_sum = 0;
  double y_sum = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      double t1 = 2.0 * M_PI / l * xs[i];
      double t2 = 2.0 * M_PI / l * xs[j];

      double s1 = (t1 + t2) / 2.0 + M_PI;
      double s2 = (t1 + t2) / 2.0;

      int k1 = j - i - 1;
      int k2 = n - 2 - k1;

      x_sum += k1 * cos(s1);
      y_sum += k1 * sin(s1);
      x_sum += k2 * cos(s2);
      y_sum += k2 * sin(s2);
      if (DEBUG) cout << x_sum << " " << y_sum << endl;
    }
  }

  x_sum /= 1.0 * n * (n - 1) / 2.0 * (n - 2) / 3.0;
  y_sum /= 1.0 * n * (n - 1) / 2.0 * (n - 2) / 3.0;
  cout << x_sum << " " << y_sum << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n); for(ll i = 0; i < (ll)n; i++)
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; }

int main() {
  ll n,d;
  cin >> n >> d;
  if(n%(1+d*2) == 0)
    cout << n/(1+d*2)<< endl;
  else
    cout << 1+n/(1+d*2)<< endl;
}

Measured memory_bytes: 3552