akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define in(s,x) s.find(x) != s.end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<pair<int,int>> VPII;
const ll mod=1000000007;
const ll INF= 1LL<<60-1;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << pair_var.first << " " << pair_var.second ;return os;}
template<class tContainer>
long long sum(tContainer const& iContainer) {return  std::accumulate(std::begin(iContainer), std::end(iContainer), 0LL);}

// head


int m,n,k,res,tmp,tmp2,tmp3,h,w,x,y;
VI a;
deque<PII> que;
string s;
//VI b;
vector<PII> g[2100600];
int b[2100000];
int c[210] = {};
int dp[1000000];
set<int> ch;

signed main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>k;
  res = 0;
  per(i,1,k){
    dp[i] = powmod(k/i,n);
    for(int j=i+i;j<=k;j+=i){
      dp[i]-=dp[j];
    }
    res += dp[i]*i%mod;
  }
  cout << res%mod << '\n';
}



Measured memory_bytes: 53632
#include <cstdio>
#include <cstring>
char c[105];
int len,s1,s2;
inline bool is(int f,int t){
	if((t-f+1)&1){
		for(int i=1;i<=(t-f+1)/2;++i)
			if(c[f+(t-f+1)/2-i] != c[f+(t-f+1)/2+i])
				return false;
	}
	else {
		for(int i=1;i<=(t-f+1)/2;++i)
			if(c[f+(t-f+1)/2-i] != c[f+(t-f+1)/2+i-1])
				return false;
	}
	return true;
}
int main(){
	scanf("%s",&c);
	len = strlen(c);
	if(is(0,len-1)&&is(0,(len-1)/2-1)&&is((len+3)/2-1,len-1))printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long llong;

#define MAX 100
const llong mod = 1000000000 + 7;

int main()
{
  int N, X[MAX];
  int ans = 100 * 100 * 100;

  scanf("%d", &N);
  for (int i = 0; i < N; i++)
  {
    scanf("%d", &X[i]);
  }

  sort(X, X + N);

  // 点P
  for (int i = X[0]; i <= X[N - 1]; i++)
  {
    int sum = 0;
    for (int j = 0; j < N; j++)
    {
      sum += (X[j] - i) * (X[j] - i);
    }

    ans = min(ans, sum);
  }

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 1728
n = int(input())
word_list = ['AC','WA','TLE','RE']
counter = [0,0,0,0]
for i in range(n):
    word = input()
    if word == 'AC':
        counter[0] += 1
    elif word == 'WA':
        counter[1] += 1
    elif word == 'TLE':
        counter[2] += 1
    elif word == 'RE':
        counter[3] += 1
    else:
        pass
for i in range(4):
    print(word_list[i] + ' x',counter[i])

Measured memory_bytes: 69908
# Acceptance of input

import sys

file_input = sys.stdin

X, Y, E = map(int, file_input.readline().split())

v_num = X + Y + 2

adj_mat = [[0] * (v_num) for i in range(v_num)]

for line in file_input:
    x, y = map(int, line.split())
    adj_mat[x][X + y] = 1

s = X + Y
t = s + 1

for i in range(X):
    adj_mat[s][i] = 1

for i in range(X, s):
    adj_mat[i][t] = 1

# Dinic's algorithm

import collections

# BFS for residual capacity network to construct level graph
def bfs(start, goal, parent):
    unvisited = [True] * v_num
    queue = collections.deque()
    queue.append(start)
    unvisited[start] = False
    while queue:
        u = queue.popleft()
        for v, r_capacity in enumerate(adj_mat[u]):
            if unvisited[v] and (r_capacity > 0):
                parent[v].append(u)
                queue.append(v)
                unvisited[v] = False
    return unvisited[goal]

# DFS for level graph and construct blocking flow
def dfs(goal, path, parent, blocking_flow):
    v = path[-1]
    if v == goal:
        aug_path_flow = 10000
        for x, y in zip(path[1:], path[:-1]):
            aug_path_flow = min(aug_path_flow, adj_mat[x][y])
        for x, y in zip(path[1:], path[:-1]):
            adj_mat[x][y] -= aug_path_flow
            adj_mat[y][x] += aug_path_flow
        blocking_flow[0] += aug_path_flow
    else:
        for u in parent[v]:
            path.append(u)
            dfs(goal, path, parent, blocking_flow)
            path.pop()

def dinic(source, sink):
    max_flow = 0
    parent = [[] for i in range(v_num)]
    while not bfs(source, sink, parent):
        blocking_flow = [0]
        path = [sink]
        # search in reverse direction from sink
        dfs(source, path, parent, blocking_flow)
        max_flow += blocking_flow[0]
        parent = [[] for i in range(v_num)]
    return max_flow

# output
print(dinic(s, t))

Measured memory_bytes: 8348
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C = MAP()

if C <= A+B+1:
	print(B+C)
else:
	print(B+A+B+1)


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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int a[100000];

int main() {
    int n, m;
    ll ans = 0;
    cin >> n >> m;
    priority_queue<int> que;
    int tmp;
    rep(i, n) {
        cin >> tmp;
        que.push(tmp);
    }
    rep(i, m) {
        tmp = que.top() / 2;
        que.pop();
        que.push(tmp);
    }
    rep(i, n) {
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 892
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key
import heapq

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    N, M = rip()
    P = [0] * M
    S = [""] * M
    for i in range(M):
        ss = rsa()
        P[i] = int(ss[0]) - 1
        S[i] = ss[1]
    
    accept = [False] * N
    penalty = [0] * N
    for i in range(M):
        if S[i] == 'AC':
            accept[P[i]] = True
            continue
        if not accept[P[i]]:
            penalty[P[i]] += 1
    
    ac_count = 0
    penalty_count = 0
    for i in range(N):
        if accept[i]:
            ac_count += 1
            penalty_count += penalty[i]
    
    print("{0} {1}".format(ac_count, penalty_count))



if __name__ == "__main__":
    main()


Measured memory_bytes: 23880
while True:
  T,H,S=map(int,input().split())
  if T==H==S==-1:
    break
  x=120*60-(T*3600+H*60+S)
  print("{:02d}:{:02d}:{:02d}".format(x//3600,(x%3600)//60,x%60))
  x*=3
  print("{:02d}:{:02d}:{:02d}".format(x//3600,(x%3600)//60,x%60))


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

int main(){
    int A,B; cin>>A>>B;

    int ans=0;
    for(int i=A;i<=B;i++){
        string str=to_string(i);
        if(str[0]==str[4]&&str[1]==str[3]) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

h,w=map(int,input().split())
a=[input() for i in range(h)]

cnt=0

itta=[[10**9]*w for i in range(h)]

d=deque()
aaa=d.append
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            aaa([i,j])
            itta[i][j]=0

# print(d)
# print(itta)

while d:
    cnt+=1
    for l in range(len(d)):
        nh,nw=d.popleft()
        for i in range(4):
            d1,d2=direction[i]
            if 0<=nh+d1<h and 0<=nw+d2<w:
                if itta[nh+d1][nw+d2]==10**9:
                    itta[nh+d1][nw+d2]=cnt
                    aaa([nh+d1,nw+d2])
    # print(d)

# print(itta)
print(cnt-1)

Measured memory_bytes: 140892
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;

/* --------------------------------------------------- */

int n;

void dfs(string s, char c) {
    if(s.size() == n) {
        cout << s << endl;
        return;
    } else {
        for(char alp = 'a'; alp <= c; alp++) {
            char v;
            if(alp == c) v = c + 1;
            else v = c;

            dfs(s + alp, v);
        }
    }
}

int main() {
    cin >> n;

    dfs("", 'a');

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll max_N = 2e5 + 10, INF = 1e15, MOD = 1e9 + 7, max_tree = 4 * max_N;
ll N, M;
vector<pair<ll, ll>> endings[max_N];
ll seg[max_tree], lazy[max_tree];

void update_lazy(ll t_idx, ll s, ll e)
{
    if (!lazy[t_idx])
        return;
    seg[t_idx] += lazy[t_idx];
    if (s != e)
    {
        lazy[t_idx * 2] += lazy[t_idx];
        lazy[t_idx * 2 + 1] += lazy[t_idx];
    }
    lazy[t_idx] = 0;
}

void seg_update(ll s, ll e, ll l, ll r, ll val, ll t_idx) // [s,e] of segment tree idx     and [l,r] is array update range
{
    update_lazy(t_idx, s, e);
    if(e < s)
        return ;
    if (l <= s && e <= r)
    {
        lazy[t_idx] = val;
        update_lazy(t_idx, s, e);
        return ;
    }
    if (e < l || r < s)
        return ;
    ll mid = (s + e) / 2;
    seg_update(s, mid, l, r, val, t_idx * 2);
    seg_update(mid + 1, e, l, r, val, t_idx *2 + 1);
    seg[t_idx] = max(seg[t_idx*2], seg[t_idx *2 + 1]);
}

ll seg_query(ll s, ll e, ll l, ll r, ll t_idx)
{
    update_lazy(t_idx, s, e);
    if(e < s || r < l)
        return 0;
    if (l <= s && e <= r)
        return seg[t_idx];
    if (e < l || r < s)
        return -INF;
    ll mid = (s + e) / 2;
    ll lres = seg_query(s, mid, l, r, t_idx * 2);
    ll rres = seg_query(mid + 1, e, l, r, t_idx *2 + 1);
    return max(lres, rres);
}

int main()
{
    cin >> N >> M;
    ll s, e, cost;
    for (int i = 0; i < M; ++i)
    {
        cin >> s >> e >> cost;
        endings[e].push_back({s, cost});
    }
    for (int i = 1; i <= N; ++i)
    {
        ll new_val = max(seg_query(1, N, 1, i - 1, 1), 0LL);
        seg_update(1, N, i, i, new_val, 1);
        for (auto interval : endings[i])
            seg_update(1, N, interval.first, i, interval.second, 1);
    }
    ll res = seg_query(1, N, 1, N, 1);
    res = max(res, 0LL);
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 21760
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please



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


	int N, M;
	cin >> N >> M;
	int A[100];
	int goukei = 0;
	rep(i, N) {
		cin >> A[i];
		goukei += A[i];
	}
	int sakai = (goukei + 4 * M - 1) / (4 * M);

	int kotae = 0;
	rep(i, N) if (A[i] >= sakai) kotae++;

	if (kotae >= M) co("Yes");
	else co("No");




	Would you please return 0;
}

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

#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int A, B, Q;
    cin >> A >> B >> Q;

    vector<ll> s(A), t(B), q(Q);
    rep(i, A) cin >> s[i];
    rep(i, B) cin >> t[i];
    rep(i, Q) cin >> q[i];

    rep(i, Q) {
        ll sr = lower_bound(s.begin(), s.end(), q[i]) - s.begin();
        ll tr = lower_bound(t.begin(), t.end(), q[i]) - t.begin();
        ll sl = sr - 1;
        ll tl = tr - 1;

        if (sr < A) sr = s[sr] - q[i];
        else sr = INF;
        if (sl >= 0) sl = s[sl] - q[i];
        else sl = INF;
        if (tr < B) tr = t[tr] - q[i];
        else tr = INF;
        if (tl >= 0) tl = t[tl] - q[i];
        else tl = INF;

        ll ans = abs(sr) + abs(tr - sr);
        ans = min(ans, abs(sr) + abs(tl - sr));
        ans = min(ans, abs(sl) + abs(tr - sl));
        ans = min(ans, abs(sl) + abs(tl - sl));

        ans = min(ans, abs(tr) + abs(sr - tr));
        ans = min(ans, abs(tr) + abs(sl - tr));
        ans = min(ans, abs(tl) + abs(sr - tl));
        ans = min(ans, abs(tl) + abs(sl - tl));

        cout << ans << endl;
    }

    return 0;
}

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

ans = 0
a_n = 1
for i in range(n):
    if (a[i] == a_n):
        a_n += 1
    else:
        ans += 1
    if (i == n - 1 and a_n == 1):
        ans = -1

print(ans)


Measured memory_bytes: 26268
import sys, math, collections, heapq, itertools
F = sys.stdin
def single_input(): return F.readline().strip("\n")
def line_input(): return F.readline().strip("\n").split()
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while a % b > 0: a, b = b, a % b
    return b
  
def solve():
    N, K = map(int, line_input())
    V = [int(v) for v in line_input()]
    maxpoint = 0
    for i in range(N + 1):
        for j in range(N - i + 1):
            if i + j <= min(N, K):
                trash = []
                heapq.heapify(trash)
                point = sum(V[:i])
                for k in range(j):
                    point += V[-1 - k]
                    heapq.heappush(trash, V[-1-k])
                for a in range(i):
                    heapq.heappush(trash, V[a])
                count = 0
                while trash and count < K - (i + j):
                    bye = heapq.heappop(trash)
                    count += 1
                    if bye > 0: break
                    else: 
                        point -= bye
                maxpoint = max(maxpoint, point)
    print(maxpoint)
    return 0
  
if __name__ == "__main__":
    solve()

Measured memory_bytes: 3440
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a1,a2,a3;
  cin >> a1 >> a2 >> a3;
  int s = a1+a2+a3;
  if (s >= 22){
  cout << "bust" << endl;}else{
    cout << "win" <<endl;
  }
}

Measured memory_bytes: 256
/*
 Educational Dp Contest Atcoder
 
 */

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define all(x) x.begin(),x.end()

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}

const ll MOD =998244353;
const ll hell=1000000007;
const int INF=1e16;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

const int N=1e5+5;
int h[N+1];int dp[N];
void solve()
{
    
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>h[i];
    dp[1]=0;
    if(n>=2)
    dp[2]=abs(h[2]-h[1]);
    for(int i=3;i<=n;i++)
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    cout<<dp[n]<<endl;
}

int32_t main()
{
    
    IOS;
    //FILE *fin = freopen("in","r",stdin);
    //FILE *fout = freopen("out","w",stdout);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


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

int main() {
  int N,M,R,Z=2000000000,A=1;
  cin>>N>>M>>R;
  vector<int> q(R);
  vector<int> p(R);
  for(int i=0;i<R;i++){
    cin>>q.at(i);
    q.at(i)--;
    p.at(i)=i;
    A*=(i+1);
  }
  vector<vector<int>> d(N,vector<int>(N,2000000000));
  for(int i=0;i<M;i++){
    int a,b,c;
    cin>>a>>b>>c;
    a--,b--;
    d.at(a).at(b)=c;
    d.at(b).at(a)=c;
  }
  for (int k = 0; k < N; k++){       // 経由する頂点
    for (int i = 0; i < N; i++) {    // 始点
      for (int j = 0; j < N; j++) { // 終点
        if(d.at(i).at(k)!=2000000000&&d.at(k).at(j)!=2000000000){
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
      }
    }
  }
  for(int i=0;i<=A;i++){
    int C=0;
    for(int j=1;j<R;j++){
      C+=d.at(q.at(p.at(j-1))).at(q.at(p.at(j)));
    }
    Z=min(Z,C);
    next_permutation(begin(p),end(p));
  }
  cout<<Z<<endl;
                        
    
}

Measured memory_bytes: 384
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;
struct BIT
{
	// [0,size)
	vector<int> tree;
	int size;
	BIT(int s){
		size=s;
		tree.resize(size+1);
	}
	void init(int s){
		size=s;
		tree.clear();
		tree.resize(size+1);
	}
	void add(int i,int v){
		i++;
		while(i<=size){
			tree[i]+=v;
			i+=(i&-i);
		}
	}

	// [0,i]
	int collect(int i){
		i++;
		int r=0;
		while(i>0){
			r+=tree[i];
			i-=(i&-i);
		}
		return r;
	}

	// [a,b]
	int collect(int a, int b){
		return collect(b)-collect(a-1);
	}
};

const int L=2e5+1;
int ms[L];
deque<int> ps[128];
int main() {
	string S;
	cin >> S;
	BIT b(S.size());
	for(int i=0;i<S.size();i++)
	{
		int c=S[i];
		ps[c].push_back(i);
	}
	int k=0;
	LL ret=0;
	bool mid=S.size()%2==0;
	for(int i=0;k<S.size()/2;i++)
	{
		int c=S[i];
		if(ps[c].size()==0||ps[c].back()<i)
		{
			continue;
		}
		if(ps[c].size()==1)
		{
			//cerr << "aaa " << i << endl;
			if(mid)
			{
				cout << -1 << endl;
				return 0;
			}
			mid=true;
			ret += S.size()/2-k;
			continue;
		}
		ps[c].pop_front();
		int j=ps[c].back();
		ps[c].pop_back();
		//cerr << char(c) << ": " << i << ", " << j << " ";
		b.add(j,1);
		int v=b.collect(j-1);
		//cerr << j << ", " << (int)S.size()-1-k-j+v << endl;
		ret += S.size()-1-k-j+v;
		k++;
	}
	cout << ret << endl;


	return 0;
}



Measured memory_bytes: 2288
n,k=map(int,input().split())
li=list(map(int,input().split()))
H=[0]*(n)
walk=[]
x=1
l=0
e=0
while True:
    walk.append(x)
    if H[x-1]==0:
        H[x-1]=1
    else:
        dd=[i for i, j in enumerate(walk) if j == x ]
        l=1
        break
    x=li[x-1]
    e+=1
    if e==k:
        break
if l==1:
    ran=dd[1]-dd[0]
    if k>=dd[0]:
        k-=dd[0]
    kk=k%ran
    print(walk[dd[0]+kk])
else:
    print(x)

Measured memory_bytes: 32348
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <cctype>
#include <bits/stdc++.h>
#include <queue>

using namespace std;
// for loop
#define F(i, L, R) for(long i = L; i < R; i++)
#define FE(i, L, R) for(long i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(long i = L; i > R; i--)
#define FRE(i, L, R) for(long i = L; i >= R; i--)

// data types
#define Int long
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]
#define pb push_back
#define InputV(a, n) F(i,0,n){long l; cin >> l; a.pb(l);}

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323


#define TST 0

int main() {
#if TST==1
    ifstream in ("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    for(int i = 0;i < 5;i++){
        int num;
        cin >> num;
        if(num == 0){
            cout << i+1 << endl;
        }
    }


#if TST==1

#endif
}



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

int main() {
  int N, l, r, sum;
  cin >> N;
  sum = 0;
  
  for (int i = 0; i < N; i++) {
    cin >> l >> r;
    sum += r - l + 1;
  }
  
  cout << sum << endl;
}

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

int main() {
    int N, K, sum = 0;
    cin >> N >> K;
    vector<int> l(N);
    for (int i = 0; i < N; i++) {
        cin >> l.at(i);
    }

    sort(l.begin(), l.end(), greater<int>());
    for (int i = 0; i < K; i++) {
        sum += l.at(i);
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

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

    vector<double> x(n);
    vector<string> u(n);

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

    double ans = 0;

    for(int i = 0; i < n; i++){
        if(u[i] == "JPY"){
            ans += x[i];
        }else{
            ans += x[i]*380000.0;
        }
    }

    cout << setprecision(17) << fixed;
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
D = Counter([int(i) for i in input().split()])
m = int(input())
T = Counter([int(i) for i in input().split()])

for k, v in T.items():
    if k not in D.keys():
        print("NO")

        quit()
    else:
        if D[k] < T[k]:
            print("NO")
            quit()
        else:
            continue

print("YES")


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

//#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
/* }}} */
signed main() 
{
  string s;
  cin>>s;
  int f,l;
  rep(i,s.length())
  {
    if(s[i]=='A')
    {
      f=i;
      break;
    }
  }
  rep(i,s.length())
  {
    if(s[i]=='Z') l=i;
  }
  print(l-f+1);

  return 0;
}

Measured memory_bytes: 720
import sys
from heapq import heappush, heappop


I = sys.stdin.readlines()
N, Q = map(int, I[0].split())
P = []
for i in range(1, N + 1):
    s, t, x = map(int, I[i].split())
    P.append((s - x, t - 1 - x, x))
P.sort()
INF = float('inf')
P.append((INF, INF, INF))

q = []
cur = 0
s, t, x = P[cur]
for i in range(N + 1, N + Q + 1):
    d = int(I[i])
    while s <= d:
        heappush(q, (x, t))
        cur += 1
        s, t, x = P[cur]
    ans = -1
    while len(q) > 0:
        x1, t1 = q[0]
        if d <= t1:
            ans = x1
            break
        else:
            heappop(q)
    print(ans)



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

int main() {
  int X, A;
  cin >> X >> A;

  if (X < A)
    cout << 0 << endl;
  else
    cout << 10 << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;i++)


int main()
{
    /*A
    vector <int> a(3);
    for(int i=0;i<3;i++)
    {
        cin>>a[i];
    }

    sort(a.rbegin(),a.rend());
    cout<<a[1]+a[2]<<endl;
    */

    int n;
    cin>>n;
    int minimum=1000010;
    vector <int> w(n);
    for(int i=0; i<n; i++)
    {
        cin>>w[i];
    }

    for(auto it = w.begin(); it != w.end(); ++it)
    {
        int sum1 = accumulate(w.begin(),it,0);
        int sum2 = accumulate(it,w.end(),0);
        minimum = min(minimum,abs(sum1-sum2));
    }

    cout<<minimum<<endl;
    return 0;
}

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

int main(){
    int N, K;
    int l, now;
    cin >> N >> K;
    double P=0;
    l = int(log2(K)) + 1;
    if(N <= K-1){
        now = pow(2, l);
        for(int i=1; i<=N; i++){
            while(now*i>=K){
                l--;
                now /=2;
            }
            l++;
            now*=2;
            P += (double)1.0/(N*now);
        }
    }else{
        now = pow(2, l);
        for(int i=1; i<=K-1; i++){
            while(now*i>=K){
                l--;
                now /=2;
            }
            l++;
            now*=2;
            P += (double)1.0/((K-1)*now);
        }
        P = (N-(K-1.0))/N + P*(K-1.0)/N;
    }
    printf("%.32f", P);
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<vector<ll>> a(n,vector<ll>(n));
    rep(i,n){
        rep (j,n) cin >> a.at(i).at(j);
    }
    ll ans=0;
    rep(i,n){
        for (int j=i+1;j<n;j++){
            int t=0;
            rep(k,n){
                if (k==i || j==k) continue;
                if (a.at(i).at(j)>a.at(i).at(k)+a.at(k).at(j)){
                    cout << -1 << endl;return 0;
                }
                if (a.at(i).at(j)==a.at(i).at(k)+a.at(k).at(j)) t=1;
            }
            if (t==0) ans+=a.at(i).at(j);
        }
    }
    cout << ans << endl;
}


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

class Main{
    public static void main(String[] args) throws IOException
	{
		Scanner sc = new Scanner(System.in);
		try{	
			int a = sc.nextInt();
			int b = sc.nextInt();
    		System.out.printf("%d %d\n", a*b, 2*(a+b) );
		}
		catch(Exception e){}
    }
}



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

int main(){
  long long int A,B,tmp;
  cin >> A >> B;
  long long int C=A;
  long long int D=B;
  if(A<B){
    tmp=A;
    A=B;
    B=tmp;
  }
  while(A%B!=0){
    tmp=A;
    A=B;
    B=tmp%B;
  }
  cout << C*D/B << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }
int main(){
  int N;
  cin >> N;
  vector<int> buka(N);
  for(int i=1; i<N; ++i){
    int A;
    cin >> A;
    ++buka[A-1];
  }
  for(int i=0; i<N; ++i) cout << buka[i] << endl;
}

Measured memory_bytes: 4048
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
#include<iostream>
#include<queue>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	if(b-a==c-b)puts("YES");
	else puts("NO");
	return 0;
	}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#define rep(i,n) for(int i = 0;i < (n); ++i)
using namespace std;

typedef long long LL;
typedef long double LD;

int main(void){
    int n;
    string s;
    cin >> n >> s;
    LL red = 0, green = 0, blue = 0; 
    for(int i = 0;i < n; i++){
        if(s[i] == 'R')red++;
        else if(s[i] == 'G')green++;
        else if(s[i] == 'B')blue++;
    }
    LL ans = red * green * blue;
    int k;
    for(int i = 1; i <= n; i++){
        for(int k = i + 2; k <= n; k += 2){
            int j = (i + k) / 2;
            if(s[i - 1] + s[j - 1] + s[k -1 ]  == 'R' + 'G' + 'B'){
                ans--;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
n, m = gets.chomp.split(' ').map(&:to_i)
xs = gets.chomp.split(' ').map(&:to_i).sort
diffs = xs.each_cons(2).map.with_index{|a, i| {i: i + 1, d: (a[1] - a[0]).abs} }.sort{|a, b| b[:d] - a[:d] }
splitter = diffs.take(n - 1).map{|h| h[:i]}.sort
split_num = ([0] + splitter + [xs.length]).each_cons(2).map{|x| x[1] - x[0]}
splitted = split_num.map{|x| xs.shift(x)}
puts splitted.map{|a| a.last - a.first}.reduce(:+)


Measured memory_bytes: 44780
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdio.h>

int main(int argc, const char * argv[]) {
    long long n,ans=0;
    scanf("%lld",&n);
    if(n==1){
        printf("0");
        return 0;
    }
    long long CN=n;
    for(long long i=2;i<=sqrt(CN)+1;i++){
        if(n%i==0){
            long long cnt=0;
            while(n%i==0){
                n/=i;
                cnt++;
            }
            for(long long j=1;cnt>=j;j++){
                cnt-=j;
                ans++;
            }
            
        }
    }
    if(n>1)ans++;
    printf("%lld",ans);
    
    return 0;
}


Measured memory_bytes: 2152
#include <stdio.h>
#include <stack>
#include <math.h>
#include <queue>

using namespace std;

int W,H;
bool visited[20][20];
char table[20][21];

struct Tile{
	int row,col;
};

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= H-1 && col >=0 && col <= W-1)return true;
	else{
		return false;
	}
}

void func(int row,int col){
	queue<Tile> Q;
	Tile tile;
	tile.row = row;
	tile.col = col;

	Q.push(tile);

	Tile tmp;
	while(!Q.empty()){
		tmp = Q.front();
		Q.pop();

		if(rangeCheck(tmp.row-1,tmp.col) == true && visited[tmp.row-1][tmp.col] == false && table[tmp.row-1][tmp.col] == '.'){
			visited[tmp.row-1][tmp.col] = true;

			Tile newTmp;
			newTmp.row = tmp.row-1;
			newTmp.col = tmp.col;
			Q.push(newTmp);
		}
		if(rangeCheck(tmp.row+1,tmp.col) == true && visited[tmp.row+1][tmp.col] == false && table[tmp.row+1][tmp.col] == '.'){
			visited[tmp.row+1][tmp.col] = true;
			Tile newTmp2;
			newTmp2.row = tmp.row+1;
			newTmp2.col = tmp.col;
			Q.push(newTmp2);
		}
		if(rangeCheck(tmp.row,tmp.col-1) == true && visited[tmp.row][tmp.col-1] == false && table[tmp.row][tmp.col-1] == '.'){
			visited[tmp.row][tmp.col-1] = true;
			Tile newTmp3;
			newTmp3.row = tmp.row;
			newTmp3.col = tmp.col-1;
			Q.push(newTmp3);
		}
		if(rangeCheck(tmp.row,tmp.col+1) == true && visited[tmp.row][tmp.col+1] == false && table[tmp.row][tmp.col+1] == '.'){
			visited[tmp.row][tmp.col+1] = true;
			Tile newTmp4;
			newTmp4.row = tmp.row;
			newTmp4.col = tmp.col+1;
			Q.push(newTmp4);
		}
	}
}

int main(){

	int x,y,count;

	while(true){
		scanf("%d %d",&W,&H);
		if(W == 0 && H == 0)break;

		for(int i = 0; i < H; i++){
			for(int k = 0; k < W; k++)visited[i][k] = false;
		}

		for(int i = 0; i < H; i++){
			scanf("%s",table[i]);

			for(int k = 0; k < W; k++){
				if(table[i][k] == '@'){
					y = i;
					x = k;
				}
			}
		}

		visited[y][x] = true;
		func(y,x);

		count = 0;

		for(int i = 0; i < H; i++){
			for(int k = 0; k < W; k++){
				if(visited[i][k] == true)count++;
			}
		}

		printf("%d\n",count);

	}


    return 0;
}

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

#define ll long long
#define ss second
#define ff first
#define pb push_back

using namespace std;

const int N = 1e6 + 69;

ll n, answer, w;

ll dp[N], W[N], V[N];

int main(){

        ios :: sync_with_stdio(0);

        cin >> n >> w;

        for(int i = 0; i <= 1e5; i++){
                dp[i] = 1e9;
        }

        dp[0] = 0;

        for(int i = 1; i <= n; i++){
                cin >> W[i] >> V[i];
                for(ll j = 1e5; j >= 0; j--){
                        if(j - V[i] >=0 && dp[j - V[i]] != 1e9){
                                dp[j] = min(dp[j - V[i]] + W[i],dp[j]);
                                if(dp[j] <= w){
                                        answer = max(answer, j);
                                }
                        }
                }
        }

        cout << answer << endl;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<int,int> P;

int main(){
  int n,k;
  cin >> n >> k;
  int p[n];
  rep(i,n)cin >> p[i];
  queue<int> q;
  int mx=0;
  int s=0;
  rep(i,n){
    s+=p[i];
    q.push(p[i]);
    if(q.size()>k){
      s-=q.front(),q.pop();
    }
    if(q.size()==k){
      chmax(mx,s);
    }
  }
  double ans = mx;
  ans = (ans+k)/2;
  printf("%.10f\n", ans);
}


Measured memory_bytes: 1792
K = int(input())

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
    
result = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            result = gcd(i, gcd(j, k)) + result

print(result)

Measured memory_bytes: 75904
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		long num = 1000000007;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
 		int t = Integer.parseInt(bf.readLine());
 		if (t == 1)
 			out.println(0);
 		else{
 			long ans = power(10, t, num)-2*power(9, t, num)+power(8,t, num);
 			
 			out.println(((ans)%num+num)%num);
 		}
 		
 		out.println();
	 		
 		out.close();
 		
 		
 		
 	}
	public static int power(long x, long y, long mod){
		long ans = 1;
		while(y>0){
			if (y%2==1)
				ans = (ans*x)%mod;
			x = (x*x)%mod;
			y/=2;
		}
		return (int)(ans);
	}
	
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 25404
#include <iostream>

using namespace std;

int main(){

    int a,b;
    int cou = -1;
    while(1){

        int count = 0;

        cin >> a >> b;
        if(a == 0 && b == 0) break;
        if(cou != -1) cout << endl;

        for(int i = a; i <= b; i++){
            cou++;
            if(i % 4 == 0 && i % 100 != 0 || i % 400 == 0){
                cout << i << endl;
                count++;
            }

        }

        if(count == 0){
            cout << "NA" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second

int n;
vector<int> adj[100001];
int dp[100001];
int dfs(int no,int par=-1){
	int xx=(int)(adj[no].size());
	if(par!=-1){
		xx-=1;
	}


	dp[no]=0;
	int co=0;
	for(auto j:adj[no]){
		if(j==par){
			continue;
		}
		dfs(j,no);
		if(dp[j]>0){
			co+=1;
		}
		dp[no]+=dp[j];
	}
	dp[no]+=max(xx-1-co,0);
//	cout<<no<<","<<dp[no]<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	int aa,bb;
	for(int i=0;i<n-1;i++){
		cin>>aa>>bb;
		adj[aa].pb(bb);
		adj[bb].pb(aa);
	}
	int ind=-1;
	for(int i=0;i<n;i++){
		if(adj[i].size()>2){
			ind=i;

		}
	}
	if(ind==-1){
		cout<<1<<endl;
	}
	else{
		dfs(ind);
		cout<<dp[ind]<<endl;
	}

	return 0;
}


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

using namespace std;

typedef long long ll;

const ll mod=1e9+7;

//ll qPow(ll a,ll b){
//	ll ans=1;
//	while(b>0){
//		if(b&1) ans=(ans*a)%mod;
//		a=(a*a)%mod;
//		b>>=1;
//	}
//	return ans;
//}
//
//ll inv(ll a){
//	ll tmp=1;
//	for(ll i=1;i<=a;i++){
//		tmp=(qPow(i,mod-2)*tmp)%mod;
//	}
//	return tmp;
//}
long long inv[1000005];
void init()
{
	inv[1]=1;
	for(int i=2;i<=1000005;i++)
	{
		inv[i]=(long long)(mod-mod/i)*inv[mod%i]%mod;
	}
}
ll C(int x,int y){
	ll ans=1;
	for(int i=0;i<y;i++)
	{
		ans=ans*(x-i)%mod*inv[i+1]%mod;
	}
	return ans;
}


int main(){
	init();
	int a,b;
	scanf("%d%d",&a,&b);
	if((2*a-b)%3!=0||(2*b-a)%3!=0||(2*a-b)<0||(2*b-a)<0){
		printf("0\n");return 0;
	}
	ll x=(2*a-b)/3;ll y=(2*b-a)/3;
	printf("%lld",C(x+y,x));
	return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const ll inf=1e9;
const int MAX = 510000;
const ll MOD = 998244353;

inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}

int main(){
  string s;ll k;cin>>s>>k;
  rep(i,0,s.size()-1){
    if(k<26-(s[i]-'a')){
      continue;
    }
    if(s[i]=='a')continue;
    k-=26-(s[i]-'a');
    s[i]='a';
    
  }
  k%=26;
  if(26-(s[s.size()-1]-'a')<=k){
    k-=26-(s[s.size()-1]-'a');
    s[s.size()-1]='a';
    s[s.size()-1]+=k;
  }
  else{
    s[s.size()-1]+=k;
  }
  cout<<s<<endl;
}







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

int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        char ch[9];
        scanf("%s", ch);
        int digit[8];
        for (int j = 0; j < 8; j++) {
            digit[j] = ch[j] - '0';
        }
        for (int j = 0; j < 7; j++) {
            for (int k = 1; k < 8 - j; k++) {
                if (digit[k] < digit[k - 1]) {
                    int temp = digit[k];
                    digit[k] = digit[k - 1];
                    digit[k - 1] = temp;
                }
            }
        }
        int max = 0, min = 0;
        for (int j = 0; j < 8; j++) {
            max += digit[j] * pow(10, j);
            min += digit[7 - j] * pow(10, j);
        }
        cout << max - min << endl;
    }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n, k;
    cin >> n >> k;
    vi64 a(n);
    forn(i, n) cin >> a[i];
    vi64 b(n);
    forn(i, n) b[i] = max(0LL, a[i]);
    vi64 as(n + 1), bs(n + 1);
    forn(i, n) as[i + 1] = as[i] + a[i], bs[i + 1] = bs[i] + b[i];

    i64 ans = -1e18;
    forn(i, n - k + 1) {
        i64 res = bs[n] - (bs[i + k] - bs[i]);
        res += max(as[i + k] - as[i], 0LL);
        uax(ans, res);
    }
    cout << ans << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 3456
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    int a,b,c,num=0;
    scanf("%d %d %d",&a,&b,&c);
    if (a>b)
    {
    	int n=a;a=b;b=n;
	}
    for (int i=a;i<=b;i++)
    {
    	if (i%c==0) num++;
	}
	printf("%d\n",num);
}


Measured memory_bytes: 3760
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let r: u32 = read();
    if r < 1200 {
        println!("ABC");
    } else if r < 2800 {
        println!("ARC");
    } else {
        println!("AGC");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(n) for(ll i=0; i<n; i++)

ll n;
string s;
vector<ll> ch;
vector<ll> child;

void ch_search()
{
  int flag = 0;
  rep(n)
  {
    if(s[i]=='L')
    {
      if(flag==0) ch.push_back(i-1);
      flag = 1;
    } else {
      flag = 0;
    }
  }
}

void count_child()
{
  int flag = 0;
  ll cur = 0;
  rep(n)
  {
    if(s[i]=='L')
    {
      flag = 1;
      ll dist = i-ch[cur];
      ll last;
      if(dist%2==0) last = ch[cur];
      else last = ch[cur] + 1;
      child[last]++;
    } else {
      if(flag == 1) cur++;
      flag = 0;
      ll dist = ch[cur]-i;
      ll last;
      if(dist%2==0) last = ch[cur];
      else last = ch[cur] + 1;
      child[last]++;
    }
  }
}

void print_vec(vector<ll> v)
{
  vector<ll>::iterator itr;
  for(itr = v.begin(); itr!=v.end(); itr++)
  {
    cout << *itr << " ";
  }
  cout << endl;
}

int main()
{
  cin >> s;
  n = s.length();
  ch_search();
  rep(n) child.push_back(0);
  count_child();
  print_vec(child);
  return 0;
}

Measured memory_bytes: 2740
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
for i in range(N):
    a = A[i]
    ans += B[a-1]
    if i != N-1:
        if a+1 == A[i+1]:
            ans += C[a-1]
print(ans)


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

int main() {
  int a, b;
  cin >> a >> b;
  int ret;
  int z = abs(b) - abs(a);
  if (z == 0) {
    if (a == b)
      ret = 0;
    else
      ret = 1;
  } else if (z > 0) {
    ret = z + (a < 0) + (b < 0);
  } else {
    ret = -z + (a > 0) + (b > 0);
  }

  cout << ret << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
const int N = 200'000;
int opt[N+2], nex[N+1][26];
char action[N+2];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    s += 'a';
    for(char& c : s) c -= 'a';
    fill(begin(nex[s.size()]), end(nex[s.size()]), s.size());
    for(int i = s.size() - 1; i >= 0; i--) {
        for(int c = 0; c < 26; c++) {
            nex[i][c] = s[i] == c ? i + 1 : nex[i+1][c];
        }
    }
    for(int i = s.size(); i >= 0; i--) {
        if(i == s.size()) {
            opt[i] = 0;
        } else {
            opt[i] = lim<int>::max();
            for(int c = 0; c < 26; c++) {
                if(opt[i] > 1 + opt[nex[i][c]]) {
                    opt[i] = 1 + opt[nex[i][c]];
                    action[i] = c;
                }
            }
        }
    }
    for(int i = 0; i < s.size(); i = nex[i][action[i]]) {
        cout << char('a' + action[i]);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 21908