akhauriyash/Code-Regression huggingface dataset:
import fractions
import functools
N, M = map(int, input().split())
A = {int(i) // 2 for i in input().split()} 
#------------------------------------------------
#リスト内の最小公倍数
def lcm(a, b):
    return a * b // fractions.gcd(a, b)
all_lcm = functools.reduce(lcm, A)  
#------------------------------------------------
# Aの最小値が2で割り切れる回数
cnt = 0
min_a = min(A)
while True:
    if min_a % 2 != 0:
        break
    min_a //= 2
    cnt += 1
# Aのすべての数が2でcnt回割り切れる
cond1 = all({i % (2**cnt) == 0 for i in A})
# cnt回割った後、さらに2で割り切れる数は存在しない
cond2 = all({(i // (2**cnt)) % 2 != 0 for i in A})

if cond1 and cond2:
    ans = -((-(M // all_lcm)) // 2)
    print(ans)
else:
    print(0)

Measured memory_bytes: 89580
#-------------------------------------------------------------------------------
#関数定義
def f(a,d,T):
    try:
        return T[d+1:].index(a)+(d+1)
    except ValueError:
        return len(T)

def g(a,d,T):
    try:
        return (d-1)-T[d-1::-1].index(a)
    except ValueError:
        return 0

#-------------------------------------------------------------------------------
#インポート
from math import inf
from random import random,randint
import time

#-------------------------------------------------------------------------------
#定数
TIME_LIMIT=1.80 #ループの時間制限
PROB=0.001 #突然変異の確率  
A=26 #アルファベットの数
START=time.time()
#-------------------------------------------------------------------------------
#読み込み部
D=int(input())

C=[0]+list(map(int,input().split())) #減る満足度のベース
S=[0]*(D+1) #S[d][i] :(d+1)日目にコンテストiを開催した時の満足度

for i in range(1,D+1):
    S[i]=[0]+list(map(int,input().split()))           
#-------------------------------------------------------------------------------
#貪欲部
L=[0]*(A+1)
T=[0]
for d in range(1,D+1):
    Y=-inf
    E=0
    for a in range(1,A+1):
        X=S[d][a]
        for s in range(1,A+1):
            if a!=s:
                X-=C[s]*(d-L[s])

        if X>Y:
            Y=X
            E=a
    L[E]=d
    T.append(E)
#-------------------------------------------------------------------------------
#調節部
while time.time()-START<=TIME_LIMIT:
    d=randint(1,D)
    p=T[d]
    q=randint(1,A)
    
    Y=(d-g(p,d,T))*(f(p,d,T)-d)
    Z=(d-g(q,d,T))*(f(q,d,T)-d)
    
    if (S[d][q]-S[d][p])+Z*C[q]-Y*C[p]>0 or random()<PROB:
        T[d]=q

for i in range(1,D+1):
    print(T[i])


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dp[100010];

int main(){
  int N,M;
  cin >> N >> M;
  vector<vector<int> > G(N);
  vector<int> deg(N,0);
  rep(i,M){
    int x,y;
    cin >> x >> y;
    x--; y--;
    G[x].push_back(y);
    deg[y]++;
  }
  queue<int> que;
  rep(i,N){
    if(deg[i]==0){
      que.push(i);
    }
  }
  while(!que.empty()){
    int v=que.front();
    que.pop();
    for(auto nv:G[v]){
      deg[nv]--;
      if(deg[nv]==0){
        que.push(nv);
        chmax(dp[nv],dp[v]+1);
      }
    }
  }
  int ans=0;
  rep(i,N){
    if(ans<dp[i])
      ans=dp[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 6528
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

const int CMax = 100002;

int n, sum, sk;

int main() {
    scanf("%d", &n);
    sk = n;

    while (sk > 0) {
        sum += sk % 10;
        sk /= 10;
    }

    if (n % sum == 0) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }


}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
int main()
{
	int d,n,m,i,j,s[100001],r,x,*p;
	while(scanf("%d",&d),d)
	{
		scanf("%d%d",&n,&m);
		s[0]=0;
		for(i=1;i<n;++i)scanf("%d",&s[i]);
		s[n]=d;
		n++;
		sort(s,s+n);
		for(r=i=0;i<m;++i)
		{
			scanf("%d",&x);
			p=lower_bound(s,s+n,x);
			if(*p-x)r+=min(abs(p[-1]-x),abs(*p-x));
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 1152
n, x, y = map(int, input().split())
ans = [0 for _ in range(n-1)]
for i in range(1, n):
  for j in range(i+1, n+1):
    a = min(j-i, abs(x-i)+abs(y-j)+1, abs(x-j)+abs(y-i)+1)
    ans[a-1] += 1
for i in range(n-1):
  print(ans[i])

Measured memory_bytes: 48092
#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>;

vector<ll> ans;
vector<vector<int>> node;

void score(int now, int parent=-1) {
    if (parent != -1) {
        ans[now] += ans[parent];
    }
    rep(i, node[now].size()) {
        if (node[now][i] == parent) continue;
        score(node[now][i], now);
    }
}

void solve() {
    int n, q;
    cin >> n >> q;
    ans.resize(n);
    node.resize(n);

    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        node[a].push_back(b);
        node[b].push_back(a);
    }

    rep(i, q) {
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    score(0);
    rep(i, n) {
        if (i == 0) {
            cout << ans[i];
        } else {
            cout << " " << ans[i];
        }
    }
    cout << endl;
}

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


Measured memory_bytes: 24320
#include<bits/stdc++.h>
using namespace std;
using ll = long long ;
int const nax = 2e5 + 10;


vector<int> a[nax];

vector<int> st[nax];

int n, col[nax], sz[nax];
ll ans[nax];

int main () {

    scanf("%d", &n);

    for (int i = 1 ; i <= n ; ++ i)
        scanf("%d", col + i);

    for (int i = 1 ; i < n ; ++ i) {
        int u, v;
        scanf("%d %d", &u, &v);
        a[u].push_back(v);
        a[v].push_back(u);
    }

    function<int(int , int) > dfs_sz = [&] (int nod, int from) -> int{
        sz[nod] = 1;
        for (int i : a[nod])
            if (i != from) sz[nod] += dfs_sz(i, nod);
        return sz[nod];
    };

    dfs_sz(1, 0);

    for (int i = 1 ; i <= n;  ++ i)
        st[i].push_back(n);

    function<void (int, int)> dfs_ans = [&] (int nod, int from) -> void {

        if (from > 0) st[col[from]].push_back(sz[nod]);

        for (int i : a[nod]) {
            if (i != from) dfs_ans(i, nod);
        }

        st[col[nod]].back() -- ;

        if (from > 0) {

            int p = st[col[from]].back();
            ans[col[from]] += 1LL * p * (p + 1) / 2;

            st[col[from]].pop_back();

            st[col[from]].back() -= sz[nod];
        }
    };

    dfs_ans(1, 0);

    for (int i = 1 ; i <= n ; ++ i) {
        ans[i] += 1LL * st[i][0] * (st[i][0] + 1) / 2;
    }


    for (int i = 1 ; i <= n ; ++ i) {
        printf("%lld\n", 1LL * n * (n + 1) / 2 - ans[i]);
    }


}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 51144
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
using namespace std;
typedef long long LL;
const int N = 5005;

template <typename T> inline void read(T &AKNOI) {
	T x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	AKNOI = flag * x;
}

template <typename T> inline void cmin(T &x, T y) {
	if (x > y) x = y;
}

int n, A, B, p[N];
LL dp[2][N], ans;

void init() {
	read(n); read(A); read(B);
	for (int i = 1; i <= n; ++i) {
        read(p[i]);
	}
}

void solve() {
	mset(dp[0], 0x3f);
	ans = dp[0][0];
	dp[0][0] = 0;
	int cur = 0, pre = 1;
	for (int i = 1; i <= n; ++i) {
        swap(cur, pre);
        mset(dp[cur], 0x3f);
        for (int j = 0; j < i; ++j) {
            if (p[i] > p[j]) {
                cmin(dp[cur][i], dp[pre][j]);
                cmin(dp[cur][j], dp[pre][j] + A);
            } else {
                cmin(dp[cur][j], dp[pre][j] + B);
            }
        }
	}
	for (int i = 1; i <= n; ++i) {
        cmin(ans, dp[cur][i]);
	}
	printf("%lld\n", ans);
}

int main() {
	init();
	solve();
	return 0;
}


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

int main() {
  int H,N;
  cin>>H>>N;
  
  int sum=0;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    sum+=a;
  }
  
  if(sum>=H) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
    
  
 
 
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; ++i) cin >> a[i];

	int cnt_l = 0;
	int pos = 0;
	int cp = 100000;
	int count = 0;
	while (pos < n){
		if (a[pos]==cp){
			if (count%2==1) ++cnt_l;
			++count;
		}
		else{
			cp = a[pos];
			count = 1;
		}
		++pos;
	}

	int cnt_r = 0;
	pos = 0;
	cp = 100000;
	count = 0;
	while (pos < n){
		if (a[pos]==cp){
			if (count%2==1) ++cnt_r;
			++count;
		}
	else{
		cp = a[pos];
		count = 1;
	}
		++pos;
	}

	cout << min(cnt_l, cnt_r) << endl;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

void solve()
{
    int a;int b;cin>>a>>b;
    int ans=a-(2*b);
    if(ans<0)
    ans=0;
    cout<<ans<<endl;
}
int32_t main()
{
         rapido;
         int t;
         //cin>>t;
         t=1;
         while(t--)
         solve();
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <map>
#include <deque>
#include <vector>
typedef unsigned int UINT;
using namespace std;
/*
3 つの整数A,B,C が与えられます。
条件を満たす場合はYes、そうでない場合はNoを出力せよ。
*/
template
<typename T>
bool BeMidl(T s, T e, T n)
{
    if (n < s)
        return false;
    if (n > e)
        return false;
    return true;
}


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

      return 0;
}

Measured memory_bytes: 256
/*Stay true to yourself, yet always be open to learn. Work hard, and never give up on your dreams, 
even when nobody else believes they can come true but you. These are not cliches but real tools you 
need no matter what you do in life to stay focused on your path.
*/
 
 /*Pppppppp    UU      UU     CCCCCCCC    CCCCCCCC     HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HH     HH     UU      UU
   pp    pp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pppppppp    UU      UU     CC          CC           HHHHHHHHH     UU      UU
   pp          UU      UU     CC          CC           HH     HH     UU      UU
   pp          UUUUUUUUUU     CCCCCCCC    CCCCCCCC     HH     HH     UUUUUUUUUU
   */
 
#include <bits/stdc++.h>
using namespace std;

#define int long long
typedef long long ll;
#define loop(i,n)  for(int i=0;i<n;i++)
#define ford(i,a,b) for(int i=b;i>=a;i--)
#define read(a) int a; cin >>a;
#define readarr(a,n) int a[n] ; for(int i=0;i<n;i++) cin >> a[i];
#define readmat(a,n,m) int a[n][m]; for(int i=0;i<n;i++) for(j=0;j<m;j++) cin >> a[i][j];
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define pi pair<int,int>
#define vii vector<vector<int>>
#define sti set<int>
#define vpi vector<pair<int,int>>
#define print(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl;
#define printmat(a,n,m) for(int i=0;i<n;i++) {for(j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
#define fast ios_base::sync_with_stdio(false);  cin.tie(NULL);
#define endl "\n"
#define mp make_pair
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{

    fast;
    int x,y,z;
    cin >>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b;
	char s[10],t[10],u[10];
	scanf("%s%s",s,t);
	scanf("%d%d",&a,&b);
	scanf("%s",u);
	if(s[0]==u[0]){
		a--;
	}
	else{
		b--;
	}
	printf("%d %d\n",a,b);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))

def comb(x):
    if x > 1:
        return int(x*(x-1)/2)
    return 0

M = [0 for _ in range(N+1)]
C = [0 for _ in range(N+1)]
_C = [0 for _ in range(N+1)]

for i in range(N):
    M[A[i]] += 1
for i in range(N):
    cnt = M[A[i]]
    C[A[i]] = comb(cnt)
    _C[A[i]] = comb(cnt-1)

S = sum(C)
for i in range(N):
    print(S - C[A[i]] + _C[A[i]])


Measured memory_bytes: 26140
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
char tochar(int x){
	if(x<26) return 'a'+x;
	return 'A'+(x-26);
}
int toint(char c){
	if('a'<=c&&c<='z') return c-'a';
	else return c-'A'+26;
}
int main(){
	while(true){
		int n,a[100];
		cin>>n;
		if(n==0) break;
		rep(i,n) cin>>a[i];
		string s;
		cin>>s;
		rep(i,s.size()) s[i]=tochar((toint(s[i])-a[i%n]+52)%52);
		cout<<s<<endl;
	}
}

Measured memory_bytes: 1204
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <numeric>
#include <iomanip>
using namespace std;
#define mod (long)(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<long> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } long C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

int main(){
    vector<int> roads(4, 0);
    for(int i = 0; i < 3; i++){
        int a, b;
        cin >> a >> b;
        roads[a - 1]++;
        roads[b - 1]++;
    }
    YES(!(roads[0] % 2 && roads[1] % 2 && roads[2] % 2 && roads[3] % 2));
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>

const int N = 2e5 + 10;
const int mod = 1e9 + 7;
typedef long long LL;

LL F[N], R[N];

LL pow_mod(LL x, int p){
	LL s = 1;
	while(p){
		if(p & 1) 	s = s * x % mod;
		x = x * x % mod;
		p >>= 1;
	}
	return s;
}

LL C(int n, int m){
	return F[n] * R[m] % mod * R[n-m] % mod;
}

int main(){
	F[0] = R[0] = 1;
	for(int i=1; i<N; i++){
		F[i] = F[i-1] * i % mod;
		R[i] = pow_mod(F[i], mod-2);
	}
    int h, w, a, b;

    while(~scanf("%d %d %d %d", &h, &w, &a, &b)){
        int c = h - a;
		int d = w - b;
        LL ans = 0;
        for(int i=1; i<=c; i++){
            if(i == c){
				ans = ans + C(a+d-1, a) * C(c-1+b, c-1) % mod;
            } else {
				if(d > 1){
					ans = ans + C(i-1+b, i-1) * C(h-i+d-2, h-i) % mod;
				}
            }
            if(ans >= mod){
				ans %= mod;
            }
        }
        printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>
int main(){
  int i,j,N,count=0,temp,flag=1;
  int A[100];
    scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  while(flag){
    flag=0;
    for(j=N-1;j>0;j--){
      if(A[j]<A[j-1]){
	temp=A[j-1];
	A[j-1]=A[j];
	A[j]=temp;
	count++;
	flag=1;
      }
    }
  }
  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n%d\n",count);
  return 0;
}



Measured memory_bytes: 2104
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[100005],b[100005];
int v[100005];
int main()
{
    int n,ans1=0,ans11=0,ans2=0,ans22=0,t1=0,t2=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&v[i]);
    for(int i=1;i<=n;i++)
    {
        if(i&1)
        {
            a[v[i]]++;
            if(a[v[i]]>ans1) ans1=a[v[i]],t1=v[i];
        }
        else
        {
            b[v[i]]++;
            if(b[v[i]]>ans2) ans2=b[v[i]],t2=v[i];
        }
    }
    int ans;
    if(t2==t1)
    {
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        for(int i=1;i<=n;i++)
        {
            if(v[i]==t2) continue;
            if(i&1)
            {
                a[v[i]]++;
                if(a[v[i]]>ans11) ans11=a[v[i]];
            }
            else
            {
                b[v[i]]++;
                if(b[v[i]]>ans22) ans22=b[v[i]];
            }
        }
        ans=max(ans1+ans22,ans2+ans11);
        ans=n-ans;
    }
    else ans=n-ans1-ans2;
    printf("%d\n",ans);
}


Measured memory_bytes: 1656
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		if(a%3==0 || b%3==0 || (a+b)%3==0){
			System.out.print("Possible");
		}else{
			System.out.print("Impossible");
		}
		sc.close();
	}
}

Measured memory_bytes: 22100
#include <stdio.h>
int main()
{
    int n, a[100];
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    for (int i = n - 1; i >= 0; i--)
    {
        if(i != 0){
        printf("%d ", a[i]);
        }
        else{
            printf("%d", a[i]);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2044
local mod=1000000007

local function bmul(x,y)
    return (x*y)%mod
end

local function badd(x,y)
    return (x+y)%mod
end

local function bsub(x,y)
  return x<y and x-y+mod or x-y
end

local function bmod(x)
    x=tostring(x)
    local ten=10
    local cry=1
    local xod=0
    for i=#x,1,-1 do
        local xub=tonumber(x:sub(i,i))
        xod=badd(xod,bmul(xub,cry))
        cry=bmul(cry,ten)
    end
    return xod
end

local function bpow(x,y)
    x=bmod(x)
    y=bmod(y)
    local xpy=1
    while 0<y do
        if y%2==1 then
            xpy=bmul(xpy,x)
            y=y-1
        end
        x=bmul(x,x)
        y=y//2
    end
    return xpy
end

local function comb(x,y)
    local xyi=1
    local yii=1
    for i=1,y do
        xyi=bmul(xyi,x+1-i)
        yii=bmul(yii,i)
    end
    return bmul(xyi,bpow(yii,mod-2))
end

local x,y=io.read("n","n")
if (x+y)%3~=0 then
    print(0)
    return
else
    local m=(2*x-y)//3
    local n=(2*y-x)//3
    if m<0 or n<0 then
        print(0)
        return
    else
        print(comb(n+m,n))
    end
end

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

vector<int> arr;

int main(){
	int n,x;
	cin>>n>>x;
	for(int i=0;i<n;i++){
		int l;
		cin>>l;
		arr.push_back(l);
	}int sum=0;
	int ans=1;
	for(int j=0;j<n;j++){
		sum+=arr[j];
		if(sum>x) break;
		ans++;
	}
	cout<<ans;
}

Measured memory_bytes: 3632
o,x,b;
main(a){
  for(scanf("%d");~scanf("%s",&a);o==3?o=b=x=!printf("%d\n",x):0)
      for(a%=6,a-5?b=b*2+1,x+=b/8,b&=7:o++;!a&b;b/=2)x++;
}
 

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn=1e5+100;
int k;
string s;
vector<string>strs;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin>>s>>k;
    for(int len=1; len<=min(k, sz(s)); ++len)
        for(int i=0; i<=sz(s)-len; ++i)
            strs.pb(s.substr(i, len));
    sort(all(strs));
    strs.erase(unique(all(strs)), strs.end());
    cout<<strs[k-1]<<"\n";
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    
    int a[n+1];
    
    memset(a,0,sizeof(a));
    
    for(int i=0;i<n-1;i++)
    {
        int x;
        cin>>x;
        a[x]++;
    }
    
    for(int i=1;i<=n;i++)
    cout<<a[i]<<endl;
  
    
    return 0;
}

Measured memory_bytes: 4376
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <ctime>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
//#include <random>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define PB push_back
#define MP make_pair
#define INF 1073741824
#define inf 1152921504606846976
#define pi 3.14159265358979323846
//#pragma comment(linker,"/STACK:10240000,10240000")
//mt19937 rand_(time(0));
const int N=3e5+7,M=2e6;
const long long mod=1e9+7;
inline int read(){int ret=0;char ch=getchar();bool f=1;for(;!isdigit(ch);ch=getchar()) f^=!(ch^'-');for(;isdigit(ch);ch=getchar()) ret=(ret<<1)+(ret<<3)+ch-48;return f?ret:-ret;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}//逆元
//int head[N],NEXT[M],ver[M],tot;void link(int u,int v){ver[++tot]=v;NEXT[tot]=head[u];head[u]=tot;}
const db EPS=1e-11;
inline int sign(db a){return a<-EPS?-1:a>EPS;}
inline int cmp(db a,db b){return sign(a-b);}
db dp[3002][3002];
db p[3002];
int main(){
    //freopen("1.txt","r",stdin);
    //ios::sync_with_stdio(false);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lf",&p[i]);
    dp[0][0]=1.0;
    for(int i=1;i<=n;i++){
        for(int j=i;j>=1;j--){
            dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i]);
        }
        dp[i][0]=dp[i-1][0]*(1-p[i]);
    }
    db ans=0.0;
    for(int i=n/2+1;i<=n;i++){
        ans+=dp[n][i];
    }
    printf("%.10f\n",ans);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}




Measured memory_bytes: 68992
# -*- coding: utf-8 -*-
N = int(input())
a = list(map(int, input().split(' ')))

def dec(i):
    while i+1 < N and a[i] >= a[i+1]:
        i += 1
    return i

def inc(i):
    while i+1 < N and a[i] <= a[i+1]:
        i += 1
    return i


ans = 0
i = 0
while i < N:
    i = max(inc(i), dec(i)) + 1
    ans += 1

print(ans)


Measured memory_bytes: 58836
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();

		if (A <= 9 && B <= 9) {
			System.out.println(A*B);
		}else {
			System.out.println(-1);
		}

	}

}


Measured memory_bytes: 21716
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<map>
using namespace std;
vector<double> v;
vector<double> s;
int main() {
	int n,k;
	scanf("%d %d",&n,&k);
	for (int i = 0; i < n;i++) {
		int a;
		scanf("%d",&a);
		double b;
		b = 1.0+(a - 1) * 1.0 / 2.0;
		v.push_back(b);
		s.push_back(b);
		if (s.size()>1) {
			s[i] += s[i - 1];
		}
	}
	double maxN = s[k-1];
	for (int i = k; i < n;i++) {
		if (s[i]-s[i-k]>maxN) {
			maxN = s[i] - s[i-k];
		}
	}
	printf("%lf\n",maxN);
	return 0;
}

Measured memory_bytes: 3564
#include <stdio.h>
#include <string.h>

int
main(void)
{
	char s[201];
	char p[100];
	int slen;

	scanf("%s", s);
	scanf("%s", p);

	slen = strlen(s);
	memcpy(s + slen, s, slen);
	s[slen*2] = '\0';
	if (strstr(s, p) == NULL)
		puts("No");
	else
		puts("Yes");

	return 0;
}



Measured memory_bytes: 2140
package main

import (
	"fmt"
	"strings"
)

func main() {
	var a string
	fmt.Scan(&a)
	// fmt.Println(ans)
	a = strings.Replace(a, "A", "x", -1)
	a = strings.Replace(a, "T", "x", -1)
	a = strings.Replace(a, "C", "x", -1)
	a = strings.Replace(a, "G", "x", -1)
	// fmt.Println(a) // HxxxxxYx

	max := 0
	ct := 0
	for _, v := range a {
		if v == 'x' {
			ct++
			if ct > max {
				max = ct
			}
		} else {
			ct = 0
		}
		// fmt.Println(v, ct, max)
	}
	fmt.Println(max)
}


Measured memory_bytes: 640
#include <stdio.h>

int main(){
	int n , m ;
	while(scanf("%d%d",&n,&m)!=EOF){
		if(n == 0 && m == 0)
			break ;
		n = n * m ;
		if(n % 2)
			puts("no") ;
		else
			puts("yes") ;
	}
	return 0 ;
}

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

using namespace std;

void solve(string S, int K) {
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '1') {
      K -= 1;
      if (K <= 0) {
        printf("1\n");
        return;
      }
    } else {
      printf("%c\n", S[i]);
      return;
    }
  }
}

int main() {
  string S;
  int K;
  cin >> S;
  cin >> K;
  solve(S, K);
  return 0;
}


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

int main() {
    ll x, y, z, k;
    cin >> x >> y >> z >> k;
    ll a[x], b[y], c[z];
    for(int i = 0; i < x; i++)
    cin >> a[i];
    for(int i = 0; i < y; i++)
    cin >> b[i];
    for(int i = 0; i < z; i++)
    cin >> c[i];
    sort(a, a + x, greater<ll>());
    sort(b, b + y, greater<ll>());
    sort(c, c + z, greater<ll>());
    priority_queue<ll> pq;
    
    for(int i = 0; i < x; i++){
        for(int j = 0; j < y; j++){
            for(int k1 = 0; k1 < z; k1++){
                if((i+1) * (j+1) * (k1+1) <= k)
                pq.push(a[i] + b[j] + c[k1]);
            }
        }
    }
    while(k > 0){
        cout << pq.top() << endl;
        pq.pop();
        k--;
    }
    return 0;
}

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

int  main()
{
	ll n; cin >> n;
	string s;
	vector <ll> a(n);
	map <ll, ll> mp;
	ll sum = 0;
	rep(i, n)
	{
		cin >> a[i];
		mp[a[i]]++;
		sum += a[i];
	}
	ll k; cin >> k;
	vector <ll> b(k);
	vector <ll> c(k);
	rep(i, k)
		cin >> b[i] >> c[i];
	rep(i, k)
	{
		if (mp[b[i]] > 0)
		{
			// long tmp = sum;
			sum -= b[i] * mp[b[i]];
			sum += c[i] * mp[b[i]];
			mp[c[i]] += mp[b[i]];
			mp[b[i]] = 0;
			cout << sum << endl;
		}
		else
		{
			cout << sum << endl;
		}
	}
	return (0);
}


Measured memory_bytes: 11216
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <bitset>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>




#define ll long long
#define uint unsigned int
#define ull unsigned ll
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define do(x) for(int i = 1; i <= x; i++){ solve(); }
#define sz(x) (int)x.size()
#define pii pair < int, int >
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
 
const ll MAXN = 1e18;
const ll SIZE = 5e5 + 10;  //are u sure?
const ll mod = 1e9+7;
ll Lpref[SIZE], Rpref[SIZE];
ll Lsuff[SIZE], Rsuff[SIZE];
ll L[SIZE], R[SIZE];
ll mR = MAXN, mL = -MAXN;


void solve(){
	int N; cin >> N;
	for(int i = 0; i < N; i++){
		cin >> L[i] >> R[i];
		mR = min(mR, R[i]);
		mL = max(mL, L[i]);
	}
	Lpref[0] = -MAXN;
	Rpref[0] = MAXN;
	for(int i = 0; i < N; i++){
		Lpref[i + 1] = max(Lpref[i], L[i]);
		Rpref[i + 1] = min(Rpref[i], R[i]);
	}

	Lsuff[N - 1] = L[N - 1];
	Rsuff[N - 1] = R[N - 1];
	for(int i = N - 1; i > 0; i--){
		Lsuff[i - 1] = max(Lsuff[i], L[i]);
		Rsuff[i - 1] = min(Rsuff[i], R[i]);
	}
	ll ans = 0;
	for(int i = 0; i < N; i++){
		ll cur = (R[i] - L[i] + 1) + max(0LL, min(Rpref[i], Rsuff[i + 1]) - max(Lpref[i], Lsuff[i + 1]) + 1);
		ans = max(ans, cur);
	}
	vector<pair<ll, ll>> vec;
	for(int i = 0; i < N; i++){
		vec.push_back(mp(L[i], R[i]));
	}
	sort(all(vec));
	for(int i = N - 1; i > 0; i--){
		vec[i - 1].second = min(vec[i - 1].second, vec[i].second);
	}
	for(int i = 0; i + 1 < N; i++){
		ll cur = max(0LL, mR - vec[i].first + 1) + max(0LL, vec[i + 1].second - mL + 1);
		ans = max(ans, cur);
	}
	cout << ans << endl;
}

int main(){
	speedhack()
	// int it; cin >> it;
	int it = 1;
	do(it);
	return 0;
}

Measured memory_bytes: 22644
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main(){
    fast;
    ll K, N;
    cin >> N >> K;
    ll A[N];
    for(ll i = 0; i < N; i++)
        cin >> A[i];
    sort(A, A + N);
    ll sum = 0;
    for(ll i = 0; i < N - K; i++)
    {
        sum = sum + A[i];
    }

        cout << sum;

    return 0;
}


Measured memory_bytes: 1792
def Partition(A,p,r):
    x = A[r]
    i = p-1
    for j in range(p,r):
        if (A[j] <= x):
            i += 1
            A[i],A[j] = A[j],A[i]
    A[i+1],A[r] = A[r],A[i+1]
    return i+1

def qsort(A,p,r):
    if p < r:
        q = Partition(A,p,r)
        qsort(A,p,q-1)
        qsort(A,q+1,r)

def marge(A,left,mid,right):
    n1 = mid -left
    n2 = right -mid
    L = []
    R = []
    for i in range(left,n1+left):
        L.append(A[i])
    for i in range(mid,n2+mid):
        R.append(A[i])
 
    L.append(card('S 10000000000'))
    R.append(card('S 10000000000'))
 
    r_id,l_id = 0,0
    for k in range(left,right):
        if(L[l_id] <= R[r_id]):
            A[k] = L[l_id]
            l_id += 1
        else:
            A[k] = R[r_id]
            r_id += 1
 
def margeSort(A,left,right):
    if left+1 < right:
        mid = int((left+right)/2)
        margeSort(A,left,mid)
        margeSort(A,mid,right)
        marge(A,left,mid,right)


class card(object):
    def __init__(self, str):
        data = str.split()
        self.symbol,self.num = data[0],int(data[1])
    
    def __le__(self,obj):
        if(self.num <= obj.num):
            return True
        else:
            return False
    def __ge__(self,obj):
        if(self.num >= obj.num):
            return True
        else:
            return False

    def display_card(self):
        print("{0} {1}".format(self.symbol,self.num))

c = []        
n = int(input())
while(n>0):
    c.append(card(input()))
    n -= 1
c_marge = c.copy()
margeSort(c_marge,0,len(c))

qsort(c,0,len(c)-1)

'''
notStable = False
for i in range(1,len(c)):
    if(c[i-1].num == c[i].num):
        firstCard = c[i-1]
        secondCard = c[i]
        is_found_1st = False
        is_found_2nd = False

        for org in c_org:
            if(org == firstCard):
                is_found_1st = True
            if(org == secondCard):
                is_found_2nd = True
                if(is_found_1st == True):
                    break
                else:
                    notStable = True
                    break
if(notstable == 1):
    print('Not stable')
else:
    print('Stable')
for x in c:
    x.display_card()
'''

is_stable = True
for i in range(0,len(c)):
    if(c[i] != c_marge[i]):
        is_stable = False
        break
if(is_stable == True):
    print('Stable')
else:
    print('Not stable')
for i in c:
    i.display_card()

Measured memory_bytes: 29800
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
vi dy = { 0,0,1,-1 };
vi dx = { 1,-1,0,0 };
constexpr auto INF = INT_MAX/2;
constexpr auto INFL = 5000000000000000;
constexpr auto MOD = 1000000007;

int main() {
	int n,x,y;
	cin >> n >> x >> y;
	x--;y--;

	vvi path(n, vi(0));
	rep(i, n - 1) {
		path[i].push_back(i + 1);
		path[i + 1].push_back(i);
	}
	path[x].push_back(y);
	path[y].push_back(x);

	vi dist(n, 0);

	rep(i, n) {
		vector<int> di(n, 0);
		queue<int> que;
		que.push(i);

		while (!que.empty()) {
			int sv = que.front();que.pop();
			rep(j, path[sv].size()) {
				int nv = path[sv][j];
				if (di[nv] != 0 || nv == i)continue;
				di[nv] = di[sv] + 1;
				que.push(nv);
			}
		}
		rep(j, n) dist[di[j]]++;
	}

	rep1(i, n-1) {
		dist[i] /= 2;
		cout << dist[i] << endl;
	}

}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
    int n, m; cin >> n >> m;
    vector<int> v(n + 1);
    for(int i = 0; i < m; i++){
        int a, b; cin >> a >> b;
        v[a]++;
        v[b]++;
    }
    for(int i = 1; i <= n; i++){
        cout << v[i] << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>

using namespace std;
long long n,k,h=0;
int a[10001];
int main()
{
    cin>>n>>k;
    for(int i=0;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=n-1;i>=n-k;i--)
    {
        h+=a[i];
    }
    cout<<h<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long int

using namespace std;

void solve()
{
    int n;
    int s;
    int c;
    int z;
    cin>>n>>s>>c>>z;
    int nd=z-n,sd=nd-s,sum=0;
    if(sd>0)
            cout<<n-sd<<endl;
    else
    {
        cout<<min(z,n)<<endl;
    }




}
signed main()

{
    FAST_IO;
    int t = 1;

    // cin>>t;

    while(t--)
    {
        solve();
    }
    
    return 0;
}

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

using namespace std;
int main(){
  int n;
   cin >>n;
  
  vector<int> a(n+1);


  for(int i=1;i<=n;i++) cin >> a[i];
  
  vector<int> b(n+1,0);  
  int m=0;
  
  for(int i=n;i>0;i--){
    int cnt=0;
    for(int j=1;i*j<=n;j++){
      cnt+=b[i*j]; 
    }  
    if(cnt%2!=a[i]) {
      b[i]++;
      m++;
    }
    } 
  
  cout << m << endl;
  
  for(int i=1;i<=n;i++){
   if(b[i]) cout << i << " "; 
  
  }
  
}

Measured memory_bytes: 2432
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL
struct node{
  struct node *p;
  struct node *r;
  struct node *l;
  int key;
};
typedef struct node * Node;
Node root;
void insert(int v){
  Node y=NIL;
  Node x=root;
  Node c;
  c=malloc(sizeof(struct node));
  c->key=v;
  c->l=NIL;
  c->r=NIL;
  while(x!=NIL){
    y=x;
    if(c->key < x->key) x=x->l;
    else x=x->r;
  }
    c->p=y;
    if(y==NIL) root=c;
    else if(c->key < y->key) y->l=c;
    else y->r=c;
}
void inorder(Node w){
  if(w!=NIL){
    inorder(w->l);
    printf(" %d",w->key);
    inorder(w->r);
  }
}
 
void preorder(Node w){
  if(w!=NIL){
    printf(" %d",w->key);
    preorder(w->l);
    preorder(w->r);
  }
}
 
Node find(Node a,int b){
  if (a==NIL || b==a->key) return a;
  if(b < a->key) return find(a->l,b);
  else return find(a->r,b);
}
 
int main(){
  int a,b,i;
  char com[20];
 
  scanf("%d",&a);
 
  for(i=0;i<a;i++){
    scanf("%s",com);
 
  if(com[0]=='i'){
    scanf("%d",&b);
    insert(b);
  }
  else if(com[0]=='p'){
    inorder(root);
    printf("\n");
    preorder(root);
    printf("\n");
  }
  else if(com[0]=='f'){
    scanf("%d",&b);
    Node s=find(root,b);
    if(s!=NIL) printf("yes\n");
    else printf("no\n");
  }
  }
  return 0;
}

Measured memory_bytes: 19364
#include <vector>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <tuple>
using namespace std;

using Graph = vector< vector< pair<int, int> > >;
int rec[500];

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

  Graph G(N);

  vector<int> indeg(N), rec_deg(N);
  for(int i=0; i<M; i++) {
    int u, v, cost; cin >> u >> v >> cost;
    indeg[v]++;
    G[u].push_back(make_pair(v, cost));
    G[v].push_back(make_pair(u, cost));
  }
  
  queue<int> que;
  que.push(0);

  while(que.size()) {
    int cur = que.front(); que.pop();

    for(auto e : G[cur]) {
      int to, cost; tie(to, cost) = e;

      rec[to] = max(rec[to], rec[cur] + cost);
      if(++rec_deg[to] == indeg[to]) {
        que.push(to);
      }
    }
  }

  cout << rec[N-1] << endl;
  return 0;
}



Measured memory_bytes: 3112
require 'openssl'; BN = OpenSSL::BN
M = BN.new(10**9+7)
H, W, A, B = gets.split.map(&:to_i)

class NCR
  @fac = []
  class << self
    def init(n); calc_fact(n); end
    def calc_fact(n)
      @fac[0] = BN.new(1)
      @fac[1] = BN.new(1)
      i = 2
      while i <= n
        @fac[i] = @fac[i-1].mod_mul(i, M)
        i += 1
      end
    end
    def nCr(n, r)
       @fac[n].mod_mul( @fac[r].mod_inverse(M).mod_mul( @fac[n-r].mod_inverse(M), M), M)
    end
  end
end

NCR.init(H+W)

def n_pats(h, w)
  NCR.nCr(h+w, h)
end

mid_row = Array.new(W){|x|
  n_pats(H-A-1, x) if x >= B
}

last_row = Array.new(W){|x|
  mid_row[x].mod_mul( n_pats(A-1, W-x-1), M) if x >= B
}

p last_row.compact.inject{|a, b| a.mod_add(b, M) }.to_i


Measured memory_bytes: 74236
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;
#define pb push_back;
#define sz(v) ((int)(v).size())
#define ll long long;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int x=max(a,b)-min(a,b);
    int f=max(c,b)-min(c,b);
    int j=max(a,c)-min(a,c);
    //cout<<x<<f<<j;
    if(x<=d&&f<=d||j<=d)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    //system("pause");
    return 0;
}
    

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;
const ll MOD = 1e9 + 7;

int main() {
    int N, A;
    cin >> N;
    vector<int> B(N, 0);
    rep(i, N) {
        cin >> A;
        B[A]++;
    }
    if (N % 2 != B[0]) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 1; i < N; i++) {
        if ((N + i) % 2) {
            if (B[i] != 2) {
                cout << 0 << endl;
                return 0;
            }
        } else {
            if (B[i] != 0) {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    ll ans = 1;
    rep(i, N / 2) ans = (ans * 2) % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep2(i, a, b) for(int i = (a); i < (b); i++)

int main() {
   int m, d;
   cin >> m >> d;
   int count = 0;

    int D = 0;
   rep2(i, 1, d + 1) {
       
       if ((i / 10) >= 2 && (i % 10) >= 2) {
           D = (i / 10) * (i % 10);
       } else {
           D = -1;
       }
       
       if (1 <= D && D <= m) {
           count++;
       }
   }
   cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>
#include<time.h>
#include<list>

#define DIV 998244353
using namespace std;
using ll = long long;
using ldb = long double;

int main() {
	string s; cin >> s;
	int len = s.size(), r = 0, p = 0;
	for (int i = 0; i < len; i++) {
		if (s[i] == 'g')r++;
		else p++;
	}

	cout << (r - p) / 2 << endl;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
using namespace std;
const int mod=1e9+7;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main(){
    fast;
    int k,n;
    cin>>k>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i>0) b[i-1]=a[i]-a[i-1];
        if(i==n-1) b[n-1]=(k-a[i])+a[0];
    }
    int sum=0;
    sort(b,b+n);
    for(int i=0;i<n-1;i++){
        sum+=b[i];
    }
    cout<<sum;
}


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

#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void()
#endif

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<string> s(3);
  cin >> s[0] >> s[1] >> s[2];
  char now = 'a', ans;
  while (true) {
    if (now == 'a') {
      if (s[0] == "") {
        ans = 'A';
        break;
      } else {
        now = s[0][0];
        s[0].erase(s[0].begin());
      }
    } else if (now == 'b') {
      if (s[1] == "") {
        ans = 'B';
        break;
      } else {
        now = s[1][0];
        s[1].erase(s[1].begin());
      }
    } else {
      if (s[2] == "") {
        ans = 'C';
        break;
      } else {
        now = s[2][0];
        s[2].erase(s[2].begin());
      }
    }
    debug(s);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3656
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int x;
        int runDistance = 0;
 
        for(int i = 0; i < N; i++){
            x = sc.nextInt();
            if(x < K - x){
                runDistance += 2 * x;
            }else{
                runDistance += 2 * (K - x);
            }
        }
 
        System.out.println(runDistance);
        
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <stdio.h>
#include <ctype.h>
#define y second
#define x first
#define lsb(x) (x&-x)
#define pb push_back
#define l(x) x<<1
#define r(x) (x<<1)|1
#define non(x) ( (x) > N? (x) - N : (x) + N)
#define y second
const int MOD=1000000007; //LOL
const int MAXM=210*210;
const int NMAX=4400;
const int HP=73;
const int SQRT=350;
using namespace std;
const double eps=1e-5;
const double PI=acos(-1.0);
typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PLD;
typedef vector<int> VI;
const int m6[]={1, -1, 1, 1, -1, -1};
const int dx[]={0, 1, 0, -1};
const int dy[]={1, 0, -1, 0};

string s;

int main()
{

	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	cout<<setprecision(10)<<fixed;
	ios_base::sync_with_stdio(0);

	cin>>s;
	for(int i=0; i<s.size(); ++i)
		for(int j=i+1; j<s.size(); ++j)
			if(s[i]=='C' && s[j]=='F')
			{
				cout<<"Yes";
				return 0;
			}
	cout<<"No";

	return 0;
}









Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d",&a);scanf("%d",&b);
	if(a>b){
		c=a-b;
	}
	if(b>a){
		c=b-a;
	}
	else{
		c=a-b;
	}
	printf("%d\n",c);
		
	
		
	return 0;
}


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

using namespace std;

int main(){
	int m1,d1,m2,d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if(m1 == m2)
		cout << 0 << endl;
	else
		cout << 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int A, B;
    cin >> A >> B;
    if (A%3 == 0 || B%3 == 0 || (A+B)%3 == 0) {
        cout << "Possible" << endl;
    }
    else {
        cout << "Impossible" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cerr << v << " ";                                                          \
  }                                                                            \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string S;
  int X, Y;
  cin >> S >> X >> Y;
  int N = S.size();
  int initPos = S.find('T');
  if (initPos == (int)string::npos) {

    if (X == N)
      print("Yes");
    else {
      print("No");
    }

    return 0;
  } else {
    // DEBUG(S);
    // DEBUG(initPos);
    X -= initPos;
    int dtype = 0; // xtype
    vec< vec< int > > xyLis(2, vec< int >());
    int cnt = 0;
    S.pb('T');
    int xyLisSum[2] = {0, 0};
    FOR(i, initPos, (int)S.size()) {
      if (S[i] == 'T') {
        if (cnt != 0) {
          xyLis[dtype].pb(cnt);
          xyLisSum[dtype] += cnt;
          cnt = 0;
        }
        dtype++;
        dtype %= 2;
      } else {
        cnt++;
      }
    }
    //
    int sx = xyLisSum[0] - X;
    int sy = xyLisSum[1] - Y;

    if (sx % 2 == 0 && sy % 2 == 0 && sx >= 0 && sy >= 0) {
      sx /= 2;
      sy /= 2;
      // DEBUG(sx);
      // DEBUG(sy);
      // PRINTALL(xyLis[0]);
      // PRINTALL(xyLis[1]);

      vec< bool > flgX(sx + 1, false);
      flgX[sx] = true;
      FORA(e, xyLis[0]) {
        REPS(i, sx) {
          if (flgX[i] && i - e >= 0) {
            if (!flgX[i - e]) {
              flgX[i - e] = true;
            }
          }
        }
      }

      vec< bool > flgY(sy + 1, false);
      flgY[sy] = true;
      FORA(e, xyLis[1]) {
        REPS(i, sy) {
          if (flgY[i] && i - e >= 0) {
            if (!flgY[i - e]) {
              flgY[i - e] = true;
            }
          }
        }
      }

      if (flgX[0] && flgY[0]) {
        print("Yes");
      } else {
        print("No");
      }
    } else {
      print("No");
    }
    return 0;
  }
}

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

int main(){
  int K , N;
  cin >> K >> N;
  vector<int> A(N); //いえの距離の配列
  for(int i =0; i < N; i++){
    cin >> A[i];
  }
  sort(A.begin(),A.end()); //昇順にソート
  //一番距離が離れている2点間を見つける
  int maxd = 0; //2点間の最長距離
  int max_id = 0;//一番距離が長いところ
  for(int i = 1; i <N; i++){
    int maxi = A[i] - A[i -1];
    if(maxi > maxd) max_id = i;
    maxd = max(maxd, maxi);
  }
  //これで，一番離れている2点間はA[max_id]とA[max_id - 1]に決まった
  //例外として,A[0]とA[N-1]間の距離がある。これはK - A[N-1] + A[0]である
  if(K - A[N-1] + A[0] > maxd){ //もしその距離が他の全ての区間の最大距離より大きければ
    cout << A[N-1] - A[0] << endl; //これだけでいい
  }
  else{ //それ以外なら
    cout << K - A[max_id] + A[max_id - 1] << endl;
  }
}


Measured memory_bytes: 1024