akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair< int, int >;

int main() {
    int K, N;
    cin >> K >> N;
    vector< int > A(N);
    rep(i, N) cin >> A[i];

    vector< int > ds(N);
    int dmax = 0;
    int ans = 0;
    rep(i, N) {
        int d = 0;
        if (i == N - 1) {
            d = K - A[i] + A[0];
        } else {
            d = A[i + 1] - A[i];
        }
        if (d > dmax) {
            ans += dmax;
            dmax = d;
        } else {
            ans += d;
        }
        ds[i] = d;
    }
    cout << ans << endl;
}

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;

  int wk_T,wk_A;
  wk_T = C/B;
  if(C%B!=0){wk_T++;}
  wk_A = A/D;
  if(A%D!=0){wk_A++;}

  if(wk_T <= wk_A){
    cout << "Yes" << endl;
  } else{
    cout << "No" << endl;
  }

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



int N;
int T[105];

int main(){

	scanf("%d",&N);
	int sum = 0;

	for(int i = 0; i < N; i++){

		scanf("%d",&T[i]);
		sum += T[i];
	}

	int M;
	scanf("%d",&M);

	int p,x;

	for(int i = 0; i < M; i++){

		scanf("%d %d",&p,&x);
		p--;

		printf("%d\n",sum-(T[p]-x));
	}

	return 0;
}


Measured memory_bytes: 256
"""
前処理で下記のようなメモを作っておく必要がある。
candidate[j] -> 昇順ソートされたBの中でインデックスj以降のパーツを使えるときに、考えられるB,Cの組み合わせの数。
candidateリストを作成するためにまずは、下記のmemoを用意して、その総和としてcandidateを作成する。
memo[j] -> Bの中のインデックスjのパーツを使った場合に使用可能なCの数。
"""

def main():
    from bisect import bisect
    import sys
    sys.setrecursionlimit(200000)

    N = int(input())
    A = sorted(list(map(int,input().split())))
    B = sorted(list(map(int,input().split())))
    C = sorted(list(map(int,input().split())))

    memo = [0]*(N)
    for j in range(N):
        b = B[j]
        cIdx = bisect(C,b)
        memo[j] = N-cIdx
    candidate = [0]*(N)
    candidate[-1] = memo[-1]
    for j in range(N-2,-1,-1):
        candidate[j] += candidate[j+1]+memo[j]

    ans = 0
    for a in A:
        bIdx = bisect(B,a)
        if bIdx < N:
            ans += candidate[bIdx]

    print(ans)
main()

Measured memory_bytes: 107876
#include<stdio.h>
int main(void) {
	int n;
	scanf("%d", &n);
	int cnt = 0;
	int ans = 0;
	if (n >= 10) {
		ans = 9;
		for (int i = 100; i <= n; i=i*100) {
			cnt = 0;
			for (int j = i; j < i*10; j++) {
				cnt++;
				if (j == n) {
					break;
				}
			}
			ans = ans + cnt;
		}
	}
	else {
		ans = n;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    string s, t;
    cin >> s >> t;

    vector<vector<ll>> alpha(26);
    for(ll i = 0; i < s.size(); i++)
    {
        alpha[ s[i] - 'a'].push_back(i);
    }

    ll ans = 0;
    ll count = 0;
    ll tpos = 0;
    ll npos = 0;
    while(tpos < t.size())
    {
        ll al = t[tpos] - 'a';
        if(alpha[al].empty())
        {
            cout << -1 << endl;
            return 0;
        }
        auto itr = lower_bound(alpha[al].begin(), alpha[al].end(), npos);
        if(itr == alpha[al].end())
        {
            npos = 0;
            count++;
            continue;
        }
        npos = *itr + 1;
        tpos++;
    }
    ans = count * ll(s.size()) + npos;
    cout << ans << endl;
}


Measured memory_bytes: 1724
# coding: utf-8
# Your code here!

def diameter(g):
    def dfs(v,p): # v からの最長点と距離を求める
        m = 0
        i = v
        for c in g[v]:
            if c == p: continue
            mc,ic = dfs(c,v)
            mc += 1  #重みつきのときは+1でなく +cost(v,c)
            if m < mc:
                m = mc
                i = ic
        return (m,i)

    m0,i0 = dfs(0,-1)
    m1,i1 = dfs(i0,-1)
    # i0, i1 が最遠頂点対
    return m1

##################################################
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
 
n = int(input())
#n,q = [int(i) for i in readline().split()]
 
g = [[] for _ in range(n)]
for i in range(n-1):
    a,b = [int(i) for i in readline().split()]
    g[a-1].append(b-1)
    g[b-1].append(a-1)

d = diameter(g)
if d%3 != 1:
    print("First")
else:
    print("Second")
    
    
    
    







Measured memory_bytes: 267828
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOJ1_4_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            int d = (int) (a/ b);
            int r = a % b;
            double f = (double)a / b;

            Console.WriteLine(d + " " + r + " " + f.ToString("F5"));
        }
    }
}



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

int main(){
   set<string>  s;
   string word;
   int i, n;
   cin >> n;
   
   for(i=1; i<=n; i++){
      cin >> word;
      s.insert(word);   
   } 

   cout << s.size();
   return 0;
}

Measured memory_bytes: 19120
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 1000000;
const int MOD = 1000000007;

signed main() {
int n,k;
cin>>n>>k;
int h[n+1];
h[0]=0;
for(int i=1;i<n+1;i++)cin>>h[i];
int dp[n+1][k+1];
for(int i=1;i<=n;i++)fill(dp[i],dp[i]+k+1,MOD*MOD);
fill(dp[0],dp[0]+k+1,0);
for(int i=1;i<=n;i++){
  for(int j=0;j<i;j++){
    for(int p=0;p+i-j-1<=k;p++){
      dp[i][p+i-j-1]=min(dp[i][p+i-j-1],dp[j][p]+max(0LL,h[i]-h[j]));
    }
  }
}
int ans=dp[n][k];
for(int i=1;n-i>=0&&k-i>=0;i++)ans=min(ans,dp[n-i][k-i]);

cout<<ans;
return 0;



}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main() {
	cin.tie(NULL);
	cout.tie(NULL);
	int n,t;
	cin>>n>>t;
	int cnt=0;
	while(n--)
	{
		double x,y;
		cin>>x>>y;
		ll d=ceil((double)sqrt(x*x+y*y));
		if(d<=t)
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3920
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########
class UnionFind():
    def __init__(self,num):
        self.n = num         #class内変数nに、外部から入力した値numを代入
        self.parents = [-1 for i in range(self.n)]
          #parentsは要素の親(1こ上のやつ)番号0~n-1を格納、自分が最親なら-(要素数)を格納(初期値は-1)

    #xの最親は誰？
    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x]) #再帰して1番上までいってる
                #調べながらparentsの値を更新してる！（経路圧縮）
            return self.parents[x]

    #結合せよ
    #xの親とyの親をくっつける
    def union(self,x,y):
        xx=self.find(x)  #xxはxの最親
        yy=self.find(y)  #yyはyの最親
        if xx==yy:
            return     #同じ屋根の下にあった場合は何もしない
        else:
            size_xx=abs(self.parents[xx]) #xが含まれる木のサイズ
            size_yy=abs(self.parents[yy]) #yが含まれる木のサイズ
            if size_xx>size_yy:
                xx,yy=yy,xx  #yyの方が大きい木、ってことにする

            self.parents[yy]+=self.parents[xx] #大きい木のサイズ更新
            self.parents[xx]=yy   #サイズが小さい木を大きい木に接ぐ

    #xの属する木の大きさ（まあunionでも使ったけど）
    def size(self,x):
        xx=self.find(x)
        return abs(self.parents[xx])

    #xとyはこの空の続く場所にいますか　いつものように笑顔でいてくれますか　今はただそれを願い続ける
    def same(self,x,y):
        return 1 if self.find(x)==self.find(y) else 0

    #xと　同じ木にいる　メンバーは？
    def members(self,x):
        xx=self.find(x)
        return [i for i in range(self.n) if self.find(i)==xx]
             #ifの条件式に漏れたら無視

    #最親だけを並べあげる
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x < 0]
        #いやこれは天才すぎる、basisのenumerate.py参照

    #すべての最親について、メンバーを辞書で
    def all_group_members(self):
        return {r:self.members(r) for r in self.roots()}

    #グループ分けどうなりましたか、２重リストで
    def state_grouping(self):
        return list(self.all_group_members().values())

n,k,l=map(int,input().split())
uf=UnionFind(n)
uf2=UnionFind(n)
for i in range(k):
    p,q=map(int,input().split())
    p-=1;q-=1
    uf.union(p,q)
for i in range(l):
    p,q=map(int,input().split())
    p-=1;q-=1
    if 1:
        uf2.union(p,q)

C= Counter( [ ( uf.find(i),uf2.find(i) ) for i in range(n)] )
ANS=[0]*n 
for i in range(n):
    ANS[i]= C[(uf.find(i),uf2.find(i))]
print(*ANS)

Measured memory_bytes: 47616
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;
#define erep(i, x, n) for (auto i = x; i<=(ll)(n); i++)
#define rep(i, x, n) for(auto i = x; i<(ll)(n); i++)
#define all(v) ((v).begin()), ((v).end())
#define sz(v) ((int)((v).size()))
#define mod(n, m) (((n%m) + m)%m)
#define reset(n, m) memset(n, m, sizeof n)
#define endl '\n'



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

	ll n, r;
	cin >> n >> r;

	if (n >= 10)
		cout << r << endl;
	else
		cout << r + 100 * (10 - n) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct frac{
  int num,dom;
  frac(){}
  frac(int num,int dom):num(num),dom(dom){}
  frac norm(){
    if(num==0) return frac(0,1);
    int tmp=__gcd(num,dom);
    return frac(num/tmp,dom/tmp);
  }
  frac norm2(){
    if(num==0) return frac(0,1);
    while(num<0) num+=dom;
    while(num>=dom) num-=dom;
    int tmp=__gcd(num,dom);
    return frac(num/tmp,dom/tmp);
  }
  frac operator+(frac a){return frac(num*a.dom+a.num*dom,dom*a.dom).norm();}
  frac operator-(frac a){return frac(num*a.dom-a.num*dom,dom*a.dom).norm();}
  frac operator*(frac a){return frac(num*a.num,dom*a.dom).norm();}
  frac operator*(int k){return frac(num*k,dom).norm();}
  frac operator/(frac a){return frac(num*a.dom,dom*a.num).norm();}
  bool operator<(const frac a)const{
    return num*a.dom<a.num*dom;
  }
  bool operator>(const frac a)const{
    return num*a.dom>a.num*dom;
  }
  bool operator==(const frac a)const{
    return num*a.dom==a.num*dom;
  }
  bool operator!=(const frac a)const{
    return num*a.dom!=a.num*dom;
  }
  bool operator<=(const frac a)const{
    return num*a.dom<=a.num*dom;
  }
  bool operator>=(const frac a)const{
    return num*a.dom>=a.num*dom;
  }
};

int H,h,m,s;
void print(frac f){
  //cout<<f.num<<":"<<f.dom<<endl;
  int t=f.num/(f.dom*60);
  cout<<(t%(60*H))/60<<" ";
  cout<<(t%60)<<" ";
  cout<<(f.num)%(f.dom*60)<<" "<<f.dom<<endl;
}
signed main(){
  while(cin>>H>>h>>m>>s,H){
    frac base(h*3600+m*60+s,1),t(max(h*3600+m*60+s-100,0LL),1);
    frac x,y,z;
    frac vh(1,3600*H),vm(1,3600),vs(1,60);
    while(1){
      x=(t*vh).norm2();
      y=(t*vm).norm2();
      z=(t*vs).norm2();
      if(y<x) y=y+frac(1,1);
      if(z<x) z=z+frac(1,1);
      frac ans(10000000,1),t1,t2;
      if(1){
	t1=frac(1,1)-(z-x);
	t2=z-y;
	if(1){
	  frac tmp=t+(t1-t2)/(vs*2-(vh+vm));
	  if(base<=tmp){
	    frac a,b,c;
	    a=(tmp*vh).norm2();
	    b=(tmp*vm).norm2();
	    c=(tmp*vs).norm2();
	    if(b<a) b=b+frac(1,1);
	    if(c<a) c=c+frac(1,1);
	    if(b<c){
	      t1=frac(1,1)-(c-a);
	      t2=c-b;
	      if(a!=b&&b!=c&&c!=a&&t1==t2)
		ans=min(ans,tmp);
	    }
	  }
	}
      }
      if(1){
	t1=z-x;
	t2=y-z;
	if(1){
	  frac tmp=t+(t2-t1)/(vs*2-(vh+vm));
	  if(base<=tmp){
	    frac a,b,c;
	    a=(tmp*vh).norm2();
	    b=(tmp*vm).norm2();
	    c=(tmp*vs).norm2();
	    if(b<a) b=b+frac(1,1);
	    if(c<a) c=c+frac(1,1);
	    if(b>c){
	      t1=c-a;
	      t2=b-c;
	      if(a!=b&&b!=c&&c!=a&&t1==t2)
		ans=min(ans,tmp);
	    }
	  }
	}
      }
      //assert(ans!=frac(10000000,1));
      if(ans!=frac(10000000,1)){
	print(ans);
	break;
      }
      t=t+frac(1,1);
    }
  }
  return 0;
}

Measured memory_bytes: 3044
using System;

class Program {
    static void Main (string[] args) {
        var inp = Console.ReadLine().Split(' ');
        long n = long.Parse(inp[0]);

        var inp2 = Console.ReadLine().Split(' ');

        int[] buka = new int[n];
        for(int i = 0;i < inp2.Length;i++) {
            buka[int.Parse(inp2[i]) - 1]++;
        }

        for(int i = 0;i < n;i++) {
            Console.WriteLine(buka[i]);
        }
    }
}

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

int main(){
	string str, trans, s;
	int q, a, b;

	cin>>str;
	cin>>q;
	
	for(int i=0;i<q;i++){
		cin>>trans>>a>>b;
		string left = str.substr(0, a);
		string right = str.substr(b+1, str.length()-b-1);

		if(trans == "print"){
			s = str.substr(a, b-a+1);
			cout<<s<<endl;
		}else if(trans == "reverse"){
			s = str.substr(a, b-a+1);
			str = left;
			for(int j=s.length()-1;j>=0;j--){
				str += s[j];
			}
			str += right;
		}else if(trans == "replace"){
			cin>>s;
			str = left + s + right;
		}
	}

	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
using namespace std;

int main()
{
  string S;
  cin >> S;
  ll N = S.size();
  vector<ll> rl;
  char last = 'R';
  ll cnt = 0;
  for (ll i = 0; i < N; ++i)
  {
    if (last == S.at(i))
    {
      cnt += 1;
    }
    else
    {
      last = S.at(i);
      rl.push_back(cnt);
      cnt = 1;
    }
  }
  rl.push_back(cnt);
  for (ll i = 0; i < rl.size() / 2; ++i)
  {
    ll r = i * 2;
    ll l = i * 2 + 1;
    if ((rl.at(r) + rl.at(l)) % 2 == 0)
    {
      ll mid = (rl.at(r) + rl.at(l)) / 2;
      rl.at(r) = mid;
      rl.at(l) = mid;
    }
    else if (rl.at(r) > rl.at(l))
    {
      if (rl.at(r) % 2 == 0)
      {
        ll mid = (rl.at(r) + rl.at(l)) / 2;
        rl.at(r) = mid;
        rl.at(l) = mid + 1;
      }
      else
      {
        ll mid = (rl.at(r) + rl.at(l)) / 2;
        rl.at(r) = mid + 1;
        rl.at(l) = mid;
      }
    }
    else
    {
      if (rl.at(r) % 2 == 0)
      {
        ll mid = (rl.at(r) + rl.at(l)) / 2;
        rl.at(r) = mid;
        rl.at(l) = mid + 1;
      }
      else
      {
        ll mid = (rl.at(r) + rl.at(l)) / 2;
        rl.at(r) = mid + 1;
        rl.at(l) = mid;
      }
    }
  }

  last = 'R';
  vector<ll> cnts;
  cnt = 0;
  for (ll i = 0; i < N; ++i)
  {
    if (last == S.at(i))
    {
      cnt += 1;
    }
    else
    {
      last = S.at(i);
      cnts.push_back(cnt);
      cnt = 1;
    }
  }
  cnts.push_back(cnt);
  cnt = 0;
  // cout << cnts.size() << endl;
  for (ll i = 0; i < cnts.size() / 2; ++i)
  {
    for (ll j = 0; j < cnts.at(i * 2) - 1; ++j)
    {
      cout << "0 ";
    }
    cout << rl.at(cnt) << ' ';
    cout << rl.at(cnt + 1) << ' ';
    for (ll j = 0; j < cnts.at(i * 2 + 1) - 1; ++j)
    {
      cout << "0 ";
    }
    cnt += 2;
  }
  cout << endl;
}


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

#define ll long long

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }
    vector<bool> vis(n, 0);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (vis[i]) continue;
        if (a[a[i]] == i) {
            vis[i] = vis[a[i]] = true;
            ans++;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 768
from collections import Counter

N=int(input())
ls=[sorted(list(input())) for _ in range(N)]
ls.sort()

l=[]
for i,s in enumerate(ls):
    if i == 0:
        l.append(1)
        continue
    
    if ls[i-1] == s:
        l[-1]+=1
    else:
        l.append(1)
sol=0
for e in l:
    if e==1:
        continue
    
    sol+=int(0.5*(e-1)*e)

print(sol)


Measured memory_bytes: 25672
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    
    String s=sc.next();
    int k=s.length();
    System.out.print(s.charAt(0));
    System.out.print(k-2);
    System.out.println(s.charAt(k-1));
    sc.close();
  }
}

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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define ALL(a) a.begin(), a.end()
#define FOR(x,to) for(x=0;x<(to);x++)

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

void solve() {
	int N,X;
	int m[100];
	cin >> N >> X;
	int mn = 1e9;
	int ans = N;
	for (int i = 0; i < N; ++i) {
		cin >> m[i];
		X -= m[i];
		mn = min(mn,m[i]);
	}
	ans += X/mn;
	cout << ans << '\n';
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

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

using namespace std;

typedef long long ll;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	vector<pair<ll,ll> > v;
	ll N, arr[100005], m1 = 0, m2 = 0, pt = 0, num, freq;
	cin >> N;
	for (int i = 0; i < N; ++i){
		cin >> arr[i];
	}
	sort(arr,arr+N);
	arr[N] = 1e9+1;
	while (pt < N){
		num = arr[pt];
		freq = 1;
		while (arr[pt] == arr[pt+1]){
			pt++;
			freq++;
		}
		v.push_back(make_pair(num,freq));
		pt++;
	}
	for (auto it : v){
		if (it.second >= 2){
			if (it.second >= 4){
				m1 = m2 = it.first;
			}
			else{
				m2 = m1;
				m1 = it.first;
			}
		}
	}
	cout << m1 * m2 << '\n';
}

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

int n;
int temp1[1000], temp2[1000];

void k_cut(int card[], int k)
{

	int i, j, l, m;

	for(i = 0; i < k; i++) temp1[i] = card[i];
	for(j = i, m = 0; j < 2 * n; j++, m++) temp2[m] = card[j];

	for(i = 0; i < m; i++) card[i] = temp2[i];
	for(j = i, l = 0; j < i + k; j++) card[j] = temp1[l++];

}

void riffle_shuffle(int card[])
{

	int i, j, l;

	for(i = 0; i < n; i++) temp1[i] = card[i];
	for(j = i, l = 0; j < 2 * n; j++, l++) temp2[l] = card[j];

	for(i = 0, j = 0; i < 2 * n; i += 2, j++) {
		card[i] = temp1[j];
		card[i + 1] = temp2[j];
	}

}

int main()
{

	int m, k;
	int card[1000];

	cin >> n >> m;

	for(int i = 0; i < 2 * n; i++) card[i] = i + 1;

	for(int i = 0; i < m; i++) {
		cin >> k;
		k > 0 ? k_cut(card, k) : riffle_shuffle(card);
	}

	for(int i = 0; i < 2 * n; i++) cout << card[i] << endl;

	return 0;

}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,i,ans=0;
  string s,t;
  map<string,int> z;
  cin>>n;
  for(i=0;i<n;i++){
    cin>>s;
    if(z.count(s)) z.at(s)++;
    else z[s]=1;
  }
  cin>>m;
  for(i=0;i<m;i++){
    cin>>t;
    if(z.count(t)) z.at(t)--;
    else z[t]=-1;
  }
  for(auto y:z) if(ans<y.second) ans=y.second;
  cout<<ans<<endl;
}

Measured memory_bytes: 3588
while True:
    H, W = map(int, input().strip().split())

    if H == 0 and W == 0:
        break

    for i in range(H):
        for j in range(W):
            if (i+j)%2 == 0:
                print('#', end='')
            else:
                print('.', end='')
        print()

    print()


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

using namespace std;
typedef long long ll;

int main()
{
    int n ;
    cin >> n;
    int arr[n];
    for(int i = 0 ; i < n ; i++)
    {
        cin >> arr[i];
    }
    int ans=0;
    for(int i = 0 ; i < n ; i++)
    {
        for(int j = i +1 ; j< n ; j++)
        {
            for(int k = j+1 ; k< n ; k++)
            {
                int x= max(max(arr[i] , arr[j]) , arr[k]);
                if(arr[i]!=arr[j]&&arr[j]!=arr[k]&&arr[i]!=arr[k]&&arr[i]+arr[j]+arr[k]-x > x)
                {
                    //cout << i+1 << " " << j+1 << " " << k+1 << "\n";
                    ans++;
                }
            }
        }
    }
    cout << ans ;
    return 0;
}


Measured memory_bytes: 3596
#abc124bc

s=[int(s) for s in raw_input()]
s0=[x%2 for x in xrange(len(s))]
s1=[(x^1)%2 for x in xrange(len(s))]
t0,t1=[],[]
for i in xrange(len(s)):
 t0.append(s[i]^s0[i])
 t1.append(s[i]^s1[i])
print min(sum(t0),sum(t1))


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

#define ll long long
#define repeat(i, x) for(register ll i = 0; i < x; i++)

using namespace std;

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

  if(S[0] == 'R' || S[1] == 'R' || S[2] == 'R') {
    if(S[0] == 'R' && S[1] == 'R' && S[2] == 'R') {
      cout << 3 << endl;
    }else if(S[1] != 'R') {
      cout << 1 << endl;
    }else if(S[0] == 'R' || S[2] == 'R') {
      cout << 2 << endl;
    }else{
      cout << 1 << endl;
    }
  }else{
    cout << 0 << endl;
  }
}

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

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

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

	int n[4];

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

	sort(n,n+4);

	if(n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;

}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    n=parseInt(readline())
    p=parseMap(split(readline()))
    ans=0
    for i in 3:n
        if maximum(p[i-2:i])!=p[i-1] && minimum(p[i-2:i])!=p[i-1]
            ans+=1
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 113748
h, w = map(int, input().split())
c = []
cn = []
for i in range(h):
    c.append(input())
for i in range(len(c)*2):
    if i%2 == 0:
        cn.append(c[int(i/2)])
    else:
        cn.append(c[int((i-1)/2)])
    
    print(cn[i])

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int k,r;cin>>k>>r;

  if(k>=10){
    cout<<r<<endl;
  }else{
    cout<<r+100*(10-k)<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//---------------------------------------------------
int n, u, v;
int pa[200000];
int a[200000];
int b[200000];
vector<int>e[200000];
int solve(int x, int pre) {
	for (auto g : e[x]) {
		if (g == pre) continue;
		a[g] = a[x] + 1;
		pa[g] = x;
		b[x] = max(b[x], solve(g, x) + 1);
	}
	return b[x];
}
signed main() {
	cin >> n >> u >> v;
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		e[a].push_back(b);
		e[b].push_back(a);
	}
	solve(v, 0);
	int ans = 0, res = 0;
	for (int x = u; x != v; x = pa[x]) {
		if (a[x] <= res) break;
		int k = res + b[x];
		int r = a[x] + b[x];
		ans = max(ans, r - 1);
		res++;
	}
	cout << ans << endl;
}

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

int main() {
	int N;
	cin >> N;
	vector<long> A(N), ans(N);
	for (long& i : A) cin >> i;
	long a = 0;
	for (int i = 1; i < N - 1; i += 2) a += A[i];
	ans.front() = accumulate(A.begin(), A.end(), 0l) - a * 2;
	for (int i = 1; i < N; i++) ans[i] = A[i - 1] * 2 - ans[i - 1];
	for (long& i : ans) cout << i << ' ';
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(i=a; i<n; i++)
#define rep(i,n) REP(i,0,n)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define foreach(it,x) for(typeof(x.begin()) it=x.begin(); it!=x.end(); it++)

bool used[40];
string dp[40];
vector<pair<int,string> > edge[40];

int main(){
    int n,a,s,g,i,j,k;

    while( cin >> n >> a >> s >> g, n|a|s|g ){

        rep(i,40) dp[i] = "";
        rep(i,40) edge[i].clear();
        memset(used, false, sizeof(used));

        //
        //cout << n << " " << a << " " << s << " " << g << endl;
        rep(i,a){
            int x,y; string lab; cin >> x >> y >> lab;
            //
            //cout << x << " " << y << " " << lab << endl;
            edge[y].push_back(make_pair(x,lab)); // ½ÎÉ·é
        }

        used[g] = true;
        bool loop = false;

        rep(i,260){
            bool flag = false;

            rep(j,n) if( used[j] ) { // j -> u
                string str = dp[j];

                rep(k,edge[j].size()){
                    int u = edge[j][k].first;
                    string& lab = edge[j][k].second;
                    if( dp[u] == "" || dp[u] > lab + str ){
                        used[u] = true;
                        dp[u] = lab + str;
                        flag = true;
                        if( u == s && i >= n-1 ){
                            loop = true;
                            break;
                        }
                    }
                }
                if( loop ) break;
            }

            if( !flag || loop ) break;
        }

        if( loop || dp[s] == "" ){
            puts("NO");
        }
        else{
            cout << dp[s] << endl;
        }
    }

    return 0;
}


/*
  Å«Åàn-1ñÅðÍoé
  ÅàA[vÉæÁÄÅ¬ªXVµ±¯çêéP[Xª éêA
  nñÚÈãÌÉdp[goal]ÌÅ¬ªXV³ê½êÍ[vÉüÁÄéÆ»fÅ«é
  ¦Ì¶ÍÅ·Åà260¶¾©çA260ñ²×êÎmÀB
 */

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <queue>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
#define INF 1000000000000
using namespace std;
using ll = long long;
int main(){
    ll n;
    cin >> n;
    ll i = 0;
    string ans = "";
    vector<bool> flag(100000,false);
    if(n==0){
        ans = "0";
    }else{
        while(true){
            if(n%(-2)==1||n%(-2)==-1){
                if(n<0){
                    n--;
                }
                flag[i] = true;
            }else{
                flag[i] = false;
            }
            n/=-2;
            if(n==0){
                break;
            }
            i++;
        }
        
        for(int j=0;j<=i;j++){
            if(flag[j]==false){
                ans="0"+ans;
            }else{
                ans="1"+ans;
            }
        } 
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
ll arr[maxn];
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    ll h; cin >> h;
    ll sum = 0, cnt = 1;
    while (h > 1) {
        sum += cnt;
        cnt *= 2;
        h /= 2;
    }
    sum += cnt;
    cout << sum << '\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
#define INF (1LL << 60)
#define ALL(x) (x).begin(),(x).end()
#define FOR(i,k,n) for(int i=(k);(i)<(n);(i)++)
#define REP(i,n) for(int i = 0;(i)<(n);(i)++)

int main() {
	LL N;
	LL ans = 1;
	string S;
	LL mod = 1e9 + 7;
	cin >> N >> S;
	
	for (char i = 'a'; i <= 'z'; i++) {
		LL count = 0;
		REP(j, N) {
			if (S[j] == i) {
				count++;
			}
		}
		ans *= count + 1;
		ans %= mod;
	}

	cout << ans - 1;
}


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

typedef pair<int,int> pii;
struct LowLink{
    int n, k;   // k  
    vector<int> ord, low;
    vector<pii> edge;
    vector<vector<int>> v;
    vector<bool> vis;

    LowLink(int n) : n(n){
        ord.resize(n);
        v.resize(n);
        low.resize(n);
        vis.resize(n, 0);
    }

    void add_edge(int a, int b){
        edge.push_back({a, b});
        v[a].push_back(b);
        v[b].push_back(a);
    }

    void dfs(int x, int p, int &k){
        ord[x] = low[x] = k++;
        vis[x] = true;
        for(int j : v[x]){
            if(vis[j]){
                if(j != p)  low[x] = min(low[x], ord[j]);
            }else{
                dfs(j, x, k);
                low[x] = min(low[x], low[j]);
            }
        }
    }

    void build(){
        k = 0;
        dfs(0, -1, k);
    }

    vector<pii> bridge(){
        vector<pii> ret;
        for(pii p : edge){
            int x = p.first, y = p.second;
            if(ord[x] > ord[y]) swap(x, y);
            if(ord[x] < low[y]) ret.push_back(p);
        }
        return ret;
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    LowLink l(n);
    while(m--){
        int u, v;
        cin >> u >> v;
        if(u > v)   swap(u, v);
        l.add_edge(u, v);
    }
    l.build();
    vector<pii> res = l.bridge();
    sort(res.begin(), res.end());
    for(pii p : res){
        cout << p.first << " " << p.second << endl;
    }
    return 0;
}


Measured memory_bytes: 4620
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	string s;
	cin>>s;
	if(s=="abc"||s=="acb"||s=="bac"||s=="cab"||s=="cba"||s=="bca"){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
signed main()
{
    string S;
    int month[2][13] = { { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
                         { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } };
 
    while ( cin >> S, S != "#" ) {
 
        int period = 0;
        for ( int i = 0; i < S.size(); i++) {
            if ( S[i] == '.' ) {
                period++;
            }
        }
 
        if ( period == 4 ) {
            int a, b, c, d, e;
 
            int cnt = 0;
            sscanf(S.c_str(), "%lld.%lld.%lld.%lld.%lld", &a, &b, &c, &d, &e);
            cnt = e + d * 20 + c * 360 + b * 7200 + a * 144000;
 
            a = 2012, b = 12, c = 21;
            for ( int i = 0; i < cnt; i++ ) {
                c++;
                bool isUru = (a % 400 == 0 || a % 100 != 0 && a % 4 == 0);
                int uru;
                if ( isUru ) {
                    uru = 1;
                } else {
                    uru = 0;
                }
                if ( month[uru][b] < c ) {
                    c = 1;
                    b++;
                    if ( b > 12 ) {
                        b = 1;
                        a++;
                    }
                }
            }
            cout << a << "." << b << "." << c << endl;
        } else {
            int a,b,c;
            sscanf(S.c_str(), "%lld.%lld.%lld", &a,&b,&c);
            int cnt = 11 + (a - 2013) * 365;
            if ( a == 2012 ) cnt--;
            for(int i=2013;i<a;i++){
                if(i%400==0||(i%100!=0&&i%4==0)){
                    cnt++;
                }
            }
            int bb = 1, cc = 1;
            while ( bb != b || cc != c ) {
                cc++;
                bool isUru = (a % 400 == 0 || a % 100 != 0 && a % 4 == 0 );
                int uru;
 
                if ( isUru ) uru = 1;
                else uru = 0;
 
                if ( cc > month[uru][bb] ) {
                    cc = 1;
                    bb++;
                }
                cnt++;
            }
            cout << (cnt / 144000) % 13 << "." << (cnt / 7200) % 20 << "." << (cnt / 360) % 20 << "." << (cnt / 20) % 18 << "." << cnt % 20 << endl;
        }
 
    }
}


Measured memory_bytes: 3216
package main
import (
    "fmt"
    "os"
    "bufio"
    "strconv"
)
var sc = bufio.NewScanner(os.Stdin)



func main() {
    sc.Split(bufio.ScanWords)
    // code goes here
    
    m := make(map[rune]int)
    s := nextString()
    for _, c := range s {
        m[c] += 1
    }
    if (m['a'] == 1 && m['b'] == 1 && m['c'] == 1) {
        fmt.Println("Yes");
    } else {
        fmt.Println("No");
    }
}



func nextInt() int64 {
    sc.Scan()
    v, e := strconv.ParseInt(sc.Text(), 10, 64)
    if e != nil {
        panic(e)
    }
    return v
}
func nextString() string {
    sc.Scan()
    return sc.Text()
}
func nextFloat() float64 {
    sc.Scan()
    v, e := strconv.ParseFloat(sc.Text(), 64)
    if e != nil {
        panic(e)
    }
    return v
}

Measured memory_bytes: 640
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
	int n, a, b, ans=0, i0, i1, i2, i3, i4, isum;

	scanf("%d %d %d", &n, &a, &b);
	
	for(int i=1; i<=n; i++){
		i4=i/10000;
		i3=i/1000-10*i4;
		i2=i/100-100*i4-10*i3;
		i1=i/10-1000*i4-100*i3-10*i2;
		i0=i-10000*i4-1000*i3-100*i2-10*i1;

		isum=i0+i1+i2+i3+i4;

		if(isum>=a && isum<=b){
			ans=ans+i;
		}
	}

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

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b,c;
    cin >> a >> b >> c;
    if(a==b and b==c){
        cout << "Yes" << enld;
    }else{
        cout << "No" << enld;
    }
    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 MOD 1000000007
#define el endl
typedef long long ll;

string f(string p, string y){
    string rel = "";
    rep(i, 6 - p.length()){
        rel += "0";
    }
    rel += p;
    rep(i, 6 - y.length()){
        rel += "0";
    }
    rel += y;
    return rel;
}

int main() {
    int n,m;
    cin >> n >> m;
    struct py {
        int num;
        int p;
        int y;
    };
    vector<py> cities;
    rep(i,m){
        py temp;
        int p,y;
        cin >> p >> y;
        temp.num = i;
        temp.p = p;
        temp.y = y;
        cities.emplace_back(temp);
    }
    sort(cities.begin(), cities.end(), [](const py& x, const py& y){return x.p < y.p;});
    
    int idx = 0;
    vector<py> pf;
    vector<string> ans(m);
    rep(i, n){
        while(idx < m){
            if(cities[idx].p != i+1) break;
            pf.emplace_back(cities[idx]);
            idx++;
        }
        sort(pf.begin(), pf.end(), [](const py& x, const py& y){return x.y < y.y;});
        rep(j, pf.size()){
            ans[pf[j].num] = f(to_string(pf[j].p), to_string(j+1));
        }
        pf = {};
    }
    rep(i, m){
        cout << ans[i] << el;
    }
}


Measured memory_bytes: 10868
# D

dct = {i: 0 for i in range(1, 10**5 + 1)}
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = 0
for i in A:
    dct[i] += 1
    ans += i
for i in range(Q):
    b, c = map(int, input().split())
    if (dct[b] == 0):
        print(ans)
        continue
    else:
        ans -= b * dct[b]
        ans += c * dct[b]
        dct[c] += dct[b]
        dct[b] = 0
        print(ans)

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

bool solve(void){
  int a, b;
  cin >> a >> b;
  string s;
  cin >> s;
  if(s.size() != a + b + 1){
    return false;
  }
  for(int i = 0 ; i < s.size() ; i++){
    if(i == a){
      if(s[i] != '-'){
        return false;
      }
    }else if(s[i] < '0' || '9' < s[i]){
      return false;
    }
  }
  return true;
}

int main(){
  if(solve()){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cctype>
using namespace std;
int main()
{
	int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<a[k-1];
	return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; ++i) {
        cin >> a.at(i);
    }

    ll sumO = 0, sumE = 0;
    for (int i=0; i<n; ++i) {
        if (i % 2 == 0) sumO += a.at(i);
        else sumE += a.at(i);
    }
    if (n % 2 == 0) {
        ll res = sumE;
        ll curO = 0, curE = 0;
        for (int i=0; i<n; ++i) {
            if (i % 2 == 0) {
                curO += a.at(i);
            } else {
                curE += a.at(i);
                chmax(res, sumE + curO - curE);
            }
        }
        cout << res << '\n';
    } else {
        ll res = sumE;
        ll curO = 0, curE = 0;
        vector<ll> diff(n);
        for (int i=0; i<n; ++i) {
            if (i % 2 == 0) {
                curO += a.at(i);
            } else {
                curE += a.at(i);
                chmax(diff.at(i), curO - curE);
                if (i > 1) chmax(diff.at(i), diff.at(i-2));
            }
        }
        chmax(res, sumE + diff.at(n-1));
        curO = curE = 0;
        ll maxi = 0;
        for (int i=n-1; i>=0; --i) {
            if (i % 2 == 0) {
                curO += a.at(i);
            } else {
                curE += a.at(i);
                chmax(maxi, curO - curE);
                if (i == 1) chmax(res, sumE + maxi);
                else chmax(res, sumE + diff.at(i-2) + maxi);
            }
        }
        cout << res << '\n';
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 6320
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());

		List<Integer> s = new ArrayList();
		int total = 0;
		for(int i =0; i <N ; i++) {
			int a =Integer.parseInt(sc.next());
			total += a;
			s.add(a);
		}
		Collections.sort(s);
		Collections.reverse(s);


		for(int m = 0; m < M; m++) {
			int a = s.get(m);
			if(a*4*M < total) {
				System.out.println("No");
				return;
			}
		}

		System.out.println("Yes");

	}
}

Measured memory_bytes: 35604
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    int N;
    string s;

    cin >> N;
    cin >> s;

    int leader = 0;
    int num = 0;
    int num_old = s.size();

    for (int i = 0; i < s.size(); i++)
    {
        if (s[i] == 'W')
        {
            num++;
        }
        else
        {
            num--;
        }

        if (num < num_old)
        {
            leader = i;
            num_old = num;
        }
    }

    int ans = 0;
    for (int i = 0; i < s.size(); i++)
    {
        if ((i < leader && s[i] == 'W') || (i > leader && s[i] == 'E'))
        {
            ans++;
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 900
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7

ll max(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
double max(double a, double b) {

	if (a > b)return a;
	else return b;

}
//a??¨b?????§?????????

ll min(ll a, ll b) {

	if (a < b)return a;
	else return b;

}
//a??¨b????°??????????

ll avd_i(ll a, ll b) {

	if (a > b)return a - b;
	else return b - a;

}
double avd_d(double a, double b) {

	double re;
	if (a > b)re = a - b;
	else re = b - a;
	return re;

}
//a??¨b???????????¶??????

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//p????´???°,a???b??????p??§?????£?????????

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//p????´???°,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

	}
	ll r;
	r = b%a;
	if (r == 0)return a;
	else return gcd(r, a);

}
//?????§??¬?´???°

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//????°???¬?????°

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

	cin >> a >> b;

	c = a / b;
	d = a%b;
	e = (double)a / (double)b;

	printf("%d %d %f\n", c, d, e);

	return 0;
}

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

int main(void){
    int h,n,sum;
    sum = 0;

    cin >> h >> n; 
    vector<int> a(n+10);

    for(int i = 1; i <= n; i++){
        cin >> a.at(i);
        sum += a.at(i);
    }

    if(sum >= h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>

using namespace std;
using ll = long long;
const ll mod =  1000000007;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define all(x) (x).begin(),(x).end()

ll power(ll base, ll exponent, ll module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ ll root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2, mod);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

vector<vector<ll>> dp;

combination table(2 * 100000 + 50);

signed main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> w(n);
  REP(i, n) cin >> w[i];
  vector<ll> cum(n+1);
  REP(i, n) cum[i+1] = cum[i] + w[i];
  ll ans = 1e9;
  REP(i, n) {
    ans = min(ans, abs(cum[n] - 2 * cum[i]));
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	int N,tmp,ma=-1,mi=1010;
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>tmp;
		ma=max(ma,tmp);
		mi=min(mi,tmp);
	}
	cout<<ma-mi<<endl;
	return 0;
}


Measured memory_bytes: 256