akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef	long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef set<int> si;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef pair<ll, pll> plll;
typedef vector<pair<int, pii>> viii;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define tc int tt;cin>>tt;while(tt--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fio ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#define RED "\033[31m"
#define GREEN "\033[32m"
#define RESET "\033[0m"
#define sleep for (int i = 1, a;i < 100000000;i++, a = a * a)
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> ranked_pairset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ranked_map;

int main() {
	fio;
	int h, w, k;
	cin >> h >> w >> k;
	vi a(h + 1), b(w + 1);
	set<pii> s;
	while (k--) {
		int x, y;
		cin >> x >> y;
		s.insert({x, y});
		a[x]++, b[y]++;
	}
	int hh = *max_element(all(a));
	int ww = *max_element(all(b));
	vi aa, bb;
	for (int i = 1;i <= h;i++)
		if (a[i] == hh)
			aa.pb(i);
	for (int i = 1;i <= w;i++)
		if (b[i] == ww)
			bb.pb(i);
	for (auto x : aa)
		for (auto y : bb)
			if (!s.count({x, y})) {
				cout << ww + hh << '\n';
				return 0;
			}
	cout << ww + hh - 1 << '\n';
}


Measured memory_bytes: 23812
paper=[[0 for i in range(10)] for j in range(10)]
#print paper

def drop(x,y):
    global paper
    if 0<=x<10 and 0<=y<10:
        paper[y][x] += 1
    return

def ink(x,y,s):
    drop(x,y)
    drop(x-1,y); drop(x+1,y)
    drop(x,y-1); drop(x,y+1)
    if s==1: return
    drop(x-1,y-1); drop(x-1,y+1)
    drop(x+1,y-1); drop(x+1,y+1)
    if s==2: return
    drop(x-2,y); drop(x+2,y)
    drop(x,y-2); drop(x,y+2)
    return

while True:
    try:
        x,y,s=map(int,raw_input().split(","))
        ink(x,y,s)
    except:
        break

print sum([i.count(0) for i in paper])
print max([max(i) for i in paper])


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

int main() {

vector<int> vec(10);
for (int i = 0; i < 9; i++) {
    cin >> vec.at(i);
}
int N, b;
cin >> N;
for (int i = 0; i < N; i++) {
    cin >> b;
    for (int i = 0; i < 9; i++) {
    if(vec.at(i)==b){
        vec.at(i)=-1;
    }
    }
}
if(vec.at(0)==vec.at(1)&&vec.at(1)==vec.at(2)||
    vec.at(3)==vec.at(4)&&vec.at(4)==vec.at(5)||
    vec.at(6)==vec.at(7)&&vec.at(7)==vec.at(8)||
    vec.at(0)==vec.at(3)&&vec.at(3)==vec.at(6)||
    vec.at(1)==vec.at(4)&&vec.at(4)==vec.at(7)||
    vec.at(2)==vec.at(5)&&vec.at(5)==vec.at(8)||
    vec.at(0)==vec.at(4)&&vec.at(4)==vec.at(8)||
    vec.at(2)==vec.at(4)&&vec.at(4)==vec.at(6)){
        cout << "Yes" << endl;
    }
else{
    cout << "No" << endl;
}

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ii pair<int,int>
#define st first
#define nd second
#define mp make_pair
#define N 105
using namespace std;

int h,w,n,x=1,y=1,yon=1,nc[N*N],a[N][N];
vector<ii> v;

void put(int now) {

  int no=v[now].st;
  int renk=v[now].nd;
  while(no--) {
    a[x][y]=renk;
    y+=yon;
    if(y>w || y<1) {
      y-=yon;
      yon=-yon;
      x++;
    }
  }

}

int main() {

  scanf("%d %d %d",&h,&w,&n);
  for(int i=1;i<=n;i++) {
    scanf("%d",&nc[i]);
    v.push_back(mp(nc[i],i));
  }
  sort(v.begin(),v.end(),greater<ii>());
  for(int i=0;i<n;i++) {
    put(i);
  }
  for(int i=1;i<=h;i++,puts("")) {
    for(int j=1;j<=w;j++) {
      printf("%d ",a[i][j]);
    }
  }
}


Measured memory_bytes: 640
while True:
    x, y, s = map(int, raw_input().split())

    if x == 0 and y == 0 and s == 0:
        break

    ans = 0

    for i in range(1, s):
        for j in range(1, s-i+1):
            if int(i * (100 + x) / 100.0) + int(j * (100 + x) / 100.0) == s:
                ans = max(ans, int(i * (100 + y) / 100.0) + int(j * (100 + y) / 100.0))

    print ans



Measured memory_bytes: 4720
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

ans = 0

a, b = li()

ap4 = a//4
bp4 = b//4

if ap4 == bp4:
    for x in range(a, b+1):
        ans ^= x

else:
    while a%4:
        ans ^= a
        a += 1

    while b%4 != 3:
        ans ^= b
        b -= 1

print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define N 100010
#define fi(n) for(long long i=0;i<n;i++)
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	int ma[N]; int h[N];
	ll n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>h[i];
		ma[i]=0;
	}
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		ma[a] = max(ma[a],h[b]);
		ma[b] = max(ma[b],h[a]);
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=(h[i]>ma[i]);
	}
	cout<<ans<<'\n';
	return 0;
}


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

#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(s) s.begin(),s.end()
#define vll vector<ll>
#define vi vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vull vector<ull>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define fi first
#define se second
#define sz(x) x.size()
#define cinarr(n,a) for(int i = 0; i < n; i++) cin >> a[i];
#define coutarr(n,a) for(int i = 0; i < n; i++) cout << a[i] << (i+1==n?'\n':' ');
#define fori(i,a,b,x) for(int i = a; i <= b; i+=x)
#define ford(i,a,b,x) for(int i = a; i >= b; i-=x)
#define tc int tt; cin >> tt; for(int cs = 1; cs <= tt; cs++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define reset(x,y) memset(x,y,sizeof x);
#define EPS 1e-10
#define INF 2000000000
#define mod 1000000007
#define debug(val) cerr << "The value of " << #val << " is = " << val << endl;
#define testing cerr << "--------------------------\n";

int main() {
	IOS
	int n,x,res=0;
	cin>>n>>x;
	int a[n+5];
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a,a+n);
	for(int i = 0; i < n; i++) {
		if(x>=a[i]) {
			x-=a[i];
			if(i==n-1 and x>0) break;
			res++;
		} else break;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 3516
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int m[50][50];
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int bfs[50][50][50][50];
struct wolf{
	int a,b,c,d;
	wolf(int A,int B,int C,int D){
		a=A;
		b=B;
		c=C;
		d=D;
	}
};
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a+b){
		int r1,r2,c1,c2;
		scanf("%d%d%d%d",&c1,&r1,&c2,&r2);
		for(int i=0;i<b;i++)
			for(int j=0;j<a;j++)
				scanf("%d",&m[i][j]);
		int inf=999999999;
		for(int i=0;i<b;i++)
			for(int j=0;j<a;j++)
				for(int k=0;k<b;k++)
					for(int l=0;l<a;l++)
						bfs[i][j][k][l]=inf;
		r1--;c1--;r2--;c2--;
		bfs[r1][c1][r2][c2]=0;
		queue<wolf> Q;
		Q.push(wolf(r1,c1,r2,c2));
		while(Q.size()){
			wolf at=Q.front();
			Q.pop();
		//	if(bfs[at.a][at.b][at.c][at.d]==99)continue;
			for(int i=0;i<4;i++){
				int s1=at.a+dx[i];
				int t1=at.b+dy[i];
				int s2=at.c-dx[i];
				int t2=at.d-dy[i];
				if(s1<0||s1>=b||m[s1][t1])s1-=dx[i];
				if(t1<0||t1>=a||m[s1][t1])t1-=dy[i];
				if(s2<0||s2>=b||m[s2][t2])s2+=dx[i];
				if(t2<0||t2>=a||m[s2][t2])t2+=dy[i];
				if(bfs[s1][t1][s2][t2]==inf){
					bfs[s1][t1][s2][t2]=bfs[at.a][at.b][at.c][at.d]+1;
					Q.push(wolf(s1,t1,s2,t2));
				}
			}
		}
		int ret=inf;
		for(int i=0;i<b;i++)for(int j=0;j<a;j++)ret=min(ret,bfs[i][j][i][j]);if(ret>=100)printf("NA\n");else printf("%d\n",ret);
	}
}

Measured memory_bytes: 26376
#include<bits/stdc++.h>
using namespace std;
#define MP make_pair
#define PB push_back
#define PII pair<int,int>
#define LL long long
int N=INT_MAX;
map<int ,int>my;
//vector<PII>v[1000005];

int main(){
    int n;
    cin>>n;
    LL f[n][3];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>f[i][j];
        }
    }
    LL a,b,c;
    for(int i=1;i<n;i++){
        f[i][0]+=max(f[i-1][1],f[i-1][2]);
        f[i][1]+=max(f[i-1][0],f[i-1][2]);
        f[i][2]+=max(f[i-1][0],f[i-1][1]);
    }
    cout<<max(max(f[n-1][0],f[n-1][1]),f[n-1][2]);
    return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>

#define N 2000001

int main(){
  int loop;
  int Before[N],After[N],Counter[N];
  int i;

  scanf("%d",&loop);
  for(i=0;i<N+1;i++){
    Counter[i]=0;
  }

  for(i=1;i<loop+1;i++){
    scanf(" %d",&Before[i]);
    Counter[Before[i]]++;
  }
  
  for(i=1;i<N+1;i++){
    Counter[i]=Counter[i]+Counter[i-1];
  }

  for(i=loop;i>=1;i--){
    After[Counter[Before[i]]]=Before[i];
    Counter[Before[i]]--;
  }

  for(i=1;i<loop;i++){
    printf("%d ",After[i]);
  }

  printf("%d\n",After[loop]);
  
  return 0;
}




Measured memory_bytes: 25176
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N, M;
  cin >> N >> M;
  int a = 0;
  int b = 0;
  for (int i = 0; i < N + M; i++)
  {
    a += i;
  }
  b += N * M;
  a -= b;
  cout << a << endl;
}

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

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

int main() {
  int N;
  cin >> N;
  vector<int> as(N);
  for(int i = 0; i < N; ++i) {
    cin >> as[i];
  }
  sort(as.begin(), as.end());
  int ans = INF;
  for(int i = as.front(); i <= as.back(); ++i) {
    int v = 0;
    for(auto a : as) {
      v += (i - a) * (i - a);
    }
    chmin(ans, v);
  }
  cout << ans << 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.io.PrintStream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class AStrings {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            String s = in.next();
            String t = in.next();

            out.print(t + s);
        }

    }

    static class FastReader {
        public BufferedReader br;
        public StringTokenizer st;
        String context = null;

        public FastReader(InputStream in) {
            this(new InputStreamReader(in));
        }

        public FastReader(InputStreamReader input) {
            br = new BufferedReader(input);
        }

        public String next() {
            if (context != null) {
                System.err.print("[" + context + "] Wait for input ...");
            }
            while (st == null || !st.hasMoreElements()) {
                try {
                    String s = br.readLine();
                    if (s == null)
                        return null;
                    st = new StringTokenizer(s);
                } catch (IOException e) {
                    e.printStackTrace();
                    throw new RuntimeException("Could not read");
                }
            }
            String res = st.nextToken();
            if (context != null) {
                System.err.println("[" + context + "] ... received : " + res);
            }
            return res;
        }

    }
}



Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const ll INF=1e9+7;
const ll N = 100002;
ll n,a[N],k,koyaku,maxa=0;
ll gojo(ll x,ll y){
	if(y>x){
		ll w=x;
		x=y;
		y=w;
	}
	ll w=1;
	while(w!=0){
		w=x%y;
		x=y;
		y=w;
	}
	return x;
}


int main(){
	cin>>n>>k;
	FOR(i,0,n){
		cin>>a[i+1];
		if(a[i+1]>maxa)maxa=a[i+1];
	}
	koyaku=a[1];
	FOR(i,2,n+1){
		koyaku=gojo(koyaku,a[i]);
	}
	if(maxa>=k&&(maxa-k)%koyaku==0){
		cout<<"POSSIBLE"<<endl;
	}else{
		cout<<"IMPOSSIBLE"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// typedef pair<ll,ll> Pair;
// ll mod=1000000007;
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll t,c,i,j,k,temp,temp2,n,m,sum=0;
    cin >> c;
    cout << 1000*(c/500) + 5*((c%500)/5);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = pow(10, 9) + 7;

int main() {
    // source
    int h, w, k;
    cin >> h >> w >> k;
    string s[h];
    rep(i, h) { cin >> s[i]; }

    int ans[h][w] = {};
    bool empty[h] = {};
    int number = 1;
    rep(i, h) {
        int num = 0;
        set<int> place;
        rep(j, w) {
            if (s[i][j] == '#') {
                num++;
                place.insert(j);
            }
        }
        if (num == 0) {
            empty[i] = true;
            continue;
        }

        int up_counter = 1;
        rep(j, w) {
            ans[i][j] = number;
            if (place.find(j) != place.end()) {
                if (j == w - 1) {
                    number++;
                } else {
                    if (up_counter != num) {
                        number++;
                        up_counter++;
                    }
                }
            }

            if (j == w - 1) {
                if (place.find(j) == place.end()) {
                    number++;
                }
            }
        }
    }

    repd(i, 1, h) {
        if (empty[i]) {
            rep(j, w) { ans[i][j] = ans[i - 1][j]; }
            if (!empty[i - 1]) {
                empty[i] = false;
            }
        }
    }

    repd(index, 1, h) {
        int i = h - index - 1;
        if (empty[i]) {
            rep(j, w) { ans[i][j] = ans[i + 1][j]; }
            empty[i] = false;
        }
    }

    rep(i, h) {
        rep(j, w) { cout << ans[i][j] << " "; }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 1280
N, W = map(int, input().split())
T = [list(map(int, input().split())) for _ in range(N)]

dp = [[0] + [-1] * W for _ in range(N+1)]
dp[0] = [0] * (W+1)

for i in range(1, N+1):
    for w in range(1, W+1):
        dp[i][w] = max(dp[i-1][w], dp[i-1][w - T[i-1][0]] + T[i-1]
                       [1]) if w - T[i-1][0] >= 0 else dp[i-1][w]

# print(*dp, sep='\n')
print(dp[N][W])


Measured memory_bytes: 139416
import numpy as np


N,M=map(int,input().split())
# A=np.array(list(map(int,input().split())))
A=np.array(list(map(int,input().split())),dtype=np.int32)
A=np.sort(A)

EXC=[]

for i in range(M):
    exc=list(map(int,input().split()))
    EXC.append(exc)
excArry=np.array(EXC,dtype=np.int32)

col_num=1
Arr=excArry[np.argsort(excArry[:,col_num])[::-1]]
# print(A)
# print(Arr)

point=0


for j in range (M):
    change_Num=Arr[j][1]
    count=np.count_nonzero(A<change_Num)
    if count > 0:
        m=min(count,Arr[j][0])
        A[point:point+m]=change_Num
        point+=m
        # A=np.sort(A)
    else:
        break

print(np.sum(A))
    
#     for j in range (B):
#         count=np.count_nonzero(A<C)
#         if count>0:
#             m=min(B,count)
#             A[:m]=C
#         else:
#             continue
    
#     A=np.sort(A)

# print(np.sum(A))

Measured memory_bytes: 48440
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

int main(){
   int n; cin >> n;
   int keta=1;
   ll sum = 0;
   for(int i=1;n/keta;i++){
      if(i%2){
         if(n/(keta*10)){
            sum += keta*10-keta;
         }else{
            sum += n-keta+1;
         }
      }
      keta*=10;
   }
   cout << sum << endl;
   return 0;
}

Measured memory_bytes: 256
n, m = tuple([int(i) for i in input().strip().split(" ")])

def pow10(n):
    if n == 0:
        return 0
    r = 1
    for i in range(n):
        r = r * 10
    return r

if m == 0:
    print(pow10(n-1))
    import sys
    sys.exit(0)

d = {}

# value = [0 for i in range(n)]
# st = set()

# for i in range(m):
#     s, c = tuple([int(i) for i in input().strip().split(" ")])
#     if s-1 in st and value[s-1] != c:
#         print(-1)
#         import sys
#         sys.exit(0)
#     value[s-1] = c
#     st.add(s-1)

# if len(value) > 1 and value[0] == 0:
#     print(-1)
#     import sys
#     sys.exit(0)

# print(int("".join([str(v) for v in value])))



for i in range(m):
    s, c = tuple([int(i) for i in input().strip().split(" ")])
    if s in d:
        d[s].append(c)
    else: 
        d[s] = [c]



for i in range(pow10(n-1), pow10(n)):
    si =  str(i)

    flag = True
    for key, values in d.items():
        for value in values:
            if  int(si[key-1]) != value:
                flag = False
                break
    if flag:
        print(i)
        import sys
        sys.exit(0)

print(-1)
    

            

    



Measured memory_bytes: 3064
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def min(a,b)
    return a>b ? b : a
end
N=gets.to_i
alphabet={}
("a".."z").to_a.each do|x|
    alphabet[x]=0
end
N.times do|i|
  s=get_nsp
  albe={}
  s.each do|x|
      albe[x]=0 if albe[x].nil?
      albe[x]+=1
  end
  ("a".."z").to_a.each do|x|
    if albe[x].nil?
        alphabet[x]=0
        next
    end
    if i.zero?
      alphabet[x]=albe[x]
    end
    alphabet[x]=min(alphabet[x],albe[x])
  end
end
ans=""
("a".."z").to_a.each do|x|
  alphabet[x].times do
      ans+=x
  end
end
puts ans

Measured memory_bytes: 1916
#include<iostream>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    int ans;
    ans = a*b;
    string s;
    if(ans % 2 == 0)
        s = "Even";
    else
        s = "Odd";

    cout << s << endl;
    return 0;
}


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

#define maxn 111111
vector<int> g[maxn];
int f[maxn];
int n;

void dfs(int v, int p)
{
    for (int i = 0; i < g[v].size(); i++)
    {
        int u = g[v][i];
        if (u == p)
        {
            continue;
        }
        dfs(u, v);
        f[v] ^= (f[u] + 1);
    }
}

int main()
{
    cin >> n;
    for (int i = 1; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    dfs(1, 0);
    if (f[1])
    {
        cout << "Alice" << endl;
    }
    else
    {
        cout << "Bob" << endl;
    }
    return 0;
}


Measured memory_bytes: 14208
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;

namespace AOJ
{
    class _1085
    {
	    static void Main()
	    {
		    while(true){
			    string [] tokens = Console.ReadLine().Split(' ');
			    var n = int.Parse(tokens[0]);
			    var S = int.Parse(tokens[1]);
			    int res = 0;
			    
			    if( n == 0 && S == 0 ) break;
                
                int [] x = new int[n];
                for(int i = 0; i < n; ++i){
				    x[i] = int.Parse(Console.ReadLine());
			    }
                Array.Sort(x);
                
			    for(int i = 0; i < n; ++i){
                    int p = Array.BinarySearch(x, S+1 - x[i]);
                    while (p > 0 && x[p - 1] == S + 1 - x[i]) --p;
                    if (p < 0) p = ~p;
                    // Console.WriteLine("Search : {0}, Result : {1}", S + 1 - x[i], p);
                    res += n - Math.Max(i+1,p);
			    }
			    Console.WriteLine("{0}", res);
		    }
	    }
    }
}

Measured memory_bytes: 6468
/*input
98765432109876543210
58

1000000009
1

30
4
*/

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define fo(i,n) for(i=0;i<n;++i)
#define sz(x) (int)(x).size()
#define pb push_back

typedef long long int ll;
typedef vector<int> vi;

const ll inf = 1e9;
const ll mod=1000000007;

ll powmod(ll a,ll b,ll mo=mod){ll res=1;a%=mo; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}

inline ll inv_(ll a) {return powmod(a, mod-2, mod);}
inline ll add(ll a, ll b){a%=mod; b%=mod; a+=b;if(a>=mod)a-=mod;return a;}
inline ll mul(ll a, ll b){a%=mod; b%=mod; return a*1ll*b%mod;}
inline ll sub(ll a, ll b){a%=mod; b%=mod; a-=b;if(a<0)a+=mod;return a;}


const int MAXN = 100005;
int d;
string k;

ll dp[10005][105][2];

ll solve(int idx, int sum, bool flag){
	// cout << idx << " " << k[idx] << " -- " << sum << " " << flag << endl;
	if(idx >= sz(k))return (sum % d == 0);
	if(dp[idx][sum][flag] != -1)return dp[idx][sum][flag];
	ll ans = 0;
	if(!flag){
		for(int i = 0; i <= 9; ++i){
			ans = ans + solve(idx + 1, (sum + i) % d, false) % mod;
		}
	}
	else{
		for(int i = 0; i < (k[idx] - '0'); ++i){
			ans = ans + solve(idx + 1, (sum + i) % d, false) % mod;
		}	
		ans = ans + solve(idx + 1, (sum + (k[idx] - '0')) % d, true) % mod;
	}
	ans = ans % mod;
	return dp[idx][sum][flag] = ans;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
	
	memset(dp, -1, sizeof(dp));

	cin >> k >> d;
	
	ll ans = solve(0, 0, true);
	
	cout << (ans + mod - 1) % mod << endl;
	
    return 0;
}




Measured memory_bytes: 17408
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)     (x).begin(),(x).end()
# define UNIQ(c)    (c).erase(unique(ALL((c))), end((c)))
# define mp         make_pair
# define eb         emplace_back
# define FOR(i,a,b) for(int i=(a);i<(b);++i)
# define REP(i,n)   FOR(i,0,n)
# define INIT       std::ios::sync_with_stdio(false);std::cin.tie(0);

int n, m, l, r, x;
LL dp[303][303][303];
vector<pair<int, int>>v[303];
const int MOD = 1e9 + 7;

bool calc(int i, int j, int k) {
	int maxpos = max({ i,j,k });
	for (int l = 0; l < v[maxpos].size(); l++) {
		if (((v[maxpos][l].first < i) + (v[maxpos][l].first < j) + (v[maxpos][l].first < k)) != v[maxpos][l].second)return false;
	}
	return true;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> l >> r >> x;
		v[r].emplace_back(mp(l - 1, x));
	}
	dp[0][0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < n; k++) {
				int maxpos = max({ i,j,k });
				if (calc(maxpos + 1, j, k))(dp[maxpos + 1][j][k] += dp[i][j][k]) %= MOD;
				if (calc(i, maxpos + 1, k))(dp[i][maxpos + 1][k] += dp[i][j][k]) %= MOD;
				if (calc(i, j, maxpos + 1))(dp[i][j][maxpos + 1] += dp[i][j][k]) %= MOD;
			}
		}
	}
	LL ans = 0;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			(ans += dp[n][i][j]) %= MOD;
			(ans += dp[i][n][j]) %= MOD;
			(ans += dp[i][j][n]) %= MOD;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 217344
#include<bits/stdc++.h>
using namespace std;
int a[4][4];
int main()
{
	std::ios::sync_with_stdio(false);
	int n;
	cin>>a[1][1]>>a[1][2]>>a[2][2];
	n=a[2][2]*3;
	a[1][3]=n-a[1][1]-a[1][2];
	a[3][3]=n-a[1][1]-a[2][2];
	a[3][2]=n-a[1][2]-a[2][2];
	a[3][1]=n-a[3][2]-a[3][3];
	a[2][1]=n-a[1][1]-a[3][1];
	a[2][3]=n-a[1][3]-a[3][3];
	for(int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		cout<<a[i][j]<<" ";
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();

		// local sum:部分和
		long lsum[][] = new long[n][n];
		// 区間の累積コスト
		long cost[][] = new long[n][n];
		for ( int i = 0; i < n; i++ ) {
			lsum[i][i] = in.nextInt();
		}
		for ( int r = 0; r < n; r++ ) {
			for ( int c = r + 1; c < n; c++ ) {
				lsum[r][c] = lsum[r][c - 1] + lsum[c][c];
			}
		}

		for ( int p = 1; p < n; p++ ) {
			for (int r = 0, c = p; c < n; r++, c++ ) {
				Long min = Long.MAX_VALUE;
				for ( int i = r; i <= c - 1; i++ ) {
					min = Math.min(min, cost[r][i] + cost[i + 1][c]);
				}
				cost[r][c] = min + lsum[r][c];
			}
		}

		System.out.println(cost[0][n - 1]);
		in.close();
	}
}


Measured memory_bytes: 95444
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define FOR(i,a) for(auto i:a)
#define pub push_back
#define pob pop_buck
#define all(in) in.begin(),in.end()

using ll = long long; // typedef long long ll; と同意
using ull = unsigned long long;
using namespace std;

int main(){
    int x , n; cin >> x >> n;
    int data[n]; 
    rep(i, n) cin >> data[i];
    int ans;
    rep(i,110){
        ans = x+i;
        bool count = true;
        rep(i,n) if(data[i]==ans) count = false;
        if(count) break;
    }
    int ans2;
    rep(i,110){
        ans2 = x-i;
        bool count = true;
        rep(i,n) if(data[i]==ans2) count = false;
        if(count) break;
    }
    if(abs(ans-x)>=abs(x-ans2)) cout << ans2 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

template <typename T>
T powi(T a, ll n) {
    T ret = 1;
    while (n > 0) {
        if (n & 1) ret *= a; 
        a *= a;
        n >>= 1;
    }
    return ret;
}

int main() {
    int n, k;
    cin >> n >> k;

    double ans = 0;
    for (int i = 1; i <= n; ++i) {
        int j = 0;
        while ((i << j) < k) ++j;
        ans += pow(0.5, j);
    }

    ans /= n;

    cout << fixed << setprecision(20) << ans << endl;

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n, k;
    cin >> n >> k;
    int h;
    int res = 0;
    for (int i = 0; i < n; ++i) {
        cin >> h;
        if (h >= k) res++;
    }
    cout << res << endl;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    string st;
    cin >> st;
    
    int n = st.size();
    vector<int> data(n);
    for (int i = 0; i < n; i++) {
        if (st[i] == 'W') {
            data[i]++;
        }
    }

    for (int i = n-1; i > 0; i--) {
        data[i-1] += data[i];
    }

    int ans = 0;
    rep(i, n) {
        if (st[i] == 'B') ans += data[i];
    }
    std::cout << ans << std::endl;
    

    return 0;
}


Measured memory_bytes: 2196
#include <iostream>
#include <stack>

using namespace std;
using ULL = unsigned long long;

struct rect {
    ULL pos, height;
};

int main() {

    int N;
    cin >> N;

    ULL ans = 0;
    stack<rect> stk;

    for (int i = 0; i <= N; i++) {
        ULL p, h;
        p = i;
        if (i < N) cin >> h;
        else h = 0;
        if (stk.empty()) {
            stk.push((rect) {p, h});
        } else {
            if (stk.top().height < h) {
                stk.push((rect) {p, h});
            } else if (stk.top().height > h) {
                while (!stk.empty() && stk.top().height >= h) {
                    rect &pre = stk.top();
                    stk.pop();
                    ans = max(ans, pre.height * (i - pre.pos));
                    p = pre.pos;
                }
                stk.push((rect) {p, h});
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 4612
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <list>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
typedef long long ll;


const int MAX_N = 1000010;
int id[MAX_N], sz[MAX_N];

void init(int n) {
  REP(i,n) id[i] = i;
}

int root(int x) {
  if (id[x] != x)
    id[x] = root(id[x]);
  return id[x];
}

bool same(int p, int q) {
  return root(p) == root(q);
}

void unite(int p, int q) {
  int i = root(p), j = root(q);
  if (sz[i] < sz[j]) {
    id[i] = j;
    sz[j] += sz[i];
  } else {
    id[j] = i;
    sz[i] += sz[j];
  }
}

int main(int argc, char *argv[])
{
  cin.tie(0);
  ios::sync_with_stdio(false);
    
  int n, q, com, x, y;

  cin >> n >> q;
  init(n);
  REP(i,q) {
    cin >> com >> x >> y;
    if (com == 0) unite(x, y);
    else if (same(x, y)) cout << 1 << endl;
    else cout << 0 << endl;
  }

  return 0;
}

Measured memory_bytes: 3288
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] w = new int[n];
		for (int i = 0; i < w.length; i++) {
			w[i] = sc.nextInt();
		}
		sc.close();

		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < w.length; i++) {
			int s1 = 0;
			int s2 = 0;
			for (int j = 0; j < w.length; j++) {
				if (j <= i) {
					s1 += w[j];
				} else {
					s2 += w[j];
				}
			}
			ans = Math.min(ans, Math.abs(s1 - s2));
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
bool cmp(int x,int y)
{
return x>y;
}
int main()
{
    int i,n,m,a[105],sum=0;
    double s;
	cin>>n>>m;
    for(i=0;i<n;i++){
    	cin>>a[i];
    	sum+=a[i];
    }
        
    sort(a,a+n,cmp);
    if(a[m-1]*4*m>=sum)cout<<"Yes";
	else cout<<"No";	
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int a[3][3];
bool d[3][3];

int main(){
    rep(i, 3) rep(j, 3) cin >> a[i][j];
    int n;
    cin >> n;
    int b[n];
    rep(k, n) cin >> b[k];
    rep(i, 3) rep(j, 3) {
        d[i][j] = false;
        rep(k, n) if (a[i][j] == b[k]) d[i][j] = true;
    }
    string ans = "No";
    rep(i, 3) {
        if (d[i][0] and d[i][1] and d[i][2]) ans = "Yes";
    }
    rep(j, 3) {
        if (d[0][j] and d[1][j] and d[2][j]) ans = "Yes";
    }
    {
        if (d[0][0] and d[1][1] and d[2][2]) ans = "Yes";
    }
    {
        if (d[0][2] and d[1][1] and d[2][0]) ans = "Yes";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import collections
import sys
cntr = collections.Counter()
for line in sys.stdin:
    cntr[int(line)] += 1
lst = []
for k,v in cntr.items():
    lst.append((v,k))
lst.sort()
t = len(lst)-1
while t>0 and lst[t][0] == lst[t-1][0]:
    t -= 1
for i in range(t,len(lst)):
    print(lst[i][1])

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

namespace abc64
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            int[] rate = { 0, 0, 0, 0, 0, 0, 0, 0 };
            int pro = 0;
            for (int i = 0; i < N; i++)
            {
                int temp = int.Parse(str[i]);
                if (temp >= 3200)
                {
                    pro++;
                }else
                {
                    rate[temp / 400] = 1;
                }
            }
            int ans = 0;
            for(int i = 0; i < 8; i++)
            {
                ans += rate[i];
            }
            if (ans == 0)
            {
                ans++;
                pro--;
            }
            Console.WriteLine("{0} {1}", ans, ans+pro);
           
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
static bool a(std::vector<int>& w, int s, int k) {
    int c = 1, d = 0;
    for (auto&& e: w) {
        if (e > s) {
            return false;
        }
        if (e + d <= s) {
            d += e;
        } else {
            d = e;
            ++c;
        }
    }
    return c <= k;
}
int main() {
    int n, k, m, s = 0;
    std::cin >> n >> k;
    std::vector<int> w;
    while (std::cin >> m) {
        w.push_back(m);
        s += m;
    }
    s /= k;
    int l = s, r = 2 * s;
    for (int m = l + (r - l) / 2; l < r; m = l + (r - l) / 2) {
        if (a(w, m, k)) {
            r = m;
        } else {
            l = m + 1;
        }
    }
    std::cout << r << std::endl;
}



Measured memory_bytes: 3516
# frozen_string_literal: true

n = gets.to_i

ht = Array.new(10) { Array.new(10) { 0 } }

def tail(n)
  n % 10
end

def head(n)
  while n > 9
    n /= 10
  end
  n
end

(1..n).each do |i|
  ht[head(i)][tail(i)] += 1
end

count = 0
(1..9).each do |i|
  (1..9).each do |j|
    count += ht[i][j] * ht[j][i]
  end
end

puts count


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int danjia[100000];
int main()
{	
	int ttq,money,cnt=0,ans=0;;
	cin>>ttq>>money;
	for(int i=1;i<=ttq;i++)
		cin>>danjia[i];
	sort(danjia+1,danjia+ttq+1);
	for(int i=2;i<=ttq;i++)
		cnt+=danjia[i];
	ans=ttq-1;
	ans+=(money-cnt)/danjia[1];
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
from collections import Counter

def warshall_floyd(c):
    for k in range(10):
        for j in range(10):
            for i in range(10):
                c[j][i] = min(c[j][i], c[j][k] + c[k][i])
    return c

h, w = map(int, input().split())
c = []
a = []
for _ in range(10):
    k = [int(i) for i in input().split()]
    c.append(k)
for _ in range(h):
    a.extend([int(i) for i in input().split()])

count = Counter(a)
c = warshall_floyd(c)
ans = 0
for i in range(10):
    if i != 1:
        ans += count[i] * c[i][1]
print(ans)


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

int n, m;
bool a[202020][2];


int main(){
  cin >> n >> m;
  rep(i, n + 1){
    a[i][0] = a[i][1] = false;
  }
  rep(i, m){
    int ant, bear;
    cin >> ant >> bear;
    //大小入れ替え
    if(ant > bear) swap(ant, bear);
    if(ant == 1){
      a[bear][0] = true;
    }
    if(bear == n){
      a[ant][1] = true;
    }
  }
  /*
  for(int i = 1; i <= n; i++){
    cerr << a[i][0]  << " " << a[i][1] << endl;
  }
  */
  string res = "IMPOSSIBLE";
  for(int i = 2; i < n; i++){
    if(a[i][0] && a[i][1]){
      res = "POSSIBLE";
      break;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 640
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int INF = 1 << 30;
#define rep(i,n) for(int i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
int main() {
	ll a, b, c, d, e, ans = 0;
	bool bb;
	string s, ss;
	cin >>    a>>b;
	cout <<    yn(a%500<=b)  << endl;
	return 0;
}

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

long long n, t, ans=1;

long long gcd(long long a, long long b)
{
    if(b==0) return a;
    return gcd(b, a%b);
}

long long lcm(long long a, long long b)
{
    return a * (b/gcd(a, b));
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> t;
        ans = lcm(ans, t);
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;

ll N, M;

ll F(ll a, ll b){

rep(i, 1, N + 1 - b){
a /= 10;
}
return a %10;
}

int main() {

cin >> N >> M;

vector<ll> s(M);
vector<ll> c(M);

rep(i, 0, M)cin >> s[i] >> c[i];
bool C = 0;
if(N == 1)C = 1;

rep(n, pow(10, N - 1), pow(10, N)){
int count = 0;
if(C){C = 0;n--;}

    rep(i, 0, M){
    if(F(n, s[i]) == c[i])count++;
    }

if(count == M){cout << n;exit(0);}
}
cout << -1;
}

Measured memory_bytes: 3908
import Control.Monad
import Data.List

main = do
  n <- readLn
  ps <- map (map read . words) <$> replicateM n getLine
  print $ solve ps

solve :: [[Double]] -> Double
solve xss = sum rs / (fromIntegral . length) rs
  where
    rs = map calcDistance . permutations $ xss

calcDistance :: [[Double]] -> Double
calcDistance xs  = snd $ foldr helper (head xs, 0) (tail xs)
  where
    helper [px1, py1] ([px0,py0], acc) = ([px1,py1], acc + sqrt ((px1-px0) ** 2 + (py1-py0) ** 2))

Measured memory_bytes: 4220
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int x, n;
  cin >> x >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  int ans = int(1e8);
  int diff = abs(ans - x);
  REPC(k, -300, 300) {
    bool ok = true;
    rep(i, n) if(k == p[i]) ok = false;
    if(!ok) continue;
    if(abs(k - x) < diff) {
      diff = abs(k - x);
      ans = k;
    } else if(abs(k - x) == diff) {
      chmin(ans, k);
    }
  }
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3640
#include<cstdlib>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<cstring>
#include<cmath>
using namespace std;
const int MAXN = (int) 5e5 + 10;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

int N;
int L[MAXN/2],R[MAXN/2];
int arr[MAXN];
int cnt;

void Merge(int A[],int n,int left,int mid,int right){
    int n1=mid-left;
    int n2=right-mid;
//    printf("left = %d , mid = %d , right = %d\n",left,mid,right);
    for(int i=0;i<n1;i++) L[i]=A[left+i];
    for(int i=0;i<n2;i++) R[i]=A[mid+i];
    L[n1]=R[n2]=INF;
    int i=0,j=0;
//    printf("L:\n");
//    for(int i=0;i<n1;i++) printf("%d ",L[i]);
//    printf("\n");
//    printf("R:\n");
//    for(int i=0;i<n2;i++) printf("%d ",R[i]);
//    printf("\n");
    for(int k=left;k<right;k++){
        cnt++;
        if(L[i]<=R[j]){
//            printf("L: A[%d] = %d\n",k,L[i]);
            A[k]=L[i++];
        }
        else{
//            printf("R: A[%d] = %d\n",k,R[i]);
            A[k]=R[j++];
        }
    }
//    for(int k=left;k<right;k++) printf("%d ",A[k]);
//    printf("\n");
}

void mergeSort(int A[],int n,int left,int right){
    if(left+1<right){
        int mid=(left+right)>>1;
        mergeSort(A,n,left,mid);
        mergeSort(A,n,mid,right);
        Merge(A,n,left,mid,right);
    }
}

void work(){
    scanf("%d",&N);
    for(int i=0;i<N;i++) scanf("%d",&arr[i]);
    cnt=0;
    mergeSort(arr,N,0,N);
    for(int i=0;i<N;i++){
        printf("%d",arr[i]);
        if(i<N-1) printf(" ");
    }
    printf("\n%d\n",cnt);
}

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



Measured memory_bytes: 7024
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s; cin >> s;
	int n = s.size();
	rep(i, 0, n + 1) {
		rep(j, i, n + 1) {
			string t = s;
			if (t.erase(i, j - i + 1) == "keyence") {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 3632
imput = gets.chomp.split("\s")
r, c = imput[0].to_i, imput[1].to_i

ans_arr = Array.new(r){ Array.new(c, 0) }

# 配列への入力
for i in 0..r - 1
	arr = gets.chomp.split("\s")
	for j in 0.. c - 1
	
		for k in 0..c - 1
			arr[k] = arr[k].to_i
		end
		
	ans_arr[i][j] = arr[j]
	end
end

# 横の計算
for p in 0..r - 1
	sum = 0
	for q in 0..c - 1
		sum += ans_arr[p][q]
	end
	ans_arr[p] += [sum]
	
end

# 縦の計算
arr_sum = Array.new(c + 1, 0)
for t in 0..c
	sum = 0
	
	for s in 0..r - 1
		sum += ans_arr[s][t]
	end
	arr_sum[t] = sum
end

# 一番下の行をドッキング
ans_arr << arr_sum

# 出力
for h in 0..r
	puts ans_arr[h].join("\s")
end

Measured memory_bytes: 6212
a,b = map(int,input().split())
s = input()
ans = 0
for i in range(len(s)):
    if s[i]=="-" and i != a:
        ans += 1
if len(s)==a+b+1 and s[a]=="-" and ans==0:
    print("Yes")
else:
    print("No")

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

int main() {
  constexpr int max = 1000000;
  vector<bool> isPrime(max, true);
  isPrime[0] = isPrime[1] = 0;
  for (int i = 2; i * i < max; i++) {
    if (isPrime[i]) {
      for (int j = 2; i * j < max; j++) {
        isPrime[i * j] = false;
      }
    }
  }
  int n;
  while (cin >> n) {
    int ans = 0;
    for (int i = 0; i <= n; i++) {
      if (isPrime[i]) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3160
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, -1, 0, 1};

char pop(stack<char>& st) {
	char c = st.top();
	st.pop();
	return c;
}

int main() {
	for (;;) {
		string s; getline(cin, s);
		if (s == ".") break;
		stack<char> st;
		bool flag = true;
		for (int i = 0; i < s.length(); i++) {
			if (s[i] == '(') st.push('(');
			if (s[i] == '[') st.push('[');
			if (s[i] == ')')
				if (st.empty() || pop(st) == '[') flag = false;
			if (s[i] == ']')
				if (st.empty() || pop(st) == '(') flag = false;
		}
		if (!st.empty()) flag = false;
		cout << (flag ? "yes" : "no") << endl;
	}
}

Measured memory_bytes: 1180