akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
// #include <set>
// #include <cmath>
// #include <map>
// #include <iomanip>

#define MOD 1000000007

using namespace std;
// typedef unsigned long long ull;
typedef long long ll;

// void p() {
//     cout << "\n";
// }
// template<class Head, class... Body>
// void p(Head head, Body... body) {
//     cout << head << ",";
//     p(body...);
// }


int main(int argc, char const *argv[]) {
    int A, B, C;
    cin >> A >> B >> C;
    bool ans = false;
    for (int i = 0; i < B; ++i) {
        if ((A * i) % B == C) {
            ans = true;
        }
    }
    if (ans) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  char a;
  cin >> a;
  if (a == 'A') {
    cout << 'T';
  } else if (a == 'T') {
    cout << 'A';
  } else if (a == 'C') {
    cout << 'G';
  } else if (a == 'G') {
    cout << 'C';
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> p(N);
	for (int i = 0; i < N; i++) {
		cin >> p.at(i);
	}

	int cnt = 0;
	vector<int> a(3);
	for (int i = 0; i < N - 1; i++) {
		if (p.at(i + 1) < p.at(i)) {
			a.at(cnt) = i;
			cnt++;
		}
		if (cnt > 2) {
			break;
		}
	}

	if (cnt == 0) {
		cout << "YES" << endl;
	}
	else if (cnt == 2) {
		bool flag = true;
		int ind1 = a.at(0);
		int ind2 = a.at(1) + 1;

		if (ind1 - 1 >= 0) {
			if (p.at(ind1 - 1) > p.at(ind2)) {
				flag = false;
			}
		}
		if (p.at(ind1 + 1) < p.at(ind2)) {
			flag = false;
		}

		if (p.at(ind2 - 1) > p.at(ind1)) {
			flag = false;
		}
		if (ind2 + 1 < N) {
			if (p.at(ind2 + 1) < p.at(ind1)) {
				flag = false;
			}
		}
		if (flag) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


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

using namespace std;

int main(void){
  long long X, Y;
  cin >> X >> Y;
  long long times = 1;
  for(int i = 0; ; ++i){
    if(X * times > Y){
      printf("%d\n", i);
      return 0;
    }else times *= 2LL;
  }
}


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

int main(){
	int n;
	while(std::cin>>n){
		int count=0;
		for(int i=9;i>=0;i--){
			for(int j=9;j>=0;j--){
				for(int k=9;k>=0;k--){
					if(0<=n-i-j-k&&n-i-j-k<=9)count++;
				}
			}
		}
		std::cout<<count<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
//#include<cmath>
#include <string>
#include<map> 
#include<deque>  
#include<vector>
#include<bitset>
#include<string>  
#include<cstring> 
#include<stack>  
#include<set>
#include<functional>
#define mst(x,y) memset(x,y,sizeof x)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<long long,long long> pll;
int k,n,a[200005],ip,ans,unq;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		scanf("%d",&ip);
	//	if(a[ip-1]==0)unq++;
		a[ip-1]++;
	}
	sort(a,a+n);reverse(a,a+n);
	int i=0;
	for(;i<k;i++);
	for(;i<n;i++){
		ans+=a[i];
	}cout<<ans<<endl;
	return 0;
}                                                    

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

int main() {
    string ans = "War";
    int n, m, X, Y;
    cin >> n >> m >> X >> Y;
    int xmax = -100, ymin = 100, num;
    rep(i, n) {
        cin >> num;
        xmax = max(xmax, num);
    }
    rep(i, m) {
        cin >> num;
        ymin = min(ymin, num);
    }
    REP(i, xmax+1, ymin+1) {
        if (X < i && i <= Y) ans = "No War";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate, product, combinations_with_replacement
import sys
import bisect
import string
import math
import time


def I(): return int(input())
def S(): return input()
def MI(): return map(int, input().split())
def MS(): return map(str, input().split())
def LI(): return [int(i) for i in input().split()]
def LI_(): return [int(i)-1 for i in input().split()]
def StoI(): return [ord(i)-97 for i in input()]
def ItoS(nn): return chr(nn+97)
def input(): return sys.stdin.readline().rstrip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def print_matrix(mat):
    for i in range(len(mat)):
        print(*['IINF' if v == IINF else "{:0=4}".format(v) for v in mat[i]])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
show_flg = False
# show_flg = True

def count_ones(n):

    # to store number of 1s
    # in smallest repunit
    # multiple of the number.
    count = 1;

    # initialize rem with 1
    rem = 7

    if n == 7:
        return 1

    # run loop until
    # rem becomes zero
    while rem != 0:
        # rem*10 + 1 here represents
        # the repunit modulo n
        # print((rem * 10 + 7))
        rem = (rem * 10 + 7) % n
        count = count + 1

        if count > 10 ** 6:
            count = -1
            break

    # when remainder becomes
    # 0 return count
    return count

def main():
    K = I()
    MAX = 10 ** 6

    if K % 2 == 0:
        print(-1)
        return

    if K == 1:
        print(1)
        return

    print(count_ones(K))



if __name__ == '__main__':
    main()


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

int main(){
    int n = 0,a;
    cin >> n>>a;
    
    int flag=0;
    int ans=0;

    if(n%500 <= a)flag=1;

    //cout <<fixed<<setprecision(16)<< << endl;
    //cout << ans << endl;

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


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(i=0; i<n; i++)

int main(void)
{
	int n;
	scanf("%d", &n);
	double m=n;
	if(n%2 == 0){
		printf("%.10lf", 0.5000000000);
	}else{
		 printf("%.10lf", ((m-1)/2+1)/m);
	}
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10000000)

N,X,Y=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

memo={}
def func(n,last,turn):  #n:カードの残り枚数、last:前の手番が最後に引いたスコア、turn: 0先手の番 1後手の番
    #print "func(",n,",",last,",",turn,")"
    if (n,turn) in memo:    #カードが残りn枚で、どちらの番かが決まっていたら最終スコアはいつも同じ
        return memo[(n,turn)]
    if n==1:
        ret=abs(last-A[N-n])
    elif turn==0:
        ret=max( func(n-1,last,0) , func(n-1,A[N-n],1) ) #手番がXのまま  手番がYに移動
    elif turn==1:
        ret=min( func(n-1,last,1) , func(n-1,A[N-n],0) ) #手番がYのまま  手番がXに移動
    memo[(n,turn)]=ret
    return ret


print func(N,Y,0)

Measured memory_bytes: 4584
//我是菜鸡
#include<bits/stdc++.h>
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
#define debug(x) cout<<x<<endl
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 2e5+5;
int mon[maxn];
void deprint() {
	//ofstream cout("E:\\acm dream\\debug.txt");
	return;
}
int main() {
	//ifstream cin("E:\\acm dream\\in.txt");
	//ofstream cout("E:\\acm dream\\out.txt");
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n, k;
	while (cin >> n >> k) {
		_for(i, 0, n)cin >> mon[i];
		sort(mon, mon + n);
		ll ans = 0;
		_for(i, 0, n - k)ans += mon[i];
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from collections import defaultdict
from bisect import bisect_right


def solve():
  ## input
  S = str(input())
  T = str(input())

  ## solve
  Sdict = defaultdict(lambda:list())
  for i,c in enumerate(S):
    Sdict[c].append(i+1)

  idx = 0
  Tidx = [0 for _ in range(len(T)+1)]
  for i,c in enumerate(T):
    if len(Sdict[c]) == 0:
      return -1
    else:
      pos = bisect_right(Sdict[c],idx)
      if pos < len(Sdict[c]):
        Tidx[i+1] = Sdict[c][pos]
      else:
        Tidx[i+1] = Sdict[c][0]
      idx = Tidx[i+1]

  ans = 0
  for i in range(1,len(Tidx)):
    if Tidx[i-1] < Tidx[i]:
      ans += Tidx[i]-Tidx[i-1]
    else:
      ans += len(S)-Tidx[i-1]+Tidx[i]
  return ans


ans = solve()
print(ans)

Measured memory_bytes: 48272
#include <iostream>

using namespace std;

int main() {
	int r, w, c, rr;
	while (cin >> r >> w >> c >> rr) {
		if (r == 0 && w == 0 && c == 0 && rr == 0) {
			break;
		}
		for (int i = 0; ; i++) {
			if (r + rr*i >= c*w) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3068
n=int(input())
h=list(map(int,input().split()))
c=[0]
for i in range(n-1):
    x=abs(h[i]-h[i+1])+c[i]
    y=x+1
    if i>0:
        y=abs(h[i-1]-h[i+1])+c[i-1]
    c.append(x if x<y else y)
print(c[n-1])

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

int main() {
  int N, M;
  cin >> N;
  string n_words[N];
  for(int i = 0; i < N; i++) {
    cin >> n_words[i];
  }
  cin >> M;
  string m_words[M];
  for(int i = 0; i < M; i++) {
    cin >> m_words[i];
  }
  
  int point = 0;
  string target = "";
  for(int i = 0; i < N; i++) {
    target = n_words[i];
    int point_dum = 0;
    for(int j = 0; j < N; j++) {
      if(target == n_words[j]) {
        point_dum++;
      }
    }
    for(int k = 0; k < M; k++) {
      if(target == m_words[k]) {
        point_dum--;
      }
    }
    if(point_dum > point) {
      point = point_dum;
    }
  }
  cout << point << endl;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, i;
  string s, a ,b;
  cin >> n;
  cin >> s;
  if(n%2!=0){
    cout << "No" <<endl;
    return 0;
  } 
 for(i=0;i<s.size()/2;i++){
   a=a+s[i];
 }
 for(i=s.size()/2;i<s.size();i++){
   b=b+s[i];
 }
  if(a==b) cout << "Yes" <<endl;
  else cout << "No" <<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

typedef complex<double> Point;

namespace std{
	template<typename T>
		bool operator<(const complex<T>& lhs,const complex<T>& rhs)
		{
			if(real(lhs)==real(rhs))
				return imag(lhs)<imag(rhs);
			else
				return real(lhs)<real(rhs);
		}
}

int main()
{
	for(int n;cin>>n,n;){
		vector<Point> p(n);
		rep(i,n)
			scanf("%lf,%lf",&real(p[i]),&imag(p[i]));

		//rep(i,n)
		//	cout<<real(p[i])<<" "<<imag(p[i])<<endl;

		sort(allof(p));

		vector<Point> uv,lv;
		rep(i,n){
			for(;;){
				if(lv.size()<2){
					lv.push_back(p[i]);
					break;
				}
				else{
					Point p0=lv[lv.size()-2];
					Point p1=lv[lv.size()-1];
					//if(arg(p[i]-p1)>arg(p[i]-p0)){
					double cross=imag(conj(p1-p0)*(p[i]-p0));
					if(cross>0){
						lv.push_back(p[i]);
						break;
					}
					else
						lv.pop_back();
				}
			}
		}
		for(int i=n;i--;){
			for(;;){
				if(uv.size()<2){
					uv.push_back(p[i]);
					break;
				}
				else{
					Point p0=uv[uv.size()-2];
					Point p1=uv[uv.size()-1];
					//if(arg(p[i]-p1)>arg(p[i]-p0)){
					double cross=imag(conj(p1-p0)*(p[i]-p0));
					if(cross>0){
						uv.push_back(p[i]);
						break;
					}
					else
						uv.pop_back();
				}
			}
			//puts("uv");
			//rep(i,uv.size())
			//	cout<<uv[i]<<endl;
		}

		//puts("uv");
		//rep(i,uv.size())
		//	cout<<uv[i]<<endl;

		//puts("lv");
		//rep(i,lv.size())
		//	cout<<lv[i]<<endl;
		
		int vn=uv.size()+lv.size()-2;
		cout<<p.size()-vn<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int H,W;
      cin >> H >> W;
      vector<vector<char>> Sh(H+2,vector<char>(W+2));//初期化されてる
      
      for(int i=0;i<H+2;i++){
        for(int j=0;j<W+2;j++){
          if(i==0 || i==H+1 || j==0 || j==W+1){
            Sh[i][j]='#';
          }else{
            cin >> Sh[i][j];
          }
          cout << Sh[i][j];
        }
        cout << endl;
      }
      
    }

Measured memory_bytes: 3604
from itertools import permutations
from scipy.sparse.csgraph import floyd_warshall
n,m,r=map(int,input().split())
vis=list(map(int,input().split()))
INF=10**18
path=[[INF]*n for i in range(n)]
for i in range(m):
  a,b,c=map(int,input().split())
  path[a-1][b-1]=c
  path[b-1][a-1]=c
path=floyd_warshall(path)
ans=10**18
for root in permutations(vis):
  cnt=0
  for j in range(1,r):
    cnt+=path[root[j-1]-1][root[j]-1]
  ans=min(ans,cnt)
print(int(ans))

Measured memory_bytes: 18868
#include <stdio.h>

int main(void)
{
  int a[100000], s, count = 0;
  int i, j;
  
  scanf("%d", &s);
  a[0] = s;
  for( i = 0; i < 1000000; i++ ){
    if( a[i] % 2 == 0 ){
        a[i+1] = a[i] / 2;
      } else {
        a[i+1] = a[i]*3 + 1;
      }
      count++;
    for( j = 0; j < i+1; j++ ){
      if( a[i] == a[j] && i != j ){
        printf("%d\n", count);
        return 0;
      }
    }
  }
	return 0;
}

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

int main(){
	int n;
    cin >> n;
    int a[n];
    int c_head[n+1];
    int c_tail[n+1];
  
    for (int i=0; i < n; i++){
    	cin >> a[i];
    }
  
    c_head[0] = 0;
    c_tail[n] = 0;
    for (int j=1; j <= n; j++){
    	c_head[j] = max(c_head[j-1], a[j-1]);
        c_tail[n-j] = max(c_tail[n-j+1], a[n-j]);
    }
    for (int k=0; k < n; k++){
    	if (k == 0){
        	cout << c_tail[1] << endl;
        }else if (k == n-1){
        	cout << c_head[n-1] << endl;
        }else{
        	cout << max(c_head[k], c_tail[k+1]) << endl;
        }
    }
  	return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
int n,m;
const int N=1e5+100;
int dis[N],d[N],f[N][20],root[N*40],lg[N];
struct edgd
{
	int v,c,w,nxt;
}e[N<<2];
int h[N],idx=0;
void add(int u,int v,int c,int w)
{
	e[++idx]={v,c,w,h[u]};
	h[u]=idx;
}
struct node
{
	int l,r,tot,sum;
} t[N*40];
int cnt=0;
void build(int l,int r,int &x)
{
	x=++cnt;
	t[x].sum=t[x].tot=0;
	if(l==r) return ;
	int mid=l+r>>1;
	build(l,mid,t[x].l);
	build(mid+1,r,t[x].r);
}
void update(int l,int r,int c,int w,int &x,int pre)
{
	x=++cnt;
	t[x]=t[pre];
	if(l==r)
	{
		t[x].sum+=w;
		t[x].tot++;
		return ;
	}
	int mid=l+r>>1;
	if(c<=mid)update(l,mid,c,w,t[x].l,t[pre].l);
    else  update(mid+1,r,c,w,t[x].r,t[pre].r);
}
pair<int,int> query(int l,int r,int x,int y,int pos)
{
	if(l==r)return {t[y].sum-t[x].sum,t[y].tot-t[x].tot};
	int mid=l+r>>1;
	if(pos<=mid) return query(l,mid,t[x].l,t[y].l,pos);
	else return query(mid+1,r,t[x].r,t[y].r,pos);
} 
void dfs(int x,int fa)
{
	f[x][0]=fa;
	for(int i=1;1<<i<=d[x];i++) f[x][i]=f[f[x][i-1]][i-1];
	for(int i=h[x];i;i=e[i].nxt)
	{
		int v=e[i].v,c=e[i].c,w=e[i].w;
		if(v==fa) continue;
		update(1,n-1,c,w,root[v],root[x]);
		dis[v]=dis[x]+w;
		d[v]=d[x]+1; 
		dfs(v,x);
	}
}
int LCA(int x,int y)
{
	if(d[x]<d[y]) swap(x,y);
	int del=d[x]-d[y];
	for(int i=0;i<=lg[d[x]]-1;i++) 
	 if(1<<i&del) x=f[x][i];
	if(x==y) return x;
	for(int i=lg[d[x]]-1;i>=0;i--)
	{
		if(f[x][i]!=f[y][i])
		x=f[x][i],y=f[y][i];
	}
	return f[x][0];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0); 
	cin>>n>>m;
	for(int i=1,x,y,z,w;i<n;i++) 
	{
		cin>>x>>y>>z>>w;
		add(x,y,z,w);add(y,x,z,w);
	}
	for(int i=1;i<=n;i++)  lg[i]=lg[i-1]+(1<<lg[i-1]==i);
	build(1,n,root[1]);
    dfs(1,0);
    //for(int i=1;i<=n;i++) cout<<dis[i]<<endl; 
    while(m--)
    {
    	int x,y,u,v;
    	cin>>x>>y>>u>>v;
    	int lca=LCA(u,v);
    	if(d[u]>d[v])swap(u,v);
    	if(lca==u)
    	{
    		int ans=dis[v]-dis[lca];
    		pair<int,int>t=query(1,n-1,root[u],root[v],x);
    		ans=ans-t.first+t.second*y;
    		cout<<ans<<endl;
    	}
    	else
    	{
    		int ans=dis[v]-dis[lca]+dis[u]-dis[lca];
            pair<int,int>t1=query(1,n-1,root[lca],root[v],x),t2=query(1,n-1,root[lca],root[u],x);
            ans=ans-t1.first+t1.second*y-t2.first+t2.second*y;
            cout<<ans<<endl;
    	}
    }
	return 0; 
}

Measured memory_bytes: 59392
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
struct Edge {
    int to, cost;
    Edge(int to, int cost): to(to), cost(cost) {}
};

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<Edge>> AdjList;
AdjList graph;

const int INF = 100000000;

int main() {
    //cout << fixed << setprecision(15);

    vector<string> v;
    v.push_back("* = ****");
    v.push_back("* =* ***");
    v.push_back("* =** **");
    v.push_back("* =*** *");
    v.push_back("* =**** ");
    v.push_back(" *= ****");
    v.push_back(" *=* ***");
    v.push_back(" *=** **");
    v.push_back(" *=*** *");
    v.push_back(" *=**** ");
    
    string n;
    int cnt=0;
    while(cin >> n){
        if(cnt) cout << endl;
        cnt++;
        while(n.size()!=5){
            n = '0' + n;
        }
        if(n.size()==5){
            for(int i=0; i<8; ++i){
                string t = "";
                for(int j=0; j<n.size(); ++j){
                    int num = n[j]-'0';
                    t += v[num][i];
                    
                }
                cout << t << endl;
            }
        }
    }
    return 0;
}


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

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

    int N;
    cin >> N;
    vector<int> T(105);
    rep(i, N){
        cin >> T[i];
    }
    int M;
    cin >> M;
    int P, X, tmp;
    rep(i, M){
        cin >> P >> X;
        tmp = T[P - 1];
        T[P - 1] = X;
        int sum = 0;
        rep(j, N){
            sum += T[j];
        }
        cout << sum << endl;
        T[P - 1] = tmp;
    }


    return 0;
}

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

using Int = long long int;
using UInt = unsigned long long int;

Int Ceil(int a, int b) {
    return ceil((double)a / (double)b);
}

int main(void) {
    Int n;
    cin >> n;
    Int rt, ra;
    cin >> rt >> ra;
 
    Int t, a;
    for (Int i = 1; i < n; ++i) {
        cin >> t >> a;
        Int times;
        if (rt <= t && ra <= a) { 
            times = 1;
        } else if (rt <= t && ra > a) {
            times = Ceil(ra, a);
        } else if (rt > t && ra <= a) {
            times = Ceil(rt, t);
        } else {
            Int times_a = ra / a;
            Int times_t = rt / t;
            if (ra % a != 0) {
                ++times_a;
            }
            if (rt % t != 0) {
                ++times_t;
            }
            times = max(times_a, times_t);
        }
        rt = t * times;
        ra = a * times;
    }
    cout << rt + ra << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Inf = 1 << 30;
int n, m;
int a[55], b[55];
int c[55], d[55];
map <int, bool> vis;
int ans;

int main() {
	int t = 0;
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
	for(int i = 1; i <= m; i++) cin >> c[i] >> d[i];
	for(int i = 1; i <= n; i++) {
		int minT = Inf;
		for(int j = 1; j <= m; j++) {
			int tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			minT = min(minT, tmp);
		}
		for(int j = 1; j <= m; j++) {
			int tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if(tmp == minT) {
				ans = j;
				break;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <stack>

using namespace std;

/* constant */

const int INF = 1 << 30;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* typedef */

typedef long long ll;

/* global variables */

/* function */

/* main */
int main() {

    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        int x = i;
        if (x % 3 == 0) {
            cout << " " << x;
        }
        else {
            while (x) {
                if (x % 10 == 3) {
                    cout << " " << i;
                    break;
                }
                x /= 10;
            }
        }
    }
    cout << '\n';
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

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

    int i = 1;
    while(x > 0) {
        x -= i;
        ++i;
    }

    cout << i - 1 << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include<iostream>
#include<cstdint>
#include<cstddef>
#include<map>

using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i32, i32>;

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    i32 h, w, d;
    cin >> h >> w >> d;
    map<i32, P> mp;
    map<P, i32> rec_dist;
    rep(i, h) {
        rep(j, w) {
            i32 a;
            cin >> a;
            mp[a] = P(i, j);
        }
    }
    map<i32,i32> root;
    for (i32 i = 1; i <= d; i++) {
        for (i32 j = i; j <= h * w; j += d) {
            if (i == j){
                rec_dist[P(i, i)] = 0;
                root[j] = i;
            }
            else {
                rec_dist[P(i, j)] += rec_dist[P(i, j - d)] + abs(mp[j].first - mp[j - d].first) +  abs(mp[j].second - mp[j - d].second);
                root[j] = i;
            }
            }
        }
        i32 q;
        cin >> q;
        rep(i, q) {
            i32 l, r;
            cin >> l >> r;
            cout << rec_dist[P(root[r], r)] - rec_dist[P(root[r],l)] << endl;
        }
    }

Measured memory_bytes: 20436
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_5_A&lang=jp


#include<iostream>
 using namespace std;

int main(){

 int H , W ;

    while(1)
 	{

    cin >> H >> W ;

 	    if ( H == 0 && W == 0 ){ //描画の終了条件
        break ;
        }else{
        // プログラムの処理を続行する
        }


        // 描画アルゴリズム
        // Y方向の描画
        for (int i = 0; i < H ; i = i + 1 )
        {

            //X方向の描画
            for (int j = 0; j < W ; j = j + 1 )
            {
            cout << "#" ;  //#の出力
            }
            cout << endl ; //改行

        }cout << endl ; //データセット間の改行



 	}

 return 0;

 }


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

int main(void)
{
	std::vector<int> data;

	int n;

	while(std::cin >> n)
	{
		data.push_back(n);
	}

	std::vector<int> count(data.size());

	for(size_t i=0; i<data.size(); ++i)
	{
			for(size_t j=0; j<data.size()-i; ++j)
		{
			if(data[i]==data[i+j])
			{
				++count[i];
			}
		}

	}

	count.push_back(0);//ここまででdataのサイズとcountのサイズは同じはずだが、count[i]とcount[i+1]の比較があるのでcountのサイズを一つ大きくしておく Max(count)!=0のはずなので0を入れておけば結果に問題はない

	int countmax = *std::max_element(count.begin(),count.end());

	std::vector<int> answer;
	
	for( size_t i=0; i<count.size(); ++i )
	{
		if(count[i]==countmax)
		{
			answer.push_back(data[i]);
		}
	}
	
	std::sort(answer.begin(),answer.end());

	for( size_t i=0; i<answer.size(); ++i)
	{
		std::cout << answer[i] << '\n';
	}
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF  numeric_limits<int>::max()
#define NINF numeric_limits<int>::min()

using namespace std;
using ll = long long;

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

    int X, A;
    std::cin >> X >> A;

    if(X < A) {
        std::cout << 0 << std::endl;
    }
    else {
        std::cout << 10 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"def solve():\n"
"    from itertools import permutations\n"
"    n,m,R=map(int,input().split())\n"
"    r=map(int,input().split())\n"
"    d=[[10**18]*n for _ in range(n)]\n"
"    for i in range(m):\n"
"        a,b,c=map(int,input().split())\n"
"        d[a-1][b-1]=c\n"
"        d[b-1][a-1]=c\n"
"    for i in range(n):\n"
"        d[i][i]=0\n"
"    for k in range(n):\n"
"        for i in range(n):\n"
"            for j in range(n):\n"
"                t=d[i][k]+d[k][j]\n"
"                if t<d[i][j]:\n"
"                    d[i][j]=t\n"
"    m=10**18\n"
"    for e in permutations(r):\n"
"        t=0\n"
"        for i,j in zip(e,e[1:]):\n"
"            t+=d[i-1][j-1]\n"
"        if t<m:\n"
"            m=t\n"
"    print(m)\n"
"if __name__=='__main__':\n"
"    solve()\n"
"\"";
  system(s);
  return 0;
}            

Measured memory_bytes: 4928
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
  int n; 
  long ans = 0;
  scanf("%d", &n);
  int cnt[10][10];
  rep(i, 10) rep(j, 10) cnt[i][j] = 0;
  for (int i = 1; i <= n; i++) {
    string s = to_string(i);
    char c = s[0];
    int top  = atoi(&c);
    int last = atoi(&s[s.size() - 1]);
    cnt[top][last] += 1;
  }
  for (int i = 1; i <= 9; ++i) {
    for (int j = 1; j <= 9; ++j) {
      ans += cnt[i][j] * cnt[j][i];
    }
  }
  printf("%ld\n", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


vector<int> fac, finv, inv;

void comb_init(int n) {
  fac  = vector<int>(n);
  finv = vector<int>(n);
  inv  = vector<int>(n);
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < n; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
 
int comb(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main() {
  int N, K; 
  cin >> N >> K;

  comb_init(1000000);

  if(N-1 <= K){
    cout << comb(N+N-1, N) << "\n";
  }else{
    int ans = 1;
    FOR(i, 1, K+1){
      (ans += (comb(N, i)*comb(N-1, i))%MOD) %= MOD;
    }
    cout << ans << "\n";
  }

  return 0;
}

Measured memory_bytes: 23680
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 10010

vector<pair<int,int> > way[SIZE];

bool visited[SIZE][3][201];

int main(){
  int n,m,x,t[SIZE],a,b,d;

  scanf("%d%d%d",&n,&m,&x);

  for(int i=0;i<n;i++) scanf("%d",t+i);

  for(int i=0;i<m;i++){
    scanf("%d%d%d",&a,&b,&d);
    a--;
    b--;
    way[a].push_back({b,d});
    way[b].push_back({a,d});
  }

  // {{cost, now},{last_t, time}}
  priority_queue<pair<pair<int,int>,pair<int,int> > > pq;
  
  pq.push({{0,0},{t[0],0}});

  while(pq.size()){
    pair<pair<int,int>,pair<int,int> > p = pq.top();
    pq.pop();
    
    int cost = p.first.first;
    int now = p.first.second;
    int last_t = p.second.first;
    int time = p.second.second;
    
    if(visited[now][last_t][time]) continue;
    visited[now][last_t][time] = true;

    if(now == n-1){
      printf("%d\n",-cost);
      return 0;
    }
    
    for(int i=0;i<way[now].size();i++){
      int to = way[now][i].first;
      int d = way[now][i].second;

      if(last_t == 1 || time + d >= x){
        pq.push({{cost-d, to},{t[to],0}});
      }else{
        if(last_t == t[to]){
          pq.push({{cost-d, to},{t[to],0}});
        }
        if(t[to] == 1){
          pq.push({{cost-d, to},{last_t,time+d}});
        }
      }
    }
  }
  
  puts("-1");
  
  return 0;
}

Measured memory_bytes: 9336
import math

a, b, c = map(float, input().split())
c *= math.pi / 180

S = a * b * math.sin(c)/2
A = a - b * math.cos(c)
B = b * math.sin(c)

print('{:.5f}'.format(S))
print('{:.5f}'.format(math.sqrt(A*A+B*B) + a+b))
print('{:.5f}'.format(B))



Measured memory_bytes: 5696
package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)
 
var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n, _ = strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func main() {
  S := NextLine()
  K := NextInt()
  A := ""
  N := len(S)
  for i, s := range S {
    if i == N - 1 {
      A += string((int(s) + K - int('a')) % 26 + int('a'))
      break
    }
    k := int('z') + 1 - int(s)
    if K < k || s == 'a' { 
      A += string(s)
      continue
    }
    K -= k
    A += "a"
  }
  Write(A)
  Output()
}

Measured memory_bytes: 17536
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 2000005;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[SIZE], finv[SIZE], inv[SIZE];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;
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; }

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T & t, const V & v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T & t, const V & v) {
	for (auto& e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS * (abs(a) + abs(b))) { return 0; }
	return a + b;
}

double len(int a, int b, int c, int d) {
	return (double)sqrt((a - c) * (a - c) + (b - d) * (b - d));
}

ll a, b, k[55], dp[55][55][5555], ans;
int main() {
	cin >> a >> b;
	ll ma = b;
	for (int i = 1; i <= a; ++i) { cin >> k[i]; ma = max(ma, k[i]); }
	dp[0][0][0] = 1;

	for (int i = 0; i <= a; ++i) {
		for (int j = 0; j <= a; ++j) {
			for (int kk = 0; kk <= ma * a; ++kk) {
				if (i > 0 && kk < k[i]) { dp[i][j][kk] = dp[i - 1][j][kk]; }
				else if (i > 0 && j > 0 && kk >= k[i]) { dp[i][j][kk] = dp[i - 1][j][kk] + dp[i - 1][j - 1][kk - k[i]]; }
			}
		}
	}

	for (int i = 1; i <= a; ++i) {
		ans += dp[a][i][i * b];
	}

	cout << ans << endl;
}

Measured memory_bytes: 123136
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	ll a,b,n;
	std::cin >> a >> b >> n;
	std::cout << (std::min(b-1,n)*a)/b << std::endl;
	return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        
        String[] h=new String[10000];
        
        for(int i=0;i<10000;i++){
            if(i<5000){
                h[i]=".";
            }else{
                h[i]="#";
            }
        }
        
        int gyo=(B-1)/50+1;
        int las=(B-1)%50;
        
        for(int i=0;i<gyo-1;i++){
            for(int j=0;j<50;j++){
                h[200*i+2*j]="#";
            }
        }
        for(int j=0;j<las;j++){
            h[200*(gyo-1)+2*j]="#";
        }
        
        gyo=(A-1)/50+1;
        las=(A-1)%50;
        
        for(int i=0;i<gyo-1;i++){
            for(int j=0;j<50;j++){
                h[200*(i+26)+2*j]=".";
            }
        }
        for(int j=0;j<las;j++){
            h[200*(gyo-1+26)+2*j]=".";
        }
        System.out.println("100 100");
        for(int i=0;i<10000;i++){
            if(i%100==99){
                System.out.println(h[i]);
            }else{
                System.out.print(h[i]);
            }
        }
    }
}


Measured memory_bytes: 23508
#include <iostream>
    #include <string>
    #include <algorithm>
    #include <cassert>
    #include <set>
    #include <vector>
    #include <cmath>
    #include <bitset>
    #include <functional>
    #include <limits>
    #include <map>
    using namespace std;

    typedef long long ll;
    #define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
    #define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

    ll pow(ll a, ll n) { //compute a^n with o(logn)
        ll res = 1;
        while (n > 0) {
            if (n & 1) res = res * a;
            a = a * a;
            n >>= 1;
        }
        return res;
    }

    ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
        ll res = 1;
        while (n > 0) {
            if (n & 1) res = res * a % mod;
            a = a * a % mod;
            n >>= 1;
        }
        return res;
    }

    int main(){
        ll n;
        cin >> n;
        ll sum = 0;
        rep1(i,n) sum += i*(1+floor(n/i))*floor(n/i)/2;
        cout << sum <<endl;
        return 0;
    }

Measured memory_bytes: 3176
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) begin(v), end(v)
#define REV(v) rbegin(v), rend(v)
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

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

	set<string> st;
	int n;
	cin >> n;
	rep(i, n){
		string s;
		cin >> s;
		st.insert(s);
	}
	int m;
	cin >> m;
	int cnt = 0;
	string out[] = { "Opened by ", "Closed by " };
	rep(i, m){
		string s;
		cin >> s;
		if (st.count(s)){
			cout << out[cnt++&1];
		}
		else{
			cout << "Unknown ";
		}
		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=5005,P=1e9+7;
int n,a[N],f[N][N],t[N],sz[N];
vector<int>G[N];
void dfs(int x,int p)
{
	f[x][1]=1;sz[x]=1;
	for(int i=0;i<G[x].size();i++)if(G[x][i]!=p)
	{
		int y=G[x][i];dfs(y,x);
		for(int j=1;j<=sz[x];j++)t[j]=f[x][j],f[x][j]=0;
		for(int j=1;j<=sz[x];j++)for(int k=0;k<=sz[y];k++)f[x][j+k]=(f[x][j+k]+1ll*t[j]*f[y][k])%P;
		sz[x]+=sz[y];
	}
	for(int i=1;i<=sz[x];i++)f[x][0]=(f[x][0]+1ll*f[x][i]*a[i])%P;f[x][0]=P-f[x][0];
}
int main()
{
	scanf("%d",&n);a[0]=1;
	for(int i=2;i<=n;i+=2)a[i]=1ll*a[i-2]*(i-1)%P;
	for(int i=1,u,v;i<n;i++)scanf("%d%d",&u,&v),G[u].pb(v),G[v].pb(u);
	dfs(1,0);printf("%d\n",P-f[1][0]);return 0;
}

Measured memory_bytes: 97536
#include <bits/stdc++.h>
using namespace std;
priority_queue<int,vector<int>,greater<int> > red,green;
int X,Y,A,B,C;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> X >> Y >> A >> B >> C;
	int a;
	for(int i=0;i<A;i++)
	{
		cin >> a;
		red.push(a);
	}
	for(int i=0;i<B;i++)
	{
		cin >> a;
		green.push(a);
//		cout << "DEB : " << green.top() << '\n';
	}
	while(red.size() > X) red.pop();
	while(green.size() > Y) green.pop();
//	cout << red.top() << ' ' << green.top() << '\n';
	for(int i=0;i<C;i++)
	{
		cin >> a;
		int rednow = red.top();
		int greennow = green.top();
		if(rednow <= greennow && rednow < a)
		{
			if(red.size() == X) red.pop();
			red.push(a);
		}
		else if(greennow < a)
		{
			if(green.size() == Y)green.pop();
			green.push(a);
		}
	}
	long long ans = 0;
	while(!red.empty())
	{
		ans += (long long)red.top();
		red.pop();
	}
	while(!green.empty())
	{
		ans += (long long)green.top();
		green.pop();
	}
	cout << ans << '\n';
	
	return 0;
}


Measured memory_bytes: 1400
fun main(args: Array<String>) {
    val s = (0..2).map {readLine()!!.toList().map {it-'a'}.toMutableList() }
    var turn = 0
    while (s[turn].isNotEmpty()) {
        turn = s[turn].removeAt(0)
    }
    println(('A'+turn).toChar())
}

Measured memory_bytes: 31772
N, K = [int(n) for n in input().split()]

A = [1] + [int(n) for n in input().split()]

dest = []

current = 0
count = 0
next_dest = A[current]
seen = {}

while not next_dest in seen:
    current = next_dest
    next_dest = A[current]
    dest.append(current)
    seen[current] = count
    count += 1

cycle_start = seen[next_dest]
cycle_length = seen[current] - cycle_start + 1

if K <= cycle_start:
    print(dest[K])
else:
    print(dest[cycle_start + ((K - cycle_start) % cycle_length)])

Measured memory_bytes: 40008
import java.io.*;
   
class Main{
public static void main(String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line="";
int count=1;
while(!(line=br.readLine()).equals("0")){
int weight=0;
int W=Integer.parseInt(line);
int n=Integer.parseInt(br.readLine());
int[] v=new int[n];
int[] w=new int[n];
for(int i=0;i<n;i++){
String[] str=br.readLine().split(",");
v[i]=Integer.parseInt(str[0]);
w[i]=Integer.parseInt(str[1]);
}
solve(W,n,v,w,count);
count++;
}
}
private static void solve(final int W,final int n,final int[] v,final int[] w,int count){
int[][] dp=new int[n+1][W+1];
int minWeight=0;
for(int i=0;i<=W;i++){
dp[n][i]=0;
}
for(int i=n-1;i>=0;i--){
for(int j=0;j<=W;j++){
if(j<w[i]){
dp[i][j]=dp[i+1][j];
}
else{
dp[i][j]=Math.max(dp[i+1][j],dp[i+1][j-w[i]]+v[i]);
}
}
}
for(int i=W;i>0;i--){
if(dp[0][W]==dp[0][i]){
minWeight=i;
}
}
System.out.println("Case "+count+":");
System.out.println(dp[0][W]);
System.out.println(minWeight);
}
}

Measured memory_bytes: 28444
#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 n;
    cin >> n;
    bool flag=false;
    rep(i,50000){
        if(i*108/100==n){
            flag=true;
            cout << i << endl;
            break;
        }
    }
    if(flag==false) cout << ":(" << endl;

}


Measured memory_bytes: 3608
#include <iostream>
    #include <vector>
    #include <algorithm>
    using namespace std;
    #pragma warning (disable: 4996)
     
    long long N, A[1009][1009], cnt[1009];
     
    vector<pair<int, int>> solve(vector<int> K) {
    	vector<pair<int, int>> L;
    	for (int pos : K) {
    		if (cnt[pos] == N) continue;
    		int v1 = A[pos][cnt[pos]];
    		int v2 = A[v1][cnt[v1]];
    		if (v2 != pos) continue;
     
    		int a1 = v1, a2 = pos; if (a1 > a2) swap(a1, a2);
    		L.push_back(make_pair(a1, a2));
    	}
    	sort(L.begin(), L.end());
    	L.erase(unique(L.begin(), L.end()), L.end());
    	return L;
    }
     
    int main() {
    	scanf("%lld", &N);
    	for (int i = 1; i <= N; i++) {
    		for (int j = 1; j <= N - 1; j++) scanf("%lld", &A[i][j]);
    		cnt[i] = 1;
    	}
     
    	vector<int> J; for (int i = 1; i <= N; i++) J.push_back(i);
    	vector<pair<int, int>> R1 = solve(J); int ret = 0;
    	while (R1.size() >= 1) {
    		vector<int> R2;
    		for (int i = 0; i < R1.size(); i++) {
    			cnt[R1[i].first]++; R2.push_back(R1[i].first);
    			cnt[R1[i].second]++; R2.push_back(R1[i].second);
    		}
    		R1 = solve(R2); ret++;
    	}
     
    	for (int i = 1; i <= N; i++) {
    		if (cnt[i] == N) continue;
    		cout << "-1" << endl;
    		return 0;
    	}
    	cout << ret << endl;
    	return 0;
    }

Measured memory_bytes: 8192
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

const int MAXN = 805;

int n,m,k;
int X,Y,ans;
int dis[MAXN][MAXN];

string s[MAXN];

void bfs()
{
	queue<pair<int,int> > Q;
	for (int i = 0;i < n;i++)
		for (int j = 0;j < m;j++)
			dis[i][j] = 1e9;
	dis[X][Y] = 0;
	Q.push(make_pair(X,Y));
	ans = 1e9;
	while (!Q.empty())
	{
		int x = Q.front().first,y = Q.front().second;
		Q.pop();
		ans = min(ans,(min(min(x,n - 1 - x),min(y,m - 1 - y)) + k - 1) / k + 1);
		if (dis[x][y] >= k)
			continue;
		if (x > 0 && dis[x - 1][y] == 1e9 && s[x - 1][y] != '#')
		{
			dis[x - 1][y] = dis[x][y] + 1;
			Q.push(make_pair(x - 1,y));
		}
		if (y > 0 && dis[x][y - 1] == 1e9 && s[x][y - 1] != '#')
		{
			dis[x][y - 1] = dis[x][y] + 1;
			Q.push(make_pair(x,y - 1));
		}
		if (x < n - 1 && dis[x + 1][y] == 1e9 && s[x + 1][y] != '#')
		{
			dis[x + 1][y] = dis[x][y] + 1;
			Q.push(make_pair(x + 1,y));
		}
		if (y < m - 1 && dis[x][y + 1] == 1e9 && s[x][y + 1] != '#')
		{
			dis[x][y + 1] = dis[x][y] + 1;
			Q.push(make_pair(x,y + 1));
		}
	}
}

int main()
{
	ios::sync_with_stdio(0);
	cin >> n >> m >> k;
	for (int i = 0;i < n;i++)
	{
		cin >> s[i];
		for (int j = 0;j < m;j++)
			if (s[i][j] == 'S')
				X = i,Y = j;
	}
	bfs();
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3456
fun main(args: Array<String>) {
	val n = readLine()!!.toInt()

	val a = arrayListOf<ArrayList<ArrayList<Int>>>()
	for (i in 0 until 4) {
		a.add(ArrayList())
		for (j in 0 until 3) {
			a[i].add(ArrayList())
			for (k in 0 until 10) {
				a[i][j].add(0)
			}
		}
	}

	for (i in 0 until n) {
		val (b, f, r, v) = readLine()!!.split(" ").map { it.toInt() - 1 }
		a[b][f][r] += v + 1
	}

	for (i in 0 until 4) {
		if (i != 0) println("#".repeat(20))
		for (j in 0 until 3) {
			println(" " + a[i][j].joinToString(" "))
		}
	}
}



Measured memory_bytes: 31884