akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main()
{
    string c1,c2;
    int s1,s2=0;
    int i =0;
    bool res = false;
    cin >> c1 >> c2;
    s1=c1.size();
    s2=c2.size();
    
        if((c2[0]==c1[2])&&(c2[1]==c1[1])&&(c2[2]==c1[0])){
            res = true;
        }
        else{
       
            res = false;
        }
  
    if(res == true){
        cout << "YES" << endl;
        
    }
    else{
        cout <<"NO"<<endl;
    }
    return 0;
    
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

for i in range(len(H)-2, -1, -1):
    if H[i] - H[i+1] == 1:
        H[i] -= 1
    elif  H[i] - H[i+1] >= 2:
        print("No")
        exit()
    else:
        continue

print("Yes")



Measured memory_bytes: 20596
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100010];
    rep(i, N){ 
        cin >> A[i];
        if(A[i] == 0) {
            cout << 0 << endl;
            return 0;
        }
    }
    int num = 1;
    rep(i, N) {
        num *= A[i];
    }
    if(num > INF2) {
        cout << -1 << endl;
        return 0;
    }
    int ans = num;
    rep(i, N) {
        num /= A[i];
    }
    if(num != 1) {
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

using int64 = long long;

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

  string in;
  cin >> in;
  string first = in.substr(0, 2);
  string second = in.substr(2, 2);
  int fi = stoi(first);
  int si2 = stoi(second);
  bool bi = (1 <= fi) && (fi <= 12);
  bool si = (1 <= si2) && (si2 <= 12);
  string answer;
  if (bi && si) {
    answer = "AMBIGUOUS";
  } else if (bi) {
    answer = "MMYY";
  } else if (si) {
    answer = "YYMM";
  } else {
    answer = "NA";
  }
  cout << answer << endl;
}


Measured memory_bytes: 256
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val A = Array.fill(N)(sc.nextInt())
    // K 個のレンガを砕いて, (N - 1以下)
    // 残ったレンガを 1 ~ K になるように並べたい
    // 最後まで見て行った時の最大を N から引いた数
    def solve(N: Int, A: Array[Int]): Int = {
      def loop(i: Int, j: Int): Int =
        if (i < N) {
          if (A(i) == j + 1) loop(i + 1, j + 1)
          else loop(i + 1, j)
        } else j
      val j = loop(0, 0)
      if (j == 0) -1
      else N - j
    }

    println(solve(N, A))
  }

}


Measured memory_bytes: 70632
#include <bits/stdc++.h>
#define rep(i , n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main (){
    string s;
    cin >> s;
    int c = 0;
    for(int i = 1; i < s.size() / 2;i++){
        if(s.substr(0 , i) == s.substr(i , i)){
            c = 2 * i;
        }
    }
    cout << c << endl;
}

Measured memory_bytes: 3616
s = list(input())
t = list(input())
s = [ord(i) for i in s]
t = [ord(i) for i in t]
s_new = sorted(s)
t_new = sorted(t,reverse=True)
flag = False
for i in range(len(s)):
    if len(t) == i:
        break
        
        
    if s_new[i] < t_new[i]:
        flag = True
        break
        
    elif s_new[i] > t_new[i]:
        break
        
    if i == len(s)-1:
        if i < len(t)-1:
            flag = True
        
print('Yes' if flag ==True else 'No')


Measured memory_bytes: 38384
n = int(input())

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

final = 1

if 0 in a:
    print(0)
    
else:
    for i in a:
        final *= i
        if final > 1000000000000000000:
            break
    if final > 1000000000000000000:
        print(-1)
    else:
        print(final)

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

typedef long long ll;

int main(){
    ll x, y;
    cin >> x >> y;
    if(x%y == 0){
        cout << -1 << endl;
    }else{
        ll first = x;
        while(first <= 1e18){
            if(first % y)   break;
            first += x;
        }

        if(first <= 1e18)   cout << first << endl;
        else                cout << -1 << endl;
    }

    return 0;
}

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

using lint = long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
#define rep(i, n) for(int i = 0; i < int(n); i++)
#define repu(i, a, b, s) for(int i = int(a); i < int(b); i += int(s))
#define repd(i, a, b, s) for(int i = int(a); i > int(b); i += int(s))
#define endl "\n"
constexpr lint INF = 2e18;
constexpr lint MOD = 1e9 + 7;

lint grid[3001][3001];
lint dp[3001][3001][4];

void solve() {
    lint R, C, K;
    cin >> R >> C >> K;

    rep(i, R) {
        rep(j, C) { grid[i][j] = -1; }
    }

    rep(i, K) {
        lint r, c, v;
        cin >> r >> c >> v;
        r--;
        c--;
        grid[r][c] = v;
    }

    rep(y, R) {
        rep(x, C) {
            rep(i, 4) { dp[y][x][i] = 0; }
        }
    }

    if(grid[0][0] != -1)
        dp[0][0][1] = grid[0][0];

    rep(y, R) {
        rep(x, C) {

            // 選ばない
            if(0 <= y - 1) {
                rep(i, 4) { dp[y][x][0] = max(dp[y][x][0], dp[y - 1][x][i]); }
            }
            if(0 <= x - 1) {
                rep(i, 4) { dp[y][x][i] = max(dp[y][x][i], dp[y][x - 1][i]); }
            }

            // 選ぶ
            if(grid[y][x] != -1) {
                if(0 <= y - 1) {
                    rep(i, 4) {
                        dp[y][x][1] =
                            max(dp[y][x][1], dp[y - 1][x][i] + grid[y][x]);
                    }
                }
            }
            if(0 <= x - 1) {
                repu(i, 1, 4, 1) {
                    dp[y][x][i] =
                        max(dp[y][x][i], dp[y][x - 1][i - 1] + grid[y][x]);
                }
            }
        }
    }

    lint ans = -INF;
    rep(i, 4) { ans = max(ans, dp[R - 1][C - 1][i]); }
    cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
    return 0;
}


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

int main(){
  int num,ans=0;
  int temp;
  cin>>num;
  for(int i=0;i<num;i++){
    cin>>temp;
    for(int j=2;j<=sqrt(temp);j++){
      if(temp%j==0)goto nex;
    }
    ans++;
  nex:;
  }

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

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define DB(x) cerr << __LINE__ << ": " << #x << " = " << (x) << "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
using namespace std;

int main() {
	IOS;

	ll n, a, b;
	cin >> n >> a >> b;
	if((b-a) % 2 == 0) {
		ll ans = (b-a)/2;
		cout << ans;
		return 0;
	} 
	ll ans1 = 1e18, ans2 = 1e18, ans3 = 1e18;
	ans1 = min(b-1, n-a);
	if(b-a == 1) {
		cout << ans1;
		return 0;
	}
	ans2 = a-1+1 + (b-(a-1+1) - 1)/2;
    ans3 = n-b+1 + (n - (a+(n-b+1)))/2;
    ll ans = min(ans1, ans2);
    ans = min(ans, ans3);
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.StringReader;
import java.io.IOException;
import java.io.Reader;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Denis Nedelyaev
 */
public class Main {
    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AtA solver = new AtA(in, out);
        solver.solve(1);
        out.close();
    }

    static class AtA {
        private final FastScanner in;
        private final PrintWriter out;

        public AtA(FastScanner in, PrintWriter out) {
            this.in = in;
            this.out = out;
        }

        public void solve(int testNumber) throws IOException {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();

            if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
                out.println(0);
                return;
            }

            int[] ar = {a, b, c};
            Arrays.sort(ar);

            out.println((long) ar[0] * ar[1]);
        }

    }

    static class FastScanner {
        private final BufferedReader br;
        private String line;
        private int pos;

        public FastScanner(String s) throws IOException {
            this(new StringReader(s));
        }

        public FastScanner(InputStream is) throws IOException {
            this(new InputStreamReader(is, "UTF-8"));
        }

        public FastScanner(Reader reader) throws IOException {
            this(new BufferedReader(reader));
        }

        public FastScanner(BufferedReader reader) throws IOException {
            br = reader;
            line = br.readLine();
            pos = 0;
        }

        public String next() throws IOException {
            if (!skipWhitespace()) {
                return null;
            }

            int start = pos;

            while (pos < line.length()) {
                char c = line.charAt(pos);

                if (c == ' ' || c == '\t') {
                    break;
                }

                pos++;
            }

            return line.substring(start, pos);
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        private boolean skipWhitespace() throws IOException {
            while (line != null) {
                while (pos < line.length()) {
                    char c = line.charAt(pos);

                    if (c != ' ' && c != '\t') {
                        return true;
                    }

                    pos++;
                }

                line = br.readLine();
                pos = 0;
            }

            return false;
        }

    }
}



Measured memory_bytes: 8148
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
const long long MOD = 1000000007;

static const int  MAX_INT = std::numeric_limits<int>::max();
static const long MAX_LONG = std::numeric_limits<long>::max();
static const ll   MAX_LL = std::numeric_limits<long long>::max();

#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
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; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {
    string S, T; cin >> S >> T;
    ll ls = S.size();
    ll lt = T.size();
    ll diff = ls - lt;
    ll cnt = 0;

    rep(i, diff+1) {
        ll tmpCnt = 0;
        rep(j, lt) {
            if (S[i + j] == T[j]) ++tmpCnt;
        }
        chMax(cnt, tmpCnt);
    }
    cout << lt - cnt << endl;

}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    std::cout << std::fixed << std::setprecision(15);
    Main();

    double tmp;
    cin >> tmp;

    return 0;
}


Measured memory_bytes: 3680
N, A = map( int, input().split())
X = list( map( int, input().split()))
dp = [ [0]*(50*N+1) for _ in range(N+1)]
dp[0][0] = 1
for k in range(N):
    x = X[k]
    for i in range(N-1,-1,-1):
        for j in range(50*N+1-x):
            dp[i+1][x+j] += dp[i][j]
ans = 0
for i in range(1,N+1):
    ans += dp[i][i*A]
print(ans)


Measured memory_bytes: 4596
N, K = map(int, input().split())
trees = []
for _ in range(N):
    tree = int(input())
    trees.append(tree)

trees.sort()

m = trees[K-1] -trees[0]
for i in range(1, N-K+1):
    m = min(m, trees[i+K-1] - trees[i])

print(m)

Measured memory_bytes: 7384
#include<stdio.h>
#define N 100
int main(){
  int A[N];
  int n,i,j,minj,x,c;

  scanf("%d", &n);
  if(n<1 || n>100) return 0;
  for(i = 0 ; i < n ; i++) scanf("%d", &A[i]);
  c = 0;
  
  for(i = 0 ; i <= n-1 ; i++){
    minj = i;
    for(j = i ; j <= n-1 ; j++){    
      if(A[j] < A[minj]){
	minj = j;
      }
    }
    if(i != minj) {
	x = A[i];
	A[i] = A[minj];
	A[minj] = x;
	c++;
    }
  }

  for(i = 0 ; i < n-1 ; i++) printf("%d ", A[i]);
  printf("%d\n",A[n-1]);
  printf("%d\n",c);
  return 0;
}



Measured memory_bytes: 2144
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

const int INF = 100000000;

int zentan(int X, const vector<vector<int>> &A, const vector<int> &C,
	    vector<int> rikai, int cost, int i, bool buy) {
  if (i == A.size()) {
    bool ok = true;
    for (int j = 0; j < rikai.size(); j++) {
      if (rikai[j] < X) {
	ok = false;
      }
    }
    return ok ? cost : INF;
  }

  if (buy) {
    for (int j = 0; j < rikai.size(); j++) {
      rikai[j] += A[i][j];
    }
    cost += C[i];
  }

  return min(zentan(X, A, C, rikai, cost, i + 1, true),
	     zentan(X, A, C, rikai, cost, i + 1, false));
}

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

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

  int cost = min(zentan(X, A, C, vector<int>(M, 0), 0, 0, true),
		 zentan(X, A, C, vector<int>(M, 0), 0, 0, false));
  cout << (cost != INF ? cost : -1) << endl;

  return 0;
}


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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__  "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a
#define lcoutln(a) cout << a << endl
#define lcerr(a) cerr << a
#define lcerrln(a) cerr << a << endl
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007
#define PI 3.141592653589793238462643383

signed main()
{
	init();
	solve();
}

int N;
ll K;
vector<int> a, b;

void init()
{
	cin >> N;
	a.resize(N);
	b.resize(N);
	rep(i, N) cin >> a[i];
	rep(i, N) cin >> b[i];
	rep(i, N) K += b[i] - a[i];
}


void solve()
{
	if (K < 0) {
		PRINT(0);
		return;
	}
	ll k[2] = {K, K};
	rep(i, N) {
		if (a[i] < b[i]) {
			a[i] += (b[i] - a[i] + 1) / 2 * 2;
			k[0] -= (b[i] - a[i] + 1) / 2;
		}
	}
	rep(i, N) {
		if (b[i] < a[i]) {
			k[1] += b[i] - a[i];
		}
	}
	PRINT(k[0] >= 0 && k[1] >= 0);
}


Measured memory_bytes: 384
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));

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

	int N;
	cin>>N;
	long double ans=0;
	REP(i,N){
		long double a;
		string s;
		cin>>a>>s;
		if(s=="BTC")
			a*=380000;
		ans+=a;
	}
	cout<<ans<<endl;
	return 0;
}




















Measured memory_bytes: 256
import heapq
from itertools import accumulate

n, m, s, t = map( int, input().split())

def dijkstra(graph, start):
    dist = [ 10**14 for _ in range(n)]
    dist[start] = 0
    q = [(0,start)]
    while q:
        l, v = heapq.heappop(q)
        if dist[v] < l:
            continue
        for u, d in graph[v].items():
            if dist[u] > l+d:
                dist[u] = l+d
                heapq.heappush(q, (dist[u], u))
    return dist

D_yen = [ dict() for _ in range(n)]
D_snuuk = [ dict() for _ in range(n)]
for _ in range(m):
    u, v, a, b = map( int, input().split())
    u, v = u-1, v-1
    D_yen[u][v] = D_yen[v][u] = a
    D_snuuk[u][v] = D_snuuk[v][u] = b

C_yen = dijkstra(D_yen, s-1)
C_snuuk = dijkstra(D_snuuk, t-1)

ANS = list( accumulate( [y+s for y, s in zip( C_yen, C_snuuk)][::-1], min))
[ print( 10**15 - ANS[i]) for i in range(n-1,-1,-1)]

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

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

#define roop(i, n) for(int i = 0;i < n;i++)

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

int main(void){

    int n;
    cin >> n;

    ll ans = 0;

    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= n;j++){
            for(int k = 1;k <= n;k++){
                ans += GCD(GCD(k,j),i);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3640
n,x=map(int,input().split())

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

import copy
b = copy.deepcopy(a) 

#a[0]から貪欲
i=1
cnt=0
while i<n:
    if a[i]+a[i-1]>x:
        tmp=(a[i]+a[i-1])-x
        cnt+=tmp
        a[i]=max(0,a[i]-tmp)
    i+=1

#a[n-1]から貪欲
b=b[::-1]
i=1
cnt1=0
while i<n:
    if b[i]+b[i-1]>x:
        tmp=(b[i]+b[i-1])-x
        cnt1+=tmp
        b[i]=max(0,b[i]-tmp)
    i+=1

print(min(cnt,cnt1))

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int k, t;
    cin >> k >> t;
    vector<int> v(t);
    for(auto& i : v) cin >> i;
    int m = MAX(v);
    cout << max(0, (m - 1) - (k - m)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define INF 100000000
typedef long long ll;

using namespace std;


int main() {
    ll n, m;
    cin >> n >> m;
    cout << (n == 1 ? 1 : n - 2)*(m == 1 ? 1 : m - 2) << endl;
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc171/tasks/abc171_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "unordered_map"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll N;
  cin >> N;

  unordered_map<ll, ll> ct_map;
  ll cur_sum = 0;

  rep(i, N) {
    ll a;
    cin >> a;
    cur_sum += a;
    ++ct_map[a];
  }

  ll Q;
  cin >> Q;

  rep(i, Q) {
    ll from, to;
    cin >> from >> to;

    cur_sum -= from * ct_map[from];
    cur_sum += to * ct_map[from];

    ct_map[to] += ct_map[from];
    ct_map[from] = 0;

    cout << cur_sum << "\n";
  }
}


Measured memory_bytes: 7064
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  size_t A, B; cin >> A >> B;
  cout << (A + B >= 10 ? "error" : std::to_string(A + B)) << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;


class Program
{
    public static long Read()
    {
        return long.Parse(Console.ReadLine());
    }

    public static long[] Reads()
    {
        return Console.ReadLine().Split().Select(long.Parse).ToArray();
    }

   
    public static void Main()
    {
        var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);

        var n = Read();
        var input = Reads();
        var h = new long[n];
        for (int i = 0; i < n; i++)
            h[i] = input[i];
        long active = 0;
        long answer = 0;
        for(int i = 0; i < n; i++)
        {
            if (active >= h[i])
                active = h[i];
            else
            {
                answer += h[i] - active;
                active = h[i];
            }
        }
        Console.WriteLine(answer);

        Console.Out.Flush();
    }
}

Measured memory_bytes: 13396
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var r = ReadSplit();
            var H = r[0].ToDecimal();
            int i = 0;
            while (H != 1)
            {
                H = Math.Floor(H / 2);
                i++;
            }

            double ans = 0;
            for (int j = 0; j < i + 1; j++)
            {
                ans += Math.Pow(2, j);
            }
            Write(ans);
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
            Read();
        }
    }
}


public static class Extentions
{
    public static int ToInt(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static decimal ToDecimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double ToDouble(this object obj)
    {
        return double.Parse(obj.ToString());
    }
}



Measured memory_bytes: 13140
import sys
sys.setrecursionlimit(100000000)

N, M = map(int, input().split())
BtoA = [[] for i in range(N + 1)]


for i in range(N - 1 + M):
    A, B = map(int, input().split())
    BtoA[B].append(A)

memo = {}
def depth(b):
    if b in memo:
        return memo[b]
    
    res = 0
    for a in BtoA[b]:
        res = max(res, depth(a) + 1)

    memo[b] = res
    return res

for i in range(1, N + 1):
    ans = 0
    for a in BtoA[i]:
        if depth(a) + 1 == depth(i):
            ans = a
            break
    print(ans)

Measured memory_bytes: 172184
/*
 * author :Sadik Hassan(_sad_)
 *
*/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include "bits/stdc++.h"
using namespace std;
using   ll =          long long;
using   ld =          long double;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define MP            make_pair
#define PI            (acos(-1.0))
#define rep1(i,n)     for(int i=1;i<=n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         (int)s.size()
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define w(t)          int t;cin>>t;while(t--)
#define TSU(s)        transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSL(s)        transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(3);

typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = (int)2e5+5;
const ll MOD =(ll)1e9+7;
const ll INF = (ll)1e18+5;
const int nn=1e6;

int main()
{
    _SAD()
    int n;
    cin>>n;
    vi a(1000,0);
    rep(i,n)
    {
        int x,y;
        cin>>x>>y;
        if(x==y)a[i]=1;
    }
    rep(i,n-2)
    {
        if(a[i]&&a[i+1]&&a[i+2])
        {
            cout<<"Yes"<<nl;return 0;
        }
    }
    cout<<"No"<<nl;
    return 0;
}



Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
int main()
{
    int n; cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    for(int i=0; i<n; i++) cin >> p[i];
    for(int i=0; i<n; i++) cin >> q[i];
    vector<int> v(n);
    for(int i=0; i<n; i++) v[i] = i+1;
    int index = 1;
    int p_index = -1;
    int q_index = -1;
    
    do{
        if(p==v) p_index = index;
        if(q==v) q_index = index;
        index++;

    } while(next_permutation(v.begin(), v.end()));

    cout << abs(p_index-q_index) << endl;

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define op_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fo(i,a,b) for(int i=a; i <b; i++)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef map<int,int> mpii;
typedef map<ll,ll> mpll;
typedef map<int,ll> mpil;
typedef map<ll,int> mpli;

string solve(string &s, string &t){
  fo(i,0,s.size()){
    if(s[i] != t[i]){
      return "No";
    }
  }
  return "Yes";
}

int main(){
  op_io;
  string s, t;
  cin>>s>>t;
  cout<<solve(s,t)<<endl;
  return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------



int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  sort(all(a), greater<int>());

  int alice=0, bob=0;
  rep(i, n) {
    if(i % 2 == 0) alice += a[i];
    else bob += a[i];
  }
  cout << alice - bob << endl;

  return 0;
}

Measured memory_bytes: 256
s=input()
n=int(input())
rng=[input()for i in range(n)]
contain=[False for i in range(n)]
l=len(s)
for i in range(len(rng)):
    t=rng[i]+rng[i][:l]
    for j in range(len(rng[i])):
        if s==t[j:j+l]:
            contain[i]=True
            break
print(contain.count(True))

Measured memory_bytes: 7768
import sys
def LI(): return map(int,sys.stdin.readline().split())

def main():
    N,T = LI()
    AB = []
    for i in range(N):
        A,B = LI()
        AB.append([A,B])

    AB.sort(key=lambda x:x[0])

    dp = [[0] * (T+1) for _ in range(N+1)]

    for i in range(N):
        for j in range(T):
            A,B = AB[i]
            dp[i+1][j] = max(dp[i+1][j],dp[i][j])
            if j+A<T:
                dp[i+1][j+A] = max(dp[i+1][j+A],dp[i][j]+B)
            else:
                dp[i+1][T] = max(dp[i+1][T],dp[i][j]+B)
        dp[i+1][T] = max(dp[i+1][T],dp[i][T])

    ans = 0
    for i in range(T+1):
        ans = max(dp[N][i],ans)
    return ans


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 114396
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var a = ReadInts();

            var array = new int[n + 1];

            for (int i = 0; i < n; i++)
            {
                array[a[i]] = i + 1;
            }
            Write(array[1]);
            for (int i = 2; i <= n; i++)
            {
                Write(" " + array[i]);
            }
        }
        



        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}

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

using namespace std ;

#define sz(v) (int)v.size()
#define ll long long
#define all(v)  v.begin() , v.end()
#define rall(v)  v.rbegin() , v.rend()
#define pf push_front
#define pb push_back
#define fast FastInputOutput() ;
#define Clear( container , value ) memset( container , value , sizeof container )
#define PI acos( -1.0 )
#define forn( t , v , be , n ) for( t v = be ; v < n ; v++ )
#define fore( x , j ) for( auto x : j )
#define se second
#define fr first
//#define c_b fflush(stdin);
#define debug(x , y) cerr << #x << " = " << x << y ;

const ll Long_max = numeric_limits < ll > :: max() ;
const int Int_max = numeric_limits < int > :: max() ;

void File_input( string pathIn ) {
    freopen( pathIn.c_str(), "r", stdin ) ;
}

void File_output( string pathOut ) {
    freopen( pathOut.c_str(), "w", stdout ) ;
}

int msg() {
    srand( time( 0 ) ) ;
    vector < string > st = {
        "Wish everyone high ratings!",
        "Good luck!",
        "Have fun!",
        "Please, read all the problems!",
        "Go Go fight!"
    } ;
    cerr << st[ rand() % sz( st ) ] ;
    return 0 ;
}

void FastInputOutput() {
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

int n ;
int a , b ;
ll sum = 0 ;
bool cmp( pair < int , int > s , pair < int , int > f ){
if( s.second != f.second ) return s.second < f.second ;
return s.first < f.first ;
}

int main(){

 cin >> n ;
 vector < pair < int , int > > a( n ) ;
 forn( int , i , 0 , n ){
   cin >> a[ i ].first >> a[ i ].second ;
 }

 sort( all( a ) , cmp ) ;


 fore( i , a ){
    if( sum + i.first <= i.second ){
        sum += i.first ;
    } else return cout << "No\n" , 0 ;
 }

 cout << "Yes\n" ;


 return 0 ;
}


/*
A B C D
try to solve A , B in 30 min as possible
If their is subtask try to solve the second one first if the constraints are only differ
Read all Problem so you could find an ex that you can solve fast
A -- don't write big code focus again
B -- greedy , math , bit mask , tricks , DP
C -- solve A , B first then solve C but fast as possible
greedy
DP
binary search
DFS , BFS , DSU
bit mask
number theory , math
meet in the middle
focus on the problem and constraints.
*/



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

typedef long long ll;
const int mod = 1e9 + 7;

ll N, K;
vector<ll> A;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
    cin >> N >> K;
    A.resize(N);
    rep(i, N) cin >> A[i];

    sort(A.begin(), A.end());
    combination comb(N + 5);
    mint ans = 0;
    rep(i, N) {
        mint now = comb(i, K - 1);
        ans += now * A[i];
    }

    reverse(A.begin(), A.end());

    rep(i, N) {
        mint now = comb(i, K - 1);
        ans -= now * A[i];
    }
    cout << ans.x << endl;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vll vector<long long>
#define MOD 1000000007

typedef long long ll;

void print(vi v){
    cout<<"Contents of vector:\n";
    for(auto x : v) cout<<x<<" ";
    cout<<endl<<endl;
}

bool check(int a, int b, int c){
    if(a+b <= c || a+c <= b || c+b <= a) return false;

    return true;
}

void solve(){
    ll x, k, d;
    cin>>x>>k>>d;

    x = abs(x);

    if(ceil(x*1.0/d*1.0) > k){
        cout<<x - d*k<<endl;
        return;
    }

    ll neededK = x/d;

    //cout<<"Needed: "<<neededK<<endl;

    x -= d*neededK;
    k -= neededK;

    if(k%2 == 1){
        cout<<abs(x - d)<<endl;
    } else {
        cout<<abs(x)<<endl;
    }

}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    //ifstream cin("saul1.in"); ofstream cout("output.txt");///cia failai

    //int T; cin>>T;
    int T = 1;

    for(int it = 1; it<=T; it++){
        solve();


    }
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 29;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int dp[401][401];

int main() {
  rep (i, 401) rep (j, 401) dp[i][j] = INF;
  dp[0][0] = 0;

  int n, ma, mb;
  cin >> n >> ma >> mb;

  rep (i, n) {
    int a, b, c;
    cin >> a >> b >> c;

    for (int j = 400; j >= 0; j--) {
      for (int k = 400; k >= 0; k--) {
        if (j + a > 400 || k + b > 400 || dp[j][k] == INF) continue;
        dp[j + a][k + b] = min(dp[j + a][k + b], dp[j][k] + c);
      }
    }
  }

  int ans = INF;
  for (int i = 1; ; i++) {
    if (ma * i > 400 || mb * i > 400) break;
    ans = min(ans, dp[ma * i][mb * i]);
  }

  if (ans == INF) ans = -1;

  cout << ans << endl;
}


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

using namespace std;

int main() {
	int n, k;
	vector<int> h;

	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		h.push_back(a);
	}

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

	int minDelta = 1e9;
	for (int i = 0; i < n - k + 1; i++) {
		minDelta = min(minDelta, h[i + k - 1] - h[i]);
	}

	cout << minDelta << endl;
	return 0;
}

Measured memory_bytes: 892
N = int(input())

if int(repr(N)[-1]) == 2 or int(repr(N)[-1]) == 4 or int(repr(N)[-1]) == 5 or int(repr(N)[-1]) == 7 or int(repr(N)[-1]) == 9:
    print('hon')
elif int(repr(N)[-1]) == 0 or int(repr(N)[-1]) == 1 or int(repr(N)[-1]) == 6 or int(repr(N)[-1]) == 8:
    print('pon')
else:
    print('bon')


Measured memory_bytes: 9204
X = int(input())

primes = [2]
for i in range(3, 10 ** 5 + 1000, 2):
  chk = True
  for p in primes:
    if p * p > i :
      break
    if i % p == 0 : 
      chk = False
      break
  if chk == True : 
    primes.append(i)
    # print(primes)

for p in primes :
  if p >= X :
    print(p)
    break

Measured memory_bytes: 41964
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

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

int N;

int main()
{
	cin >> N;
	vector<int> A;
	map<int,int> M;
	int a;
	rep(i,0,N){
		cin >> a;
		A.push_back(a);
		M[a]++;
	}
	sort(A.begin(),A.end());
	A.erase(unique(A.begin(),A.end()),A.end());
	vector<int> C;
	int es = 0;
	rep(i,0,A.size()){
		if(M[A[i]]%2==0){
			es++;
		}
	}
	int num = A.size();
	if(es%2==1)num--;
	cout << num << endl;

	return 0;
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n; cin >> n;

    vector<int> a(n+2);

    a[0] = 0;
    a[n+1] = 0;

    int s = 0;

    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        s += abs(a[i] - a[i-1]);
    }

    s += abs(a[n+1] - a[n]);

    for (int i = 1; i <= n; ++i) {
        cout << s - (abs(a[i+1] - a[i]) + abs(a[i] - a[i-1])) + abs(a[i+1] - a[i-1]) << endl;
    }
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

const int MAX = 5100000;
ll fac[MAX], finv[MAX], inv[MAX];

void cominit()
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll 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;
  }
}

ll com(ll n, ll 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()
{
  cominit();
  ll X; cin >> X;
  ll Y; cin >> Y;

  if ((X+Y)%3!=0||min(X,Y)<(X+Y)/3) {
    cout << 0 << endl;
    return 0;
  }

  ll n = (X+Y)/3+1;
  ll t = (n-1)*3;
  ll i = 0;
  for (; i<=n; i++) {
    if (t-(n-1)-i==X) break;
  }
  cout << com(n-1, i) << endl;

  return 0;
}


Measured memory_bytes: 119808
#include <stdio.h>

#define MAX 44

int Fib(unsigned int n);

int main(void) {
  unsigned int n;
  scanf("%d", &n);

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

  return 0;
}

int Fib(unsigned int n) {
  int memo[MAX] = {1, 1};

  for(int i=2; i<=n; ++i) {
    memo[i] = memo[i-1] + memo[i-2];
  }

  return memo[n];
}



Measured memory_bytes: 2140
#include <algorithm>
#include <iostream>
#include <cstdio>

using namespace std ;

const int N=1e5+10 ;

struct State
{
	string name ;
	int p , k ;
	bool operator < ( const State x ) const 
	{
		if ( name==x.name ) return p>x.p;
		return name<x.name;
	}
};
State a[N] ;
int n ;

int main ()
{
	int i ;
	cin >> n ;
	for ( i=1 ; i<=n ; a[i].k=i,i++ ) cin >> a[i].name >> a[i].p ;
	sort(a+1,a+n+1);
	for ( i=1 ; i<=n ; i++ ) printf("%d\n",a[i].k);
	return 0 ;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+5,mod=998244353;
int n,tot,sum[N],must[N],a[N],b[N],vis[N],vv[N];
int t[N<<2];
void fix(int l,int r,int k,int x,int y,int v)
{
    if(r<x||l>y) return;
    if(l>=x&&r<=y){t[k]=max(t[k],v);return;}
    int m=l+r>>1;
    fix(l,m,k<<1,x,y,v);fix(m+1,r,k<<1|1,x,y,v);
}
void push(int l,int r,int k)
{
    if(l==r){b[l]=t[k];return;}
    int m=l+r>>1;
    t[k<<1]=max(t[k<<1],t[k]);
    t[k<<1|1]=max(t[k<<1|1],t[k]);
    push(l,m,k<<1);push(m+1,r,k<<1|1);
}
void solve(int l,int r,int v)
{
    if(l>=1&&r<=n) fix(1,n,1,l,r,v);
    else if(l<1&&r>n) fix(1,n,1,1,n,v);
    else if(l<1)
    {
        fix(1,n,1,1,r,v);
        l--;
        fix(1,n,1,n-l+1,n,v);
    }
    else if(r>n)
    {
        fix(1,n,1,l,n,v);
        r-=n;
        fix(1,n,1,1,r,v);
    }
}
pair<int,int>pi[N];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int p=0;
    bool flag=true;
    for(int i=n;i>=1;i--)
    if(a[i]==1&&a[i-1]!=1){p=i;break;}
    if(!p) flag=false;
    for(int i=p;i<=n;i++) b[++tot]=a[i];
    for(int i=1;i<p;i++) b[++tot]=a[i];
    for(int i=1;i<=n;i++)
    {
        if(b[i]!=b[i-1]) vis[b[i]]++;
        if(pi[b[i]].first&&i>=pi[b[i]].first&&i<=pi[b[i]].second) vv[b[i]]++;
    }
    for(int i=1;i<=n;i++)
        if(vis[i]>=2) flag=false;
    int len=0;
    for(int i=1;i<=n;i++)
        if(b[i]==1) len++;
    else break;
    if(len==n)
    {
        ll ans=1;
        for(int i=1;i<=n;i++) ans=ans*i%mod;
        printf("%lld\n",ans);
        return 0;
    }
    int t=1;
    for(int i=2;i<=n;i++)
    {
        if(b[i]==b[i-1]) t++;
        else
        {
            if(t>1)
                solve(i-(t-1),i-1,b[i-1]+1);
            solve(i-len,i-t,b[i-1]);
            pi[b[i-1]]={i-len,i-t};
            solve(i-t-len+1,i-len-1,b[i-1]+1);
            t=1;
        }
        if(t>len) flag=false;
    }
    if(t>1)
        solve(n+1-(t-1),n+1-1,b[n]+1);
    solve(n+1-len,n+1-t,b[n]);
    pi[b[n]]={n+1-len,n+1-t};
    solve(n+1-t-len+1,n+1-len-1,b[n]+1);
    for(int i=1;i<=n;i++) must[b[i]]=true;
    push(1,n,1);
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=n;i++) sum[i]=1;
    for(int i=1;i<=n;i++)
    {
        vis[b[i]]++;
        if(must[b[i]]&&i>=pi[b[i]].first&&i<=pi[b[i]].second) vv[b[i]]++;
    }
    ll ans=1;
    //for(int i=1;i<=n;i++) printf(i==n?"%d\n":"%d ",sum[i]);
    //for(int i=1;i<=n;i++) printf(i==n?"%d\n":"%d ",b[i]);
    //for(int i=1;i<=n;i++) printf(i==n?"%d\n":"%d ",must[i]);
    for(int i=n+1;i>=1;i--)
    {
        if(must[i])
        {
            if(!sum[i]||!vv[i]||!vis[i]) {flag=false;break;}
            ans=ans*vv[i]%mod;
            sum[i]--;vis[i]--;
        }
        sum[i]+=sum[i+1];
        while(vis[i])
        {
            if(!sum[i]) {flag=false;break;}
            ans=ans*sum[i]%mod;
            sum[i]--;
            vis[i]--;
        }
    }
    if(!flag) ans=0;
    printf("%lld\n",ans);
}


Measured memory_bytes: 14336
/*
* @author:  codancer
* @createTime:  2020-05-04, 20:44:59
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const ll inf = 1e18;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
const int N = 2e5+100;
vector<int> G[N];
ll dp[N],w[N],ans[N];
int n;
void dfs(int u,int fa){
	int x=lower_bound(dp,dp+n,w[u])-dp;
	ll val=dp[x];
	dp[x]=w[u];
	ans[u]=lower_bound(dp,dp+n,inf)-dp;
	for(int v:G[u]){
		if(v==fa) continue;
		dfs(v,u);
	}
	dp[x]=val;
}
int main(){
	cin>>n;
	rep(i,0,n)dp[i]=inf;
	rep(i,0,n-1){
		cin>>w[i];
	}
	int u,v;
	rep(i,1,n-1){
		cin>>u>>v;
		--u;
		--v;
		G[u].pb(v);
		G[v].pb(u);
	}
	dfs(0,-1);
	rep(i,0,n-1) cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 33516