akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstddef>
#include <iostream>
#include <map>
#include <numeric>
#include <unordered_map>
#include <vector>

using namespace std;

// Convenience function to read a vector of values from standard input
template <typename T>
auto readVector(T N) {
    vector<T> A;
    for (T i = 0; i < N; i++) {
        T Ai;
        cin >> Ai;
        A.push_back(Ai);
    }
    return A;
}

size_t findFirstLess(const vector<int>& current, const vector<int>& h) {
    for (auto i = 0u; i < current.size(); i++) {
        if (current[i] < h[i]) {
            return i;
        }
    }
    return current.size();
}

auto solve(const vector<pair<int,int>>& A, unsigned int K) {
    unordered_map<int,int> toppings;
    multimap<int,int,greater<int>> best;
    vector<pair<int,int>> temp;
    auto totalD = 0ull;
    // Add K unique values to the map
    for (auto p: A) {
        if (toppings.count(p.second)) {
            temp.push_back(p);
        } else {
            toppings[p.second] = 1;
            best.insert(p);
            totalD += p.first;
        }
        if (best.size() == K) break;
    }
    auto bestScore = totalD + static_cast<unsigned long long>(toppings.size()*toppings.size());
    // Try adding each non-unique value one by one and checking if score is improved
    for (auto p: temp) {
        // Remove the lowest item if we already have K items
        if (best.size() == K) {
            auto& last = *best.rbegin();
            toppings[last.second]--;
            if (toppings[last.second] == 0) {
                toppings.erase(last.second);
            }
            totalD -= last.first;
            best.erase(prev(best.end()));
        }
        // Add the current item
        toppings[p.second]++;
        totalD += p.first;
        best.insert(p);
        bestScore = max(bestScore, totalD + static_cast<unsigned long long>(toppings.size()*toppings.size()));
    }
    return bestScore;
}


// Read parameters from standard input and call main solution function
int main() {
    int N, K;
    cin >> N >> K;
    vector<pair<int,int>> A;
    for (auto i = 0; i < N; i++) {
        int t, d;
        cin >> t >> d;
        A.push_back(make_pair(d, t));
    }
    sort(A.begin(), A.end(), greater<pair<int,int>>());
    cout << solve(A, K) << endl;
    return 0;
}

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

int main() {
    int n ;
    cin >> n ;
    vector<int> p (n) ;
    rep(i, n){
        cin >> p[i] ;
    }
    vector<int> m = p ;
    sort(m.begin(), m.end()) ;
    int num = 0;
    rep(i, n){
        if(m[i] != p[i]){
            num++ ;
        }
    }
    if(num == 2 || num == 0){
        cout << "YES" << endl ;
    }
    else {
        cout << "NO" << endl ;
    }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int A,B;
    cin >> A >> B;
    for (int i = 0; i < 1000; i++) {
        int cnt = (i-1)*(A-1) + A;
        if (cnt >= B) {
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}

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

signed main(){
  int N;
  string S;
  cin>>N>>S;
  int WH=0;
  rep(i,N){
    if(S[i]=='W')WH+=1;
  }
  int ans=0;
  int i=N-1;
  while(WH!=0){
    if(S[i]=='R'){
      ans+=1;
      WH-=1;
    }else{
      WH-=1;
    }
    if(WH==0)break;
    i-=1;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3724
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <map>
#include <algorithm>
#include <stack>
#include <cstring>
 
#define ll long long
#define MP make_pair
#define PB push_back
#define P push
#define f first
#define se second
#define S size()
#define B begin()
#define E end()
#define rB rbegin()
#define rE rend()
#define PI acos(-1)

 
const int N = 1e5 + 100;
const int M = 1e6 + 100;
const ll oo = 1e18;
 
ll n, m, k, t, q, h, a, b, d, c, e, w, x, y, z;
using namespace std;


ll dp[3009][3009];



int main() {


	string a, b;
	cin >> a >> b;

	n = a.S;
	m = b.S;



	a.insert(0, " ");
	b.insert(0, " ");

	for(int i = 1; i <= n; i++){
		for(int j = 1; j <=m; j++){
			dp[i][j] = max({dp[i - 1][j], dp[i][j - 1], dp[i - 1][j - 1] + (a[i] == b[j])});
		}
	}	


	int i = n, j = m;

	string ans;

	while(i && j){
		if(dp[i][j] == dp[i - 1][j]) i--;
		else if(dp[i][j] == dp[i][j - 1]) j--;
		else {
			ans.PB(a[i]);
			i--, j--;
		}
	}

	reverse(ans.B, ans.E);

	cout << ans << endl;

    return 0;
}




Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std; 
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define ld long double
#define fi first 
#define se second 
#define mp make_pair
#define pb push_back
#define ull unsigned long long int
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define mo 1000000007
/*int const nmax = 1000006; 
vector<int> v[nmax]; 
void dfs(int i , int p)
{
	for(int j = 0; j<v[i].size(); j++)
	{
		int node = v[i][j]; 
		if(node!=p)
		{
			dfs(node,i); 
		}
	}
}*/
/////////////////////////////
ll gcd(ll a ,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll poww(ll a,ll n){if(n==0)return 1;ll p=poww(a,n/2);p=(p*p)%mo;if(n%2)p=(a*p)%mo;return p;}
////////////////////////////////////////////////////

int hh[100005]; vector<int> v[100005];ll vis[100005]; 
void solve()
{
ll n , m; cin>>n>>m; 
lp(i,0,n)
{
	int x ; cin>>x; 

	hh[i+1]=x; 
}
lp(i,0,m)
{
	int x,y;  cin>>x>>y; 
	v[x].pb(y); 
	v[y].pb(x); 
}
int ans = 0 ; 
lp(i,1,n+1)
{
	int f =1; 
	lp(j,0,v[i].size())
	{
		if(hh[i]<=hh[v[i][j]])
		f=0; 
	}
	ans+=f;
}
cout<<ans<<endl; 
}
int main()
{ ios; 

ll t =1; 
 while(t--)
	solve(); 
	return 0 ; 
}

Measured memory_bytes: 9152
//AND BAND KA TOLA JO MERA CODE DEKHRA WO BHEN KA ....
//------------------------------------------Template------------------------------------------------
#include<bits/stdc++.h>
using namespace std;

typedef long long int ll;
#define lp(i,a,b) for(ll i=a;i<b;i++)
#define rlp(i,a,b) for(ll i=b;i>=a;i--)
#define TEZI_BOLTEY ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back 
#define mp make_pair 
#define endl "\n"
ll nCr(ll n, ll k) {double res = 1;lp(i,1,k+1){res = res * (n - k + i) / i;}return (int)(res + 0.01);}
//---------------------------------------------------------------------------------------------------
//---------------------------------<<< DRAGON SIN MELIODAS >>>---------------------------------------
//---------------------------------------------------------------------------------------------------
int main()
{
	TEZI_BOLTEY
	string a,b;
	cin >> a >> b;
	ll c=0;
	lp(i,0,a.length())
	{
		if(a[i]!=b[i])
			c++;
	}
	cout << c << endl;
}


Measured memory_bytes: 3776
#include <stdio.h>

int main(void){
  char str[20];
  int i,state;
  while(scanf("%s",str)!=EOF){
    state=0;
    for(i=0;i<3;i++){
      if(str[i]!='s'&&str[i]==str[i+3]&&str[i]==str[i+6]){
	printf("%c\n",str[i]);
	state++;
	break;
      }
      if(str[3*i]!='s'&&str[3*i]==str[3*i+1]&&str[3*i]==str[3*i+2]){
	printf("%c\n",str[3*i]);
	state++;
	break;
      }
    }
    if(state==0){
      if(str[0]!='s'&&str[0]==str[4]&&str[0]==str[8]){
	printf("%c\n",str[0]);
	state++;
      }else if(str[2]!='s'&&str[2]==str[4]&&str[2]==str[6]){
	printf("%c\n",str[2]);
	state++;
      }
    }
    if(state==0){
      printf("d\n");
    }
  }
  return 0;
}

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

int main (void){
  vector<char> some(3);
  int sum = 0;

  for(int i = 0;i < 3;i++) {
    cin >> some.at(i);
    if(some.at(i) == 'o'){
        sum++;
    }else{
    sum += 0;
    }
  }
  cout << sum*100 + 700 << endl;
  }


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

int main() {
//  int A,B,C;
//  cin >> A >> B >> C;
  int N;
  cin >> N;
  int sum=0;
  for(int i=1; i<=N;i++){
    sum += i;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn];
int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n>>k;
	for(int i = 0;i < n; ++i)
	{
		cin>>a[i];
	}
	int ans = 0x3f3f3f3f;
	for(int i = 0;i <= n - k; ++i)
	{
		int left = a[i];
		int right = a[i + k - 1];
		if(left >= 0)
		{
			ans = min(ans,right);
		}
		else if(right <= 0)
		{
			ans = min(ans,abs(left));
		}
		else
		{
			if(right > -left)
			{
				ans = min(ans,right - 2 * left);
			}
			else
			{
				ans = min(ans,2 * right - left);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
def LI(): return list(map(int, input().split()))
n, m, d = LI()
if d == 0:
    one = n
    two = 0
else:
    hidari = d - max(0, 2*d-n)
    migi = n-hidari

    one = hidari*2
    two = max(0, migi - hidari)
    #print(hidari, migi,one,two)
a = one + 2*two
ans = (a*(m-1))/n**2
print(ans)



Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;
//int ksm(int a,int b){
//	int ans = 1;
//	while(b){
//		if(b&1){
//			ans = ans*a;
//		}
//		a = a*a;
//		b>>=1;
//	}
//	return ans;
//}
int main()
{
	string a;
	cin >> a;
	int flag = 0;
	int len = a.length();
	if(len%2==1){
		cout << "No" << endl;
		return 0;
	} 
	for(int i = 0;i < len;i++){
		if(i%2==0){
			if(a[i]=='h')
			continue;
			else{
				flag = 1;
				break;
			}
		}
		else{
			if(a[i]=='i'){
				continue;
			}
			else{
				flag = 1;
				break;
			}
		}
	}
	if(flag == 0){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	return 0;
}

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

using namespace std;
int fun(int n)
{
    int cnt=0;
    while(n!=0)
    {
        cnt++;
        n/=10;
    }
    return cnt;
}
int main()
{
    long long int n;
    int m,mn=1000000000,l;
    cin >> n;
    m=sqrt(n);
    for(int i=1;i<=m;i++)
    {
        if(n%i==0)
        {
            l=max(fun(n/i),fun(i));
            mn=min(mn,l);
        }
    }
    cout << mn << endl;
    return 0;
}


Measured memory_bytes: 256
list=[]
for x in range(9):
    a,b,c=input().split()
    list.append((a,int(b),int(c)))
    
i=1
for i in range(i):
    print(list[0][0],list[0][1]+list[0][2],list[0][1]*200+(list[0][2]*300))
    print(list[1][0],list[1][1]+list[1][2],list[1][1]*200+(list[1][2]*300))
    print(list[2][0],list[2][1]+list[2][2],list[2][1]*200+(list[2][2]*300))
    print(list[3][0],list[3][1]+list[3][2],list[3][1]*200+(list[3][2]*300))
    print(list[4][0],list[4][1]+list[4][2],list[4][1]*200+(list[4][2]*300))
    print(list[5][0],list[5][1]+list[5][2],list[5][1]*200+(list[5][2]*300))
    print(list[6][0],list[6][1]+list[6][2],list[6][1]*200+(list[6][2]*300))
    print(list[7][0],list[7][1]+list[7][2],list[7][1]*200+(list[7][2]*300))
    print(list[8][0],list[8][1]+list[8][2],list[8][1]*200+(list[8][2]*300))


Measured memory_bytes: 5616
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
    int n,i,j,x;
    long long int ans=0,a[200014],b[200014];
    b[0]=0;
    cin >> n;
    long long int MOD=1000000007;
    
    for(i=0;i<n;i++)
    {
        cin >> a[i];
    }
    for(i=1;i<n+1;i++)
    {
        b[i]=a[i-1]+b[i-1];
    }
    for(i=0;i<n;i++)
    {
        
        ans+=(b[n]-b[i+1])%MOD*a[i]%MOD;
        ans=ans%MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6712
#include <stdio.h>
#include <math.h>

#define ELETYPE int

#define MAXNUM ((int)(1e6))	// MAXNUM未満を扱える
#define ELESIZE (sizeof(ELETYPE) << 3)
#define TABLESIZE ((int)(MAXNUM / ELESIZE) + 1)

int numOfBits(ELETYPE);

int main()
{
	ELETYPE table[TABLESIZE] = {0x55555553}, mask = (ELESIZE - 1), shift;
	int i, j, k, f, l, n, p, num;
	int  max = MAXNUM >> 1;
	
	for (shift = 0; ELESIZE >> shift > 1; ++shift);
	
	for (i = 1; i < TABLESIZE; ++i) table[i] = 0x55555555;
	
	for (p = 3; p <= max; p += 2) {
		if ((table[p >> shift] & (1 << (p & mask))) == 0) {
			for (i = p << 1; i < MAXNUM; i += p) {
				table[i >> shift] |= (1 << (i & mask));
			}
		}
	}
	
	while (scanf("%d", &n) != EOF) {
		num = 0;
		max = (n >> shift);
		for (i = 0; i < max; ++i) {
		    num += numOfBits(~table[i]);
		}
		
		num += numOfBits((~table[max] & ((0xffffffff >> (ELESIZE - (n & mask) - 1)))));
		printf("%d\n", num);
	}
	
	return 0;
}

int numOfBits(ELETYPE bits)
{
	bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
	bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
	bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
	bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
	return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

Measured memory_bytes: 724
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 > b) System.out.println("a > b");
        else if(a == b) System.out.println("a == b");
        else System.out.println("a < b");
    }
}


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


int main(){

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

  }
  int sum = 0;
  sort(a,a+n);
  for(int i=0;i<k;i++){
    sum += a[i];
  }
  cout<<sum<<"\n";


  return 0;
}

Measured memory_bytes: 3640
#include <iostream>                                                                                                          

using namespace std;

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

   if(K==0){
      cout << N*N << endl;
      return 0;
   }   

   long long ans = 0;
   for(long long b=K+1; b<=N; ++b){
      long long x = b-K;
      long long y = (N-K)/b;
      ans += x*y;
      ans += min(x,N-y*b-K+1);
   }   
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
#define w(x) int x; cin>>x; while(x--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
using namespace std;
int main(){
#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll h;
	ll c=2,s=1;
	cin>>h;
	while(h){
		if(h==1)
			break;
		h=h/2;
		s+=c;
		c*=2;
	}
	cout<<s;
	

}

Measured memory_bytes: 3588
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
const ll mod=1e+9;

int main(){
    vector<int> a(3);
    for(int i=0;i<3;i++)cin>>a.at(i);
    sort(a.begin(),a.end());
    int count=0;
    while(a.at(0)!=a.at(1)||a.at(1)!=a.at(2)){
        if(a.at(1)!=a.at(2)){
            a.at(0)++;
            a.at(1)++;
            count++;
        }
        else {
            a.at(0)+=2;
            count++;
            if(a.at(0)>a.at(2)){
                a.at(1)++;
                a.at(2)++;
                count++;
            }
        }

    }

    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define INF -1
#define MAX 26
using namespace std;
struct BinNode
{
    int parent;

    int left_child;
    int right_child;

    int height;
    int depth;
};

BinNode nodes[MAX];
void Set_Depth(int x,int d)
{
    nodes[x].depth=d;
    if(nodes[x].left_child!=INF) Set_Depth(nodes[x].left_child,d+1);
    if(nodes[x].right_child!=INF) Set_Depth(nodes[x].right_child,d+1); //???????????°
}

int Set_Height(int x)
{
    //????????\?????????????????°
    if(x==INF) return -1; //?????????????????????
    return nodes[x].height=max(Set_Height(nodes[x].left_child),Set_Height(nodes[x].right_child))+1; //??±??\??????
}

void print(int n)
{
    for(int i=0;i<n;i++)
    {
        cout<<"node "<<i<<": ";
        cout<<"parent = "<<nodes[i].parent<<", ";
        cout<<"sibling = "<<(nodes[i].parent!=INF?(i==nodes[nodes[i].parent].left_child?nodes[nodes[i].parent].right_child:nodes[nodes[i].parent].left_child):(-1))<<", ";
        cout<<"degree = "<<(nodes[i].left_child==INF?(nodes[i].right_child==INF?0:1):(nodes[i].right_child==INF)?1:2)<<", ";
        cout<<"depth = "<<nodes[i].depth<<", ";
        cout<<"height = "<<nodes[i].height<<", ";
        cout<<(nodes[i].parent==INF?("root"):((nodes[i].left_child==INF&&nodes[i].right_child==INF)?"leaf":"internal node"));
        cout<<endl;
    }
}
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++) nodes[i].parent=nodes[i].left_child=nodes[i].right_child=INF;
    for(int i=0;i<n;i++)
    {
        int j,lc,rc;
        cin>>j>>lc>>rc;
        nodes[j].left_child=lc;nodes[j].right_child=rc;  //?????????
        nodes[lc].parent=j; nodes[rc].parent=j; //??????
    }
    int root=0;
    for(int i=0;i<n;i++)
        if(nodes[i].parent==INF)
        {root=i;break;}
    Set_Height(root);
    Set_Depth(root,0);
    print(n);
}

Measured memory_bytes: 3124
#include <algorithm>
#include <cstdio>
#define rg register
using namespace std;
typedef long long ll;
const int maxn=100010;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
int n,m,pos,top;
ll rem,stk[maxn],mul[maxn],cnt[maxn];
void input()
{
	ll x;
	read(n);read(m);
	stk[top=1]=n;
	for(rg int i=1;i<=m;i++)
	{
		read(x);
		while(top&&stk[top]>=x) --top;
		stk[++top]=x;
	}
}
int main()
{
	input();
	mul[top]=1;
	for(rg int i=top;i>1;i--)
	{
		mul[i-1]+=stk[i]/stk[i-1]*mul[i];rem=stk[i]%stk[i-1];
		while(1)
		{
			if(rem<=stk[1]){cnt[rem]+=mul[i];break;}
			pos=lower_bound(stk+1,stk+top+1,rem)-stk-1;
			mul[pos]+=rem/stk[pos]*mul[i];rem%=stk[pos];
		}
	}
	cnt[stk[1]]+=mul[1];
	for(rg int i=n-1;i;i--) cnt[i]+=cnt[i+1];
	for(rg int i=1;i<=n;i++) printf("%lld\n",cnt[i]);
	return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const ll inf=1e18;
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(5);
    cout.setf(ios::fixed,ios::floatfield);
    set<ll>s;
    s.insert(1),s.insert(2),s.insert(3);
    ll a,b;
    cin>>a>>b;
    s.erase(a),s.erase(b);
    cout<<*s.begin()<<endl;
      // }

}


Measured memory_bytes: 256
//auto 関数名 = [(&:ラムダ外の引数をとる時))](引数の型1 引数名1, 引数の型2, 引数名2, ...) { 関数の処理 }; //inside main() define function. take care of };
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//   bitset<ビット数> s(tmp);
//   // (ビット列sに対する処理)
// }
// sort(配列変数.begin(), 配列変数.end());
// do {
//   // 順列に対する処理
// } while (next_permutation(配列変数.begin(), 配列変数.end()));
//const double PI = acos(-1); M_PI
// cout << fixed << setprecision(10);
// set<int>st{ 3,1,4,1,5,9,2,6,5,3,5 };
//     for (auto itr = st.begin(); itr != st.end(); ++itr) {
//         cout << *itr;
//     }
#include <bits/stdc++.h>
#include <regex>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define _GLIBCXX_DEBUG 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end() //sort(all(vec)); ,reverse(all(vec));etc
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    rep(i,n){
        cin>>a.at(i);
    }
    int64_t t=0;
    int64_t m=1000;
    int min;
    int max;
    bool flag = 1; 
    rep(i,n-1){
        if(flag){
        if(a.at(i)>a.at(i+1)){
            continue;
        }
        if(a.at(i)<a.at(i+1)){
            min=a.at(i);
            t=m/min;
            m=m-t*min;
            flag=0;
        }}
        if(!flag){
            if(a.at(i)<a.at(i+1)){
            continue;
        }
        if(a.at(i)>a.at(i+1)){
            max=a.at(i);
            m=m+t*max;
            t=0;
            flag=1;
        }}
    }
    if(!flag){
        m=m+t*a.at(n-1);
        t=0;
        flag=0;
    }
    cout<<m<<endl;

  
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <map>
#include <functional>
using namespace std;

typedef long long ll;
const ll InF = 1e15;

int main() {
  int N,M;
  cin>>N>>M;
  vector<int> X(M);
  for (int i = 0; i < M; i++) cin>>X[i];
  sort(X.begin(),X.end());
  ll ans;
  vector<ll> sabun(M+1,0);
  ans = 0;
  for (int i = 0; i < M - 1; i++) sabun[i+1] = X[i+1] - X[i];
  sort(sabun.begin(),sabun.end());
  int M1 = N - 1;
  for (int i = 0; i <= M - M1; i++) ans += sabun[i];
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1408
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] w = new String[n];
        for (int i = 0; i < n; i++) {
            w[i] = sc.next();
        }
        for (int i = 0; i < n - 1; i++) {
            if (w[i].charAt(w[i].length() - 1) != w[i + 1].charAt(0)) {
                System.out.println("No");
                System.exit(0);
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                if (w[i].equals(w[j])) {
                    System.out.println("No");
                    System.exit(0);
                }
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 22736
#include<iostream>

using namespace std;

double class_w[] = {91, 81, 75, 69, 64, 60, 57, 54, 51, 48, 39};
char class_n[11][32] = {"heavy", "light heavy", "middle", "light middle", "welter", "light welter", "light", "feather", "bantam", "fly", "light fly"};

int main() {
  double w;
  while( cin >> w ) {
    int i = 0;
    while(1) {
      if(w > class_w[i]) {
	cout << class_n[i] << endl;
	break;
      }
      i++;
    }
  }

  return 0;
}

Measured memory_bytes: 1220
import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt(),n = sc.nextInt();
    int a[]=new int[n];
    a[0]=sc.nextInt();
    int max=0;
    for(int i=1;i<n;i++){
      a[i]=sc.nextInt();
      if(max<a[i]-a[i-1]){
        max = a[i]-a[i-1];
      }
    }
    if(max<a[0]+k-a[n-1]){
      max = a[0]+k-a[n-1];
    }

    pl((k-max)+"");
  }

  public static void pr(String str){
    System.out.print(str);
  }
  public static void pl(String str){
    System.out.println(str);
  }
}


Measured memory_bytes: 78260
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Integer[] a = new Integer[n];
		for(int i = 0;i < n;i++) a[i] = sc.nextInt();
		Arrays.sort(a, Collections.reverseOrder());
		
		int dif = 0;
		for(int i = 0;i < a.length;i++) {
		    if(i % 2 == 0) dif += a[i];
		    else dif -= a[i];
		}

		System.out.println(dif);
    }
}

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

using namespace std;

int main (int argc, char * const argv[]) {
    // insert code here...
    int a, b, c;
	
	while(cin >> a >> b ){
		c=1;
		a+=b;
		while(a/=10){
			c++;
		}
		cout<<c<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<iostream>
#define out(u,v) printf("%d %d\n",u,v)
#define lowbit(x) (x&(-x))
using namespace std;
int n,m,a,b;
int main(){
    // freopen("atcoder5140.in","r",stdin);
    // freopen("atcoder5140.out","w",stdout);
    scanf("%d",&n);
    if(n==lowbit(n)||n<3) return puts("No"),0;
    puts("Yes");
    out(1,2);out(2,3);out(3,n+1);out(n+1,n+2);out(n+2,n+3);
    for(int i=4;i<n;i+=2) out(1,i+1),out(i+1,i),out(1,i+n),out(i+n,i+1+n);
    if(!(n&1)) out(n,lowbit(n)+n),out(n+n,(n^lowbit(n))^1);
    return 0;
}


Measured memory_bytes: 2304
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
h = [INT() for _ in range(N)]

h.sort()

ans = INF
for i in range(N-K+1):
	ans = min(ans, h[i+K-1]-h[i])

print(ans)


Measured memory_bytes: 8124
#include <iostream>

using namespace std;

typedef long long llong;
const llong MOD=1000000007;

int main(){
  llong n,m; cin >> n >> m;
  llong sumx=0,sumy=0;
  for(llong i=1;i<=n;i++){
    llong x; cin >> x;
    sumx=(sumx+(2*i-n-1)*x)%MOD;
  }
  for(llong i=1;i<=m;i++){
    llong y; cin >> y;
    sumy=(sumy+(2*i-m-1)*y)%MOD;
  }
  cout << (sumx*sumy)%MOD << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define DBG(a) cout<<#a<<" ->->->-> "<<a<<endl
#define EN cout<<"\n"
#define fi first
#define se second
#define PI (acos(-1))
#define fastread ios::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 200005
template<class T> ostream& operator<<(ostream &s,pair<T,ll> a)
{
    s<<a.fi<<' '<<a.se;
    return s;
}
ll fastpow(ll val,ll pwr,ll md=0)
{
    if(pwr==0)return 1;
    if(md){
    if(pwr%2)return (val*fastpow((val*val)%md,pwr/2,md))%md;
    return fastpow((val*val)%md,pwr/2,md);
    }
    else
    {
        if(pwr%2)return val*fastpow(val*val,pwr/2);
        return fastpow(val*val,pwr/2);
    }
}
ll f[asz];
ll nck(ll n,ll k)
{
    return f[n]*fastpow(f[k],mod-2,mod)%mod*fastpow(f[n-k],mod-2,mod)%mod;
}
int main()
{
    fastread;
    ll T=1;
    f[0]=1;
    for(int i=1;i<asz;i++)f[i]=(f[i-1]*i)%mod;
//    cin>>T;
    for(ll qq=1;qq<=T;qq++)
    {
        ll n,k;
        cin>>n>>k;
        k=min(n-1,k);
        ll ans=0;
        for(int i=0;i<=k;i++)
        {
            ans=(ans+nck(n-1,i)*nck(n,i)%mod)%mod;
//            DBG(i);
//            DBG(ans);
        }
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 1792
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back

string solve(string s){
    sort(s.begin(),s.end());
    string a=s;
    string b="";
    for(int i=s.size()-1;i>=0;i--)b+=s[i];
    
    int res=stoi(b)-stoi(a);
    return to_string(res);
}


int main(){
    string s;
    int l;
    while(cin>>s>>l){
        if(s=="0" && l==0)break;
        string tmp="";
        for(int i=0;i<l-s.size();i++)tmp+='0';
        s=tmp+s;
        
        string data[50]={};
        data[0]=s;
        
        for(int i=1;i<30;i++){
            s=solve(s);
            data[i]=s;
            rep(j,i){
                if(data[j]==data[i]){
                    cout<<j<<" "<<s<<" "<<i-j<<endl;
                    goto end;

                }
            }
            string tmp="";
            for(int i=0;i<l-s.size();i++)tmp+='0';
            s=tmp+s;

        }
    end:;
        
    }
    return 0;
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,a[100],ans[101];

main() {
    cin >> n;
    rep(i,n) cin >> a[i];
    rep(i,n) {
        if (a[i] > i+1) {cout << -1 << endl;return 0;}
        int tmp = a[i],tmptmp;
        for(int j=a[i]-1;;j++) {
            tmptmp = ans[j];
            ans[j] = tmp;
            tmp = tmptmp;
            if (a[j+1] == 0) break;
        }
    }
    rep(i,n) cout << ans[i] << endl;
}



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

int main(){
	int n;
	const double pi = 3.14159265358979;

	while( cin >> n , n != -1 ){
		double x=0.0, y=0.0, angle=0.0;
		for(int i=0 ; i < n ; i++ ){
			x += cos( angle );
			y += sin( angle );
			angle = atan2( y , x ) + pi/2.0;
		}
		cout << x << endl << y << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    int maxa=0;
    int count=0;

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

    for (int i = 0; i < n; ++i) {
        if(a[i]>=maxa)
        {
            maxa=a[i];
            count++;
        }
    }
    cout<<count;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
int A[200000];
int new_A[200001];
int main(){
  int N;
  int K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }

  
  for(int i = 0; i < K; i++){
    for(int j = 0; j < N; j++){
      int begin_ind = max(0, j - A[j]);
      new_A[begin_ind] ++;
      int end_ind = min(N, j + A[j] + 1);
      new_A[end_ind] --;
    }
    for(int i = 1; i < N; i++){
      new_A[i] = new_A[i] + new_A[i - 1];
    }
    for(int i = 0; i < N; i++){
      A[i] = new_A[i];
      new_A[i] = 0;
    }

    bool all_N = true;
    for(int i = 0; i < N; i++){
      if(A[i] != N){
        all_N = false;
        break;
      }
    }
    if(all_N){
      break;
    }
  }

  for(int i = 0; i < N; i++){
    if(i != N - 1){
      cout << A[i] << " ";
    } else {
      cout << A[i] << endl;
    }
  }

  return 0;
}


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

#define fi first
#define se second
#define FO(x, n) for (int x = 0; x < n; ++x)
#define FOR(x, a, b) for (int x = a; x < b; ++x)
#define RFO(x, n) for (int x = n - 1; x >= 0; --x)
#define RFOR(x, a, b) for (int x = b - 1; x >= a; --x)
#define FOR_ITER(x, a) for(auto x = a.begin(); x != a.end(); ++x)



using namespace std;
typedef unsigned char byte;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;
typedef pair<ll, ll> pll;
inline bool feq(const double& a, const double& b) { return fabs(a - b) < 1e-10; }

using namespace std;


int main(){
//    int n, l;
//    cin >> n >> k;
//    vector<bool> dislike(10, false);
//
//    FOR(i, 0, k) {
//        int t;
//        cin >> t;
//        dislike[t] = true;
//    }

string str;
cin >> str;
cin >> str;

    cout << "A" << str.at(0) << "C" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>

const long INF = (1l << 30);
const long LINF = (1l << 60);

typedef std::pair<long, long> P;

long v, e;
std::vector<long> edge[100005];
long depth[100005], lowlink[100005];
std::vector<P> ans;

void dfs(long par, long vis){
  for(int i = 0; i < edge[vis].size(); i++){
    long nx = edge[vis][i];
    if(depth[nx] == LINF){
      lowlink[nx] = depth[nx] = depth[vis]+1;
      dfs(vis, nx);
      lowlink[vis] = std::min(lowlink[vis], lowlink[nx]);
    }else{
      if(nx != par){
        lowlink[vis] = std::min(lowlink[vis], depth[nx]);
      }
    }
  }
}

int main(){
  scanf("%ld%ld", &v, &e);
  for(int i = 0; i < e; i++){
    long a, b;
    scanf("%ld%ld", &a, &b);
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  for(int i = 0; i < v; i++){
    depth[i] = lowlink[i] = LINF;
  }
  depth[0] = lowlink[0] = 0;
  dfs(0, 0);
  /*
  for(int i = 0; i < v; i++){
    printf("%ld (%ld,%ld)\n", i, depth[i], lowlink[i]);
  }
  //*/
  for(long i = 0; i < v; i++){
    for(int j = 0; j < edge[i].size(); j++){
      long k = edge[i][j];
      if(depth[i] < lowlink[k]){
        ans.push_back(P(std::min(i, k), std::max(i, k)));
      }
    }
  }
  std::sort(ans.begin(), ans.end());
  for(int i = 0; i < ans.size(); i++){
    printf("%ld %ld\n", ans[i].first, ans[i].second);
  }
}



Measured memory_bytes: 7548
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    while (n--)
    {
        int a,b,c,d,e,f;
        cin>>a>>b>>c;
        d=a*a;
        e=b*b;
        f=c*c;
        if (d==e+f || e==d+f || f==d+e)
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 3072
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		char[] vals = sc.next().toCharArray();
		int N = vals.length, cant = 0;
		long cur = 0, max = 0;
		for (int i = 0; i < N; i++) {
			if (vals[i] == 'B') {
				cur += i;
				cant++;
			}
		}
		for (int i = 0; i < cant; i++) {
			max += N - i - 1;
		}
		out.println(max - cur);
		
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 25172
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

int main() {
	int n, a[100], cnt[10] = {}, min = 0, max;
	cin >> n ;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < 400) cnt[1]++;
		else if (a[i] < 800) cnt[2]++;
		else if (a[i] < 1200) cnt[3]++;
		else if (a[i] < 1600) cnt[4]++;
		else if (a[i] < 2000) cnt[5]++;
		else if (a[i] < 2400) cnt[6]++;
		else if (a[i] < 2800) cnt[7]++;
		else if (a[i] < 3200) cnt[8]++;
		else cnt[9]++;
	}
	for (int i = 1; i <= 8; i++) {
		if (cnt[i] > 0) min++;
	}
	max = min + cnt[9];
	if (min == 0) min = 1;
	cout << min << ' ' << max << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
    int n;
    cin>>n;
    int eo[n],sp[n],asp[n-1];
    for(int i = 0;i<n;i++)
    {
        cin>>eo[i];
    }
    for(int i = 0;i<n;i++)
    {
        cin>>sp[i];
    }
    for(int i = 0;i<n-1;i++)
    {
        cin>>asp[i];
    }
    int ans = 0;
    for(int i = 0 ;i<n;i++)
    {
        ans = ans + sp[eo[i]-1];
        if(i>0&&eo[i] == eo[i-1]+1)
        {
            ans = ans + asp[eo[i-1]-1];
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3648
#!/usr/bin/env python3
import sys, math
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod


mod = 10**9+7  # 出力の制限
N = 10**6
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

#!/usr/bin/env python3
import sys, math
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans=count=0
mod=10**9+7
x,y=map(int,input().split())
a=b=0
n=10**6
while x>0 and y>0:
    if x>=y:
        x-=2
        y-=1
        a+=1
    else:
        x-=1
        y-=2
        b+=1
    # print(x,y,a,b)
if not (x==0 and y==0):
    print(0)
    exit()
a%=mod
b%=mod
# print(math.factorial(a+b)%mod//math.factorial(a)%mod//math.factorial(b)%mod)
print(cmb(a+b, b, mod))


Measured memory_bytes: 127572
#include <bits/stdc++.h>
using namespace std;
int n,dp[100001],WW,v,m,w,ans;
main(){
    cin>>n>>WW;
    while(n--){
        int x=1;
        cin>>v>>w>>m;
        while(m){
            if(m<x)x=m,m=0;
            else m-=x;
            int V=v*x,W=w*x;
            for(int i=WW;i-W>=0;i--){
                dp[i]=max(dp[i],dp[i-W]+V);
                ans=max(dp[i],ans);
            }
            x<<=1;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3164
#include<stdio.h>
#include<stdlib.h>
struct node{   
  int key;
  struct node *parent;
  struct node *right;
  struct node *left;
};
typedef struct node *Node;
Node T;
#define NIL NULL;
void Insert(int);
void Preorder(Node);
void Inorder(Node);
int main()
{
  int n,i,key;
  char S[7];  
 
  scanf("%d",&n);
 
  for(i=0;i<n;i++){
    scanf("%s",S);
    if(S[0]=='i'){
      scanf("%d",&key);
      Insert(key);
    }
    else{
      Inorder(T);
      printf("\n");
      Preorder(T);
      printf("\n");
       
    }
  }
  return 0;
}
 
void Insert(int key)
{
  Node y,x,z;
  y=NIL;
  x=T;
  z=malloc(sizeof(struct node));
  z->key=key;
  z->left=NIL;
  z->right=NIL;
  while(x!=NULL){
    y=x;
    if( z->key < x->key )x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NULL){
    T=z;
  }
  else if(z->key<y->key){
      y->left=z;
  }
  else{
    y->right=z;
  }
}
 
void Preorder(Node T)
{
  printf(" %d",T->key);
  if(T->left!=NULL){
    Preorder(T->left);
  }
  if(T->right!=NULL){
    Preorder(T->right);
  }
    
}
void Inorder(Node T)
{
  if(T->left!=NULL && T->right!=NULL){
    Inorder(T->left);
    printf(" %d",T->key);
    Inorder(T->right);
   
  }
  if(T->left!=NULL && T->right==NULL){
   Inorder(T->left);
     printf(" %d",T->key);  
  }
   
  if(T->right!=NULL && T->left==NULL){
  printf(" %d",T->key);
 Inorder(T->right); 
   
  }
  if(T->left==NULL && T->right==NULL)printf(" %d",T->key);
  
}


Measured memory_bytes: 25140
#include <stdio.h> 
    #include <stdlib.h>    
    	int main(void){
    	int N;
    	int w, x, y, z;
    	char a;
    	scanf("%d",&N);
    		if(1<= N || 100>= N){
    			x = 800 * N;
    			z = (int)(N /15);
    			y = 200 * z;
    			w = x - y;
    			printf("%d\n", w);
    			return 0;    			
      	}else{
      		exit(1);
      	}
    	}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

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

#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define mod 1000000007
#define PI acos(-1)

void solve() {
	int x, n, ele;
	cin >> x >> n;
	unordered_map<int, int> mp;
	while(n--) {
		cin >> ele;
		mp[ele]++;
	}
	for(int d = 0; d <= x; d++) {
		for(auto s : {-1, +1}) {
			int a = x + (s * d);
			if(mp[a] == 0) {
				cout << a;
				return;
			}
		}
	}
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int tc = 1;
	// cin >> tc;
	while(tc--) {
	    solve();
	}
	return 0;
}


Measured memory_bytes: 3640
/*
Author-> Codie_1(Akash)
*/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(n) for(int i=0;i<n;i++)
#define repi(n) for(int i=0;i<n;i++)
#define repj(n) for(int j=0;j<n;j++)
#define repp(n) for(int i=0;i<=n;i++)
#define repab(a,b) for(int i=a;i<b;i++)
#define w(t) int t; cin>>t; while(t--)
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vi vector<int> v
#define vl vector<long long> v;
typedef long long ll;



int main()
{
	fast
	char ch;
	cin>>ch;
	if(ch>=65 and ch<=90)
		cout<<"A";
	else
		cout<<"a";

	return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <utility>
#include <math.h>
using namespace std;

int main() {
    long long a, b, r = 0;
    cin >> a >> b;
    for (long long i = b; i <= a + 1; i++) {
        r += (a - i + 1) * i + 1;
        r %= 1000000007;
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 3624
/**
 *    author: kalyan       
**/
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
using namespace std;
 
void solve(){
    int n;
    cin >> n;
    string str;
    cin >> str;
    int cnt=0;
    for(int i =0;i<=n-3; ++i){
        if(str.substr(i,3) == "ABC") cnt++;
    }
    cout << cnt;
    
}
 
int main(){
    fastio;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t;
    t = 1;
    // cin >> t;
    while(t--){
    	solve();
    }
    return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

std::string S;

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    std::cin >> S;

    int m = std::stoi(S.substr(5, 2)), d = std::stoi(S.substr(8, 2));

    if(m <= 3 || (m == 4 && d <= 30)){
        std::cout << "Heisei" << std::endl;
    }else{
        std::cout << "TBD" << std::endl;
    }
}


Measured memory_bytes: 256
N=int(input())
SList=[input() for i in range(N)]
SList=[[i for i in S] for S in SList]
MList=[]
M=""
for c in [chr(ord('a') + i) for i in range(26)]:
    _min=min([S.count(c) for S in SList])
    if _min:
        MList.append([c,_min])
for i in MList:
    for n in range(i[1]):
        M+=i[0]
print(M)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <time.h>
#define mp(a,b)   make_pair(a,b)
#define ll        long long
#define mp(a,b)   make_pair(a,b)
#define si(n)     scanf("%d",&n)
#define sl(n)     scanf("%lld",&n)
#define pi(n)     printf("%d\n",n)
#define pl(n)     printf("%lld\n",n)
#define           newline cout << endl;
#define           ff first
#define           ss second
using namespace std;

int main(){
  //clock_t tStart = clock();
  string a,b;
  cin >> a >> b;
  bool ans = false;
  for(int i=0;i<(int)a.length();i++){
    string t1 = a.substr(0+i,a.length());
    string t2 = a.substr(0, 0+i);
    string t = t1+t2;
    if(t==b){
      ans=1;
      break;
    }
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;
  //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
  return 0;
}

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

int gra[101][101];
int used[101];
int tt[101][2];
int n, a, b, c;

int dfs(int time, int ind){
	used[1] = 1;
	tt[ind][0] = time;
	for(int i=1; i<=n; i++){
		if(used[i]!=1 && gra[ind][i]==1){
			used[i] = 1;
			time = dfs(time+1, i);
		}
	}
	tt[ind][1] = ++time;
	return time;
}

int main(){
	cin>>n;
	int t = 0;
 	for(int i=0; i<n; i++){
 		cin>>a>>b;
		for(int j=1; j<=b; j++){
  			cin>>c;
 			gra[a][c]=1;
 		}
 	}
 	for(int i=1; i<=n; i++){
 		if(used[i]==0)t = dfs(++t, i); 		
	}
 	for(int i=1; i<=n; i++){
 		cout<<i<<" "<<tt[i][0]<<" "<<tt[i][1]<<"\n";
	}
 
 return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	//ios_base::sync_with_stdio(false);
	string s;
	cin>>s;
	int i=0,ans=0;
	int flag=false;
	while(i<s.length()){
		if(flag && s[i]==s[i-1]){
			i+=2;
			flag=false;
			if(i!=s.length()+1)
				ans++;
		}
		else{
			i+=1;
			flag=true;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long ll;
int main() {
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll m=b/c-(a-1)/c;
  ll n=b/d-(a-1)/d;
 ll x = c * d;
 
  /* 自然数 a > b を確認・入替 */
  if(c<d){
    ll tmp = c;
    c = d;
    d = tmp;
  }
 
  /* ユークリッドの互除法 */
  ll r = c % d;
  while(r!=0){
    c = d;
    d = r;
    r = c % d;
  }
  ll k=x/d;
  ll l=b/k-(a-1)/k;
  cout << (b-a+1)-(m+n-l);
  return 0;
}

Measured memory_bytes: 256