akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int max = 0;
  int min = 1000000001;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    if (A > max) max = A;
    if (A < min) min = A;
  }
  cout << max - min << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

#include <string>

#include <vector>
#include <list>
#include <map>

#include <algorithm>
#include <utility>

using namespace std;

int main(const int argc, const char **argv){
  int N;
  scanf("%d¥n", &N);

  vector<int> input(N);
  for(int i = 0; i < N; i++){
    scanf("%d¥n", &input[i]);
  }

  map<int, int> map;
  pair<int, int> first(0, 0), second(0, 0);

  for(int i = 0; i < N; i++){
    map[input[i]]++;
    if(first.second < map[input[i]]){
      first = make_pair(input[i], map[input[i]]);
    }else if(second.second < map[input[i]]){
      second = make_pair(input[i], map[input[i]]);
    }
  }

  /*
  cout << "first\t" << first.first << endl;
  cout << "second\t" << second.first << endl;
  */

  int odd_first = 0, odd_second = 0, even_first = 0, even_second = 0;

  for(int i = 0; i < N; i++){
    if(i % 2 == 1){
      if(input[i] == first.first){
        odd_first++;
      }else if(input[i] == second.first){
        odd_second++;
      }
    }else{
      if(input[i] == first.first){
        even_first++;
      }else if(input[i] == second.first){
        even_second++;
      }
    }
  }

  /*
  cout << "first\t" << odd_first << endl;
  cout << "second\t" << odd_second << endl;

  cout << "first\t" << even_first << endl;
  cout << "second\t" << even_second << endl;
  */

  int cost1 = ((input.size() / 2) - odd_first) + ((input.size() / 2) - even_second);
  int cost2 = ((input.size() / 2) - even_first) + ((input.size() / 2) - odd_second);

  int ans = min(cost1, cost2);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
    int y, m, d;
    char c1;
    cin >> y >> c1 >> m >> c1 >> d;
    cout << (m <= 4 ? "Heisei" : "TBD") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef vector<vector<int>> Graph;

int main() {

	int a;
	cin >> a;

	long long ans = 0;
	rep(i, a)
		ans += i;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(a) a.begin(), a.end()
typedef long long int ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;

    int c = n;
    if (c % 2 != 0) {
        c = c / 2 + 1;

    } else {
        c /= 2;
    }

    if (c - k >= 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repA(a,i,n) for(int i=a;i<n;i++)
#define trav(a,x)for(auto &a: x)
#define fll(a) memset(a,0,sizeof(a));
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define itr(it,x) for(auto it=x.begin();it!=x.end();it++)
typedef long long ll;
typedef long double ld;
typedef pair<int,int>pii;
typedef vector<int>vi;
typedef map<int,int>ma;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
void fopen()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);	
}
int main()
{
//	fopen();
	char c,d;
	cin>>c;
	d=c+1;
	cout<<d;

}


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

int main() {
	string a,b;
	cin >> a >>b;
	int z=a.length();
	int o=0;int i;
	for(i=0;i<z;i++)
	{
	    if(a[i]!=b[i])
	    o++;
	}
	cout<< o;
	return 0;
}

Measured memory_bytes: 3848
#include <string>
#include <vector>
#include <cstring>
#include <algorithm>
#include <iostream> 
#include <cmath>
#include <map>
#include <queue>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
const ll MOD=ll(1e9+7);
 
//repetition
#define REP(i,n)  for(ll i=0;i<n;i++)
 
ll P_POW(ll i, ll n) {
  if(n==0) return 1;
 
  n--;
  ll rep = i;
 
  while(n) {
    rep = rep * i;
    n--;
  }
  return rep;
} 
 
unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
 
unsigned binarySearch(ll target, ll max, ll min) {
  while((max - min) > 1) {
      if((max + min)/2 > target) {
        max = (max + min)/2;
        min = min;
      } else {
        max = max;
        min = (max + min)/2;
      }
    }
}
 
ll solve(ll n) {
    if (n % 2 == 1) return 0;
 
    ll res = 0;
    n /= 2;
    int c = 1;
 
    while ((ll) n/((ll)pow(5,c))) {
      res += n/P_POW(5,c);
      c++;
    }
    return res;
}
 
void f(int rest, string s) {
  char abc[] = "abc";
  if(rest == 0) {
    cout << s << endl;
  } else {
    for(int i=0; i < 3; i++) {
      f(rest - 1, s+abc[i]);
    }
  }
} 
 
int main() {
  ll n;
  cin >> n;
  // vector<vector<ll>> a(n ,vector<ll>{2,0});
  // vector
  // vector<ll> s(n,0);
  // vector<vector<ll>> v;
  // map<ll,ll> m;
  // priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
  // vector<pair<ll, ll>> epv(n, {0, 0});
  
  /* iterator
  for(auto&& m: em) {
    epv.push_back({ m.second, m.first });
  }
  */

  vector<ll> v(10000010, 0);

  REP(i, 10000000) {
    if(i == 0) {
      v[i] = 1;
    } else {
      v[i] = v[i-1] + (i+1);
    }
  }

  ll total = n;
  ll max = n;
  vector<ll> s;

  while(total != 0) {
    REP(i, v.size()) {
      if(v[i] >= total) {
        max = (i+1);
        total -= max;
        s.push_back(max);
        break;
      }
    }
  }

  sort(s.begin(), s.end());

  REP(i, s.size()) {
    cout << s[i] << endl;
  }

}



Measured memory_bytes: 78464
#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

const int MAX_N = 1000000;

int num[MAX_N * 2 - 1];
int dat[MAX_N];

struct SegTree {
  int n;
  int size, lim;
  map<int, int> mp;
  SegTree(int _n, int lim) : lim(lim) {
    for (n=1; n<_n; n*=2);
    fill(num, num+2*n-1, 0);
    fill(dat, dat+n, -1);
    size = 0;
  }
  void add(int a) {
    int k = size++;
    dat[k] = a;
    mp[a] = k;
    k += n - 1;
    while(1) {
      num[k]++;
      if (k==0) break;
      k = (k-1) / 2;
    }
    lim--;
    if (lim<0) {
      del2(0);
    }
  }
  void del2(int index) {        // cÁÄ¢ézñÌindexðó¯æÁÄÁ
    del(q(0, index));
  }
  void del(int k) {             // datÅÌindexðó¯æÁÄÁ
    dat[k] = -1;
    k += n-1;
    while(1) {
      num[k]--;
      if (k==0) break;
      k = (k-1) / 2;
    }
    lim++;
  }
  int query(int index) {        // cÁÄ¢ézñÌindexÔÚÌf[^ðæ¾
    return dat[q(0, index)];
  }
  int q(int a, int index) {     // cÁÄ¢éÅindexÔÚÌf[^ÌdatÅÌindexðæ¾
    if (a >= n-1) return a-n+1;
    if (index < num[a*2+1]) return q(a*2+1, index);
    return q(a*2+2, index-num[a*2+1]);
  }
  void print() {
    REP(i, n) {
      cout << dat[i] << " ";
    }cout << endl;
    REP(i, n*2-1)
      cout << num[i] << " ";
    cout << endl;
  }
};

int main() {
  int q, lim;
  while(cin >> q >> lim, q||lim) {
    SegTree seg(400000+2, lim);
    REP(i, q) {
      int query, x;
      cin >> query >> x;
      if (query == 0) {
        seg.add(x);
      } else if (query == 1) {
        seg.del2(x-1);
      } else if (query == 2) {
        cout << seg.query(x-1) << endl;
      } else {
        seg.del(seg.mp[x]);
      }
      // cout << "i = " << i << endl;
      // seg.print();
    }
    cout << "end" << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll M=1000000007;
const ll N=200010;
ll n,a,b,tot,r,ca,cb;
ll in[N],jc[N],jcin[N];
ll quickex(ll base,ll exp,ll mod){
	if(!exp) return 1;
	ll t=quickex(base,exp/2,mod)%mod;
	if(exp%2==0) return t*t%mod;
	if(exp%2==1) return t*t%mod*base%mod;
}
int main()
{
    scanf("%lld%lld%lld",&n,&a,&b);
    tot=quickex(2,n,M)-1;
    if(n>200000) r=200000;
    else r=n;
    jc[1]=in[1]=jcin[1]=1;
    for(int i=2;i<=r;++i){
    	jc[i]=jc[i-1]*i%M;
	}
	for(int i=2;i<=r;++i){
		in[i]=(M-M/i*in[M%i]%M)%M;
	}
	for(int i=2;i<=r;++i){
		jcin[i]=jcin[i-1]*in[i]%M;
	}
	ca=1;cb=1;
	for(int i=n;i>n-a;--i){
		ca*=i;ca%=M;
	}
	for(int i=n;i>n-b;--i){
		cb*=i;cb%=M;
	}
	ca*=jcin[a];ca%=M;
	cb*=jcin[b];cb%=M;
	printf("%lld",(tot+2*M-ca-cb)%M);
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repi(i,x,n) for(ll i=x;i<(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
//cin.tie(0);
//ios::sync_with_stdio(false);

ll dp[61][2][2][2]={};

signed main(){
    ll l,r,ans=0;cin>>l>>r;
    dp[60][1][1][0]=1;

    for(int i=60;0 < i;i--)
    {
        int lb=(l>>(i-1) & 1),rb=(r>>(i-1)&1);
        rep(j,2){
            rep(k,2){
                rep(s,2){

                    rep(x,2){
                        rep(y,2){
                            int nj=j,nk=k,ns=s;

                            if(x && !y)continue;//x==1 y==0
                            if(!s && (x!=y))continue;

                            if(x && y)ns=1;

                            if(j){
                                if(lb && !x)continue;
                                else if(!lb && x)nj=0;

                            }
                            if(k){
                                if(!rb && y)continue;
                                else if(rb == !y)nk=0;
                            }

                            dp[i-1][nj][nk][ns]+=dp[i][j][k][s];
                            dp[i-1][nj][nk][ns]%=mod;

                        }
                    }
                }
            }
        }
         
    }

    rep(j,2)rep(k,2)rep(s,2){
        ans+=dp[0][j][k][s];
        ans%=mod;
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll; typedef long double ld;
const int INF32 = 1e9+10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S; cin >> S;
  if (S.length() == 2)
    cout << S << endl;
  else
    cout << S[2] << S[1] << S[0] << endl;
}


Measured memory_bytes: 256
n = int(input())
reds = []
for i in range(n):
    reds.append(tuple(map(int, input().split())))
reds = sorted(reds, key=lambda tup: tup[1], reverse=True)
#print(reds)

blues = []
for i in range(n):
    blues.append(tuple(map(int, input().split())))
#print(blues)
blues = sorted(blues, key=lambda tup: tup[0])
#print(blues)

count = 0
for b in blues:
    tmp = []
#    print(len(reds))
    for i in range(len(reds)):
        r = reds[i]
        if b[0] > r[0] and b[1] > r[1]:
            tmp.append(i)
            break
            
    if len(tmp) > 0:
        del reds[tmp[0]]
        count += 1

print(count)


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

int main() {
  int h,w,k,f=0;
  string word;
  bool flag;
  cin>>word;
  vector<vector<int>> sss(h,vector<int>(w));
  vector<int> a(k),b(k);
  char x;
  
  if (word== "SUN")cout<<7<<endl;
  else if(word== "MON")cout<<6<<endl;
  else if(word== "TUE")cout<<5<<endl;
  else if(word== "WED")cout<<4<<endl;
  else if(word== "THU")cout<<3<<endl;
  else if(word== "FRI")cout<<2<<endl;
  else if(word== "SAT")cout<<1<<endl;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;


const int maxn = 1e5 + 10;
const ll inf = 1e10;

int n, m;
ll a[maxn][2]; // color, val
bool viz[maxn];
vector<pair<ll,int>> g[maxn];

void dfs(int at) {
    viz[at] = true;
    for (auto ed: g[at]) {
	int to = ed.second;
	ll s = ed.first;
	if (viz[to]) continue;
	a[to][0] = -a[at][0];
	a[to][1] = s - a[at][1];
	dfs(to);
    }
}



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

    cin>>n>>m;
    for (int i=0; i<m; i++) {
	int u,v,s; cin>>u>>v>>s;
	g[u].push_back({s,v});
	g[v].push_back({s,u});
    }


    a[1][0] = 1;
    dfs(1);

    ll lo = 1;
    ll hi = inf;

    ll ans = -1; //non-bipartite answer

    for (int i=1; i<=n; i++) {
	if (a[i][0] == -1) {
	    hi = min(hi, a[i][1]-1);
	} else {
	    lo = max(lo, 1-a[i][1]);
	}

	for (auto ed: g[i]) {
	    ll s = ed.first;
	    int to = ed.second;
	    if (a[i][0]+a[to][0] == 0) { //-1,1
		if (a[i][1]+a[to][1] != s) {
		    out(0);
		}
	    } else {
		// not bipartite
		ll cur = s - a[i][1] - a[to][1];
		if (cur%2) out(0);
		cur /= (a[i][0]+a[to][0]);
		if (cur<=0) out(0);
		if (ans == -1) {
		    ans = cur;
		} else if (ans != cur) {
		    out(0);
		}
	    }
	}
    }

    if (~ans) {
	if (lo <= ans && ans <= hi) out(1);
	out(0);
    } else {
	ll res = max(0ll,hi-lo+1);
	out(res);
    }
    
    
    return 0;
}


Measured memory_bytes: 17432
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int MOD=1e9+7;

int main()
{
	for(int n,t;cin>>n>>t;){
		vector<int> ds(n);
		for(int i=0;i<n;i++) cin>>ds[i];
		
		sort(begin(ds),end(ds));
		
		vector<int> dp(n);
		dp[0]=1;
		for(int i=1;i<n;i++){
			int j=lower_bound(begin(ds),end(ds),ds[i]-t)-begin(ds);
			dp[i]=((long long)dp[i-1]*(i-j+1))%MOD;
		}
		cout<<dp[n-1]<<endl;
	}
}

Measured memory_bytes: 1788
sub f{my$i=pop;$i-$u[$i]?$u[$i]=f($u[$i]):$i}
($a,$b)=map{
	@u=0..$`;
	for(1..$_){
		<>=~$";
		$u[$%]=$=if($%=f$`)-($==f$'+0)
	}
	[map f($_),@u]
}<>=~/ \d+/g;
print${$$a[$_]}{$$b[$_]},$/for grep++${$$a[$_]}{$$b[$_]},1..$`


Measured memory_bytes: 166144
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools

mod = int(1e9+7)

class Library():
    @staticmethod
    def Swap(a,b):
        return [b,a]

    @staticmethod
    def myRound(a,dig=0): # 四捨五入
        # dig => 桁数
        # dig = 1 => 10の位
        # dig = -1 => 小数第一位
        p = 10 ** dig
        return (a * p * 2 + 1) // 2 / p

    @staticmethod
    def Roundup(a): # 切り上げ
        if a < 0:
            return int(a)
        else:
            return int(a + 0.9)
    # 整数の切り上げ => (a + b - 1) // b

    @staticmethod
    def Gcd(a,b): #最大公約数
        if (a<b):
            a,b = Library.Swap(a,b)
        if (b==0):
            return a
        else:
            return Library.Gcd(b,a%b)

    @staticmethod
    def Lcm(a,b): #最小公倍数
        return a//Library.Gcd(a,b)*b

    @staticmethod
    def Divisors(a): # 約数列挙
        divisors = []
        for i in range(1,int(a**0.5)+1):
            if a%i==0:
                divisors.append(i)
                if i!=a//i:
                    divisors.append(a//i)
        divisors.sort()
        return divisors

class Prime():
    # コンストラクタ
    # エラストテネスの篩
    def __init__(self,num):
        self.num = num
        self.sieve = [0] * (self.num + 1)
        self.sieve[0] = -1
        self.sieve[1] = -1
        for i in range(2,self.num + 1):
            if not self.sieve[i]:
                self.sieve[i] = i
                for j in range(i * i,self.num + 1,i):
                    if self.sieve[j]:
                        self.sieve[j] = i
    
    # 素数判定
    def isPrime(self,num = None):
        if num is None:
            num = self.num
        if self.sieve[num] == num:
            return True
        else:
            return False
    
    # 素数列挙
    def PrimeNum(self,num = None):
        if num is None:
            num = self.num
        prime = []
        for i in range(2,num):
            if self.sieve[i] == i:
                prime.append(i)
        return prime
    
    # 素因数分解
    def PrimeFact(self,num = None):
        if num is None:
            num = self.num
        fact = []
        while self.sieve[num] != num:
            fact.append(self.sieve[num])
            num //= self.sieve[num]
        fact.append(num)
        return fact

def main():
    abc = list(map(int,input().split()))
    abc.sort()
    if abc[0] == 5 and abc[1] == 5 and abc[2] == 7:
        print('YES')
    else:
        print('NO')
    return

if __name__=='__main__':
    main()


Measured memory_bytes: 38384
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    boolean c1 = false, c2 = false, c3 = false;
    if(a == 1 || b == 1){
      c1 = true;
    }
    if(a == 2 || b == 2){
      c2 = true;
    }
    if(a == 3 || b == 3){
      c3 = true;
    }
    
    int ans = 0;
    if(c1 && c2){
      ans = 3;
    }else if(c2 && c3){
      ans = 1;
    }else{
      ans = 2;
    }
    System.out.println(ans);
  }
}

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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N; cin >> N;
	vector<LL> A(N),B(N);
	vector<int> s(N);
	repp(i,0,N){
		cin >> A[i] >> B[i];
		s[i] = i;
	}
	sort(s.begin(),s.end(),[&](const int &i, const int &j){return A[i]+B[i] > A[j]+B[j];});
	LL ans = 0;
	repp(i,0,N){
		if(i%2 == 0) ans += A[s[i]];
		else ans -= B[s[i]];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include<string>
#include<map>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int f = 0;
	
	for (int i = 0; i < s.size()/2; i++)
	{
		//[s[i]-'a']++;
		if (s[i] != s[s.size() - i - 1])
			f = 1;
	}
	for (int i = 0; i <s.size()/4 ; i++)
	{
		if (s[i] != s[s.size()/2 - i - 1])
			f = 1;

	}
	
	if (f == 1)
		cout << "No";
	else
		cout << "Yes";
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def roundUp(a, b):
        return -(-a // b)

    @staticmethod
    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    @staticmethod
    def toLowerMultiple(a, x):
        return (a // x) * x

    @staticmethod
    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    @staticmethod
    def sign(n):
        if n == 0:
            return 0
        if n < 0:
            return -1
        return 1

    @staticmethod
    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


class PriorityQueue:
    def __init__(self, l=[]):
        self.__q = l
        heapq.heapify(self.__q)
        return

    def push(self, n):
        heapq.heappush(self.__q, n)
        return

    def pop(self):
        return heapq.heappop(self.__q)


MOD = int(1e09) + 7
INF = int(1e15)


def main():
    # sys.stdin = open("sample.txt")
    N, K = Scanner.map_int()
    R, S, P = Scanner.map_int()
    T = Scanner.string()
    ans = 0
    M = {"r": P, "s": R, "p": S}
    prevs = [""] * N
    for i in range(N):
        if 0 <= i - K:
            if T[i] == prevs[i-K]:
                continue
        ans += M[T[i]]
        prevs[i] = T[i]
    print(ans)
    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 44140
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))
#define DEBUG 0

string solve()
{
    string S;
    cin >> S;
    vector<ll> cnt(26, 0);
    for (auto c : S) {
        cnt[c - 'a'] = 1;
    }
    for1 (i, 26) {
        if (cnt[i] == 0) {
            string str{'a'+(char)i};
            return str;
        }
    }
    return "None";
}

int main()
{
    do {
        cout << solve() << endl;
    } while (DEBUG);
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;

void Main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while(1){
    	c -= b;
      	if(c <= 0) {
        	puts("Yes");
          	return;
        }
      	a -= d;
      	if(a <= 0) {
        	puts("No");
          	return;
        }
    }
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


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

int n, mx[202000], sz[202000], fa[202000], ans[202000];

vector<int>G[202000];

struct TR{
    int lc, rc, sz;
}tr[10001000];
int rt[202000], cntr;

void U(int x){
    tr[x].sz=tr[tr[x].lc].sz+tr[tr[x].rc].sz;
}
void add(int &x,int l,int r,int p,int v){
    if (!x) x=++cntr;
    if (l==r){
        tr[x].sz+=v;
        return;
    }
    int mid=l+r>>1;
    if (p<=mid) add(tr[x].lc,l,mid,p,v);
    else add(tr[x].rc,mid+1,r,p,v);
    U(x);
}
int que(int x,int l,int r,int p){
    if (r<=p) return tr[x].sz;
    if (l>p) return 0;
    int mid=l+r>>1;
    return
        que(tr[x].lc,l,mid,p) + que(tr[x].rc,mid+1,r,p);
}
void kill(int &x,int l,int r,int p){
    if (r<=p){
        x=0; return;
    }
    if (l>p) return;
    int mid=l+r>>1;
    kill(tr[x].lc,l,mid,p);
    kill(tr[x].rc,mid+1,r,p);
    U(x);
}
void mg(int &x,int y,int l,int r){
    if (!y) return;
    if (!x){
        x=y; return;
    }
    if (l==r){
        tr[x].sz+=tr[y].sz;
        return;
    }
    int mid=l+r>>1;
    mg(tr[x].lc,tr[y].lc,l,mid);
    mg(tr[x].rc,tr[y].rc,mid+1,r);
    U(x);
}

void dfs(int x,int fff){
    fa[x]=fff;
    mx[x]=max(x,mx[fff]);
    for (auto y:G[x])
        if (y!=fff){
            dfs(y,x);
            mg(rt[x],rt[y],1,n);
        }
    int cnt=que(rt[x],1,n,x-1);
    kill(rt[x],1,n,x-1);
    add(rt[x],1,n,x,cnt+1);
    if (fa[x]&&fa[fa[x]]){
        sz[x]=que(rt[x],1,n,mx[fa[fa[x]]]);
    }
}

void sfd(int x,int fff,int bas){
    int sum=1;
    for (auto y:G[x])
        if (y!=fff)
            sum+=sz[y];
    ans[x]=sum+bas;
    for (auto y:G[x])
        if (y!=fff)
            sfd(y,x,bas+sum-sz[y]);
}

int main(){
    cin>>n;
    for (int i=1;i<n;++i){
        int x, y; cin>>x>>y;
        G[x].push_back(y); G[y].push_back(x);
    }
    dfs(1,0);
    for (auto x:G[1])
        sfd(x,1,0);
    for (int i=2;i<=n;++i) cout<<ans[i]<<' ';
    cout<<endl;
}

Measured memory_bytes: 64512
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 300010
#define INF 0x3FFFFFFF
using namespace std;
int n;
int a[MAXN];
bool used[MAXN];
bool check(int l,int r){
	if(l>r)
		return 0;
	if(l==r)
		return a[l]!=l;
	int minv=INF;
	int maxv=0;
	for(int i=l;i<=r;i++){
		minv=min(minv,a[i]);
		maxv=max(maxv,a[i]);	
	}
	if(minv!=l||maxv!=r)
		return 1;
	for(int i=l+1;i<=r;i+=2)
		if(a[i]!=i)
			return 1;
	for(int i=l;i<=r;i+=2)
		if(a[i]==i)
			return 1;
	int lasx=0,lasy=0;
	for(int i=l;i<=r;i+=2){
		if(i<a[i]){
			if(a[i]<lasx)
				return 1;
			lasx=a[i];
		}
		if(i>a[i]){
			if(a[i]<lasy)
				return 1;
			lasy=a[i];	
		}
	}
	return 0;
}
int main(){
	SF("%d",&n);
	for(int i=1;i<=n;i++)
		SF("%d",&a[i]);
	for(int i=1;i<=n;i++)
		used[i]=(a[i]==i);
	int las=1;
	used[0]=1;
	for(int i=1;i<=n;i++){
		if(used[i]==1&&used[i-1]==1){
			if(check(las,i-2)){
				PF("No");
				return 0;
			}
			las=i+1;
		}
		else if(used[i]==1&&used[i-2]==1)
			continue;
		else if(used[i]==1&&used[i-3]==1){
			if(check(las,i-2)){
				PF("No");
				return 0;
			}
			las=i-1;
		}
		else if(used[i]==1){
			PF("No");
			return 0;	
		}
	}
	if(check(las,n))
		PF("No");
	else
		PF("Yes");
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;

#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define graph vector< vector<int> >
#define vs vector<string>
#define mn -
#define pls +
#define mod %
#define E =
#define EE ==
#define le <=
#define ge <=
int mx=9999999;
/**  '' "\n" - ^ **/
bool test(int x,int y)
{
    return (x>y?true:false);
}
class Template{
    public:
    void yes()
    {
        cout<<"Yes\n";
    }

    void no()
    {
        cout<<"No\n";
    }
    void YES()
    {
        cout<<"YES\n";
    }

    void NO()
    {
        cout<<"NO\n";
    }

    void Case(int i,int n)
    {
        cout<<"Case:"<<i<<" "<<n<<endl;
    }
    /**  '' "\n" x ^ **/
    /** printf("\n") */
};

Template root;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string str;
    cin>>str;
    reverse(str.begin(),str.end());
    if(str[0]=='2'||str[0]=='4'||str[0]=='5'||str[0]=='7'||str[0]=='9')printf("hon\n");

    else if(str[0]=='0'||str[0]=='1'||str[0]=='6'||str[0]=='8')printf("pon\n");

    else printf("bon\n");
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;
using ll = long long;

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

int main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int ans = 0;
    if(a + b > 2*c){
        ans = 2 * c * min(x,y);
        if(x > y){
            if(a > 2*c){
                ans += 2*c*(x-y);
            }else{
                ans += a*(x-y);
            }
        }else{//x<y
            if(b>2*c){
                ans += 2*c*(y-x);
            }else{
                ans += b*(y-x);
            }
        }
    }else{
        ans = x * a + y * b;
    }
    cout << ans << endl;
    return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int) a.size()
#define ALL(a) a.begin(),a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 100100;

VI g[MAX];
bool U[MAX];
int C[MAX];
int CNT[2];

int ed = 0;

bool dfs(int x, int c)
{
	C[x] = c;
	CNT[c]++;
	U[x] = true;

	bool res = true;

	ed += SZ(g[x]);

	FOR (i, 0, SZ(g[x]))
	{
		int to = g[x][i];
		if (U[to])
		{
			if (C[x] == C[to]) res = false;
			continue;
		}

		if (!dfs(to, c^1)) res = false;
	}

	return res;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	int n, m;
	scanf("%d%d", &n, &m);
	FOR (i, 0, m)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		x--;
		y--;
		g[x].PB(y);
		g[y].PB(x);
	}

	LL res = 0;

	FOR (i, 0, n)
	{
		if (U[i]) continue;

		CNT[0] = CNT[1] = 0;
		ed = 0;
		bool v = dfs(i, 0);
		ed /= 2;
		if (v)
		{
			LL cnt = CNT[0] * (LL)CNT[1];
			cnt -= ed;
			res += cnt;
		}
		else
		{
			LL cnt = CNT[0] + CNT[1];
			cnt = cnt * (cnt - 1) / 2;
			cnt -= ed;
			res += cnt;
		}
	}

	cout<<res<<endl;
}


Measured memory_bytes: 7808
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

vector<vector<int>> d;
vector<int> cache;

int dfs(int n) {
    if (SIZE(d[n]) == 0) return 0;
    if (cache[n] != -1) return cache[n];
    
    auto size = SIZE(d[n]);


    vector<int> depth;
    for (auto x: d[n]) {
        // cout << "x:" << x << endl;
        depth.pb(dfs(x));
    }
    sort(ALL(depth));

    int o = size;
    int mx = 0;
    for(auto d : depth) {
        mx = max(mx, o + d);
        --o;
    }

    return mx;
}
    

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;

    d.resize(N+2);
    cache.resize(N+2, -1);

    REP(n, N-1) {
        int loser = n + 2;
        int winner;
        cin >> winner;
        d[winner].push_back(loser);
    }

    cout << dfs(1) << endl;
    return 0;
}


Measured memory_bytes: 17024
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, start, end) for(int i = start; i < (int)(end); ++i)
int dp[201][201];
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main(){
    int k = 0;
    cin >> k;
    long long ans = 0;
    rep(a,1,k+1){
        rep(b,1,k+1){
            rep(c,1,k+1){
                ans += gcd(a,gcd(b,c));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
    int a,b;
    cin >>a;
    cin >>b;
    string c;
    if(a>b){
        c=" > ";
    }else if(a<b){
        c=" < ";
    }else{
        c=" == ";
    }
    cout << "a"<<c<<"b"<<endl;
}


Measured memory_bytes: 3216
#sys.stdin.readline()
import sys
input = sys.stdin.readline

N = int(input())
X,Y,H = [],[],[]
for i in range(N):
 x,y,h = map(int,input().split())
 if(h != 0):
  X.append(x),Y.append(y),H.append(h)

Cx,Cy = [],[]
for i in range(101):
  for j in range(101):
    Cx.append(i),Cy.append(j)

if(len(X) == 1):
  print(X[0],Y[0],H[0])
else:
 # H = hi+|Xi-Cx|+|Yi-Cy|
 ans_cx,ans_cy,ans_h = 0,0,0
 for i in range(101*101): 
  judge = 1 #1:全ての点が条件を満たす,0:NG
  for j in range(len(X)):
   if(j == 0): 
     ans_H = H[j] + abs(X[j]-Cx[i]) + abs(Y[j]-Cy[i])
   else:
     tmp_H = H[j] + abs(X[j]-Cx[i]) + abs(Y[j]-Cy[i])
     if(ans_H != tmp_H):
       judge = 0
       break
  if(judge == 1):
    ans_cx,ans_cy = Cx[i],Cy[i]
    break

 print(ans_cx,ans_cy,ans_H)
    

Measured memory_bytes: 3316
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long ll;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MAX = 200005;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(MAX);

ll f[MAX];
void init() 
{
    f[0] = 1;
    for(int i = 1; i < MAX; ++i) f[i] = (f[i - 1] * i) % mod;
}
 
 //! count the combination of distributing d people to r rooms
 mint dist(int r, int d)
 {
     return mint(f[d+r-1]) / (mint(f[r-1]) * mint(f[d]));
 }

//! count the combinations when d meaningful move takes place
 mint count(int n, int d)
 {
     mint c = comb(n, d); //! variation of empty rooms
     return c * dist(n-d, d);
 }


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

    init();

    int n, k;
    cin >> n >> k;

    mint ans;

    for (int d = 0; d <= min(k, n-1); ++d) {
        ans += count(n, d);
    }

    cout << ans.x << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
const int INF = 100100100;
using namespace std;

int main()
{
  string S;
  cin >> S;

  int len= S.length();
  int res = 0;

  string sub1 = S.substr(0,len/2);
  string sub2 = S.substr(len/2+len%2);
  reverse(sub2.begin(),sub2.end());
  
  for(int i=0;i<len/2;i++){
    if(sub1.back()!=sub2.back()) res++;
    sub1.pop_back();
    sub2.pop_back();
  }
  cout <<res << endl;
}

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

#define ld long double
#define ll long long
#define ull unsigned long long

#define f first
#define s second

#define endl '\n'
#define pii pair <ll, ll>

#define ios ios_base::sync_with_stdio(0), cin.tie()
#define pb push_back
#define mp make_pair

#define pi 3.14159265358979323846264
#define y1 abacaba

using namespace std;

const int MXN = 2e6 + 30;
const int MAXN = 1e3 + 2;
const ll INF = 1e9 + 7;
const ll BINF = 1e15;
const int MOD = 1e9 + 7;
const ld EPS = 1e-15;   
const ll dx[] = {0, 0, 1, -1};
const ll dy[] = {1, -1, 0, 0};

int n;
int a[MXN];

set < int > st;
int sz;

int main(){
    #ifdef DIAS
        freopen("input.txt", "r", stdin);
    #elif NAME   
    	freopen(fq".in", "r", stdin);
    	freopen(fq".out", "w", stdout);
    #endif   
    cin >> n;
    for(int i = 1; i <= n; i++){
    	cin >> a[i];
    } for(int i = 1; i <= n; i++){
    	sz = st.size();
    	st.erase(a[i]);
    	if(sz == st.size()) st.insert(a[i]);
    } cout << st.size();
    return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<string.h>
using namespace std;
static const int MAX = 1200;

int main(){
  string s;
  getline(cin, s);
  for(int i=0; i<s.size(); i++){
    if(isupper(s[i]))
      s[i] = tolower(s[i]);
    else if(islower(s[i]))
      s[i] = toupper(s[i]);
  }
  cout << s << endl;
  return 0;
}



Measured memory_bytes: 3148
import java.util.Random;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        //int n = 200000;
        int[] a = new int[n];
        long[] fq = new long[n + 1];
        //Random rnd = new Random(12313);
        for (int i = 0; i < n; ++i) {
            a[i] = sc.nextInt();
            //a[i] = rnd.nextInt(2) + 1; //rnd.nextInt(n + 1) + 1;
            fq[a[i]]++;
        }
        long c = 0;
        for (int i = 1; i <= n; ++i) {
            c += (fq[i] >= 2) ? (fq[i] * (fq[i] - 1)) / 2 : 0;
        }
        for (int i = 0; i < n; ++i) {
            if (fq[a[i]] >= 2) {
                System.out.println(c - (fq[a[i]] - 1));
            }
            else {
                System.out.println(c);
            }
        }
    }
}


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

int main(){
  string N;
  cin >> N;
  
  int sum = 0;
  int a = 0;
  int k = N.size();
  for(int i = 0;i < k;i++){
    sum = sum + N.at(i) - 48;
    a = a + std::pow(10, k-i-1) * (N.at(i) - 48);
  }
  
  if( a % sum == 0 ){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
  
  

Measured memory_bytes: 256
//マージソート
//二分探索を応用したソート
using System;
using System.Linq;

namespace tst
{
    static class Define
    {
        public const int Infty = 1000000001;//const 上書きできない
    }
    class Program
    {
        public static int cnt = 0;
        public static int n = 0;
        public static int[] A = new int[n];
        public static void Merge(int[] A, int left, int mid, int right)
        {
            int n1 = mid - left;
            int n2 = right - mid;
            //L[0,,,n1]、R[0,,,n2]を生成
            int[] L = new int[n1 + 1];
            int[] R = new int[n2 + 1];
            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] = Define.Infty;
            R[n2] = Define.Infty;
            int l = 0;
            int m = 0;
            for (int k = left; k < right; k++)//k=0～n-1
            {
                cnt++;
                if (L[l] <= R[m])
                {
                    A[k] = L[l];
                    l++;
                }
                else
                {
                    A[k] = R[m];
                    m++;
                }
            }

        }
        public static void MergeSort(int[] A, int left, int right)
        {
            if (right - left > 1)
            {//継続条件
                int mid = left + (right - left) / 2;
                MergeSort(A, left, mid);
                MergeSort(A, mid, right);
                Merge(A, left, mid, right);
            }
        }

        public static void Main()
        {
            //入力
            n = int.Parse(Console.ReadLine());
            string[] text1 = Console.ReadLine().Split(' ');
            A = text1.Select(s => int.Parse(s)).ToArray();
            //探索ソート
            MergeSort(A, 0, n);
            //出力
            Console.Write(A[0]);
            for (int i = 1; i < n; i++)
            {
                Console.Write(" {0}", A[i]);
            }
            Console.WriteLine();
            Console.WriteLine(cnt);
        }

    }
}


Measured memory_bytes: 70032
#!/usr/bin/env python

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
INF = float("inf")

def popcount(n):
    ret = 0
    for i in range(18):
        if n>>i & 1:
            ret += 1
    return ret

def main():
    N = int(input())
    X = input().decode().rstrip()

    # X に含まれる "1" の数
    x_cnt = X.count("1")

    # i 桁目が 0 : x_cnt += 1
    # i 桁目が 1 : x_cnt -= 1
    # より, X mod x_cnt +1, X mod x_cnt-1 を事前計算しておく
    x_mod_pl,x_mod_mi = 0,0
    d_pl,d_mi = 1,1
    mod_pl,mod_mi = x_cnt+1,max(1,x_cnt-1)
    for i in range(N-1,-1,-1):
        if X[i]=="1":
            x_mod_pl = (x_mod_pl + d_pl) % mod_pl
            x_mod_mi = (x_mod_mi + d_mi) % mod_mi
        d_pl = (d_pl*2) % mod_pl
        d_mi = (d_mi*2) % mod_mi
    
    for i in range(N):
        ans = 1
        if X[i] == "1":
            # 1 -> 0 に変換した結果, １が全く存在しない場合
            if x_cnt == 1:
                print(0)
                continue
            a = (x_mod_mi - pow(2,(N-1-i), mod_mi)) % mod_mi
        else:
            a = (x_mod_pl + pow(2,(N-1-i), mod_pl)) % mod_pl

        while a > 0:
            pop_cnt = popcount(a)
            a %= pop_cnt
            ans += 1

        print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9640
//列にあるブロックの数を単純に趣味レートする(ただし、ブロックは常に左詰めにする)
#include<iostream>
using namespace std;
#define DB(x) 

int N,b[10102];
int ans[20],cor = 0;

int main(){
	int i;
	while(cin >> N){
		if(N == 0)
			break;
		for(i = 0;i < 10102;i++)
			b[i] = 0;
		for(i = 0;i < N;i++)
			cin >> b[i];
		//シュミレーション
		int wide = N;			//ブロックが何列積まれているか
		while(ans[cor] <= 10000){
			for(i = 0;i < wide;i++){
				if(b[i] != i+1)
					break;
			}
			if(i == wide)
				break;
			//一番下段を抜く(抜いた数をカウント)
			int count = 0;
			for(i = 0;i < wide;i++){
				if(b[i] > 0){
					b[i]--;
					count++;
				}
			}
			//一番右の列よりもう一個右にブロックを移動
			b[wide] = count;
			//空白の数を数えながら各列O(1)でシフトする。
			int emp = 0;
			for(i = 0;i <= wide;i++){
				if(b[i] > 0)
					b[i-emp] = b[i];
				else
					emp++;
			}
			wide -= emp-1;	//-1が重要！
			ans[cor]++;
			DB(for(i = 0;i <= wide;i++)cout << b[i] << " ";cout << endl;)
		}
		DB(for(i = 0;i <= wide;i++)cout << b[i] << " ";cout << endl;)
		if(ans[cor] > 10000)
			ans[cor] = -1;
		cor++;
	}
	for(i = 0;i < cor;i++)
		cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 1204
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;



public class Main {



    public static void main(String[] args)  {

    	try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String line;
            while((line=br.readLine())!=null){if(line.isEmpty())break;
            //store vector data.
            	String spl[] = line.split(" ");
        		int n = Integer.parseInt(spl[0]);
        		int[] ints = new int[n];

        		if(n==0){return ;}

        		line= br.readLine(); spl = line.split(" ");
        		for(int i = 0; i<n ; i++){
        			ints[i] = Integer.parseInt(spl[i]);
        		}

        		int count=0;
        		while(true){
        			int[] backup = Arrays.copyOf(ints, ints.length);
	        		count++;
	        		ints = makeC(ints);
	        		boolean sameflag = true;
	        		for(int i=0; i<ints.length; i++){
	        			if(ints[i] != backup[i]){sameflag = false; break;}
	        		}
	        		if(sameflag){break;}
        		}

	        		System.out.println(count-1);
	        		for(int i = 0; i<ints.length; i++){
	        			System.out.print(ints[i]);
	        			if(i!=ints.length-1){System.out.print(" ");}
	        		}System.out.println();

            }//End WHILE

        }catch(Exception e){e.printStackTrace();}

    }

    static  int[] makeC(int ints[]){
    	int[] ret = new int[ints.length];
    	for(int i=0; i<ints.length; i++){
    		for(int j=0; j<ints.length; j++){
    			if(ints[i]==ints[j]){ret[i]++;}
    		}
    	}
    	return ret;
    }

}

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

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; }

const long long INF = 1LL << 60;

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

  set<char> st;
  for(char c='a'; c<='z'; c++){
    st.insert(c);
  }

  rep(i, s.size()){
    st.erase(s[i]);
  }

  if(st.empty()) cout << "None" << endl;
  else{
    cout << *st.begin() << endl;
  }

  return 0;
}


Measured memory_bytes: 512
import functools


def new_ingredient(x, y):
    return (x + y) / 2


def main():
    n = int(input())
    v = [int(x) for x in input().split()]

    v.sort()
    max_value = functools.reduce(new_ingredient, v)

    print(max_value)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3572
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <functional>

using namespace std;
static const int INF = 1e9;
typedef pair<int, int> P;

void solve()
{
	int N, K;
	cin >> N >> K;
	set<int> D;
	for (int i = 0; i < K; ++i)
	{
		int d;
		cin >> d;
		D.insert(d);
	}
	int ans = 1;
	while (true)
	{
		int temp = ans;
		bool isOK = true;
		while (temp)
		{
			if (D.find(temp % 10) != D.end())
			{
				isOK = false;
				break;
			}
			temp /= 10;
		}
		if (isOK && ans >= N)
		{
			break;
		}
		++ans;
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 256