akhauriyash/Code-Regression huggingface dataset:
class UnionFind:#「貼るだけ」
    from typing import List, Set

    def __init__(self, n):
        self.n = n
        self.parent = [-1] * n

    def merge(self, x, y) -> int:
        x = self.leader(x)
        y = self.leader(y)

        if x == y:
            return 0

        if self.parent[x] > self.parent[y]:
            x, y = y, x

        self.parent[x] += self.parent[y]
        self.parent[y] = x

        return self.parent[x]

    def same(self, x, y) -> bool:
        return self.leader(x) == self.leader(y)

    def leader(self, x) -> int:
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.leader(self.parent[x])
            return self.parent[x]

    def size(self, x) -> int:
        return -self.parent[self.leader(x)]

    def groups(self) -> List[Set[int]]:
        groups = dict()

        for i in range(self.n):
            p = self.leader(i)
            if not groups.get(p):
                groups[p] = set()
            groups[p].add(i)

        return list(groups.values())

def main():
    N,M = map(int, input().split())

    uf = UnionFind(N)

    for _ in range(M):
        A, B = map(lambda x: int(x) - 1, input().split())
        uf.merge(A,B)

    print(len(uf.groups()) - 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 102172
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    n = int(input())
    hl = [0] + list(map(int, input().split()))

    for i in range(n):
        if hl[i+1] > hl[i]:
            hl[i+1] -= 1
        if hl[i+1] < hl[i]:
            print("No")
            exit()

    print("Yes")


Measured memory_bytes: 14396
#include<stdio.h>
int nc[1000], nr[1000];

int main()
{
	char grid[1000][1000];
	int i, j, r;
	int n, m;
	scanf("%d%d", &n, &m);
	
	for(i=0; i<n; i++)
	{
			scanf("%s", grid[i]);
	}
	
	for(i=0; i<n; i++)
	{   
		r=0;
		
		for(j=0; j<m; j++)
		{
			if(grid[i][j] == '#')	break;
			else if(j == m-1)		r=1;
		}
		
		if(r == 1)
		{
			nr[i] =  1;
		}
	}

	for(j=0; j<m; j++)
	{   
		r=0;
		
		for(i=0; i<n; i++)
		{
			if(grid[i][j] == '#')	break;
			else if(i == n-1)		r=1;
		}
		
		if(r == 1)
		{
			nc[j] =  1;
		}
	}
	i=0;
	
	for(i=0; i<n; i++)
	{
		if(nr[i] == 1) continue;
		
		for(j=0; j<m; j++)
		{
			if(nc[j] != 1)	printf("%c", grid[i][j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>
#include <bitset>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

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

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

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  vector<ulint> us_vec[32];
  unordered_multiset<ulint> us[32];
  unordered_multiset<ulint> a_all;

  int n;
  cin>>n;
  int count=0;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    a_all.insert(a);
  }

  for(auto a:a_all){
    bitset<32> bs(a);
    for(int i=0;i<32;i++){
      if(bs[i]){
        us[i].insert(a);
        us_vec[i].push_back(a);
        break;
      }
    }
  }

  for(int i=0;i<32;i++){
    std::sort(us_vec[i].begin(), us_vec[i].end(), std::greater<>());
    for(auto v:us_vec[i]){
      if(us[i].find(v)==us[i].end()){
        continue;
      }

      bitset<40> bs_a(v);
      bitset<40> bs_b(0);
      bs_b[i]=true;
      for(int j=i+1;j<32;j++){
        bs_b[j]=!bs_a[j];
        bitset<40> bs_c(bs_a.to_ullong()+bs_b.to_ullong());
        if(bs_c.count()==1){
          if(us[i].find(bs_b.to_ulong())!=us[i].end()){
            auto it=us[i].find(v);
            assert(it!=us[i].end());
            us[i].erase(it);
            it=us[i].find(bs_b.to_ulong());
            assert(it!=us[i].end());
            us[i].erase(it);
            count++;
            break;
          }
        }
      }

    }

    for(auto v:us_vec[i]){
      bitset<40> bs(v);
      if(bs.count()==1){
        count+=us[i].count(v)/2;
      }
      us[i].erase(v);
    }
  }
  cout<<count<<endl;

  return 0;
}




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

int main(){
	int i, N, M, a[50], b[50];

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

	std::vector<int> N_NUM(N);

	for(i = 0; i < M; i++){
		scanf("%d %d", &a[i], &b[i]);
	}

	for(i = 0; i < N; i++){
		N_NUM[i] = 0;
	}

	for(i = 0; i < M; i++){
		N_NUM[a[i] - 1]++;
		N_NUM[b[i] - 1]++;
	}

	for(i = 0; i < N; i++){
		printf("%d\n", N_NUM[i]);
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int q[N];
int main()
{
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);
	string s,t;
	cin>>s>>t;
	int ans=0;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]!=t[i])ans++;
	}
	cout<<ans;

}


Measured memory_bytes: 3836
#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<ll,ll>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

priority_queue<P>pq;
ll solve(int n){
    ll ans=0;
    int cnt=n;
     while(cnt>0)
     {
         P pairs=pq.top();pq.pop();
         if(cnt>=pairs.second){
             ans+=pairs.first*pairs.second;
             cnt-=pairs.second;
         }else{
             ans+=cnt*pairs.first;
             cnt-=pairs.second;
         }
     }
     return ans;  
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);

int n,m;
cin>>n>>m;

rep(i,n){
  ll a;
  cin>>a;
  pq.push(P(a,1));
}
 rep(i,m){
        ll b,c;
        cin>>b>>c;
        pq.push(P(c,b));
}
cout<<solve(n)<<endl;

return 0;
}

Measured memory_bytes: 6256
N = int(input())
A = [0]*10000
for i in range(1,100):
    for j in range(i,100):
        for k in range(j,100):
            if i==j==k and i**2+j**2+k**2+i*j+j*k+k*i <= 10**4:
                A[i**2+j**2+k**2+i*j+j*k+k*i-1] += 1
            elif (i==j or j==k or k==i)and i**2+j**2+k**2+i*j+j*k+k*i <= 10**4:
                A[i**2+j**2+k**2+i*j+j*k+k*i-1] += 3
            elif i**2+j**2+k**2+i*j+j*k+k*i <= 10**4:
                A[i**2+j**2+k**2+i*j+j*k+k*i-1] += 6
for i in range(N):
    print(A[i])

Measured memory_bytes: 69592
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int N, A[MAXN], nxt[MAXN], prv[MAXN], vis[MAXN];
long long K;
int main()
{
	cin>>N>>K; 
	for(int i = 0; i < N; i++)
		cin>>A[i];
	memset(prv, -1, sizeof prv);
	for(int i = 0; i < 2 * N; i++)
	{
		if(prv[A[i % N]] != -1)
			nxt[prv[A[i % N]]] = i % N;//第二次出现的位置 
		prv[A[i % N]] = i % N;//第一次出现的位置 
	}
	vector <int> ans;
	memset(vis, -1, sizeof vis);
	int j = 0, k = 0;
	while(k < K)
	{
		//如果就在后面，不需要再来一遍 
		if(nxt[j] > j)
		{
			//直接变过去 
			j = nxt[j] + 1;
			if(j >= N)//超过长度了，次数记得加以，重新循环 
			{
				j -= N;
				k++;
			}
		}
		else//说明到了 下一次循环 
		{
			if(k + 1 < K)//先判断 是否要退出 ，先进行不会退出的 
			{
				j = nxt[j] + 1;//退出当前环 
				k++;//循环次数++ 
				if(j >= N)//这个时候也能要进行下一次循环 
				{
					j -= N;
					k++;
				}
			}
			else//说明要退出 
			{
				ans.push_back(A[j]);
				j = j + 1;//这个时候要一点一点往下推进 
				if(j >= N)
					break;
			}
		}
		//判断这个 位置 是否出现过，作为循环的起点 ，如果出现过的话，就是一次彻底的循环 
		if(vis[j] != -1)
		{
			int d = k - vis[j];//此时的循环 - 出现时的循环次数 
			K = k + (K - k) % d;//还需要的次数 
		}
		vis[j] = k;//记录第一次出现时的循环次数 
	}
	for(auto x : ans)
		cout<<x<<" "; 
	return 0;
}


Measured memory_bytes: 5492
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 1000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
struct edge{
	int from,to;
	edge(){}
	edge(int f,int t):from(f),to(t){}
};
struct Tree{
	int V;
	int root;
	vector<int> depth;
	vector<int> par;
	vector<int> subtree_size;
	vector<int> centroid;
	vector<vector<edge> > G;
	Tree(){}
	Tree(int v,int r=0){
		V = v;
		root = r;
		G.resize(V);
		depth.resize(V);
		par.resize(V);
		subtree_size.resize(V);
	}
	void add_edge(int u,int v){
		G[u].pb(edge(u,v));
		G[v].pb(edge(v,u));
	}
	int dfs(int v,int p,int d){
		depth[v]=d;
		par[v]=p;
		subtree_size[v]=1;
		bool is_centroid = true;
		for(int i=0;i<G[v].size();i++){
			int u = G[v][i].to;
			if(u==p)continue;
			subtree_size[v]+=dfs(u,v,d+1);
			if(subtree_size[u]>V/2)is_centroid=false;
		}
		if(V-subtree_size[v]>V/2)is_centroid=false;
		if(is_centroid)centroid.pb(v);
		return subtree_size[v];
	}
	void dfs(){
		dfs(root,-1,0);
	}
	int rec(int v,int p){
		vector<int> vec;
		int ret = 0;
		for(int i=0;i<G[v].size();i++){
			int u = G[v][i].to;
			if(u==p)continue;
			int res = rec(u,v);
			ret |= res;
			vec.pb(res);
		}
		vector<int> cnt(20,0);
		int m = 0;
		for(int i=0;i<20;i++){
			for(int j=0;j<vec.size();j++){
				if(vec[j]&(1<<i))cnt[i]++;
			}
			if(cnt[i]>=2)m = max(m,i+1);
		}
		while(cnt[m]>0)m++;
		ret = ((ret>>m)<<m);
		ret |= (1<<m);
		return ret;
	}	
};
int N;
int main(){
	cin >> N;
	Tree G(N);
	for(int i=0;i<N-1;i++){
		int x,y;
		cin >> x >> y;
		x--;y--;
		G.add_edge(x,y);
	}
	G.dfs();
	int ans = G.rec(0,-1);
	int a = 0;
	for(int i=0;i<20;i++){
		if(ans&(1<<i))a = max(a,i);
	}
	cout << a << endl;
	return 0;
}


Measured memory_bytes: 12160
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
using namespace std;
int main(void){
    int H , W ;
    cin >> H >> W ;
    char a[H][W];
    bool b[H][W];
    int count = 0 ;

    for( int i = 0; i < H ; i++){
        for(int j = 0; j < W ; j++){
            cin >> a[i][j] ;
           if(a[i][j] == '.' ){
               count++ ;
           }
        }

        if(count == W ){
            for(int m = 0; m <W ;m++){
                b[i][m] = false ;
              }
         }else{
             for(int n = 0; n < W; n ++ ){
                 b[i][n] = true ;
              }
        }
        count = 0 ;
    }


    for( int k = 0; k < W ; k++){
        for(int l = 0; l < H ; l++){
        
           if(a[l][k] == '.' ){
               count++ ;
           }
        }

        if(count == H ){
             for(int o = 0; o <H ;o++){
                b[o][k] = false ;
             }
        }

           
        
        count = 0 ;
    }
    
    for(int q = 0; q < H ; q++ ){
        for(int r = 0; r < W; r ++){
            if(b[q][r] == true){
                cout << a[q][r] ;
            }
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s=new Scanner(System.in);
		int m1=s.nextInt();
		int d1=s.nextInt();
		int m2=s.nextInt();
		int d2=s.nextInt();
		if(m1!=m2)
		System.out.println("1");
		else
		System.out.println("0");
	}
}

Measured memory_bytes: 21972
n = int(input())
a = list(map(int, input().split()))
a.sort()
c = [0]*(1000001)
for i in a:
    c[i] += 1
b = list(set(a))
ans = []
b.sort()

num = [True]*(1000001)

for i in range(len(b)):
    now = b[i]
    if num[now]:
        ans.append(now)
        for j in range(now, 1000001, now):
            num[j] = False


count = 0
for i in ans:
    if c[i] == 1:
        count += 1

print(count)


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

int main() {
  int N;
  vector<int>a(109);
  cin >> N;
  for(int i=0;i<N;i++) cin >> a.at(i);
  int sum=0;
  for(int i=0;i<N;i++) sum += a.at(i);
  int pre, pos, mini,dif;
  for(int i=0;i<N;i++){
    pre=0;
    pos=0;
    for(int j=0;j<i;j++){
      pre += a[j];
    }
    pos = sum-pre;
    dif = abs(pos-pre);
    if(i==0){
      mini = dif;
    } else {
      mini = min(mini, dif);
    }
  }
  cout << mini << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define MOD 10000
//#define MOD 1145141919

string A, B;
int M;
int dp[510][10][2][3][2][510];

int f(string &X, int i, int L, int lc, bool d, int e, bool zero, int m) {
  if (dp[i][lc][d][e][zero][m] != -1) return dp[i][lc][d][e][zero][m];
  if (i == L-1) {
    return dp[i][lc][d][e][zero][m] = (e == 2 ? 0 : zero ? 0 : m == 0);
  }
  int ret = 0;
  for (int c=0; c<10; c++) {
    int nz = false;
    if (zero) {
      if (c == 0) nz = true;
    }
    else {
      if (d == 0 && lc <= c) continue;
      if (d == 1 && lc >= c) continue;
    }
    int ne = e;
    int h = (int)X[i+1] - (int)'0';
    if (e == 1 && c < h) ne = 0;
    if (e == 1 && c > h) ne = 2;
    ret = (ret + f(X, i+1, L, c, !d, ne, nz, (m*10 + c) % M)) % MOD;
  }
  return dp[i][lc][d][e][zero][m] = ret;
}

void reset() {
  for (int i=0; i<510; i++) {
    for (int j=0; j<10; j++) {
      for (int k=0; k<2; k++) {
        for (int e=0; e<2; e++) {
          for (int zero=0; zero<2; zero++) {
            for (int l=0; l<510; l++) {
              dp[i][j][k][e][zero][l] = -1;
            }
          }
        }
      }
    }
  }
}

int solve(string X) {
  if (X.length() == 1) {
    int t = (int)X[0] - (int)'0';
    int x = 0;
    for (int i=1; i<=t; i++) if (i % M == 0) x++;
    return x;
  }

  int x = 0;
  for (int i=1; i<10; i++) if (i % M == 0) x++;
  int i = X[0] == '0';
  int ans = -x;
  reset();
  int L = X.length();
  for (int c=0; c<10; c++) {
    int h = (int)X[i] - (int)'0';
    int e = c < h ? 0 : (c == h ? 1 : 2);
    ans = (ans + f(X, i, L, c, true , e, c == 0, c % M)) % MOD;
    ans = (ans + f(X, i, L, c, false, e, c == 0, c % M)) % MOD;
  }
  return ans;
}

int main() {
  cin >> A >> B >> M;
  // A -= 1
  int h = A.length() - 1;
  while (true) {
    if (A[h] > '0') {
      A[h] = (char)((int)A[h]-1);
      break;
    }
    A[h] = '9';
    h -= 1;
  }
  cout << (solve(B) - solve(A) + MOD) % MOD << "\n";
  return 0;
}

Measured memory_bytes: 125180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
    int n,d;
    cin >> n >> d;
    
    int i = 1;
    int j = 0;
    int cnt = 0;
    int cnt2 = 0;
    while(true){
        cnt = 0;
        j = i;
        while(j%100 == 0){
            cnt++;
            j /= 100;
        }
        if(cnt == n){
            cnt2++;
        }
        if(cnt2 == d){
            cout << i << endl;
            break;
        }
        i++;
    }
}



Measured memory_bytes: 256
n,k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for i in range(n+1):
    for j in range(i,n+1):
        a = v[:i]+v[j:]
        if len(a)>k:
            continue
        else:
            a.sort()
            a.reverse()
            for l in range(k-len(a)):
                if len(a)>0 and a[-1]<0:
                    a.pop()
                else:
                    break
            ans = max(ans, sum(a))
print(ans)




Measured memory_bytes: 41584
#include<stdio.h>
#include<string.h>
int main()
{
	char input[20],temp[20];
	scanf("%s",input);
	int len = strlen(input);
	int i = 0,j = 0;
	while(len--)
	{
		if(input[j] == 'B')
		{
			if(i > 0)
			{
				i--;
			}
			temp[i] = ' ';
			j++;
		}
		else{
			temp[i] = input[j];
			i++;
			j++;
		}
	}
	temp[i] = '\0';
	printf("%s\n",temp);
	return 0;
}

Measured memory_bytes: 1612
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
 
int main() {
    int h,w,n;
    cin>>h>>w>>n;
    cout<<(n+max(h,w)-1)/max(h,w)<<endl;

 return 0;
}

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

int main() {
  string S;
  int cnt=0;
  cin >> S;
  rep(i, S.size()-1){
    if(S.at(i)==S.at(i+1) && S.at(i)=='0'){
      S.at(i+1)='1';
      cnt++;
    }
    if(S.at(i)==S.at(i+1) && S.at(i)=='1'){
      S.at(i+1)='0';
      cnt++;
    }
  }
  cout << cnt << endl;
}

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

    // 入力
    int n;
    cin >> n;
    int a[n];
    rep(i, n) { cin >> a[i]; }

    // 処理
    sort(a, a + n);
    // check
    // rep(i, n) {
    //     if (i > 0) cout << " ";
    //     cout << a[i];
    // }
    int cnt = 0;
    rep(i, n - 1) {
        if (a[i] < a[i + 1]) {
            cnt++;
        }
    }

    // 出力
    cout << cnt + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop
n = int(input())
a = list(map(int, input().split()))
max_sum_fh = [0] * (n + 1)
min_sum_lh = [0] * (n + 1)
 
hq_fh = []
hq_lh = []
 
for i in range(n):
    heappush(hq_fh, a[i])
    heappush(hq_lh, -a[-1 - i])

max_sum_fh[0] = sum(hq_fh)
min_sum_lh[n] = -sum(hq_lh)

for i in range(n):
    if a[i + n] > hq_fh[0]:
        value_in = a[i + n]
        value_out = heappop(hq_fh)
        heappush(hq_fh, value_in)
        max_sum_fh[i + 1] = max_sum_fh[i] - value_out + value_in
    else:
        max_sum_fh[i + 1] = max_sum_fh[i]
    if -a[-1 - i - n] > hq_lh[0]:
        value_in = -a[-1 - i - n]
        value_out = heappop(hq_lh)
        heappush(hq_lh, value_in)
        min_sum_lh[-2 - i] = min_sum_lh[-1 - i] + value_out - value_in
    else:
        min_sum_lh[-2 - i] = min_sum_lh[-1 - i]
    
print(max([max_sum_fh[i] - min_sum_lh[i] for i in range(n + 1)]))
        

Measured memory_bytes: 38288
Q = 998244353
def getInv(N):
    inv = [0] * (N + 1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, N + 1):
        inv[i] = (-(Q // i) * inv[Q%i]) % Q
    return inv

N, A, B, K = map( int, input().split())
ans = 0
invs = getInv(N)
nCk = [1]*(N+1)
for i in range(1,N+1):
    nCk[i] = (nCk[i-1]*(N-i+1)*invs[i])%Q
for i in range(N+1):
    j = (K-A*i)//B
    if A*i + B*j == K and j <= N and 0 <= j:
        j = (K-A*i)//B
        ans = (ans + nCk[i]*nCk[j])%Q
print(ans)

Measured memory_bytes: 26720
#include<bits/stdc++.h>
#define test int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
int main()
{
ll a,b,c;
  cin>>a>>b;
  c=a-(b*2);
  if(2*b>=a) cout<<0<<endl;
  else cout<<c<<endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long b, a, n, d,rem, ans;
    cin>> n>> b>> a;
    if(n>a+b)
    {
        d= n/(a+b);
        rem=n%(a+b);
        if(rem>=b)
            ans= (d+1)*b;
            else
                ans= d*b+ rem;


    }
    else if(n<=a+b)
    {
        if(n>=b)
            ans=b;
        else
            ans= n;
    }
    cout<< ans<< endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split("\\s+");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		long n = Long.parseLong(strArr[0]);
		long a = Long.parseLong(strArr[1]);
		long b = Long.parseLong(strArr[2]);

		long ans = 0;
		long v = 0;

		ans = b - 1;
		v = n - a;
		if (ans > v)
			ans = v;

		if ((b - a) % 2 == 0) {
			v = (b - a) / 2;
			if (ans > v)
				ans = v;
		} else {
			v = (a - 1) + 1 + ((b - a - 1) / 2);
			if (ans > v)
				ans = v;
			v = (n - b) + 1 + ((b - a - 1) / 2);
			if (ans > v)
				ans = v;
		}

		System.out.println(ans);
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 21332
"""Binary Trees."""

class Node:
    def __init__(self, num, leftChild, rightChild):
        self.id = num
        self.parent = -1
        self.sibling = -1
        self.degree = 0
        self.depth = 0
        self.height = 0
        self.type = 'leaf'
        self.leftChild = leftChild
        self.rightChild = rightChild
        
    def show_info(self):
        print('node {}:'.format(self.id), 'parent = {},'.format(self.parent),
              'sibling = {},'.format(self.sibling),
              'degree = {},'.format(self.degree),
              'depth = {},'.format(self.depth),
              'height = {},'.format(self.height),
              '{}'.format(self.type))


def set_attributes(n_i, parent, sibling, depth):
    h1 = 0
    h2 = 0
    node = T[n_i]
    lc = node.leftChild
    rc = node.rightChild
    node.parent = parent
    node.sibling = sibling
    node.depth = depth
    if lc != -1:
        node.degree += 1
        node.type = 'internal node'
        h1 = set_attributes(lc, n_i, rc, depth + 1) + 1
    if rc != -1:
        node.degree += 1
        node.type = 'internal node'
        h2 = set_attributes(rc, n_i, lc, depth + 1) + 1
    node.height = max(h1, h2)
    return node.height



import sys

n = int(sys.stdin.readline())

T = [None] * n

rt_n = int(n * (n - 1) / 2)

for x in sys.stdin.readlines():
    num, leftChild, rightChild = list(map(int, x.split()))
    node = Node(num, leftChild, rightChild)
    T[num] = node
    rt_n -= (max(0, leftChild) + max(0, rightChild))

set_attributes(rt_n, -1, -1, 0)

T[rt_n].type = 'root'

for n in T:
    n.show_info()

Measured memory_bytes: 7856
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

struct timer{
	time_t start;
	timer(){start=clock();}
	~timer(){cerr<<1.*(clock()-start)/CLOCKS_PER_SEC<<" secs"<<endl;}
};

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int W,H,N,X[100010],Y[100010];
int x[100010],y[100010];

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	
	cin>>W>>H>>N;
	rep(i,N){
		cin>>X[i]>>Y[i];
		x[i]=X[i],y[i]=Y[i];
	}
	sort(x,x+N);
	sort(y,y+N);
	ll ans=INF*INF,ansx,ansy;
	rep2(mx,(N-1)/2,N/2+1)rep2(my,(N-1)/2,N/2+1){
		ll res=0,maxi=0,d;
		rep(i,N){
			d=abs(X[i]-x[mx])+abs(Y[i]-y[my]);
			res+=d*2;
			maxi=max(maxi,d);
		}
		res-=maxi;
		if(res<ans){
			ans=res;
			ansx=x[mx];
			ansy=y[my];
		}
	}
	cout<<ans<<endl<<ansx<<" "<<ansy<<endl;
}

Measured memory_bytes: 2784
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
	int A, B, K;

	cin >> A >> B >> K;

	for (int i = min(A,B); i >= 1; i--) {
		if (!(A % i) && !(B % i)) {
			K--;
			if (!K)
			{
				cout << i << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include<algorithm>
using namespace std;
long long inf=100000000000007;
#define int long long
typedef pair<int,int>  P;
string alph("abcdefghijklmnopqrstuvwxyz");
signed main(){
    int n;cin>>n;
    int n1=n/11;
    int n2=n%11;
    int cl;
    if(n2>6)cl=2;else if(n2==0)cl=0;else cl=1;
    int key=n1*2+cl;
    cout<<key<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef tuple<int, int> ti2;
typedef tuple<int, int, int> ti3;
typedef tuple<int, int, int, int> ti4;
typedef tuple<ll, ll> tl2;
typedef tuple<ll, ll, ll> tl3;
typedef tuple<ll, ll, ll, ll> tl4;
typedef vector<int> vi;
typedef vector<ti2> vti2;
typedef vector<ti3> vti3;
typedef vector<ti4> vti4;
typedef vector<ll> vl;
typedef vector<tl2> vtl2;
typedef vector<tl3> vtl3;
typedef vector<tl4> vtl4;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vti2> vvti2;
typedef vector<vti3> vvti3;
typedef vector<vti4> vvti4;
typedef vector<vl> vvl;
typedef vector<vtl2> vvtl2;
typedef vector<vtl3> vvtl3;
typedef vector<vtl4> vvtl4;
typedef vector<vs> vvs;
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i < i##_len; i++)
#define FORD(i, a, b) for (int i = (a), i##_len = (b); i > i##_len; i--)
#define FORR(t, a) for (auto t : a)
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SORT(a, func) sort(ALL(a), [](const auto& x, const auto& y) func)
#define GET(i, j) get<j>(i)
#define MT(x, ...) make_tuple(x, __VA_ARGS__)
#define PRINT(i) cout << i << endl
#define PRINT2(i, j) cout << i << " " << j << endl
#define PRINT3(i, j, k) cout << i << " " << j << " " << k << endl
#define PRINT4(i, j, k, l) cout << i << " " << j << " " << k << " " << l << endl
#define PRINTL(a)                                       \
    for (const auto& d9aw : a) { cout << d9aw << " "; } \
    cout << endl

//演算子オーバーロード
bool operator<(const ti2 x, const ti2 y) {
    if (GET(x, 0) != GET(y, 0))
        return GET(x, 0) < GET(y, 0);
    else
        return GET(x, 1) < GET(y, 1);
}
bool operator>(const ti2 x, const ti2 y) {
    if (GET(x, 0) != GET(y, 0))
        return GET(x, 0) > GET(y, 0);
    else
        return GET(x, 1) > GET(y, 1);
}

int main() {
    int a, b;
    cin >> a >> b;
    PRINT2(a * b, 2 * (a + b));
}


Measured memory_bytes: 3080
(n, m) = map(int, input().split(" "))

sets = []
for _ in range(m):
    (a, b) = map(lambda x:int(x)-1, input().split(" "))
    sets += [(a, b)]

num = 0
for (a, b) in sets:
    gi = [[False for _ in range(n)] for _ in range(n)]
    for (x, y) in sets:
        gi[x][y] = True
        gi[y][x] = True
    
    gi[a][b] = False
    gi[b][a] = False
     
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if gi[i][k] and gi[k][j]:
                    gi[i][j] = True
    
    found = False
    for i in range(n):
        for j in range(n):
            if not gi[i][j]:
                found = True
                break
        if found:
            num += 1
            break

print(num)

Measured memory_bytes: 3064
N, L = map(int, input().split())
apl_val = [L + i - 1 for i in range(1, N+1)]
# print(apl_val)
sumpi = sum(apl_val)

diff = 1000
for j in apl_val:
  if diff >= abs(j):
    diff = abs(j)
    ans = sumpi - j
  
print(ans)

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


int main() {
    long long k;
    cin >> k;
    #define ll long long
    priority_queue<long long, vector<ll>, greater<ll>> q;
    for (int i = 1; i <= 9; ++i) q.push(i);
    --k;
    while (k--) {
        ll t = q.top();
        ll v = t % 10;
        q.pop();
        if (v != 0) q.push(t * 10 + v - 1);
        q.push(t * 10 + v);
        if (v != 9) q.push(t * 10 + v + 1);
    }
    cout << q.top();

}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int n; cin>>n;
	vector<int> h(n);
	for (int i=0; i<n; i++)
		cin>>h[i];
	h[0]--;
	for (int i=1; i<n; i++) {
		if(h[i]-1>=h[i-1])
			h[i]--;
		if(h[i]<h[i-1]) {
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 640
s = list(input())
t = list(input())
x = list(set(s))
y = list(set(t))
a = []
b = []
for i in range(len(set(s))):
  a.append(s.count(x[i]))
for j in range(len(set(t))):
  b.append(t.count(y[j]))
a.sort()
b.sort()
if a == b:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 6704
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define alpha_size 26


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);    

    int k;
    cin >> k;
    int ret = 0;
    for (int a = 1; a <= k; a++)
      for (int b = 1; b <= k; b++)
        for (int c = 1; c <= k; c++)
          ret += __gcd(a, __gcd(b, c));
    cout << ret << endl;
}




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

int main() {
	int a, z;
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'A') {
			a = i;
			break; 
		}
	}
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == 'Z') z = i;
	}
	cout << z - a + 1 << endl;
}


Measured memory_bytes: 640
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  while(a >= 500) a -= 500;
  if(a <= b) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
from functools import reduce
N,M,C = map(int,input().split(" "))
B = list(map(int,input().split(" ")))

ans = 0
for i in range(N):
    A = list(map(int,input().split(" ")))
    s = reduce(lambda x,y:x+y,[ a*b for a,b in zip(A,B) ]) + C 
    if s > 0:
        ans += 1

print(ans)
    

Measured memory_bytes: 38256
n=int(input())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))

sort_ab = sorted(ab, key=lambda x:(x[1], x[0]))
#print(sort_ab)
count=0
for i in range(n):
    count+=sort_ab[i][0]
    if sort_ab[i][1]<count:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 67824
import scala.io.StdIn

object Main extends App {
  val Array(a, b, c, x, y) = StdIn.readLine().split(' ').map(_.toInt)

  //println((a + b) / (c * 2))
  if ((a + b) / (c * 2) >= 1) {
    // cで買った方が安い
    val r1 = if (x > y) x * c * 2 else y * c * 2
    val r2 = if (x > y) (x - y) * a + y * c * 2 else (y - x) * b + x * c * 2
    println(if (r1 > r2) r2 else r1)

  } else {
    println(a * x + b * y)
  }
}

Measured memory_bytes: 27300
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    int n;
    cin >> n;
    ll ans = 0;
    rep(i, n) ans += ll(i + 1) * ll(n - i);
    rep(i, n - 1){
        int x, y;
        cin >> x >> y;
        if (x > y) swap(x, y);
        ans -= ll(x) * ll(n - y + 1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
import java.util.Scanner;

class Main{
    static int MAX_N = 1000000;
    static boolean isprime[] = new boolean[MAX_N];

    public static void eratosthenes(){
        for(int i = 0; i < MAX_N; i++){
            isprime[i] = true;
        }
        isprime[0] = isprime[1] = false;
        for(int x = 0; x * x < MAX_N; x++){
            if(isprime[x]){
                for(int y = x * x; y < MAX_N; y += x){
                    isprime[y] = false;
                }
            }
        }
    }

    public static void main(String[] args){
        eratosthenes();
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int n = in.nextInt(), ans = 0;
            for(int i = 0; i <= n; i++){
                if(isprime[i]){
                    ans += 1;
                }
            }
            System.out.println(ans);
        }
    }
}

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

#define int long long
#define vi vector<int>
#define vvi vector<vi>
#define pqMax priority_queue<int>
#define pqMin priority_queue<int, vector<int>, greater<int>>
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie();                        \
    cout.tie()
int n, t, i, j, k;

void solve() {
    cin >> i >> j;
    cout << i * j;
}

int32_t main() {
    FAST;
    solve();
}

Measured memory_bytes: 3656
#include<stdio.h>
#include<stdlib.h>
#define N 10000
#define NIL NULL
struct node{
  struct node *left;
  struct node *right;
  struct node *parent;
  int key;
};
 
typedef struct node * Node;
Node root;
 
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
   
  while(x != NIL){
    y = x;
    if(z->key < x->key)
      x = x->left;
    else{
      x = x->right;
    }
  }
  z->parent = y; 
    if(y==NIL){
      root=z;
    }
    else if(z->key < y -> key){
      y->left = z;
    }
    else{
      y->right =z;
    }
}
void inorder(Node u){
  if(u != NIL){
    inorder(u->left);
    printf(" ");
    printf("%d",u->key);
    inorder(u->right);
  }
  
}
void preorder(Node u){ 
    if (u != NIL) {
      printf(" ");
      printf("%d",u->key); 
      preorder(u->left);
      preorder(u->right);
     
    }
}
Node IterativeTreeSearch(Node x,int k){
  if(x == NIL || k == x -> key) return x;
  if(k < x -> key) return IterativeTreeSearch(x -> left, k);
  else return IterativeTreeSearch(x -> right, k);
 
  
}
 
int main(){
  int i,n1,n2,n3;
  char str[10];
  scanf("%d",&n1);
  for(i=0;i<n1;i++){
    scanf("%s",str);
    if(str[0]=='f'){
      scanf("%d", &n2);
      Node t = IterativeTreeSearch(root, n2);
      if ( t != NIL ){ 
    printf("yes\n");
      }
      else {
    printf("no\n");
      }
    }
    else if(str[0]=='i'){  
      scanf("%d",&n3);
      insert(n3);
    }
     
    else if(str[0]=='p'){
       
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
return 0;
}

Measured memory_bytes: 19364
import java.util.*;

public class Main {
    public static void main(String args[]){
        int N,T;
        int min = 0;
        int count = 0;
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        T = scanner.nextInt();
        for(int i = 1; i <= N; i++){
            int c = scanner.nextInt();
            int t = scanner.nextInt();
            if(t <= T){
                if(min == 0){
                    min = c;
                }else{
                    if(c < min){
                        min = c;
                    }
                }
            }else{
                count++;
            }
        }
        if(count == N){
            System.out.println("TLE");
        }else{
            System.out.println(min);
        }
    }
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(void){
    int a,b;
    long double h,m,deg;
    scanf("%d %d %Lf %Lf",&a,&b,&h,&m);
    deg=2*3.141592653589793238462643383*(h/12+m/60/12-m/60);
    printf("%20.20f",sqrt(a*a+b*b-2*a*b*cos(deg)));
}


Measured memory_bytes: 2560
n = int(input())
a = list(map(int, input().split()))

b = [0 for _ in range(n+1)]

ans = 0
for i in range(n):
    if a[i] > n:
        ans += 1
    else:
        b[a[i]] += 1 

for i in range(n+1):
    if b[i] > i: ans += b[i] - i
    if b[i] < i: ans += b[i]

print(ans) 


Measured memory_bytes: 64228
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int N;
	cin>>N;
	for(int i=0;i<N;i++) {
		string A,B,C;
		cin>>A>>B;
		reverse(A.begin(),A.end());
		reverse(B.begin(),B.end());
		if(A.size()>80||B.size()>80) {
			cout<<"overflow"<<endl;
			continue;
		}
		for(int i=0;i<A.size()||i<B.size();i++) {
			int n=0;
			if(i<A.size())n+=(A[i]-'0');
			if(i<B.size())n+=(B[i]-'0');
			C.push_back(n);
		}
		C.resize(C.size()+1);
		C[C.size()-1]=0;
		for(int i=0;i<C.size();i++) {
			if(i!=C.size()-1)C[i+1]+=C[i]/10,C[i]%=10;
		}
		if(C[C.size()-1]==0) {
			C.resize(C.size()-1);
		}
		reverse(C.begin(),C.end());
		if(C.size()>80) {
			cout<<"overflow"<<endl;
		}else {
			for(int i=0;i<C.size();i++) {
				cout<<(char)(C[i]+'0');
			}
			cout<<endl;
		}
	}
}

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

int main(){
    int A[3],i,sum=0,maxim=0;
    cin >> A[0] >> A[1] >> A[2];
    sum += abs(A[0]-A[2]);
    maxim = abs(A[0]-A[2]);
    for(i=0;i<2;i++){
        sum += abs(A[i+1]-A[i]);
        maxim = max(maxim,abs(A[i+1]-A[i]));
    }
    cout << sum - maxim << endl;
    return 0;
}

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

int main() {
    int D;
    cin >> D;
     
    switch(D) {
      case 25:
        cout << "Christmas" << endl;
        break;
      case 24:
        cout << "Christmas Eve" << endl;
        break;
       case 23:
        cout << "Christmas Eve Eve" << endl;
        break;
       case 22:
        cout << "Christmas Eve Eve Eve" << endl;
        break;
    }
}


Measured memory_bytes: 256
from collections import defaultdict

N,C=map(int,input().split())

D=[[int(x) for x in input().split()] for y in range(C)]
c=[[int(x) for x in input().split()] for y in range(N)]

grid=defaultdict(int)
grid2=defaultdict(int)
grid3=defaultdict(int)

def culc(dict,c):
  ans=0
  for a,b in dict.items():
    ans+=D[a-1][c]*b
  return ans

for i in range(N):
  for j in range(N):
    if (i+j)%3 == 0:
      grid[c[i][j]]+=1
    elif (i+j)%3 == 1:
      grid2[c[i][j]]+=1
    else:
      grid3[c[i][j]]+=1

res=10000000000000000000
for i in range(C):
  for j in range(C):
    for k in range(C):
      if i!=j and j!=k and i!=k:
        res=min(res,culc(grid,i)+culc(grid2,j)+culc(grid3,k))
print(res)

Measured memory_bytes: 5740
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <list>
#include <math.h>
#include <iomanip>

typedef unsigned int uint;

using namespace std;

int main(void) {
    cin.tie(0);
    int i,j,k = 0;

    long long N , A , B , C;

    cin >> N >> A >> B >> C;

    long long* L = new long long[N];

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

    int ans = 3000;

    for(uint i=0;i<pow(4,N); i++) {
        //コスト
        int cost = 0;

        // 結合した竹の長さを計算する
        int length[4] = {0};
        uint k = i;
        for(int j=0; j<N; j++) {
            if(k % 4 != 3 && length[k % 4] > 0) {  //結合する場合
                cost += 10;
            }
            length[k % 4] += L[j];
            k = k / 4;
        }

        // 竹のが選ばれない場合
        bool flag = false;
        for(int j=0; j<3; j++) {
            if(length[j] == 0) {
                flag = true;
                break;
            }
        }
        if(flag){
            continue;
        }

        cost += abs(length[0] - A) + abs(length[1] - B) + abs(length[2] - C);

        if(cost < ans) {
            ans = cost;
        }
    }

    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 256
//encoding:utf-8
//#include <iostream> //c++
//#include<stack> //スタックに関して　最新のデータから捨てる
//#include<queue> //キューに関して　最古のデータから捨てる
//#include<math.h>
//#include<vector>
//#include<algorithm> //sort とかにいる
#include<bits/stdc++.h>//vector,algorithm,que
#include<time.h> //時間にかんして

#define ll long long
#define MOD 1000000007
#define INF (1<<29)
using namespace std;


int H,W;
int cnt;
char S[2001][2001];
ll lights[2001][2001][2];

int count_ver(int i,int j){
  int cnt = 0;
  for(int x=i;x<W;x++){
    if (S[j][x] == '.') {
      cnt ++;
    }
    else{
      break;
    }
  }
  for(int x=i;x<W;x++){
    if (S[j][x] == '.') {
      lights[j][x][0] = cnt;
    }
    else{
      break;
    }
  }
  return cnt;
}


int count_hor(int i,int j){
  cnt = 0;
  for(int y=j;y<H;y++){
    if (S[y][i] == '.') {
      cnt ++;
    }
    else{
      break;
    }
  }
  for(int y=j;y<H;y++){
    if (S[y][i] == '.') {
      lights[y][i][1] = cnt;
    }
    else{
      break;
    }
  }
  return cnt;
}

int main(){
  cin>>H>>W;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>S[i][j];
    }
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      for(int k=0;k<2;k++){
        lights[i][j][k] = 0;
      }
    }
  }
  int ans = -1;
  int ver = 0,hor =0 ;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      // cout<<S[i][j]<<endl;
      if(S[i][j] == '.'){
        ver = lights[i][j][0];
        hor = lights[i][j][1];
        if(ver==0){
          ver = count_ver(j,i);
        }
        if(hor==0){
          hor = count_hor(j,i);
        }
        ans = max(ans,hor+ver-1);
        // cout<<ans<<endl;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 66688
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  string s = to_string(n);
  ll k = 0;
  for(int i=0;i<s.size();i++) k += s[i] - '0';
  if(n%k==0) std::cout << "Yes" << '\n';
  else std::cout << "No" << '\n';
}


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

#define loop(i, num) for (int i = 0; i < num; i++)

using namespace std;

int main() {
    
    int a, b, ans = 0;
    
    cin >> a >> b;
    
    vector<int> n(a);
    
    loop (i, a)  cin >> n[i];
    
    sort(n.begin(), n.end());
    
    loop (i, b)  ans += n[a - i - 1];
    
    cout << ans << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	string s,t;
	cin>>s>>t;
	sort(begin(s),end(s));
	sort(begin(t),end(t));
	reverse(begin(t),end(t));
	if(s<t) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n, m;
        cin >> n >> m;
        cout << (n * (n - 1)) / 2 + (m * (m - 1)) / 2 << '\n';
    }
}

Measured memory_bytes: 31488
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val (n, m) = sc.nextLine().split(" ").map { it.toInt() }
    var ans =0

    if(m>1){
        ans += m*(m-1)/2
    }
    if (n>1){
        ans += n*(n-1)/2
    }

    println(ans)
}

Measured memory_bytes: 35820
using System;

namespace ITP1_5_C
{
    class Program
    {
        static void Main()
        {
            while (true)
            {
                string[] x = Console.ReadLine().Split(' ');
                int h = int.Parse(x[0]);
                int w = int.Parse(x[1]);
                
                if (h == 0 && w == 0) break;
                
                for (int i = 0; i < h; i ++)
                {
                    for (int j = 0; j < w; j++)
                    {
                        //(奇数行かつ奇数列)または(偶数行かつ偶数列)の場合、行番号i+列番号j=偶数
                        //(奇数行かつ偶数列)または(偶数行かつ奇数列)の場合、行番号i+列番号j=奇数
                        if ((i + j) % 2 == 0)
                        {
                            Console.Write("#");
                        }
                        else
                        {
                            Console.Write(".");
                        }
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
            
        }
    }
}


Measured memory_bytes: 15876