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

ll n, ans = 0;

void bfs(ll x, ll a, ll b, ll c) {
  if (x > n) return;
  if (a && b && c) ans++;

  bfs(10*x+3, 1, b, c);
  bfs(10*x+5, a, 1, c);
  bfs(10*x+7, a, b, 1);
}

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

  cin >> n;
  bfs(0, 0, 0, 0);
  cout << ans << endl;
}


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

int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
  int k;
  cin >> k;
  cout << a[k-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;


int32_t main(){
	IOS
	int n,m;cin>>n>>m;
	vector<int>degree(n+1);
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		degree[u]++;
		degree[v]++;
	}
	int ok = 1;
	for(int i=1;i<=n;i++){
		ok &= degree[i] % 2 == 0;
	}
	cout << ( ok ? "YES" : "NO" );

	
}
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    unsigned long ans{0};
    for(unsigned long i{1}, j{2}; i <= N; i = j){
        j = N / (N / i) + 1;
        ans += (j - i) * (i + j - 1) * (N / i) * (N / i + 1) / 4;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
//#include<cmath>
using namespace std;

int w[100010];

int f(int P, int n, int k)
{
	int sum = 0, p = P, i;
	for (i = 0; i < n;) {
		if (p >= w[i]) {
			p -= w[i];
			sum += w[i];
			i++;
		}
		else {
			k--;
			p = P;
		}
		if (k == 0)
			break;
	}
	return i;
}

int main(void)
{
	int n, k, ans = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> w[i];
	int left = 1, right = 1000000000, mid;
	mid = (left + right) / 2;
	while (right - left >= 50) {
		mid = (left + right) / 2;
		if (f(mid, n, k) >= n) {
			right = mid;
		}
		else {
			left = mid;
		}
	}
	for (int i = left; i <= right; i++) {
		if (f(i, n, k) >= n) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}


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

// 無限大を表す値
const long long INF = 1LL<<60;

int main() {
    // 頂点数，辺数
    int N, M;
    cin >> N >> M;

    // dp 配列 (INF で初期化します)
    vector<vector<long long> > dp(N, vector<long long>(N, INF));

    // dp 初期条件
    for (int e = 0; e < M; ++e) {
        int a, b;
        long long w;
        cin >> a >> b >> w;
        dp[a][b] = w;
    }
    for (int v = 0; v < N; ++v) dp[v][v] = 0;

    // dp 遷移 (Floyd--Warshall)
    for (int k = 0; k < N; ++k)
        for (int i = 0; i < N; ++i)
            for (int j = 0; j < N; ++j)
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);

    // 結果出力
    // もし dp[v][v] < 0 なら負閉路あり
    bool exist_negative_cycle = false;
    for (int v = 0; v < N; ++v) if (dp[v][v] < 0) exist_negative_cycle = true;
    if (exist_negative_cycle) {
        cout << "NEGATIVE CYCLE" << endl;
    }
    else {
        for (int i = 0; i < N; ++i) {
            for (int j = 0; j < N; ++j) {
                if (j) cout << " ";
                if (dp[i][j] < INF/2) cout << dp[i][j];
                else cout << "INF";
            }
            cout << endl;
        }
    }                              
}




Measured memory_bytes: 3252
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

uint64_t gcd(uint64_t a, uint64_t b){ 
  if (a == 0) 
      return b;  
    return gcd(b % a, a);  
 } 
  
   
// Function to return LCM of two numbers  
uint64_t lcm(uint64_t a, uint64_t b)  
{  
  return (a*b)/gcd(a, b);  
}  

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

  uint64_t div_C_B = B/C, div_C_A = (A-1)/C;
  uint64_t div_D_B = B/D, div_D_A = (A-1)/D;
  uint64_t LCM = lcm(C,D);
  uint64_t div_LCM_B = B/LCM, div_LCM_A = (A-1)/LCM;

  int64_t ans = B-A+1 + div_C_A + div_D_A - div_LCM_A - div_C_B - div_D_B + div_LCM_B;
  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,c,i,box=0;
  scanf("%d %d %d",&a,&b,&c);
  for(i=a;i<=b;i++){
    if(c%i==0){
      box++;
    }
  }
  printf("%d\n",box);
  return(0);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	long long int n;
	cin >> n;
	long long int res = 1;
	for (long long int i = 1; i * i <= n - 1; i++) {
		if ((n - 1) % i == 0) {
			long long int a = i, b = (n - 1) / i;
			if (a == b) {
				if (n % a != 0) res++;
			} else {
				if (n % a != 0) res++;
				if (n % b != 0) res++;
			}
		}
	}
	long long int nn = n;
	for (long long int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			nn = n;
			while (nn % i == 0) nn /= i;
			if ((nn - 1) % i == 0) res++;
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    ll ans = 0;
    for(int i=1; i<n; i++){
        if(a[i-1]>a[i]){
            ans += a[i-1]-a[i];
            a[i] = a[i-1];
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 25;

int n, m;

char a[N][N];
int d[N][N];
bool used[N][N];

int posx[] = {1, -1, 0, 0};
int posy[] = {0, 0, 1, -1};

bool valid (int x, int y) {
	return (x >= 1 && x <= n && y >= 1 && y <= m);
}

void bfs (int x, int y) {
	queue <pair <int, int>> q;
	q.push({x, y});
	d[x][y] = 0;
	used[x][y] = true;
	while (!q.empty()) {
		pair <int, int> p = q.front();
		int px = p.first;
		int py = p.second;
		q.pop();
		for (int i = 0; i < 4; i ++) {
			int tox = px + posx[i];
			int toy = py + posy[i];
			if (valid(tox, toy) && a[tox][toy] == '.' && !used[tox][toy]) {
				d[tox][toy] = d[px][py] + 1;
				used[tox][toy] = true;
				q.push({tox, toy});
			}
		}
	}
}

void init() {
	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= m; j ++) {
			d[i][j] = 0;
			used[i][j] = false;
		}
	}
}

int main() {

	FAST;
	cin >> n >> m;
	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= m; j ++) {
			cin >> a[i][j];
		}
	}
	int ans = 0;
	for (int x1 = 1; x1 <= n; x1 ++) {
		for (int y1 = 1; y1 <= m; y1 ++) {
			if (a[x1][y1] == '#') {
				continue;
			}
			init();
			bfs(x1, y1);
			for (int x2 = 1; x2 <= n; x2 ++) {
				for (int y2 = 1; y2 <= m; y2 ++) {
					ans = max(ans, d[x2][y2]);
				}
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

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

ans = 0
for i in range(n,100000):
    s = str(i)
    pay = True
    for j in range(len(s)):
        if s[j] in d:
            pay = False
            break
    if pay:
        ans = i
        break
print(ans)


Measured memory_bytes: 3060
//#pragma GCC optimize("O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int ans = 0;
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int cnt = 0;
        int m = i;
        while (m) {
            cnt++;
            m /= 10;
        }
        if (cnt & 1) {
            ans++;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
import math
if K > N:
  a = sum([2 ** -(math.ceil(math.log2(K/i))) for i in range(1,N+1)])
  a = a / N
  print(a)
else:
  a = sum([2 ** -(math.ceil(math.log2(K/i))) for i in range(1,K)])
  a = a /N + (N-K+1)/N
  print(a)

Measured memory_bytes: 3316
#include <stdio.h>
int main()
{
	char n[3];
	scanf("%s",&n);
	for(int i=0;i<3;i++)
	{
		if(n[i]=='1')
		{
			n[i]='9';
		}
		
		else if(n[i]=='9')
		{
			n[i]='1';
		}
	}
	
	for(int j=0;j<3;j++)
	{
		printf("%c",n[j]);
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using std::cerr;
using std::endl;

const int N = 2e5 + 10;

int n, fa[N], vis[N], cir[N], cnt, mex[N], buc[N];
std::vector<int> G[N];

void dfs(int x) {
  for (int y : G[x])
    if (!cir[y])
      dfs(y);
  for (int y : G[x])
    if (!cir[y])
      buc[mex[y]] = 1;
  while (buc[mex[x]]) ++mex[x];
  for (int y : G[x])
    if (!cir[y])
      buc[mex[y]] = 0;
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", fa + i), G[fa[i]].push_back(i);
  int x = 1;
  while (!vis[x]) vis[x] = 1, x = fa[x];
  while (!cir[x]) cir[x] = 1, x = fa[x], ++cnt;
  int same = 1, val = -1;
  for (int i = 1; i <= n; ++i)
    if (cir[i]) {
      dfs(i);
      if (val == -1) val = mex[i];
      else if (val != mex[i]) {
        same = 0; break;
      }
    }
  if (same && (cnt & 1)) puts("IMPOSSIBLE");
  else puts("POSSIBLE");
  return 0;
}


Measured memory_bytes: 14080
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <set>
#include <cmath>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

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

int main() {
    int T;
    ll A, B, C, D;
    cin >> T;
    REP(i, T) {
        cin >> A >> B >> C >> D;
        ll g = gcd(B, D);
        if (B > A || B > D) cout << "No" << endl;
        else if (C >= B) cout << "Yes" << endl;
        else if (B - g + (A % g) > C) cout << "No" << endl;
        else cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
# define BUFSIZE 10000
int a,b,c;
int d;
int  main(void){
scanf(" %d %d %d",&a,&b,&c);

d=a+b+c;
if(a<14 &&b<14 &&c<14 && a>0 && b>0 && c>0){
	if(d>21){
			printf("bust");
		}else{
			printf("win");
			}
	}else{
			printf("bust");
		}
}
	
	
	


	
	



Measured memory_bytes: 128
import Data.List
    import Control.Monad
    import Control.Applicative
     
    rInt = read :: String -> Int
     
    main = do
        n <- rInt <$> getLine
        t <- map ((\[l, r] -> r - l + 1) . (map rInt) . words) <$> replicateM n getLine
        print $ sum t

Measured memory_bytes: 1660
H,W,d = gets.split.map(&:to_i)
S = ["RG","BY"]
H.times { |i|
  puts (0...W).map{ |j| 
    S[(i+j) % (2*d) / d][(i-j+H*W*2*d) % (2*d) / d]
  }.join
}



Measured memory_bytes: 2428
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=310;
int dis[maxn][maxn];
bool vis[maxn][maxn];
int main()
{
     int i,j,k,n,m;
     scanf("%d",&n);
     for(i=1;i<=n;i++)
     {
          for(j=1;j<=n;j++)
               scanf("%d",&dis[i][j]);
     }
     bool flag=true;
     for(i=1;i<=n;i++)
     {
          for(j=1;j<=n;j++)
          {
               for(k=1;k<=n;k++)
               {
                    if(i!=j&&i!=k&&j!=k)
                    {
                         if(dis[i][j]+dis[j][k]<dis[i][k])
                              flag=false;
                         if(dis[i][j]+dis[j][k]==dis[i][k])
                              vis[i][k]=true;
                    }
               }
          }
     }
     if(!flag)
          printf("-1\n");
     else
     {
          long long ans=0;
          for(i=1;i<=n;i++)
          {
               for(j=i+1;j<=n;j++)
               {
                    if(!vis[i][j])
                         ans+=dis[i][j];
               }
          }
          printf("%lld\n",ans);
     }
	return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string n,s;
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> n >> s;
    cout << unique(s.begin(), s.end())-s.begin() << '\n';;

}


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

int main(){
    int n;
    cin >> n;
    vector<int> ar(n+2);
    ar[0] = 0;
    ar[n+1] = 0;
    rep(i,n){
        cin >> ar[i+1];
    }
    ll ans = 0;
    rep(i,n+1){
        ans += abs(ar[i+1] - ar[i]);
    }
    repp(i,n+1,1){
        cout << ans - abs(ar[i] - ar[i-1]) - abs(ar[i] - ar[i+1]) + abs(ar[i+1] - ar[i-1]) << endl;
    }
}

Measured memory_bytes: 1664
/**
*
* Author: Mouhanad
* Lang: GNU C++14
*
**/
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define ii pair < int , int >
#define LS pair < ll , string >
typedef long long ll;
const int inf = 1<<30;
const int N =100100;
int n , a[N] , q ;

int main ( ){

   ll x , y ;
   cin >> x >> y ;
   if ( x % y == 0 ){
    printf("-1");
    return 0;
   }
   for  ( ll i = x ; i <= 1000000000000000000 ; i += x  ){
                 if ( i %y ){
                    printf("%lld",i);
                    return 0;
                 }
   }
   printf("-1");
return 0 ;
}


Measured memory_bytes: 256
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define maxn 200005
#include <bits/stdc++.h>
using namespace std;

bool isPal(string s){
    int n = s.size();
    for(int i=0;i<n;i++){
        if(s[i] != s[n-i-1]) return false;
    }
    return true;
}

int main() {
    int n;
    string s, t, p;
    cin >> s;
    n = s.size();
    int l, r;
    l = 1;
    r = (n-1) / 2;
    for(int i=l;i<=r;i++){
        t += s[i-1];
    }
    l = (n+3) / 2;
    r = n;
    for(int i=l;i<=r;i++){
        p += s[i-1];
    }
    if(isPal(s) && isPal(t) && isPal(p)){
        cout << "Yes" << endl;

    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


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

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

    for (int i = 0; i < 20; i++){
        if(n < (1 << (i+1))){
            cout << (1 << i) << endl;
            break;
        }
    }
    return 0;
}


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

dp = [float('inf')]*n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
if n > 2:
  for i in range(2,n):
    dp[i] = min(dp[i-2]+abs(h[i]-h[i-2]), dp[i-1]+abs(h[i]-h[i-1]))

print(dp[n-1])

Measured memory_bytes: 20600
#include<stdio.h>

int main()
{
	int deck[50], buf[50];
	int n, r, p, c;
	int i, j, k;
	
	while(1)
	{
		scanf("%d%d", &n, &r);
		
		if(n == 0 && r == 0) break;
		
		for(i = 0; i < n; i++)
		{
			deck[i] = i + 1;
			buf[i] = 0;
		}
		
		for(i = 0; i < r; i++)
		{
			scanf("%d%d", &p, &c);
			
			for(j = 0; j < c; j++)
			{
				buf[j] = deck[n - p - c + 1 + j];
			}
			
			for(j = 0; j < p - 1; j++)
			{
				deck[n - p - c + 1 + j] = deck[n - p + 1 + j];
			}
			
			for(j = 0; j < c; j++)
			{
				deck[n - c + j] = buf[j];
				buf[j] = 0;
			}
		}
		
		printf("%d\n", deck[n - 1]);
	}
	
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define ll long long int 
using namespace std;
int main()
{ios_base::sync_with_stdio(0);
	cin.tie(0);
	//freopen("frog.txt","r", stdin);
ll n,net,sum,k;
cin>>n>>k;
ll a[n];
for(ll i=0;i<n;i++)
{ cin>>a[i];}
ll dp[n+1];
dp[0]=0;
dp[1]=dp[0]+abs(a[1]-a[0]);

for(ll i=2;i<n;i++)
{ ll j=0;
	dp[i]=INT_MAX;
	 while(j<k)
		{ 
 	 	if(i - j < 1){break;}
 	 	dp[i]=min(dp[i],min((dp[i-j-1]+abs(a[i]-a[i-j-1])),(dp[i-j]+abs(a[i]-a[i-j]))));
			j++;
	}
if(k<1){ dp[i]=dp[i-1]+abs(a[i-1]-a[i-2]);}
}
 if(n==2){cout<<(dp[1]-dp[0]); return 0; }
 else if(n<2){ cout<<0<<endl; return 0; }
cout<<dp[n-1]<<endl;
return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int A, B, C; cin >> A >> B >> C;
    int diff = A-B;
    cout << (max(0,C-diff)) << '\n';
}



Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include<string>
#include<algorithm>
#include<iomanip>
#include<stdlib.h>
#include<vector>



using namespace std;


int main() {
	
	int num;
	cin >> num;
	while (num != 0) {
		vector<int> money(num);
		for (int i = 0; i < num; i++) {
			cin >> money[i];
		}
		int av = 0;
		for (int i = 0; i < num; i++) {
			av += money[i];
		}
		av /= num;
		int counter = 0;
		for (int i = 0; i < num; i++) {
			if (money[i] <= av)counter++;
		}
		cout << counter << endl;
		cin >> num;
	}
	
}




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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define fst first
#define snd second

#define INF 2147483647
const int MAX_N = 1 << 17;

int dat[2 * MAX_N - 1];

struct RangeMinimumQuery {
  int N;

  RangeMinimumQuery() {}
  RangeMinimumQuery(int N_) {
    N = 1;
    while (N < N_)
      N <<= 1;
  
    for (int i = 0; i < 2 * N - 1; i++)
      dat[i] = INF;
  }

  // 0-indexed
  void update(int k, int val) {
    k += N - 1;
    dat[k] = val;

    while (k > 0) {
      k = (k - 1) / 2;
      dat[k] = min(dat[2 * k + 1], dat[2 * k + 2]);
    }  
  }

  // min [a, b)
  int query(int a, int b) {
    return query(a, b, 0, 0, N);
  }
  int query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return INF;
    if (a <= l && r <= b) return dat[k];

    int mid = (l + r) / 2;
    return min(query(a, b, 2 * k + 1, l, mid),
	       query(a, b, 2 * k + 2, mid, r));
  }
};

int main() {
  ios_base::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  RangeMinimumQuery segtree = RangeMinimumQuery(n);

  REP(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      segtree.update(x, y);
    } else if (com == 1) {
      cout << segtree.query(x, y+1) << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 2224
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define ar array
 
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
 
    int n;
    cin >> n;
    vector<int> a(n + 1), b(n);
    for (int i = 0; i <= n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        int val = min(a[i], b[i]);
        a[i] -= val; b[i] -= val;
        ans += 1ll * val;
        if (b[i]) {
            val = min(a[i + 1], b[i]);
            a[i + 1] -= val; b[i] -= val;
            ans += 1ll * val;
        }
    }
    cout << ans << '\n';
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
constexpr lnt INF = 2e18;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

int main() {
	// dont forget to count
	lnt n;
	std::cin >> n;
	std::vector<lnt> a(n);
	rep(i,n) std::cin >> a[i];
	lnt N=(lnt)1e6+1;
	std::vector<lnt> ok(N,false);
	rep(i,n) {
		ok[a[i]]=true;
	}
	std::sort(all(a));
	rep(i,N) {
		if(!ok[i]) continue;
		for(lnt j=2;i*j<N;j++) ok[i*j]=false;
	}
	std::map<lnt,lnt> map;
	rep(i,n) map[a[i]]++;
	int count=0;
	rep(i,n) {
		if(ok[a[i]]&&map[a[i]]==1) count++;
	}
	print(count);
}


Measured memory_bytes: 25044
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def FLI(): return [int(i) for i in input().split()]
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N,K = FLI()
d = [0]*K
m = []
for i in range(K):
    d[i] = I()
    for j in FLI():
        m.append(j)
print(N-len(set(m)))


Measured memory_bytes: 27168
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority_queue
#include<deque>//double_ended queue
#include<map>//map
using namespace std;
typedef long long LL; 
typedef pair<LL,LL> P;//Pでpair<-,->を表す。
const LL MAX=2000010;
const LL MOD=1000000007;
typedef map<LL,LL>::iterator Itr;
/*ここから*/
#include<cmath>//三角関数,逆三角関数,絶対値,ルート、累乗など(これ以外を使うこともないだろう)
#include<iomanip>//不動小数点表示精度の調整
double PI=acos(-1);

int main()
{ 
    cout<<setprecision(15);//有効数字15桁
    //整数部分が大きくなると精度が失われるため注意すること
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    int x=h*60+m;
    double ang=cos(PI*x*11.0/360.0);
    double ans=sqrt(1.0*a*a+1.0*b*b-2.0*a*b*ang);
    cout<<ans<<endl;
    return 0;
}

/*ここまで*/

Measured memory_bytes: 4228
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        long r = sc.nextLong();
        long g = sc.nextLong();
        long b = sc.nextLong();
        long n = sc.nextLong();
        long ans = 0;
        for(int i=0; i<3010; i++){
            if(r*i > n) break;
            for(int j=0; j<3010; j++){
                if(r*i + j*b > n) break;
                if((n-r*i - j*b) % g == 0) ans++;
            }
        }
        System.out.println(ans);
    }


    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}


Measured memory_bytes: 21332
#include <stdio.h>

int main(void) {
	int m, n;
	int t[128];
	int i;

	while(1) {
		int top = 1500000, bottom = 0;
		scanf("%d %d", &m, &n);
		if(!m && !n)
			break;
		for(i = 0; i < n; i++)
			scanf("%d", &t[i]);

		while(top != bottom) {
			int med = (top + bottom) / 2;
			int tmp = 0, tmp2 = 0, tmp3 = 0;

			for(i = 0; i < n && tmp2 <= m; i++) {
				if(tmp + t[i] <= med) {
					tmp += t[i];
				}
				else {
					tmp = 0;
					tmp2++;
					i--;
				}
			}

			if(tmp2 < m)
				top = med;
			else
				bottom = med + 1;
		}

		printf("%d\n", bottom);
	}

	return 0;
}

Measured memory_bytes: 600
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	int M, N; cin >> M >> N;
	int K; cin >> K;
	map<char, int>mp;
	mp['J'] = 0;
	mp['O'] = 1;
	mp['I'] = 2;
	vector<vector<vector<int>>>sums(M+1, vector<vector<int>>(N+1, vector<int>(3)));
	for (int i = 0; i < M; ++i) {
		string st; cin >> st;
		for (int j = 0; j < N; ++j) {
			sums[i + 1][j + 1][mp[st[j]]]++;
		}
	}
	for (int k = 0; k < 3; ++k) {
		for (int i = 1; i <= M; ++i) {
			for (int j = 1; j <= N; ++j) {
				sums[i][j][k] += sums[i][j - 1][k] + sums[i - 1][j][k] - sums[i - 1][j - 1][k];
			}
		}
	}
	for (int i = 0; i < K; ++i) {
		int a, b, c, d; cin >> b >> a >> d >> c;
		b--; a--;
		vector<int> anss(3);
		for (int j = 0; j < 3; ++j) {
			anss[j] = sums[d][c][j]-sums[d][a][j] -sums[b][c][j] + sums[b][a][j];
		}
		cout << anss[0] << " " << anss[1] << " " << anss[2] << endl;
	}
	return 0;
}

Measured memory_bytes: 57128
#include <iostream>
using ll = long long;

int main() {
    ll n; std::cin >> n;
    ll ans=0;
    for(ll x=1; x<=n; ++x) {
        ll y = n/x;
        ans += x*y*(y+1)/2;
    }
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
    int n,k;
    cin>>n>>k;
    ll x=0,y=0;
    bool ok=(k%2==0)?true:false;
    arep(i,1,n+1){
        if(i%k==0)x++;
        if(ok&&i%k==(k/2))y++;
    }
    ll ans=0;
    ans+=x*x*x;
    ans+=y*y*y;
    cout<<ans<<endl;

    return 0;
}

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

long s[1<<19];
int n;
void update(int p, long x, int k=0, int l=0, int r=n)
{
    if (r-l<2) { s[k]=x; return; }
    int m=(l+r)/2;
    if (p<m)
        update(p, x, 2*k+1, l, m);
    else
        update(p, x, 2*k+2, m, r);
    s[k]=max(s[2*k+1], s[2*k+2]);
}

long query(int a, int b, int k=0, int l=0, int r=n)
{
    if (a>=r || b<=l) return 0;
    if (a<=l && r<=b) return s[k];
    int m=(l+r)/2;
    return max(query(a, b, 2*k+1, l, m), query(a, b, 2*k+2, m, r));
}

int main()
{
    cin>>n;
    vector<pair<int, int>> p(n);
    for(int i=0; i<n; ++i) {
        int t; cin>>t;
        p[i]={t, i};
    }
    vector<int> a(n);
    for(auto& e: a) cin>>e;

    sort(begin(p), end(p));
    for(auto& e: p) {
        int i=e.second;
        auto x=query(0, i);
        update(i, x+a[i]);
    }
    cout<<query(0, n)<<endl;
}


Measured memory_bytes: 6656
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        Strategy strategy = new MyStrategy();
        strategy.solve(out, sc);
        out.flush();
    }
}

class MyStrategy implements Strategy {
    @Override
    public void solve(PrintWriter out, FastScanner sc) {
        int N = sc.nextInt();
        int K = sc.nextInt();
        int Q = sc.nextInt();
        int[] A = new int[N];
        Arrays.fill(A, K-Q);
        for (int i=0; i<Q; i++) {
            int a = sc.nextInt();
            A[a-1] += 1;
        }
        for (int i=0; i<N; i++) {
            if(A[i] <= 0) {
                out.println("No");
            } else {
                out.println("Yes");
            }
        }
        out.println();
    }
}

interface Strategy {
    void solve(PrintWriter out, FastScanner sc);
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


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

int main(){
    int N, D;
    cin >> N >> D;

    int a = N / (2*D+1);

    if (N%(2*D+1)==0){
        cout << a << endl;
    }

    else{
        cout << (a+1) << endl;
    }

    return 0;
}

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

using namespace std ;

int main(void){
    int N;
    // std::vector<int> a(100);
    long int a[200000], b[200000];
    long int b1,r=0;


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

    for(int i=0; i<N; i++) {
        b[i] = a[i] - i;
    }

    sort(b, b+N);
    b1 = b[N/2];
    //cout << b1 << endl;

    for(int i=0; i<N; i++) {
        r += abs( a[i] - (b1 + i) );
    }
    cout << r << endl;

    return 0;
}




Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF=1<<29;
ll inf=1LL<<50;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int H,W;
	cin>>H>>W;
	vector<string> arr(H);
	for(int i=0;i<H;i++) cin>>arr[i];

	int tab[H][W],tmp=0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			tab[i][j]=0;
		}
	}
	for(int i=0;i<H;i++){
		tmp=0;
		for(int j=0;j<W;j++){
			if(arr[i][j]=='#') tmp=0;
			else{
				tmp++;
			}
			tab[i][j]=tmp;
		}
	}
	for(int i=0;i<H;i++){
		tmp=0;
		for(int j=W-1;j>=0;j--){
			if(arr[i][j]=='#') tmp=0;
			else{
				if(tab[i][j]>=tmp) tmp=tab[i][j];
			}
			tab[i][j]=tmp;
		}
	}

	int tab2[H][W];
	tmp=0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			tab2[i][j]=0;
		}
	}
	for(int i=0;i<W;i++){
		tmp=0;
		for(int j=0;j<H;j++){
			if(arr[j][i]=='#') tmp=0;
			else{
				tmp++;
			}
			tab2[j][i]=tmp;
		}
	}
	for(int i=0;i<W;i++){
		tmp=0;
		for(int j=H-1;j>=0;j--){
			if(arr[j][i]=='#') tmp=0;
			else{
				if(tab2[j][i]>=tmp) tmp=tab2[j][i];
			}
			tab2[j][i]=tmp;
		}
	}

	int ans=0;
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			int tmp2=tab[i][j]+tab2[i][j]-1;
			ans=max(ans,tmp2);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 35840
#include <iostream>
#include <map>

using namespace std;

int main() {
  int n, m;
  map<string, int> s;
  string x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (s.find(x) == s.end()) {
      s[x] = 0;
    }
    s[x]++;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> x;
    if (s.find(x) != s.end()) {
      s[x]--;
    }
  }
  int max = 0;
  for (map<string, int>::iterator it = s.begin(); it != s.end(); it++) {
    if (max < it->second) {
      max = it->second;
    }
  }
  cout << max << endl;

  return 0;
}


Measured memory_bytes: 3252
let content = '';
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', buf => {
  content += buf;
});
process.stdin.on('end', () => {
  const rects = content
    .trim()
    .split('\n')
    .map(line => line.split(' ').map(n => parseInt(n, 10)));

  for (const rect of rects) {
    if (rect[0] !== 0 || rect[1] !== 0) {
      console.log(drawReact(rect));
    }
  }
});

const drawReact = ([h, w]) => {
  const hline = '#'.repeat(w) + '\n';
  return hline + `#${'.'.repeat(w - 2)}#\n`.repeat(h - 2) + hline;
};


Measured memory_bytes: 16048
import numpy as np

MOD = 10 ** 9 + 7

S = input()

n = len(S)
dp = np.zeros((n+1, 4), np.int64)
dp[0, 0] = 1
for i, c in enumerate(S):
    if c == 'A' or c == '?':
        dp[i+1] += dp[i]
        dp[i+1, 1] += dp[i, 0]
    if c == 'B' or c == '?':
        dp[i+1] += dp[i]
        dp[i+1, 2] += dp[i, 1]
    if c == 'C' or c == '?':
        dp[i+1] += dp[i]
        dp[i+1, 3] += dp[i, 2]
    dp[i+1] %= MOD

print(dp[n, 3])



Measured memory_bytes: 29372
import sys


def check(bits, M, k, s, p):
    for x in range(M):
        dec = 0
        for K in range(k[x]):
            if bits >> (s[x][K] - 1) & 1:
                dec += 1
            else:
                pass

        if dec % 2 == p[x]:
            pass
        else:
            return 0

    return 1


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

    k = [0] * M
    s = [0] * M
    for i in range(M):
        k[i], *s[i] = map(int, input().split())


    p = list(map(int, input().split()))

    ans = 0
    for bits in range(2 ** N):
        ans += check(bits, M, k, s, p)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
s = input()
n = len(s)
mod = 10**9+7

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

for i in range(1,n+1):
    for k in range(4):
        moji[i][k] += moji[i-1][k]
    if s[i-1] == 'A':
        moji[i][0] += 1
        continue
    elif s[i-1] == 'B':
        moji[i][1] += 1
        continue
    elif s[i-1] == 'C':
        moji[i][2] += 1
        continue
    else:
        moji[i][3] += 1

h = s.count('?')
mt = [1]
for i in range(h+1):
    mt.append(mt[-1]*3 % mod)
mt += [1/9,1/3]
ans = 0
for i in range(n):
    al,cr,hl,hr = moji[i][0], moji[n][2]-moji[i+1][2], moji[i][3], moji[n][3]-moji[i+1][3]
    if s[i] == 'B' or s[i] == '?':
        k = (al*3 + hl) * (cr*3 + hr) * mt[hr+hl-2]
        ans += int(k) % mod
print(ans%mod)

Measured memory_bytes: 29064
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    string S;
    cin >> S;
    
    int ans = 0;
    
    for(int i = 0; i < S.size()/2; i++) {
        if (S[i] != S[S.size()-1-i]) ans ++;    
    }

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

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

vector<ll> fac(1000001); //n!(mod M)
vector<ll> ifac(1000001); //k!^{M-2} (mod M)
//a,bの範囲的にこれだけ配列を用意していけば十分

int M= pow(10,9)+7;

ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % M;
        x = x*x % M;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % M;
    return tmp * fac[a] % M;
}

signed main(){
    int X, Y; cin>>X>>Y;

    //何回ナイトを動かせばよいかを求められれば良い
    //つまり、
    // a + 2*b = X
    // 2a + b = Y
    //これから、 
    //b = (2X-Y)/3
    //a = (2Y-X)/3
    //この両方が正の整数でないと死亡
    if((2*X-Y)%3!=0 ||(2*Y-X)%3!=0){
        cout<<0<<endl;
        return 0;
    }
    int a = (2*X-Y)/3;
    int b = (2*Y-X)/3;
    if(a<0 || b<0){
        cout<<0<<endl;
        return 0;
    }

    //あとは(a+b)の長さの0と1の列のどこにa個の1を入れるかを求める問題になる。
    //つまり(a+b)Caを求めればよい。


    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<1000000; i++){
        fac[i+1] = fac[i]*(i+1) % M; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, M-2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
    }

    ll answer = comb((a+b),a)%M;
    cout<<answer<<endl;





    return 0;
}

Measured memory_bytes: 15872
#include<cstdio>
#include<algorithm>
#define SF scanf
#define PF printf
#define MAXN 2010
#define MOD 1000000007
using namespace std;
typedef long long ll;
int n;
ll dp[MAXN],ans;
int main(){
	SF("%d",&n);
	dp[0]=1;
	for(int i=1;i<=n;i++)
		for(int j=3;j<=i;j++){
			dp[i]=(dp[i]+dp[i-j])%MOD;	
		}
	PF("%lld",dp[n]);
}

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

int main(void){
   int N,M,X;
   cin>>N>>M>>X;
   vector<int> C(N);
   vector<vector<int>> A(N,vector<int>(M));
   for(int i=0;i<N;i++){
      cin>>C[i];
      for(int j=0;j<M;j++){
         cin>>A[i][j];

      }
   }
   int ans=10000000;
   for(int i=0;i<(1<<N);i++){
      int money=0;
      vector<int> result(M,0);
      for(int j=0;j<N;j++){
         if(i&(1<<j)){
            for(int k=0;k<M;k++){
               result[k]+=A[j][k];
            }
            money+=C[j];
         }
      }
      bool flag=true;
      for(int i=0;i<M;i++){
         if(result[i]<X) flag=false;
      }
      if(flag) ans=min(ans,money);
   }
   if(ans==10000000) cout<<-1<<endl;
   else cout<<ans<<endl;
   return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <math.h>
using namespace std;
typedef long long int ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define FOREQ(i, a, b) for (int i = (a); i <= (b); i++)
#define REPEQ(i, n) FOREQ(i, 0, n)

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  if (A + B >= C)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;


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

  int n;
  cin >> n;
  vector<vector<P>> G(n);
  vl ans(n-1);
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(P(b,i));
    G[b].push_back(P(a,i));
  }
  queue<int>q;
  q.push(0);
  vector<int>used(n);
  used[0]=1;
  while(!q.empty()){
    int v = q.front(); q.pop();
    int c = -1;
    for(auto nv:G[v]){
      int next = nv.first, id=nv.second;
      if(used[next]) c=ans[id];
    }
    int k = 1;
    for(auto nv:G[v]){
      int next = nv.first, id=nv.second;
      if(used[next]) continue;
      if(k == c) k++;
      ans[id] = k;
      k++;
      q.push(next);
      used[next] = 1;
    }
  }
  
  
  int m=0;
  rep(i,n)m=max(m,(int)G[i].size());
  cout << m << endl;
  rep(i,n-1) cout<<ans[i] << endl;
  return 0;
  
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
    typedef long long ll;
    #define FOR(i,a,b) for(int i=(a);i<(b);i++)
    #define REP(i,a) FOR(i,0,a)
    	
    using namespace std;
    const int MAX_N=2e5,MAX_M=2e5;
    const int INF=1e8;
    int N,M;
    typedef pair<int,int> P;
    P pnt[MAX_N];
    int M2;
    int seg[(MAX_M+1)<<2],laz[(MAX_M+1)<<2];
    void lazpro(int k,int a,int b){
    	if (laz[k]!=0){
    		seg[k]+=laz[k];
    		if (b-a>1){
    			laz[k*2+1]+=laz[k];
    			laz[k*2+2]+=laz[k];
    		}
    		laz[k]=0;
    	}
    }
    void add(int l,int r,int x,int k,int a,int b){
    	if (r<=a || b<=l){
    		return;
    	}
    	if (l<=a && b<=r){
    		laz[k]+=x;
    		return;
    	}
    	lazpro(k,a,b);
    	add(l,r,x,k*2+1,a,(a+b)>>1);
    	add(l,r,x,k*2+2,(a+b)>>1,b);
    	lazpro(k*2+1,a,(a+b)>>1);
    	lazpro(k*2+2,(a+b)>>1,b);
    	seg[k]=max(seg[k*2+1],seg[k*2+2]);
    }
    	
    int query(int l,int r,int k,int a,int b){
    	if (r<=a || b<=l){
    		return -INF;
    	}
    	lazpro(k,a,b);
    	if (l<=a && b<=r){
    		return seg[k];
    	}
    	return max(query(l,r,k*2+1,a,(a+b)>>1),query(l,r,k*2+2,(a+b)>>1,b));
    }
    int main(){
    	cin>>N>>M;
    	REP(i,N){
    		int l,r;
    		cin>>l>>r;
    		pnt[i]=P(l,r);
    	}
    	sort(pnt,pnt+N);
    	int ans=max(N-M,0);
    	M2=1;
    	while(M2<M+1){
    		M2<<=1;
    	}
    	REP(i,M+1){
    		seg[M2-1+i]=-M+i;
    	}
    	REP(i,M2-M-1){
    		seg[M2-1+M+1+i]=-INF;
    	}
    	REP(i,M2-1){
    		int k=M2-2-i;
    		seg[k]=max(seg[k*2+1],seg[k*2+2]);
    	}
    	REP(i,N){
    		add(0,pnt[i].second,1,0,0,M2);
    		ans=max(ans,query(0,M+1,0,0,M2)-pnt[i].first);
    	}
    	cout<<ans<<endl;
    	return 0;
    }

Measured memory_bytes: 7552
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a[3];
  FOR(i,0,3) cin >> a[i];
  sort(a, a + 3);
  cout << a[2] * 10 + a[1] + a[0] << endl;
}

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

ll PowMod(ll N, ll P, ll M){
    ll ans = 1;
    for(ll i=0; i<P; ++i){
        ans *= N;
        ans %= M;
    }
    return ans;
}
 
int main(){
    ll n;cin>>n;
    ll ans=PowMod(10,n,mod)-PowMod(9,n,mod)-PowMod(9,n,mod)+PowMod(8,n,mod);
    while(ans<0) ans+=mod;
    cout << ans <<endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <algorithm>
#include <vector>
#define file(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)

inline int read()
{
	int data = 0, w = 1; char ch = getchar();
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') w = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') data = data * 10 + (ch ^ 48), ch = getchar();
	return data * w;
}

const int N(18), maxn(1 << 17), Mod(1e9 + 7);
inline void Add(int &x, int y) { x = (x + y) % Mod; }
int bin[N], fac[maxn], inv[maxn], n, m, ans, f[N][maxn], cnt[maxn], A[N];
inline int C(int n, int m) { return n < m ? 0 : 1ll * fac[n] * inv[m] % Mod * inv[n - m] % Mod; }
int fastpow(int x, int y)
{
	int ans = 1;
	for (; y; y >>= 1, x = 1ll * x * x % Mod)
		if (y & 1) ans = 1ll * ans * x % Mod;
	return ans;
}

int main()
{
	n = read(), m = read(), cnt[0] = bin[0] = fac[0] = inv[0] = 1;
	for (int i = 1; i <= n; i++) bin[i] = bin[i - 1] << 1;
	for (int i = 1; i <= bin[n]; i++) fac[i] = 1ll * fac[i - 1] * i % Mod;
	inv[bin[n]] = fastpow(fac[bin[n]], Mod - 2);
	for (int i = bin[n] - 1; i; i--) inv[i] = 1ll * inv[i + 1] * (i + 1) % Mod;
	for (int i = 1; i <= bin[n]; i++) cnt[i] = (i & 1) ? Mod - cnt[i >> 1] : cnt[i >> 1];
	for (int i = 1; i <= m; i++) A[i] = read(); std::sort(A + 1, A + m + 1);
	f[m + 1][0] = 1;
	for (int i = m; i; i--) for (int S = 0; S < bin[n]; S++) if (f[i + 1][S])
	{
		Add(f[i][S], f[i + 1][S]); int t = (bin[n] - 1) ^ S;
		for (int j = 0; j < n; j++) if (!(S & bin[j]))
			Add(f[i][S | bin[j]], 1ll * C(t - A[i] + 1, bin[j] - 1) *
					f[i + 1][S] % Mod * fac[bin[j]] % Mod);
	}
	for (int i = 0; i < bin[n]; i++)
		Add(ans, 1ll * f[1][i] * fac[bin[n] - 1 - i] % Mod * cnt[i] % Mod);
	ans = 1ll * ans * bin[n] % Mod; printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 9344