akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <climits>
using namespace std;


#define ll long long

int main() {
  int L, R;
  cin >> L >> R;

  int ans = INT_MAX;
  if (R - L < 2019) {
    vector<int> A { L % 2019 };
    for (int i = L + 1; i <= R; i++) {
      for (int a : A) {
        ans = min(ans, (a * (i % 2019)) % 2019);
      }
      A.push_back(i % 2019);
    }
  } else {
    ans = 0;
  }
  cout << ans << endl;
  return 0;
}


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


Measured memory_bytes: 2108
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<int>
#define COUT(x) cout<<(x)<<endl
#define MA map<int,int>
#define SE set<int>
#define PQ priority_queue


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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

int fact[200010];

inline int modpow(int x, int pow) {
	if (pow == 0)return 1;
	int a = modpow(x, pow / 2); a = a * a%MOD;
	if (pow % 2 == 1)a *= x;
	return a % MOD;
}
inline int fact_mod(int x) {
	if (x == 0)return 1;
	if (fact[x] != 0)return fact[x];
	return fact[x] = (x*fact_mod(x - 1)) % MOD;
}
inline int modncr(int n, int r) {
	return fact_mod(n)*modpow(fact_mod(r)*fact_mod(n - r) % MOD, MOD - 2) % MOD;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h, w, a, b; cin >> h >> w >> a >> b;
	VE vec(w - b);
	for (int i = b + 1; i <= w; i++) {
		vec[i - b - 1] = modncr(h - a + i - 2, h - a - 1);
	}
	int ans = 0;
	rep(i, vec.size()) {
		int tmp = modncr(a + w - b - i - 2, a - 1);
		ans = (ans + (vec[i] * tmp) % MOD) % MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4352
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class BResistorsInParallel {
public:
	void solve(std::istream& in, std::ostream& out) {
	    int N;
	    in >> N;
	    vector<double> A(N);
	    REP(i,0,N) in >> A[i];
	    double denominator = 0;
	    REP(i,0,N) {
	        denominator += 1.0 / A[i];
	    }
	    out << std::fixed << setprecision(10) << 1.0 / denominator << "\n";
	}
};


int main() {
	BResistorsInParallel solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;

int main()
{
  int q;
  cin >> q;
  while (q--) {
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    int m;
    if (a >= b)
      m = a / (b + 1) + (a % (b + 1) ? 1 : 0);
    else
      m = b / (a + 1) + (b % (a + 1) ? 1 : 0);

    // find na (== l)
    int l = -1, r = a+1;

    while (r > l + 1) {
      int na = (r - l) / 2 + l;
      int nb = max(0, (na - 1) / m);
      if (b - nb <= 1LL * (a - na + 1) * m)
        l = na;
      else
        r = na;
    }

    int n = l + max(0, (l - 1) / m);
    for (int i = c; i <= d; i++) {
      if (i <= n) {
        printf(i % (m+1) ? "A" : "B");
      } else {
        printf((a + b - i + 1) % (m+1) ? "B" : "A");
      }
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 384
H, W = map(int, input().split())
S = [input() for i in range(H)]

S_dim = [[0] * W for i in range(H)]
for i in range(H):
    for j in range(W):
        S_dim[i][j] = S[i][j:j + 1]

S_num = [[0] * W for i in range(H)]
for i in range(H):
    for j in range(W):
        count = 0
        if S_dim[i][j] == ".":
            for dy in [-1, 0, 1]:
                for dx in [-1, 0, 1]:
                    if i + dy < 0 or i + dy >= H or j + dx < 0 or j + dx >= W:
                        continue
                    if S_dim[i + dy][j+ dx] == "#":
                        count += 1
            S_num[i][j] = str(count)
        else:
            S_num[i][j] = "#"

for i in range(H):
    for j in range(W):
        print(S_num[i][j], end ="")
    print()

Measured memory_bytes: 3572
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
	char a[15];
	int n,i,s=0,c=0;
	scanf("%s",a);
	n=strlen(a);
	for(i=2;i<=n-2;i++)
	{
		if(a[i]=='C')
		s++;
	}
	for(i=0;i<n;i++)
	{
		if(a[i]>='a'&&a[i]<='z')
		c++;
	}
	if(a[0]=='A'&&s==1&&c==n-2)
		cout<<"AC";
	else
		cout<<"WA";
	return 0;
}

Measured memory_bytes: 256
a, b, k = list(map(int,input().split()))
def yakusu(n):
    ys = []
    for i in range(1, n+1):
        if n % i == 0:
            ys.append(i)
    return ys
ys_a = yakusu(a)
ys_b = yakusu(b)
ys_ab = list(set(ys_a)&set(ys_b))
ys_ab = sorted(ys_ab)
print(ys_ab[-k])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 1000000000
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(i) cout<<i<<endl;
const int mod=1e9 +7;
int main(){
IOS;
lli l,r,i,j;
cin>>l>>r;
vector<lli> v;
for(i=1;i<=min((lli)2019,r-l+1);i++){
    v.pb((l+i-1)%2019);
}
lli mini=2019;
for(i=0;i<v.size();i++){
    for(j=i+1;j<v.size();j++){
        mini=min(mini,(v[i]*v[j])%2019);
    }
}
cout<<mini<<endl;
}


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

using namespace std;

using ll = long long;

int grundy(int x, int k) {
    if (x < k) return 0;
    if (x % k == 0) return x / k;
    int d = x / k + 1;
    if (x % k % d == 0) return x / k;
    return grundy(x / k * k - d + x % k % d, k);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int a, k;
        cin >> a >> k;
        ans ^= grundy(a, k);
    }
    cout << (ans == 0 ? "Aoki" : "Takahashi") << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import defaultdict
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())
    BC = [tuple(map(int, input().split())) for _ in [0] * Q]

    num = defaultdict(list)
    for i, a in enumerate(A):
        num[a].append(i)

    sum_a = sum(A)
    for b, c in BC:
        d = c - b
        sum_a += d * len(num[b])
        num[c] += num[b]
        del num[b]
        print(sum_a)


main()


Measured memory_bytes: 45008
#include<bits/stdc++.h>
using namespace std;
typedef vector<int>V;
int n,i,j,ans=1<<30,x;
V L,R,S,T;
string s,t;
int main(){
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n>>s>>t;
	if(n<3){for(i=0;i<n;++i)x+=s[i]!=t[i];cout<<x<<endl;return 0;}
	for(i=0;i+1<n;++i){
		if(s[i]!=s[i+1])S.push_back(i+1);
		if(t[i]!=t[i+1])T.push_back(i+1);
	}
	L=V(n);R=V(n,n);
	if((s[S[0]-1]!=t[T[0]-1])!=(n&1))L.push_back(0);
	L.insert(L.end(),S.begin(),S.end());
	L.insert(L.end(),R.begin(),R.end());
	for(i=0;i+T.size()<=L.size();i+=2){
		x=0;
		for(j=0;j<T.size();++j)x+=abs(L[i+j]-T[j]);
		for(j+=i;j<L.size();++j)x+=n-L[j];
		for(j=0;j<i;++j)x+=L[j];
		ans=min(ans,x);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i, a, b) for (int i = a; i < b; i++)
#define VREP(it, v) for (vector<int>::iterator it = v.begin(); it != v.end(); it++)
typedef pair<ll,ll> pi;
typedef vector<ll> vi;

template <typename T>
using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename K, typename V>
using pbds_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>;
ll n;
map<ll, ll> m; //maps primes to its power
ll arr[14];

ll power(ll a, ll b, ll m){
	a %= m;
	if (b == 0) return 1;
	if (b == 1) return a;
	ll half = power(a, b/2, m);
	half *= half;
	half %= m;
	if (b % 2 == 1) half *= a;
	return half%m;
}

ll inv(ll a, ll m){
	//cout << "inv " << a << " " << m << endl; 
    ll m0 = m, t, q; 
    ll x0 = 0, x1 = 1; 
  
    if (m == 1){
    	//cout << "done" << endl;
    	return 0;
	} 

    while (a > 1){ 
    	//cout << "m : " << m << endl;
        q = a / m; 
        t = m; 
        m = a % m, a = t; 
        t = x0; 
        x0 = x1 - q * x0; 
        x1 = t; 
    } 
    if (x1 < 0) x1 += m0; 
  	//cout << "done" << endl;
    return x1; 
}

ll qmult(ll a, ll b, ll m){
	//cout << a << " " << b << " " << m << endl;
	a %= m;
	b %= m;
	if (a < b) swap(a, b);
	if (b == 0) return 0;
	if (b == 1) return a;
	ll half = qmult(a, b/2, m);
	half += half;
	half %= m;
	if (b % 2 == 1) half += a;
	return half%m;
}


int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	ll ans = 2*n - 1;
	if (n % 2 == 0) n *= 2;
	//cout << n << endl;
	while (n % 2 == 0){
		n /= 2;
		if (m.find(2) != m.end()) m[2]++;
		else m[2] = 1;
	}
	for (ll i = 3; i*i <= n; i+=2){
		while (n % i == 0){
			n /= i;
			if (m.find(i) != m.end()) m[i]++;
			else m[i] = 1;
		}
	}
	if (n != 1) m[n] = 1;
	ll tot = m.size();
	ll c = 0;
	ll prod = 1;
	for (map<ll,ll>::iterator it = m.begin(); it != m.end(); it++){
		arr[c] = 1;
		REP(i, 0, it -> second) arr[c] *= (it -> first);
		prod *= arr[c];
		c++;
	}

	for (ll i = 0; i < (1 << tot); i++){
		//cout << "up" << endl;
		ll x = 1;
		ll y = 1;
		for (ll j = 0; j < tot; j++){
			if ((i & (1 << j)) > 0) x *= arr[j];
			else y *= arr[j];
		}
		//cout << x << " " << y << endl;
		if (y == 1){
			ans = min(ans, x);
			continue;
		}
		
		ans = min(ans, (qmult(qmult(y - 1, prod/y, prod), inv(prod/y, y), prod)));
		/*
		if (y >= x){
			for (ll j = 1; j <= (x + 1); j++){
				if ((j*y - 1) == 0) continue;
				if ((j*y - 1)%x == 0){
					ans = min(ans, j*y - 1);
					break;
				}
			}
		} else {
			for (ll j = 1; j <= y; j++){
				if ((j*x + 1)%y == 0){
					ans = min(ans, j*x);
					break;
				}
			}
		}*/
	}
	cout << ans << endl;
	
}

//cout.flush()
//cout << fixed << setprecision(9) << x << endl;

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string S;
    cin >> S;
    int r1 = (S.size() - 1) / 2, l2 = (S.size() + 2) / 2;
    string S1{S.begin(), S.begin() + r1}, S2{S.begin() + l2, S.end()};

    string revS = S, revS1 = S1, revS2 = S2;
    reverse(revS.begin(), revS.end()); reverse(revS1.begin(), revS1.end()); reverse(revS2.begin(), revS2.end());

    if (S == revS && S1 == revS1 && S2 == revS2) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sz(a) (a.size())
#define int long long
#define SYNC ios_base::sync_with_stdio(false), cin.tie(NULL);
#define all(c) c.begin(), c.end()
#define pb push_back
#define F first
#define S second
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define debug(x) cout << #x << " = " << x << endl;
#define debug2(x, y) cout << #x << " = " << x << " , " << #y << " = " << y << endl;
#define debug3(x, y, z) cout << #x << " = " << x << " , " << #y << " = " << y << " , " << #z << " = " << z << endl;
const int M = 1000000007;
const int N = 4e3 + 4;

signed main() {
    int h, n, i, j;
    cin >> h >> n;
    int a[n], b[n];
    int dp[h + 1];
    for (i = 0; i <= h; i++) dp[i] = INT_MAX;
    for (i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    dp[0] = 0;
    for (i = 0; i <= h; i++)
    {
        for(j=0 ; j<n ; j++)
        {
            int x = i + a[j];
            if( x > h ) x = h;
            dp[x] = min(dp[x] , dp[i] + b[j]);
        }
    }
    cout<<dp[h]<<endl;

}




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

using namespace std;

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

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	ll n;
	cin >> n;
	ll o[n], c[n+1]={0};
	REP(i, 0, n){
		cin >> o[i];
		++c[o[i]];
	}
	ll pos = 0, val;
	REP(i, 0, n+1){
		val = c[i];
		pos += val* (val - 1)/2;
		c[i] = (val - 1)*(val - (val-2))/2;
	}
	for(auto i: o){
		cout <<  pos - c[i] << endl;
	}
		

}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define ll long long
#define ui unsigned int
#define ull unsigned long long
using namespace std;
const int N = 1e5+7;
int main()
{
    double n, m, d;
    scanf("%lf%lf%lf", &n, &m, &d);
    if(d==0)
    {
        printf("%lf\n", (n-d)*(m-1)/n/n);
    }
    else
    {
        printf("%lf\n", 2*(n-d)*(m-1)/n/n);
    }
	return 0;
}


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

int main(){
    int H, W;
    
    while(1){
        cin >> H >> W;
        if (H == 0 && W == 0) break;
        
        for (int i = 0; i < H; i++){
            for (int j = 0; j < W; j++){
                if ((i + j) % 2 == 0) {
                    cout << "#" ;
                } else {
                    cout << ".";
                }
            }
            cout << "\n";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class DChatInACircle {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<ll> a(n);
      rep(i, n) {
        cin >> a[i];
      }
      sort(a.rbegin(), a.rend());
      ll ret = a[0];
      int cnt = 1;
      for(int i=1; i<n-1; i++) {
        ret += a[i];
        cnt++;
        if (cnt == n-1) break;
        ret += a[i];
        cnt++;
        if (cnt == n-1) break;
      }
      cout << ret << endl;

    }
};

signed main() {
  DChatInACircle solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 4824
n,m=map(int,input().split())
a,b=[0]*m,[0]*m
c=[False]*(n+1)
d=[False]*(n+1)
for i in range(m):
    a[i],b[i] = map(int,input().split())
    if a[i]==1: c[b[i]]=True
    if b[i]==n: d[a[i]]=True
for i in range(n):
    if c[i] and d[i]:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')

Measured memory_bytes: 52056
#include <stdio.h>

int main()
{
	int i, N, A, max = 0;
	long long sum = 0;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		scanf("%d", &A);
		if (A < max) sum += (max - A);
		else max = A;
	}
	printf("%lld\n", sum);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1704
///
// File:  grl_2_a.cpp
// Author: ymiyamoto
//
// Created on Fri Oct 20 22:04:46 2017
//

#include <algorithm>
#include <cstdint>
#include <cstdio>
#include <vector>

using namespace std;
#define SIZE 100

struct node_t {
  node_t *parent;
  uint32_t val;
  node_t(uint32_t val) : parent(this), val(val){};
};

struct edge_t {
  uint32_t from;
  uint32_t to;
  uint32_t weight;
  bool operator<(const edge_t &e) const
  {
    return weight < e.weight;
  }

  void print()
  {
    printf("from: %u, to: %u, weight: %u\n", from, to, weight);
  }
};

static vector<node_t *> nodes;
static vector<int32_t> height;
static vector<edge_t> edges;

node_t *root(node_t *node)
{
  if (node->parent == node) {
    return node;
  } else {
    return root(node->parent);
  }
}

void join(uint32_t a, uint32_t b)
{
  node_t *a_root = root(nodes[a]);
  node_t *b_root = root(nodes[b]);
  if (height[a_root->val] < height[b_root->val]) {
    a_root->parent = b_root;
  } else {
    b_root->parent = a_root;
    if (height[a_root->val] == height[b_root->val]) {
      height[b_root->val]++;
    }
  }
}

bool same(uint32_t a, uint32_t b)
{
  return root(nodes[a])->val == root(nodes[b])->val;
}

int32_t main()
{
  uint32_t V, E;
  scanf("%u %u", &V, &E);

  for (uint32_t i = 0; i < V; i++) {
    node_t *node = new node_t(i);
    nodes.push_back(node);
    height.push_back(1);
  }

  for (uint32_t i = 0; i < E; i++) {
    uint32_t f, t, w;
    scanf("%u %u %u", &f, &t, &w);
    edges.push_back({f, t, w});
  }

  sort(edges.begin(), edges.end());

  uint64_t weight = 0;
  for (uint32_t i = 0; i < edges.size(); i++) {
    edge_t edge = edges[i];
    if (!same(edge.from, edge.to)) {
      join(edge.from, edge.to);
      weight += edge.weight;
    }
  }

  printf("%lu\n", weight);

  return 0;
}

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

using namespace std;

int add (int a , int b , int mod) {
    a += b;
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}

int mul (int a , int b , int mod) {
    return a * 1ll * b % mod;
}

int main() {
    ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0);
#ifdef LOCAL
    freopen("input.in" , "r" , stdin);
#endif
    int n , p;
    string s;
    cin >> n >> p >> s;

    long long ans = 0;
    if (p == 2) {
        for (int i = 0 ; i < n ;i++) {
            int d = s[i] - '0';
            if (d % 2 == 0)
                ans += i + 1;
        }
    } else if (p == 5) {
        for (int i = 0 ; i < n ;i++) {
            int d = s[i] - '0';
            if (d == 5 || d == 0)
                ans += i + 1;
        }
    } else {
        reverse(s.begin() , s.end());

        vector<int> f(p);
        f[0]++;

        int power = 1 , h = 0;
        for (int i = 0 ;i < n ;i++) {
            int d = s[i] - '0';
            h = add(h , mul(power , d , p) , p);
            ans += f[h];
            f[h]++;
            power = mul(power , 10 , p);
        }
    }

    cout << ans;
}

Measured memory_bytes: 3776
n,k = map(int, input().split())
R, S, P = map(int, input().split())
t = input()
        

#%%


hand_points = {'r':P, 's':R, 'p':S}
ans = 0
for i in range(k):
    hands = t[i::k]
    tmp = ''
    for hand in hands:
        if hand == tmp:
            tmp = ''
        else:
            ans+= hand_points[hand]
            tmp = hand

print(ans)

Measured memory_bytes: 41708
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double EPS = 1e-9;
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//

int N;
lint A[100005];

int main() {
	cin >> N;
	for_(i,0,N) cin >> A[i];
	
	lint ans = 0;
	int P = 1;
	for_(i,0,N) {
		if (A[i] > P) {
			if (P == 1) {
				ans += A[i] - 1;
				++P;
			} else {
				ans += A[i] / P + (A[i] % P == 0 ? -1 : 0);
			}
		} else if (A[i] == P) {
			++P;
		}
	}
	cout << ans << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//


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

int main(){
   string s; cin >> s;
  
   int l=s.length(),rcnt=0,lcnt=0,right,left;
   vector<int> ans(l);
   rep(i,l)ans[i]=0;
   rep(i,l){
      if(s[i]=='R'&&s[i+1]=='L'){
         if(rcnt%2){
            ans[i]=1+rcnt/2;
            ans[i+1]=2+rcnt/2;
         }else{
            ans[i]=1+rcnt/2;
            ans[i+1]=1+rcnt/2;
         }
         left=i; right=i+1; rcnt=0;
         i++;
         continue;
      }
       if(s[i]=='L'&&s[i+1]=='R'){
          lcnt++;
         if(lcnt%2){
            ans[left]+=1+lcnt/2;
            ans[right]+=lcnt/2;
         }else{
            ans[left]+=lcnt/2;
            ans[right]+=lcnt/2;
         }
          lcnt=0;
         continue;
      }
      if(s[i]=='R') rcnt++;
      if(s[i]=='L') lcnt++;
   }
   if(l>0){
      if(lcnt%2){
            ans[left]+=1+lcnt/2;
            ans[right]+=lcnt/2;
         }else{
            ans[left]+=lcnt/2;
            ans[right]+=lcnt/2;
         }
   }
   rep(i,l) cout << ans[i] << " ";
   //cout << "L"<< lcnt<<endl; 
   cout << endl;
   return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>
int main(){
  int n,t,i,j,d[10010][5];
  double l,r[2][2]={-60,-1,-60,-1};
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<5;j++)scanf("%d",&d[i][j]);
  }
  for(i=1;i<n;i++){
    if(d[i-1][1]==d[i][1]||d[i-1][2]-d[i][2])continue;
    l=hypot(d[i-1][3]-d[i][3],d[i-1][4]-d[i][4]);
    t=d[i][2];
    if(r[t][1]<l||fabs(r[t][1]-l)<1e-9&&r[t][0]>d[i][0]-d[i-1][0]){
      r[t][0]=d[i][0]-d[i-1][0];
      r[t][1]=l;
    }
  }
  printf("%f %f\n%f %f\n",r[0][1],r[0][0]/60.0,r[1][1],r[1][0]/60.0);
  return 0;
}

Measured memory_bytes: 656
months, days = map(int,input().split())
cnt = 0
for m in range(1, months + 1):
    for d in range(1, days + 1):
        d1 = d % 10
        d = d//10
        d10 = d % 10
        if d1 > 1 and d10 > 1:
            if m == d1 * d10:
                cnt += 1
print(cnt)

Measured memory_bytes: 3060
import sys
input=sys.stdin.readline
n,k=map(int,input().split())
A=tuple(map(int,input().split()))
DP=[False]*(k+1)
for i in range(1,k+1):
    DP[i]=any(not DP[i-a] for a in A if i-a>=0)
print('First' if DP[k] else 'Second')

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

int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
   	ll n;
   	cin>>n;
   	ll a = n%1000;
   	if(a!=0){
   		a=1000-a;	
   	}
   	cout<<a<<"\n";
	return 0;
}

Measured memory_bytes: 3648
'use strict';
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    const s = input[0];
    if(s[0] != "A"){
        console.log("WA");
        return 0;
    }
    let numC = 0;
    for(let i = 1; i < s.length; i++){
        if(i >= 2 && i <= s.length - 2 && s[i] == "C"){
            numC++;
            if(numC > 1){
                console.log("WA");
                return 0;
            }
        }else if(s[i].search(/[a-z]/) == -1){
            console.log("WA");
            return 0;
        }
    }
    if(numC != 1){
        console.log("WA");
    }else{
        console.log("AC");
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>

using namespace std;

int main()
{
    long long int i,sum=0,y, z, max, mini;

    cin>> y >> z;
    max=z;
    mini=z;
    for (i=1;i<=y;i++)
    {
        sum+=z;
        if (z<mini)
        {
            mini=z;
        }
        if (z>max)
        {
            max=z;
        }   
        cin >> z;
    }
    cout << mini << " " << max << " " << sum<< endl;
    return 0;
}


Measured memory_bytes: 3108
N = gets.to_i
p = gets.split.map(&:to_i)

s = Array.new(N)
N.times { |i| s[i] = p[i]-1 != i ? true : false }

ans = 0
N.times do |i|
  
  if s[i] == false
    s[i] = true
    ans += 1
    
    s[i+1] = true if i+1 <= N - 1 
  end
end

puts ans

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

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

    bool s[1000] = {};
    int i = 0;
    long long mod = 2;

    while (n != 0) {
        if (n % mod) {
            s[i] = true;
            n -= pow(-2, i);
        }
        i++;
        mod *= 2;
    }

    for (i -= 1; i > 0; i--) cout << s[i];
    cout << s[0] << endl;
}

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

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
  
  int count=0;
  
  for(int i=0;i<s.size();i++)
  {
    if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C' )
    {
      count++;
    }
  }
  
  cout<<count<<endl;
}

Measured memory_bytes: 256
import bisect

n=int(input())
L=sorted(list(map(int,input().split())))

ans=0
for i in range(n-1):
  for j in range(i+1,n):
    idx=bisect.bisect_left(L,L[j]+L[i])
    ans+=max(0,idx-j-1)

print(ans)

Measured memory_bytes: 3188
#include <stdio.h>

int to_stop[10001];

int main(void) {
	int n,a,b,c,x;
	int i;
	int now_stop;
	while(1) {
		scanf("%d%d%d%d%d",&n,&a,&b,&c,&x);
		if((n|a|b|c|x)==0)break;
		for(i=0;i<n;i++) {
			scanf("%d",&to_stop[i]);
		}
		for(i=0,now_stop=0;i<=10000;i++) {
			if(x==to_stop[now_stop]) {
				now_stop++;
				if(now_stop>=n)break;
			}
			x=(a*x+b)%c;
		}
		printf("%d\n",i<=10000?i:-1);
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
using namespace std;
struct id{
    int c[101];
    int d=0;
    int f=0;
    int u=0;
};
int n,t=0;
id a[101];
void time(int e){
    if(a[e].u==0){
        a[e].u++;
        a[e].d=++t;
        for(int i=1;i<=n;i++){
            if(a[e].c[i]==1){
                time(i);
            }
        }
        a[e].f=++t;
    }
}
int main(){
    int x,y,z;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x>>y;
        for(int j=0;j<y;j++){
            cin>>z;
            a[x].c[z]=1;
        }
    }
    for(int i=1;i<=n;i++){
        if(a[i].u==0){
            time(i);
        }
    }
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<a[i].d<<" "<<a[i].f<<endl;
    }
    return 0;
}


Measured memory_bytes: 3032
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<limits>
#include<algorithm>
#include<numeric>
#include<utility>
#include<iomanip>

using ULLI = unsigned long long int;
using LLI = long long int;

using namespace std;

template<class T>
class ModCal{
private:
    const ULLI MAX = 1000000;
    ULLI mod;

    std::vector<T> fac;
    std::vector<T> finv;
    std::vector<T> inv;

    void COMinit() {
        fac.resize(MAX);
        finv.resize(MAX);
        inv.resize(MAX);

        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++){
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod%i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
public:
    ModCal(ULLI _mod){
        this->mod = _mod;
        ModCal<T>::COMinit();
    }
    ModCal(){
        this->mod = 0;
    }

    T add(T a, T b){
        T tmp;
        tmp = a + b;
        if(mod != 0) tmp %= mod;
        return tmp;
    }

    T sub(T a, T b){
        T tmp;
        tmp = a - b;
        if(mod != 0){
            if(tmp < 0) tmp += mod;
            tmp %= mod;
        }
        return tmp;
    }

    T mul(T a, T b){
        T tmp;
        tmp = a * b;
        if(mod != 0) tmp %= mod;
        return tmp;
    }

    T modinv(T a, T m){
        T b = m, u = 1, v = 0;
        while (b) {
            T t = a / b;
            a -= t * b; std::swap(a, b);
            u -= t * v; std::swap(u, v);
        }
        u %= m;
        if (u < 0) u += m;
        return u;
    }

    T div(T a, T b){
        if(mod == 0){
            return a / b;
        }
        a %= mod;
        T tmp = a * ModCal<T>::modinv(b, mod) % mod;
        return tmp;
    }

    T pow(T a, T b){
        T tmp = 1;
        while(b > 0){
            if(mod != 0){
                if(b & 1) tmp = tmp * a % mod;
                a = a * a % mod;
            }else{
                if(b & 1) tmp *= a;
                a *= a;
            }
            b >>= 1;
        }
        return tmp;
    }

    // 以下の関数はMODを設定しない限り使えない
    // 無理やり使う場合は "ModCal<T> cal(Tの最大値)" でオブジェクトを作る
    T com(T n, T k){
        if(n < k) return 0;
        if(n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
    }

    T fact(T n){
        return fac[n];
    }
};

struct S{
    int A;
    int B;
    double v;

    S(int A, int B){
        this->A = A;
        this->B = B;
    }

    bool operator<(const S &l) const{
        return static_cast<double>(B)/A < static_cast<double>(l.B)/l.A;
    };
};

int main() {
    ULLI A1, A2, A3;
    cin >> A1 >> A2 >> A3;

    cout << ((A1+A2+A3>=22)?"bust":"win") << endl;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif
#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define debug(x) cerr << #x << " = " << x << endl;
const int MOD=1e9+7;
const int INF=1<<29;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" ";}
inline int powerexp(int a,int b,int m){int res=1;while(b){if(b&1)res=res*a%m;a=a*a%m,b>>=1;}return res%m;}
const int N=1e5+11;
using ii=pair<int,int>;
vector<ii> g[N];
int l[N];
void dfs(int v,int u,int sum){
  l[v]=sum;
  for(auto it:g[v]){
	   if(it.f==u)continue;
	   dfs(it.f,v,sum+1ll*it.s);  
	}	
}
void solve(){
	int n,q,k;
	cin>>n;
	for(int i=0;i<n-1;i++){
	   int a,b,c;
	   cin>>a>>b>>c;
	   g[a].push_back({b,c});
	   g[b].push_back({a,c});	
	}
	cin>>q>>k;
	dfs(k,-1,0ll);
	for(int i=0;i<q;i++){
	  int x,y;
	  cin>>x>>y;
	  cout<<l[x]+l[y]<<endl;
	}
}
//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
    IOS;
    solve();
    #ifdef LOCAL_DEFINE
    cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
    #endif
}


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

using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) (x).begin(),(x).end()
#define int ll

#define pt pair<int, int>
#define x first
#define y second

void chkmin(int & a, int b) {
	a = min(a, b);
}

ld dist(pt a, pt b) {
	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}

bool check(string s) {
	auto t = s;
	reverse(all(t));
	return s == t;
}

const int MAXN = 10, MAXM = 1010;

int n, m, k;
char table[MAXN][MAXM];

int calc(int mask) {
	vector<int> sum(n);
	int ans = 0;
	for (int j = 0; j < m; j++) {
		for (int i = 0; i < n; i++) {
			sum[i] += table[i][j] == '1'; 
		}
		int now = 0;
		bool flag = false;
		for (int i = 0; i < n; i++) {
			now += sum[i];
			if (now > k) flag = true;
			if ((mask >> i) & 1) now = 0;
		}
		if (!flag) continue;
		ans++;
		for (int i = 0; i < n; i++) {
			sum[i] = table[i][j] == '1';
		}
		now = 0;
		flag = false;
		for (int i = 0; i < n; i++) {
			now += sum[i];
			if (now > k) flag = true;
			if ((mask >> i) & 1) now = 0;
		}
		if (!flag) continue;
		return n * m;
	}
	return ans;
}

int get(int mask) {
	return __builtin_popcount(mask);
}

void solve() {
	cin >> n >> m >> k;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) 
			cin >> table[i][j];

	int ans = n * m;
	for (int i = 0; i < (1 << (n - 1)); i++) {
		chkmin(ans, get(i) + calc(i));
	}
	cout << ans << endl;
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cout.precision(20);
	int t;
	//cin >> t;
	t = 1;
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
 
#define PII pair<LL,LL>
#define mem(v, x) memset(v, x, sizeof v)
 
#define si(x) scanf("%d", &x)
#define sii(x, y) scanf("%d %d", &x, &y)
#define siii(x, y, z) scanf("%d %d %d", &x, &y, &z)
 
#define sf(x) scanf("%lf", &x)
#define endl '\n'

#define FOR(i , N) for(int i = 0  ; i < N ; i++)
#define FOR1(i , N) for(int i = 1  ; i <= N ; i++)

template <typename T> T six(T &n){n = 0;bool neg = false;char c = getchar();while( c < '0' || c > '9'){if(c == '-') neg = true;c = getchar();}while(c >= '0' && c <= '9'){n = n*10 + c-48;c = getchar();}if(neg) n = ~(n-1);return n;}

using namespace std;
 
typedef long long LL;
 
int SET(int N,int pos){return N=N | (1<<pos);}
int RESET(int N,int pos){return N= N & ~(1<<pos);}
bool CHECK(int N,int pos){return (bool)(N & (1<<pos));}


/*
   D er iterative parlam na
   D te First WA Why???
   Probability Expected Value pari na
*/

LL add(LL x, LL y) {
   x %= 1000000007;
   y %= 1000000007;
   x += y;
   x %= 1000000007;
   return x;
}

string digit;
int D;
LL dp[2][2][10001][101];

LL digitDP(bool start = true, bool small = false, int pos = 0, int dv = 0) 
{
   if(pos == (int) digit.size()) {
      // cout << dv << endl;
      return (dv == 0) * 1LL;
   }
   LL &ret = dp[start][small][pos][dv];
   if(ret != -1) return ret;
   int dg = digit[pos] - '0';
   int maxx = (small == true) ? 9 : dg;
   LL ans = 0;
   for(int i = (start == true) ; i <= maxx ; i++)
      ans = add(ans, digitDP(false, small || (i < dg), pos + 1, (dv+ i) % D));
   if(start) ans = add(ans, digitDP(true, true, pos + 1, 0));
   return ret = ans % 1000000007;
}

LL solve()  {
   memset(dp, -1, sizeof dp);
   return digitDP(); // don’t count All zero (000....) case..
   // if you wanna count that, add a one :) 
}

int main()
{

#ifndef ONLINE_JUDGE // dont use this in toph/codemarshal
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif
    cin >> digit;
    cin >> D;
    cout << (((solve() % 1000000007) - 1 + 1000000007) % 1000000007) << endl;
}  


Measured memory_bytes: 32896
num = 0
line1=raw_input()
line2=raw_input()
line3=raw_input()
line4=raw_input()
num1 = 0
num2 = 0

A=line2.split(" ")
B=line4.split(" ")


for b in B:
    num1 = int(b)
    for a in A:
        num2 = int(a)
        if num1 == num2:
            num += 1 
            break
print(num)


Measured memory_bytes: 5072
#include <stdio.h>
int main(void){
    int x;
    scanf("%d",&x);
    if (x%7==0){
        printf("thu\n");
    }
    else if (x%7==1){
        printf("fri\n");
    }
    else if (x%7==2){
        printf("sat\n");
    }
    else if (x%7==3){
        printf("sun\n");
    }
    else if (x%7==4){
        printf("mon\n");
    }
    else if (x%7==5){
        printf("tue\n");
    }
    else if (x%7==6){
        printf("wed\n");
    }
    return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <set>
using namespace std;
struct union_find{
    vector<int> par; 
    vector<int> size;
    //1からnまで初期化:par[i] = i(1<=i<=n)
    union_find(int n){
        par.push_back(0);
        for(int i = 1;i<=n;i++){
            par.push_back(i);
            size.push_back(1);
        }
    }
    int root(int a){
        if (par[a] == a) return a;
        par[a] = root(par[a]);
        return root(par[a]);
    }
    void unite(int a,int b){
        if (root(a) == root(b)) return;
        size[root(b)]+=size[root(a)];
        par[root(a)] = root(b);
    }
    bool same(int a,int b){
        return (root(a) == root(b));
    }
    //頂点aが含まれる木の大きさ(頂点数)
    int treesize(int a){
        return size[root(a)];
    }
};
int main(){
    int n,m;
    cin >> n >> m;
    union_find tree(n);
    int x,y,z;
    for(int i = 0;i<m;i++){
        cin >> x >> y >> z;
        tree.unite(x,y);
    }
    set<int> ans;
    for(int i = 1;i<=n;i++){
        ans.insert(tree.root(i));
    }
    cout << ans.size() << endl;
}

Measured memory_bytes: 5748
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }

const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
   fac[0] = fac[1] = 1;
   finv[0] = finv[1] = 1;
   inv[1] = 1;
   for (int i = 2; i < MAX; i++){
       fac[i] = fac[i - 1] * i % MOD;
       inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
       finv[i] = finv[i - 1] * inv[i] % MOD;
   }
}

// 二項係数計算
long long COM(int n, int k){
   if (n < k) return 0;
   if (n < 0 || k < 0) return 0;
   return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(int argc, char const *argv[]) {
  ll x,y;
  cin >> x >> y;
  ll m=(2*x-y)/3,n=(2*y-x)/3;

  if((x+y)%3!=0 || m<0 || n<0){
    cout << "0" << endl;
    return 0;
  }
  COMinit();

  cout << COM(m+n,n)%MOD << endl;

  return 0;
}


Measured memory_bytes: 23808
unittest
{
	assert( [ "2 2" ].parse.expand.solve == 1 );
	assert( [ "5 7" ].parse.expand.solve == 24 );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto ab = input.front.split.to!( int[] );
	
	return tuple( ab[ 0 ], ab[ 1 ] );
}

auto solve( in int a, in int b )
{
	return ( a - 1 ) * ( b - 1 );
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> PA;
typedef priority_queue<int, vector<int>, greater<int> > PQG;
#define REP(i, a, n) for(ll i = (ll) a;i < (ll) n;i++)
#define fi first
#define se second
#define pb push_back
#define INF 1000000009
#define INFL 1000000000000000018
#define MOD 1000000007
#define MAXN 200005
#define MAXM 200005

ll n, a[MAXN], sum, sum2, ans, ans2;

int main()
{
    cin >> n;
    REP(i, 0, n){
        cin >> a[i];
        if(i == 0){
            if(a[i] > 0){
                sum = a[i];
                ans2 += a[i] + 1;
                sum2 = -1;
            }
            else if(a[i] < 0){
                sum = 1;
                sum2 = a[i];
                ans += 1 - a[i];
            }
            else{
                sum = 1;
                sum2 = -1;
                ans++;
                ans2++;
            }

            continue;
        }
        if(sum > 0 && sum + a[i] < 0 || sum < 0 && sum + a[i] > 0){
            sum += a[i];
        }
        else{
            ans += abs(sum + a[i]) + 1;
            if(sum > 0)sum = -1;
            else sum = 1;
        }
    }
    REP(i, 1, n){
        if(sum2 > 0 && sum2 + a[i] < 0 || sum2 < 0 && sum2 + a[i] > 0){
            sum2 += a[i];
        }
        else{
            ans2 += abs(sum2 + a[i]) + 1;
            if(sum2 > 0)sum2 = -1;
            else sum2 = 1;
        }
    }
    ans = ans < ans2 ? ans : ans2;
    cout << ans << endl;


    return 0;
}
/*
*/





Measured memory_bytes: 1024
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        int sum = 0;
        int m = n;
        while (n > 0)
        {
            int dig = n % 10;
            sum += dig;
            n /= 10;
        }
        if (m % sum == 0)
        {
            System.out.println("Yes");
        }
        else
        {
            System.out.println("No");
        }
    }
}


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

ll ans;

ll gcd(ll a,ll b){//b is not bigger
	if(b==0) return a;
	ans+=(a/b)*2*b;
	return gcd(b,a%b);
}

int main(){
	ll n,x;
	cin>>n>>x;
	if(n-x<x) x=n-x;
	ans=n;
	ans-=gcd(n-x,x);
	cout<<ans<<endl;
}

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

typedef long long int ll;

ll ans;
ll cur;
vector<ll>g[200005];
ll vis[200005];


void dfs (ll src) {
	cur++;
	vis[src] = 1;
	
	for (ll i=0 ; i<(ll)g[src].size() ; i++) {
		ll neigh = g[src][i];
		if (vis[neigh]==0) dfs(neigh);
	}
}

int main () {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    ll n,m;
    cin >> n >> m;
    
    for (ll i=0 ; i<=n ; i++) {
		g[i].clear();
		vis[i] = 0;
	}
	
	ll u,v;
	for (ll i=0 ; i<m ; i++) {
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	ans = 0;
	
	for (ll i=1 ; i<=n ; i++) {
		if (vis[i]==0) {
			cur = 0;
			dfs(i);
			ans = max(ans, cur);
		}
	}
	
	cout << ans << "\n";
    
}


Measured memory_bytes: 22332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i,m,n) for(ll i = (m); i < (n); i++)
#define all(v) v.begin(), v.end()
#define print(x) cout << (x) << endl
//宣言
int K ,S;

void solve(){
    int cnt = 0;
    for(int x = 0;x <= min(S,K);x++){
        cnt += max(0,min(K,S-x) -max(0,S-x-K) +1);
    }
    print(cnt);
}

int main() {
    //入力忘れるなよ～//vec = vector<ll>(N,0);もね
    cin >> K >> S;

    solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, A[100000], cnt, MIN;
ll res;
int main() {
	cin >> N;
	MIN = intmax;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		if (A[i] < 0) {
			++cnt;
			A[i] = -A[i];
		}
		MIN = min(MIN, A[i]);
	}
	if (cnt & 1) {
		for (int i = 0; i < N; ++i) {
			res += A[i];
		}
		res -= MIN * 2;
	}
	else {
		for (int i = 0; i < N; ++i) {
			res += A[i];
		}
	}
	cout << res << endl;
}

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

int GCD(int a, int b) {
  return b ? GCD(b, a%b) : a;
}

int main() {
  int N; cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<int> left(N+1, 0), right(N+1, 0);
  // 累積 GCD
  // left[p] := [0, p) の GCD
  // right[p] := [p, N) の GCD
  for (int i = 0; i < N; i++) left.at(i+1) = GCD(left.at(i), A.at(i));
  for (int i = N-1; i >= 0; i--) right.at(i) = GCD(right.at(i+1), A.at(i));
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int l = left.at(i);  // [0, i)
    int r = right.at(i+1);  // [i+1, N)
    ans = max(ans, GCD(l, r));  // GCD(l, r) ... A[i] 以外
  }
  cout << ans << endl;
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;



void solve(){
	ll a,b,ans=0;
	cin>>a>>b;
	while(a<=b){
		ans++;
		a*=2;
	}
	cout<<ans<<'\n';

}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	//ll t;cin>>t;while(t--)
	solve();

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;
//printf("%.10f\n", n);

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}

ll test[1234][1234];
signed main() {
	/*ll n, x, l, q, a = 0, b = 0, c = 0, d = 0, ans = 0; cin >> n >> x;
	for (int h = 0; h < n; h++) {
		cin >> test[h];
		if (test[h] % 2 == 0) { a++; }
		else { b++; }
	}
	b /= 2; a += b;
	cout << modpow(2, a) << endl;*/
	ll D, c, s; cin >> D;
	for (int h = 0; h < 26; h++) {
		cin >> c;
	}
	for (int i = 0; i < D; i++) {
		for (int h = 0; h < 26; h++) {
			cin >> test[i][h];
		}
	}
	vector<ll> ng;
	for (int h = 0; h < D; h++) {
		if (h % 26 == 0) { ng.clear(); }
		ll a = 0, ans1 = 0, ans2 = 0;
		for (int i = 0; i < 26; i++) {
			if (a != ng.size() && i == ng[a]) { a++; continue; }
			if (ans1 < test[h][i]) {
				ans1 = test[h][i]; ans2 = i;
			}
		}
		cout << ans2 + 1 << endl;
		sort(ng.begin(), ng.end());
	}
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  int a = N%10;
  if(a==3)cout << "bon" << endl;
  else if(a == 0||a==1||a==6||a==8)cout << "pon" << endl;
  else cout << "hon" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  rep(i,n-1){
    if(a[i]==a[i+1]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 1024