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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,m,k;
const int FMAX = 1252521;
ll fact[FMAX];
ll ifact[FMAX];
ll tri[FMAX];

ll modpow(ll a,ll b,ll c){
  ll r = 1;
  while(b){
    if(b&1)r=r*a%c;
    a=a*a%c;
    b>>=1;
  }
  return r;
}
ll modinv(ll a,ll c){
  return modpow(a,c-2,c);
}

int main(){
  scanf("%d%d%d",&n,&m,&k);
  // fact init
  fact[0] = 1;
  FOR(i,1,FMAX)fact[i]=fact[i-1]*i%MOD;
  ifact[FMAX-1]=modinv(fact[FMAX-1],MOD);
  FORR(i,0,FMAX-1)ifact[i]=ifact[i+1]*(i+1)%MOD;
  // tri init
  tri[0] = 1;
  FOR(i,1,FMAX)tri[i]=tri[i-1]*3%MOD;
  // a == n-1 && b <= m && c <= k
  ll ans = 0;
  int a = n-1;
  ll bipow = 1;
  ll subsum = 0;
  int befbeg,befend;
  FOR(s,0,m+k+1){
    // c = s-b
    // 0<=c<=k
    // 0<=b<=m

    // s-b>=0 -> b<=s
    // s-b<=k -> b>=s-k
    int abc = a+s;
    int rest = n+m+k-abc-1;
    ll unit = fact[abc]*ifact[a]%MOD*ifact[s]%MOD*tri[rest]%MOD;
    ll add = 0;
    int beg = max(s-k,0);
    int end = min(s,m);
    if(s>0){
      bipow *= 2;
      subsum *= 2;
      if(befbeg+1==beg){
        subsum += fact[s-1]*ifact[befbeg]%MOD*ifact[s-1-befbeg]%MOD;
      }
      if(befend==end){
        subsum += fact[s-1]*ifact[befend]%MOD*ifact[s-1-befend]%MOD;
      }
      bipow %= MOD;
      subsum %= MOD;
    }
    befbeg = beg;
    befend = end;
    ans += unit*(bipow+MOD-subsum)%MOD;
    if(ans>=MOD)ans-=MOD;
  }
  printf("%lld\n",ans);
  return 0;
}


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

using namespace std;

int main()
{
    set<int>s;
    int a;
    for(int i=1;i<=3;i++){
        cin>>a;
        s.insert(a);
    }
    if(s.size()==2) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

//プロセスを表す構造体
typedef struct pp {
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) {return a<b ? a : b;} //最小値を返す

int main(){
    int elaps = 0,c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);

    //すべてのプロセスをキューに順番に追加する
    for(i=1; i<=n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n+1;

    //シミュレーション
    while(head != tail){
        u = dequeue();
        c = min(q, u.t); //qまたは必要な時間u.tだけ処理を行う
        u.t -= c; //残りの必要時間を計算
        elaps += c; //経過時間を加算
        if (u.t > 0) enqueue(u); //処理が完了していなければキューに追加
        else{
            printf("%s %d\n", u.name, elaps);
        }
    }

    return 0;
}


Measured memory_bytes: 12720
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define m 1000000007

int main()
{
	int a,b;
	cin>>a>>b;
	if(a>9 or a<1 or b>9 or b<0) cout<<-1;
	else cout<<a*b<<endl;
	return 0;
} 

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

using namespace std;

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

    vector<int> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }

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

    long long count = 0;
    int ans = 0;

    for (int i = 0; i < N; ++i) {
        count += a[i];

        if (count > x) {
            break;
        } else {
            if (i == N-1) {
                if (count == x) ++ans;
            } else {
                ++ans;
            }
        }
    }


    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int[] a=new int[n];
		Arrays.setAll(a,i->s.nextInt());
		Arrays.sort(a);
		//System.err.println(Arrays.toString(a));
		System.out.println(a[n/2]-a[n/2-1]);
	}
}


Measured memory_bytes: 60676
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <math.h>
#include <time.h>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	int m, d;
	cin >> m >> d;
	int cnt = 0;
	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= d; j++)
		{
			if (j % 10 >= 2 && j / 10 >= 2 && (j % 10) * (j / 10) == i)
			{
				cnt++;
			}
		}
	}
	cout << cnt << '\n';
}

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

int main(){
	vector<vector<int> > field(14, vector<int>(14, 0));
	int x,y,s;
	while(scanf("%d,%d,%d", &x, &y, &s)!=EOF){
		x+=2; y+=2;
		for(int i=-2; i<=2; i++){
			for(int j=-2; j<=2; j++){
				if(s==1 && abs(i)+abs(j)<=1){
					field[x+i][y+j]++;
				}
				if(s==2 && abs(i)<=1 && abs(j)<=1){
					field[x+i][y+j]++;
				}
				if(s==3 && abs(i)+abs(j)<=2){
					field[x+i][y+j]++;
				}
			}
		}
	}
	
	int white = 0;
	int deep = 0;
	for(int i=2; i<=11; i++){
		for(int j=2; j<=11; j++){
			deep = max(deep, field[i][j]);
			if(field[i][j] == 0 ) white++;
		}
	}
	cout << white << endl << deep << endl; 
    return 0;
}

Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];
deque<int> Q;

void go(ll x){
	if(x == 1) return;
	int now;
	if(x&1){
		go(x-1);
		now = Q.size() + 1;
		Q.push_front(now);
	}
	else{
		go(x/2);
		now = Q.size() + 1;
		Q.push_back(now);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll i,n,k,j;
	cin >> n;
	go(n+1);
	cout << Q.size() * 2 << endl;
	for(int x: Q) cout << x << " " ;
	int cnt = 1;
	while(cnt <= Q.size()) cout << cnt++ << " " ;
	cout << endl;

	return 0;
} 

int mpow(int base, int exp) {
	base %= mod;
	int result = 1;
	while (exp > 0) {
	if (exp & 1) result = ((ll)result * base) % mod;
	base = ((ll)base * base) % mod;
	exp >>= 1;
	}
	return result;
}

void ipgraph(int m){
	int i, u, v;
	fo(i, m){
		cin>>u>>v; 
		u++, v++;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 7296
#include<iostream>
#include<string>
#include<math.h>

using namespace std;

int main()
{	int a , b , c , d , e;
	cin >> a >> b;
	c = a + b;
	d = a - b;
	e = a * b;
	a = max(c , d);
	a = max(a , e);
	cout << a;
}

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

int main() {

  int x;
  cin >> x;
  int k = 1;

  if(360%x == 0) {
    cout << 360/x;
  } else{
    for (int i = 0; i < 10000; i++) {
    if (k*x%360 == 0) {
      cout << k;
      break;
    }
      k++;
  }
  }
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<algorithm>
 
using namespace std ;
int main () {
  string S;
  string T;
  int K,kotae=0,cnt=0;
  int lens;
  cin >> S;
  cin >> K;
  lens = S.size();
  for(int i=0;i<lens;i++) {
    if(S[i]=='1') {
      cnt = cnt+1;    
    }
    else break;
  }
  if(K<=cnt) {
    T[0] = S[0];
  }
  else T[0] = S[cnt];
  cout << T[0] << endl;
  return(0);
}

Measured memory_bytes: 256
S = input()
N = len(S)
A = [0] * (N+1)
C = [0] * (N+1)
X = [0] * (N+1)
Y = [0] * (N+1)

for i in range(N):
    A[i+1] = A[i] + (1 if S[i] == "A" else 0)
    X[i+1] = X[i] + (1 if S[i] == "?" else 0)
for i in range(N)[::-1]:
    C[i] = C[i+1] + (1 if S[i] == "C" else 0)
    Y[i] = Y[i+1] + (1 if S[i] == "?" else 0)

P = 10**9 + 7
POW = [1]
for i in range(2*N+10):
    POW.append(POW[-1]*3%P)
    
ans = 0
for i in range(N):
    if S[i] == "B" or S[i] == "?":
        a, x, c, y = A[i], X[i], C[i+1], Y[i+1]
        ans += a * c * POW[x+y]
        if x: ans += x * c * POW[x+y-1]
        if y: ans += a * y * POW[x+y-1]
        if x and y: ans += x * y * POW[x+y-2]
        ans %= P
print(ans)

Measured memory_bytes: 58096
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){

  vector <int> so,sum;
  int a[110001]={0},from,n,p,i,j;
  
   for(i=2;i<=110000;i++){
    if(a[i]==0){
      so.push_back(i);
      for(j=i;j<=110000;j+=i) a[j]=1;
    }
   }
   //for(i=0;i<20;i++) cout<<so[i]<<endl;
   while(cin>>n>>p,n!=-1){
  from=0;
  for(i=0;n>=so[i];i++) from++;
  //cout<<from<<endl;
  sum.clear();
  for(i=from;i<from+p;i++) for(j=i;j<from+p;j++) sum.push_back(so[i]+so[j]);
  sort(sum.begin(),sum.end());

  cout<<sum[p-1]<<endl;
   }
  
  return 0;

}

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

int main() {
	int n;
	cin>>n;
	string s;
	cin>>s;
	int count1=0;
	int count2=0;
	for(int i=0;i<n;i++){
		if(s[i]=='R')
		 count1++;
		else
		 count2++;
	}
	int count3=0;
	for(int i=0;i<count1;i++){
		if(s[i]=='W')
		 count3++;
	}
	cout<<count3<<endl;
	return 0;
}

Measured memory_bytes: 3748
#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int n;cin>>n;
    vector<P> v;
    for(int i=0;i<n;i++){
      ll a;cin>>a;
      v.push_back(P(a,0));
    }
    for(int i=0;i<n;i++){
      ll b;cin>>b;
      v.push_back(P(b,1));
    }
    sort(v.begin(),v.end());
    ll acnt=0,bcnt=0;
    ll res=1;
    for(int i=0;i<2*n;i++){
      if(v[i].second==0){
        if(bcnt){
          res *= bcnt;
          res %= MOD;
          bcnt--;
          continue;
        }
        acnt++;
      }
      else{
        if(acnt){
          res *= acnt;
          res %= MOD;
          acnt--;
          continue;
        }
        bcnt++;
      }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 3444
#include <stdio.h>

int main(void)
{
	int a[4], b[4];
	int hit, blow, i, j;
	
	while (scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]) != EOF){
		scanf("%d %d %d %d", &b[0], &b[1], &b[2], &b[3]);
		hit = blow = 0;
		
		for (i = 0; i < 4; i++){
			if (a[i] == b[i]){
				hit++;
			}
		}
		
		for (i = 0; i < 4; i++){
			for (j = 0; j < 4; j++){
				if (i != j && a[i] == b[j]){
					blow++;
				}
			}
		}
		printf("%d %d\n", hit, blow);
	}
	
	return (0);
}

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

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define fast_work {ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}

const ll INF = 1e18, NMAX = 1e6 + 5, MOD = 1000000007, N = 1e9 + 5, LOG = 25;
const ld EPS = 1e-8, pi = 3.14159265358979323846;

int p[5005], n;
ll answer = -INF, k, c[5005];
vector<pll> a;

void dfs(int v, ll cur) {
    ll deep = a.size();
    if(deep > 0 && v == a[0].f) {

        if(cur >= 0) {
            ll ost = k % deep, d = k / deep, add = 0;

            if(ost == 0) {
                add = cur;
                ost = deep - 1;
                --d;
            }

            for(int i = 1; i <= ost; ++i) add = max(add, a[i].s);
            answer = max(answer, d * cur + add);
        }

        answer = max(answer, cur);
        return;
    }

    if(deep > 0) answer = max(answer, cur);
    if(deep == k) return;

    a.pb({v, cur});
    dfs(p[v], cur + c[p[v]]);
}

signed main() {
    cin >> n >> k;

    for(int i = 1; i <= n; ++i) cin >> p[i];
    for(int i = 1; i <= n; ++i) cin >> c[i];

    answer = c[1];
    for(int i = 1; i <= n; ++i) {
        a.clear();
        dfs(i, 0);
    }

    cout << answer;
}





Measured memory_bytes: 4040
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

typedef struct Edge {
    int to;
    long long int dist;
} edge;

int main() {
    int N;
    cin >> N;
    
    vector<vector<edge> > E(N+1);
    for(int n=0; n<N-1; n++) {
        int a, b;
        long long int c;
        cin >> a >> b >> c;
        edge e={a, c};
        E[b].push_back(e);
        e.to = b;
        E[a].push_back(e);
    }
    
    int Q;
    long long int K;
    cin >> Q >> K;
    vector<long long int> dist(N+1, -1);
    queue<int> que;
    que.push(K);
    dist[K]=0;
    while(!que.empty()) {
        int cur=que.front();
        que.pop();
        
        for(int i=0; i<E[cur].size(); i++) {
            if(dist[E[cur][i].to]!=-1) continue;
            
            dist[E[cur][i].to] = dist[cur]+E[cur][i].dist;
            que.push(E[cur][i].to);
        }
    }
    
    for(int q=0; q<Q; q++) {
        int x, y;
        cin >> x >> y;
        cout << dist[x]+dist[y] << endl;
    }

    return 0;
    
}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    map<string,int>tmp;


    tmp["AC"]=0;
    tmp["WA"]=0;
    tmp["TLE"]=0;
    tmp["RE"]=0;

    for(int i = 0 ; i  < n ;i++)
    {
        string s;cin>>s;

        tmp[s]++;
    }

    cout<<"AC x " << tmp["AC"]<<endl;
    cout<<"WA x " << tmp["WA"]<<endl;
    cout<<"TLE x " << tmp["TLE"]<<endl;
    cout<<"RE x " << tmp["RE"]<<endl;
    return 0;
}


Measured memory_bytes: 3600
import math
a,b,x = map(int,input().split())

ans = 0

sw = 2*x/(a**3)
sw_c = abs(math.atan(sw))

ans = abs(math.atan(2/a*(b-x/(a**2))))
ans_1 = abs(math.atan(a*b**2/(2*x)))

if(ans < sw_c):
    print(math.degrees(ans))
else:
    print(math.degrees(ans_1))

'''
print("------")
print(math.degrees(ans))
print(math.degrees(sw_c))
print(math.degrees(ans_1))
'''

Measured memory_bytes: 3064
#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using  namespace std;

#define endl '\n'
#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x <<'\n';

using db = long double;
using pii = pair < int, int >;
typedef tuple<int, int> tii;
using pll = pair < ll, ll >;
#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define all(a)      (a).begin(),(a).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
const db pi = acos(-1);
const long long infl = LLONG_MAX;

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 1; _tt <= tt; _tt++) // testcase 

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n,d,x,b,a,t,i;		string s;
  cin>>n>>a>>b;	x=b;
  cin>>s;	t=0;
  rep(i,0,n,1){
  	if(s[i]!='a' && s[i]!='b'){
  		ce("No")	
  	}else if(s[i]=='a'){
  		if(t< a+b){	ce("Yes")	t++;}
  		else ce("No")
  		
  	}else {
  		if(t<a+b && x>0){	ce("Yes")		t++;	x--;}
  		else ce("No")
  	
  	}
  }
  return 0;
}


Measured memory_bytes: 848
#include<bits/stdc++.h>
#define N 1005
#define int long long
using namespace std;
int n,m,a[N];
char c[N];
long long ans;
signed main(){
	scanf("%lld%lld",&n,&m);
	long long ans=n+m;
	ans=max(ans,n-m);
	ans=max(ans,n*m);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;
const int MAX_N=5000;
int N;
typedef pair<ll,ll> P;
ll dp[MAX_N+1][MAX_N+1];
const ll INF=1e18;
P per[MAX_N];
int main(){
	cin>>N;
	REP(i,N){
		ll h,p;
		cin>>h>>p;
		per[i]=P(h,p);
	}
	sort(per,per+N,[](P a,P b){
		return a.first+a.second<b.first+b.second;
	});
	dp[0][0]=0;
	REP(i,N){
		dp[0][i+1]=INF;
	}
	REP(i,N){
		REP(j,N+1){
			dp[i+1][j]=dp[i][j];
			if(j>0 && dp[i][j-1]<=per[i].first){
				dp[i+1][j]=min(dp[i+1][j],dp[i][j-1]+per[i].second);
			}
		}
	}
	int ans=0;
	REP(i,N+1){
		if(dp[N][i]<INF){
			ans=i;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 195712
// D - Cake 123

// 解説pdfの解法 #2

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

ll A[1000], B[1000], C[1000];

int main() {
	ll X, Y, Z, K;
	cin >> X >> Y >> Z >> K;

	for (int i=0; i<X; i++) {
		cin >> A[i];
	}
	sort(A, A+X, greater<ll>());

	for (int i=0; i<Y; i++) {
		cin >> B[i];
	}
	sort(B, B+Y, greater<ll>());

	for (int i=0; i<Z; i++) {
		cin >> C[i];
	}
	sort(C, C+Z, greater<ll>());

	vector<ll> P;
	for (int i=0; i<X; i++) {
		for (int j=0; j<Y; j++) {
			for (int k=0; k<Z; k++) {
				if ((i+1) * (j+1) * (k+1) > K) break;
				else P.push_back(A[i] + B[j] + C[k]);
			}
		}
	}

	sort(P.begin(), P.end(), greater<ll>());

	for (int i=0; i<K; i++) {
		cout << P[i] << endl;
	}

	return 0;
}

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

int main(){
    int i, s;
    string number;
    while(1){
        s = 0;
        cin >> number;
        if (number[0] == '0') break;
        for ( int i = 0; i < number.size(); i++ ){
            s += number[i] - '0';
        }
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3224
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
using namespace std;
const int MAXN = 100005;
const int INF = 2000000000;
int numEdge, n, k;
int head[MAXN], id[MAXN];
int L[MAXN], R[MAXN];
struct Edge
{
    int v, next;
}edge[MAXN << 1];
void addEdge(int u, int v)
{
    edge[numEdge].v = v;
    edge[numEdge].next = head[u];
    head[u] = numEdge++;
}
void dfs(int u, int pre)
{
    for(int i = head[u]; i != -1; i = edge[i].next)
    {
        int v = edge[i].v;
        if(v == pre) continue;
        dfs(v, u);
        if(R[v] + 1 < L[u] || L[v] - 1 > R[u]) id[u] = 2;
        L[u] = max(L[u], L[v] - 1);
        R[u] = min(R[u], R[v] + 1);
        if(id[v] != 2 && id[v] != -1 && id[u] == -1) id[u] = id[v] ^ 1;
        else if(id[u] == id[v] && id[u] != -1) id[u] = 2;
    }
}
void dfs(int u, int pre, int nxtL, int nxtR)
{
    if(pre != -1)
    {
        if(id[u] == -1 && id[pre] != 2 && id[pre] != -1) id[u] = id[pre] ^ 1;
        else if(id[u] == id[pre] && id[u] != -1) id[u] = 2;
        if(nxtR < L[u] || nxtL > R[u]) id[u] = 2;
        L[u] = max(L[u], nxtL);
        R[u] = min(R[u], nxtR);
    }
    int max1 = L[u], max2 = -INF;
    int min1 = R[u], min2 =  INF;
    for(int i = head[u]; i != -1; i = edge[i].next)
    {
        int v = edge[i].v;
        if(v == pre) continue;
        if(L[v] - 1 >= max1) max2 = max1, max1 = L[v] - 1;
        else if(L[v] - 1 > max2) max2 = L[v] - 1;

        if(R[v] + 1 <= min1) min2 = min1, min1 = R[v] + 1;
        else if(R[v] + 1 < min2) min2 = R[v] + 1;
    }
    for(int i = head[u]; i != -1; i = edge[i].next)
    {
        int v = edge[i].v;
        if(v == pre) continue;
        int tmpL = max1 - 1, tmpR = min1 + 1;
        if(L[v] - 1 == tmpL + 1) tmpL = max2 - 1;
        if(R[v] + 1 == tmpR - 1) tmpR = min2 + 1;
        dfs(v, u, tmpL, tmpR);
    }
}
int main()
{
    scanf("%d", &n);
    numEdge = 0;
    memset(head, -1, sizeof(head));
    memset(id, -1, sizeof(id));
    for(int u, v, i = 1; i < n; i++)
    {
        scanf("%d%d", &u, &v);
        addEdge(u, v);
        addEdge(v, u);
    }
    for(int i = 1; i <= n; i++) L[i] = -INF, R[i] = INF;
    scanf("%d", &k);
    for(int v, p, i = 0; i < k; i++)
    {
        scanf("%d%d", &v, &p);
        id[v] = p & 1;
        L[v] = R[v] = p;
    }
    dfs(1, -1);
    dfs(1, -1, -INF, INF);
    bool flag = true;
    for(int i = 1; i <= n; i++) if(id[i] == 2) flag = false;
    if(!flag) puts("No");
    else
    {
        puts("Yes");
        for(int i = 1; i <= n; i++) printf("%d\n", L[i]);
    }
    return 0;
}


Measured memory_bytes: 11904
#[macro_use]
mod utils {
    macro_rules! input {
        ($($r:tt)*) => {
            let stdin = std::io::stdin();
            let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
            let mut next = move || -> String{
                bytes
                    .by_ref()
                    .map(|r|r.unwrap() as char)
                    .skip_while(|c|c.is_whitespace())
                    .take_while(|c|!c.is_whitespace())
                    .collect()
            };
            input_inner!{next, $($r)*}
        };
    }
    macro_rules! input_inner {
        ($next:expr) => {};
        ($iter:expr, ) => {};
 
        ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
            let $var = read_value!($next, $t);
            input_inner!{$next $($r)*}
        };
        ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
            let mut $var = read_value!($next, $t);
            input_inner!{$next $($r)*}
        };
    }
    macro_rules! read_value {
        ($next:expr, ( $($t:tt),* )) => {
            ( $(read_value!($next, $t)),* )
        };
        ($next:expr, [ $t:tt ; $len:expr ]) => {
            (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        };
        ($next:expr, chars) => {
            read_value!($next, String).chars().collect::<Vec<char>>()
        };
        ($next:expr, usize1) => {
            read_value!($next, usize) - 1
        };
        ($next:expr, $t:ty) => {
            $next().parse::<$t>().expect("Parse error")
        };
    }
}
 

fn main() {
    input!{
        x: u64
    }
    println!("{}",(x/500)*1000+((x%500)/5)*5);
}

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

namespace AtCoder {
    class Program {
        static void Main(string[] args) {

            var n = int.Parse(Console.ReadLine());
            var sum = 0.0;
            for (int i = 0; i < n; i++) {
                var input = Console.ReadLine().Split(' ').ToArray();
                sum += input[1] == "BTC" ? double.Parse(input[0]) * 380000.0 : double.Parse(input[0]);
            }

            Console.WriteLine(sum);
        }
    }
}

Measured memory_bytes: 13268
N = int(input())
sum = 0

if (1 <= N and N <= 10 ** 6):
    for i in range(1, N + 1):
        if (i % 3 == 0 & i % 5 == 0):
            N = "FizzBuzz"
        elif i % 3 == 0:
            N = "Fizz"
        elif i % 5 == 0:
            N = "Buzz"
        else:
            sum += i
    print(sum)

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

int main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H - h)*(W - w) << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
import sys


if __name__ == '__main__':
    a = list(map(int,input().split()))
    a = sorted(a)

    answer = sys.maxsize
    for e in list(itertools.permutations(a)):
        a1, a2, a3 = e
        answer = min(answer, abs(a2-a1) + abs(a3-a2))
    print(answer)





Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  vector<char> v(W + 2, '#'), y(W);
  
  for(int i = 0; i < W + 1; i++){
   cout << v.at(i);
  }
  cout << '#' << endl;
  
  for(int i = 0; i < H; i++){
    cout << '#';
    for(int n = 0; n < W; n++){
      cin >> y.at(n);
      cout << y.at(n);
    }
    cout << '#' << endl;
  }
  for(int i = 0; i < W + 2; i++){
   cout << v.at(i);
  }
}

Measured memory_bytes: 3596
S = list(input().split(" "))
tmp = []

for i in range(len(S)):
  if S[i] == "+":
    tmp.append(tmp.pop()+tmp.pop())
  elif S[i] == "-":
    tmp.append(tmp.pop(-2)-tmp.pop())
  elif S[i] == "*":
    tmp.append(tmp.pop()*tmp.pop())    
  else:
    tmp.append(int(S[i]))
print(int(tmp[0]))
#print(" ".join(map(str, S)))


Measured memory_bytes: 5600
from collections import defaultdict
S = list(input())
T = list(input())

Ms = defaultdict(int)
Mt = defaultdict(int)

for i in range(len(S)):
    Ms[S[i]] += 1
    Mt[T[i]] += 1

ans = "Yes"

A = list(Ms.values())
A.sort()
B = list(Mt.values())
B.sort()

for i in range(len(A)):
    if A[i] != B[i]:
        ans = "No"
        break

print(ans)


Measured memory_bytes: 6960
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end()) 
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);


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

  int h, a;
  cin >> h >> a;
  int ans = h / a;
  if (h%a != 0) ans++;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
a.reverse()
ans=0
while x>0:
  if x==0:
    break
  elif len(a)==0:
    ans-=1
    break
  if a[-1]<=x:
    x-=a.pop()
    ans+=1
  else:
    break
print(ans)

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

int main() {
  int N , K ;
  cin >> N >> K ;
  vector<int>d(N);
  for(int i=0; i < K ; i++){
    int m;
    cin >> m;
    for(int j=0 ; j < m ; j++){
      int a;
      cin >> a;
      d.at(a-1)=1;
    }
  }
  int ans=0;
  for( int i =0; i<N ;i++){
    if(d.at(i)==0){
      ans++;
    }
  }
  cout << ans << endl;
}
    
    
    
    

Measured memory_bytes: 3600
#include <iostream>
using namespace std;
int main()
{
    int lsum = 0, n, l, lmax = 0;
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> l;
        lsum += l;
        lmax = (l > lmax ? l : lmax);
    }
    cout << (lsum > 2 * lmax ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CCandles solver = new CCandles();
        solver.solve(1, in, out);
        out.close();
    }

    static class CCandles {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt(), k = in.nextInt();
            int[] x = new int[n];
            int[] y = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = in.nextInt();
                y[n - i - 1] = -x[i];
            }
            int ans = Integer.MAX_VALUE;
            for (int i = 0; i < n - k + 1; i++) {
                ans = Math.min(ans, x[i + k - 1] - x[i] + Math.abs(x[i]));
                ans = Math.min(ans, y[i + k - 1] - y[i] + Math.abs(y[i]));
            }
            out.println(ans);
        }

    }
}



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

using namespace std;

char f[610][610];
bool ok[610][610];

int main()
{
	int n;
	cin >> n;
	for (int i(0); i < n; ++i)
		for (int j(0); j < n; ++j)
			cin >> f[i][j];
	for (int i(0); i < n; ++i)
		for (int j(0); j < n; ++j)
		{
			ok[i][j] = true;
			for (int k(0); k < n; ++k)
				if (f[(i + k) % n][j] != f[i][(j + k) % n])
					ok[i][j] = false;
		}
	int ans(0);
	for (int i(0); i < n; ++i)
		for (int j(0); j < n; ++j)
		{
			int cur(1);
			for (int k(0); k < n; ++k)
				if (!ok[(i + k) % n][(j + k) % n])
					cur = 0;
			ans += cur;
		}
	cout << ans;
}


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

int main(){
  int n;
  bool ans=true;
  cin >> n;
  vector<string>s(n);
  for(int i=0;i<n;i++){
    cin>>s.at(i);
  }
   for(int i=1;i<n;i++){
     if((s.at(i)).front()!=(s.at(i-1)).back()){
       ans=false;
       break;
     }
     for(int j=0;j<i;j++){
       if(s.at(i)==s.at(j)){
	 ans=false;
	 break;
       }
     }
     if(ans==false)break;
   }
   if(ans==true)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}

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


int main(){
  int n,m;
  cin>>n>>m;
  set <int> count_all;//出てくるものすべてを足したやつ
  set <int> count_no;
  vector<int> h(n);

  rep(i,n){
    cin>>h.at(i);
  }



  for(int j = 0 ;j<m ; j++){
    int a;
    int b;
    cin>>a>>b;
    a-=1;
    b-=1;
    count_all.insert(a);
    count_all.insert(b);
    int c;
    if(h.at(a)==h.at(b)){
      count_no.insert(a);
      count_no.insert(b);
    }
    else if(h.at(a)<h.at(b)){
      count_no.insert(a);
    }
    else {
      count_no.insert(b);
    }
  }
  cout<<(n-count_all.size())+(count_all.size()-count_no.size())<<endl;


}


Measured memory_bytes: 10396
#include<bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
 
#define limit (int) (5e5 + 5) 
#define maxn (long long int) (2147483647)
 
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;
 
int n,q;
int c[limit],ft[limit] = {},ans[limit];
vector<int> a,ql[limit],qid[limit];
 
void update(int in,int d)
{
    // cout << n;
    // cout << in << " " << d << "\n";
    
    for (int i = in+1; i <= n ; i += i&(-i))
    {
        // cout << in << " " << i << " " << d << "\n";
        ft[i] += d;
    }

    return;
}

int sum(int in)
{
    in++;

    int ans = 0;

    for (int i = in; i > 0; i -= i&(-i))
    {
        ans += ft[i];
    }

    // cout << ans << " ";
    return ans;
}


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    
    cin >> n >> q;

    a.assign(n,-1);

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

    int l,r;

    for (int i = 0; i < q; ++i)
    {
        cin >> l >> r;
        l--;r--;

        ql[r].push_back(l);
        qid[r].push_back(i);
    }
    
    for (int i = 0; i < n; ++i)
    {
        // for (int j = 0; j < n; ++j)
        // {
        //     cout << ft[j] << " ";
        // }
        // cout << "\n";

        if (a[c[i]] != -1)
        {
            update(a[c[i]],-1);
        }

        a[c[i]] = i;
        update(a[c[i]],1);

        for (int j = 0; j < ql[i].size(); ++j)
        {
            ans[qid[i][j]] = sum(i) - sum(ql[i][j] - 1);
        }
    }
    
    for (int i = 0; i < q; ++i)
    {
        cout << ans[i] << "\n";
    }

    return 0;
}
 
 

Measured memory_bytes: 52972
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val c = (1..3).map { (1..3).map { sc.nextInt() } }
    for (a0 in 0..100) {
        for (a1 in 0..100) {
            for (a2 in 0..100) {
                val a = arrayOf(a0, a1, a2)
                val set = mutableSetOf<Triple<Int,Int,Int>>()
                for (i in 0 until 3) {
                    val b0 = c[i][0] - a[i]
                    val b1 = c[i][1] - a[i]
                    val b2 = c[i][2] - a[i]
                    set.add(Triple(b0, b1, b2))
                }
                if (set.size == 1) {
//                    println("$a0 $a1 $a2")
//                    val b = set.first()
//                    println("${b.first} ${b.second} ${b.third}")
                    println("Yes")
                    return
                }
            }
        }
    }
    println("No")
}

Measured memory_bytes: 121212
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<iomanip>
using namespace std;

int main()
{
    int a,j=0,k=0,m=0;
    scanf("%d",&a);
    int q,w,e,r;
    r=a%10;
    e=a/10%10;
    w=a/100%10;
    q=a/1000%10;

    for(j=0; j<2; ++j)
    {
        for(k=0; k<2; ++k)
        {
            for(m=0; m<2; ++m)
            {
                if(q+w*pow(-1,j)+e*pow(-1,k)+r*pow(-1,m)==7)
                {
                    cout<<q;
                    if(j==0)cout<<"+";
                    else cout<<"-";
                    cout<<w;
                    if(k==0)cout<<"+";
                    else cout<<"-";
                    cout<<e;
                    if(m==0)cout<<"+";
                    else cout<<"-";
                    cout<<r<<"=7"<<endl;
                    return 0;


                }
            }
        }
    }


}


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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<double, double> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int n, k;
    cin >> n >> k;
    int ans = n % k;
    cout << ans << endl;

}


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

namespace ClassLibrary1
{
    public class ListNode
    {
        public int val;
        public ListNode next;
        public ListNode(int x) { val = x; }
    }


    public class Class1
    {

        static void Main(string[] args)
        {
            long n = Int64.Parse( Console.ReadLine());
            var s = Console.ReadLine().ToCharArray();

            if (s.Length%2 == 1)
            {
                Console.WriteLine("No");
                return;
            }
            for( long i = 0; i< (n/2); i++)
            {
                if (s[i] == s[(n/2) + i]) continue;
                else
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            Console.WriteLine("Yes");
            return;

        }

        static int rec(int[] n, int i, int j, int x)
        {
            if (i + 1 == j)
            {
                return Math.Min(n[j], x);
            }
            return rec(n, i + 1, j, n[i]) + rec(n, i, j - 1, n[j]);
        }


    }
}


Measured memory_bytes: 13140
a,b,c,x = [int(input()) for i in range(4)]
x /= 50
result = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if 10 * i + 2 * j + k == x:
                result += 1
print(result)

Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
// #pragma GCC target ("avx")
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int D;
int C[26];
int S[365][26];
int T[365];

int M;
int qq[100011], qd[100011];

int last[26];

VI se[26];
int initial_score() {
    int cur = 0;

    REP (c, 26) {
	last[c] = -1;
	se[c].push_back(-1);
    }

    REP (i, D) {
	int t = T[i];
	last[t] = i;
	se[t].push_back(i);

	cur += S[i][t];
	REP (c, 26) cur -= C[c] * (i - last[c]);
    }
    
    REP (c, 26) {
	se[c].push_back(D);
    }
    return cur;
}


int score(int day) {
    int cur = 0;

    REP (c, 26) {
	last[c] = -1;
	se[c].push_back(-1);
    }

    REP (i, day) {
	int t = T[i];
	last[t] = i;

	cur += S[i][t];
	REP (c, 26) cur -= C[c] * (i - last[c]);
    }
    return cur;
}

void solve() {
    REP (day, D) {
	int best = 0, bestc = 0;
	REP (c, 26) {
	    T[day] = c;
	    int s = score(day+1);
	    if (best < s) {
		best = s;
		bestc = c;
	    }
	}
	T[day] = bestc;
	// eprintf("%d\n", best);
    }
}

int tri(int n) {
    return n * (n-1) / 2;
}

int modify_diff(int d, int q) {
    int p = T[d];
    if (p == q) return 0;
    T[d] = q;

    int ret = 0;

    int pos = lower_bound(se[p].begin(), se[p].end(), d) - se[p].begin();
    int left = se[p][pos-1], right = se[p][pos+1];
    ret -= C[p] * (tri(right - left) - tri(d - left) - tri(right - d));
    ret -= S[d][p];
    se[p].erase(se[p].begin() + pos);

    pos = lower_bound(se[q].begin(), se[q].end(), d) - se[q].begin();
    left = se[q][pos-1];
    right = se[q][pos];
    ret += C[q] * (tri(right - left) - tri(d - left) - tri(right - d));
    ret += S[d][q];
    se[q].insert(se[q].begin() + pos, d);

    return ret;
}

void solveC() {
    int cur = initial_score();
    REP (q, M) {
	int old = T[qd[q]];
	int diff = modify_diff(qd[q], qq[q]);
	cur += diff;
	printf("%d\n", cur);
	// REP (c, 26) rprintf("%d", se[c].begin(), se[c].end());
    }
}

void output() {
    REP (d, D) printf("%d\n", T[d]+1);
}

void MAIN() {
    scanf("%d", &D);
    REP (c, 26) scanf("%d", C+c);
    REP (i, D) REP (c, 26) scanf("%d", S[i]+c);
    REP (i, D) scanf("%d", T+i), T[i]--;

    scanf("%d", &M);
    REP (i, M) {
	scanf("%d%d", qd+i, qq+i);
	qd[i]--;
	qq[i]--;
    }

    solveC();
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 4612
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
 
using vd=vector<double>;
using vvd=vector<vd>;
 
 
int main(){
    int h,w;
    cin>>h>>w;
    vvi f(h+2,vi(w+2,1));
    vvi walk(h+2,vi(w+2,0));
    int gy,gx,y=0,x=0,v=0;
    range(i,1,h+1)range(j,1,w+1){
        char c;
        cin>>c;
        switch(c){
            case 'G': gy=i,gx=j,f[i][j]=0; break;
            case '.': f[i][j]=0;break;
            case '#': break;
            case '^': y=i,x=j,v=0,f[i][j]=0; break;
            case '>': y=i,x=j,v=1,f[i][j]=0; break;
            case 'v': y=i,x=j,v=2,f[i][j]=0; break;
            case '<': y=i,x=j,v=3,f[i][j]=0; break;
        }
    }
    walk[y][x]=1;
    rep(loop,10000){
        vvi vec={{-1,0},{0,1},{1,0},{0,-1}};
        if(f[y+vec[(v+1)%4][0]][x+vec[(v+1)%4][1]]==0){ //右手が道なら右に曲がって前に進む
            //cout<<"hoge";
            v=(v+1)%4;
            y+=vec[v][0], x+=vec[v][1];
            walk[y][x]=1;
        }else if(f[y+vec[v][0]][x+vec[v][1]]==1){ //（右が壁で、）正面が壁なら左に回る
            //cout<<"fuga";
            v=(v+3)%4;
        }else{ //そうでないならまえに進む
            //cout<<"zako";
            y+=vec[v][0],x+=vec[v][1];
            walk[y][x]=1;
        }
        if(y==gy&&x==gx){
            break;
        }
        // cout<<y<<","<<x<<","<<v<<endl;
        // rep(i,h+2){
        //     rep(j,w+2){
        //         if(i==y&&j==x){
        //             cout<<"^>v<"[v];
        //         }else{
        //             cout<<".#"[f[i][j]];
        //         }
        //     }
        //     cout<<endl;
        // }
    }
    if(y==gy&&x==gx){
        int ans=0;
        rep(i,h+2)rep(j,w+2)ans+=walk[i][j];
        cout<<ans<<endl;
    }else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3188
#include<iostream>
#include<stdio.h>
#include<vector>

using namespace std;

int main(){
    int n,cnt=0;
    string s;
    cin>>n;
    cin>>s;
    for(int i=0;i<n-2;i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C')
            cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}

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

int main(){
    ll n, k; cin >> n >> k;
    vector<ll> p(n); rep(i,n) cin >> p[i];

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

    ll ans = 0;
    for(long long i = 0; i < k; i++){
        ans += p[i];
    }
    put(ans);
}

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

long long comb(long long n, long long k) {
    if (k == 1) return n;

    return n * comb(n - 1, k - 1) / k;
}

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

    long long ans = 0;
    for (auto s: m) {
        if (s.second >= 2) {
            ans += comb(s.second, 2);
        } 
    }
    cout << ans << endl;
}       

Measured memory_bytes: 11136
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <climits>
using namespace std;
using ll = long long;
int memo[(unsigned int)2e5];
int main() {
  int n; ll k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  //memo : その町がいくつ目の町か
  int next = 1;
  int it = 1;
  do {
    memo[next - 1] = it++;
    next = a[next - 1];
  } while (memo[next - 1] == 0 && it < k + 1);
  if (it == k + 1) {
    cout << next << endl;
    return 0;
  }
  int t = it - memo[next - 1];
  k -= memo[next - 1] - 1; //ループに入る前に通った町の数
  k %= t;
  while (k-- > 0) {
    next = a[next - 1];
  }
  cout << next << endl;
  return 0;
}


Measured memory_bytes: 4908
#include <stdio.h>
#include <limits.h>
int R[100],C[100][100],n;

void MatrixChainMultiplication()
{
  int i,j,k,l,cost;
  for(i=1;i<=n;i++)
    {
      C[i][i]=0;
    }
  for(l=2;l<=n;l++)
    {
      for(i=1;i<=n-l+1;i++)
	{
	  j=i+l-1;
	  C[i][j]=INT_MAX;
	  for(k=i;k<=j-1;k++)
	    {
	      cost=C[i][k]+C[k+1][j]+R[i-1]*R[k]*R[j];
	      if(cost<C[i][j])
		{
		  C[i][j]=cost;
		}
	    }
	}
    }
  printf("%d\n",C[1][n]);
}




main(){
  int i,r,c;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d %d",&r,&c);
      R[i]=r;
      R[i+1]=c;
    }
  MatrixChainMultiplication();
  return 0;
}

Measured memory_bytes: 636
import re
n=int(input())

s = ""
for _ in range(n):
    d1,d2 = input().split()
    if d1==d2:
        s+="1"
    else:
        s+="0"
#print(s)
try:
    a = max([len(x) for x in re.findall(r"1+", s)])
    if a >= 3:
        print("Yes")
    else:
        print("No")
except:
    print("No")

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

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


int main() {


    int h, w;
    while(1) {
        scanf("%d %d", &h, &w);
        if(h == 0 && w == 0) {
            break;
        }
        REP(i, h) {
            REP(j, w) {
                if(i == 0 || i == h-1 || j == 0 || j == w-1) {
                    printf("#");
                } else {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}



Measured memory_bytes: 3132
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<cctype>
#include<complex>
#include<algorithm>
#include<iomanip>
#include<map>
#define rep(X,Y) for(int X=0;(X)<(Y);++X)
#define rrep(X,Y) for(int X=(Y)-1;(X)>=0;--X)
#define X first
#define Y second
#define pb push_back

using namespace std;

typedef pair<int,int> pii;
typedef pair<int,pii> piii;

typedef vector<vector<int>> Graph;

int usd[50],v[50],n,re,rem[50];

void dfs(int u,Graph &g,int sum){
  re=max(re,sum);
  if(u==n)return;
  if(sum+rem[u]<re)return;
  dfs(u+1,g,sum);
  for(int w:g[u])
    if(usd[w])return;
  usd[u]=1;
  dfs(u+1,g,sum+v[u]);
  usd[u]=0;
}

int main(){
  while(cin>>n,n){
    vector<string> name(n);
    vector<vector<string>> tmp(n);
    map<string,int> toi;
    rep(i,n){
      int sz;
      cin>>name[i]>>v[i]>>sz;
      tmp[i].resize(sz);
      rep(j,sz)
	cin>>tmp[i][j];
      toi[name[i]]=i;
    }
    Graph g(n);
    rep(i,n)
      for(string &str:tmp[i])
	g[i].pb(toi[str]);
    fill(usd,usd+50,0);
    fill(rem,rem+50,0);
    re=0;
    rrep(i,n)
      rem[i]=rem[i+1]+v[i];
    usd[0]=1;
    dfs(1,g,v[0]);
    cout<<re<<endl;
  }
}

Measured memory_bytes: 1368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#include<map>
#include<iomanip>
#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;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using vvi = vector<vector<int> >;
using vvll =  vector<vector<ll> >;

const ll inf = 1LL << 60;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    char c; cin >> c;
    char d = c + 1;
    cout << d << endl;
}

Measured memory_bytes: 3576