akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <utility>

#include <cassert>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define FOR(i,a,b) for(ll i=(a); i < (b); i++)
#define RFOR(i,a,b) for(ll i=(b)-1; i >= (a); i--)
#define rep(i,n) FOR(i,0,(n))
#define rrep(i,n) RFOR(i,0,(n))

int main() {
	int N, A, B;
	int LDS = 0;
	vector<int> res;
	cin >> N >> A >> B;
	if(A>N || B>N || B < N/A + !!(N%A)) {
		cout << -1 << endl;
		return 0;
	}
	for(int i = 0; i < A; i++) {
		res.push_back(N-A+i+1);
	}
	LDS = 1;
	N -= A;
	while(N) {
		vector<int> t;
		for(int i = 0; i < A && LDS+N>=B; i++) {
			t.push_back(N);
			N--;
		}
		if(t.size() == 0) {
			t.push_back(N);
			N--;
		}
		LDS++;
		res.insert(res.end(), t.rbegin(), t.rend());
	}

	if(LDS != B) {
		cout << -1 << endl;
		return 0;
	}
	for(int i = 0; i < res.size(); i++) {
		if(i) cout << " ";
		cout << res[i];
	} cout << endl;

	return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  cout << "Christmas";
  rep(i,25-D){
    cout << " Eve";
  }
  cout << endl;
  
  return 0;
}


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

int k, n, a[200005];
long long cur, ans;

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

	cin >> k >> n;
	ans = 1e18;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	for (int i = 1; i <= n; i++) {
		// step 1
		cur = a[n] - a[i];
		if (i > 1) {
			cur += (k - a[n]) + a[i-1];
		}
		ans = min(ans, cur);

		// step 2
		cur = a[i];
		if (i < n) {
			cur += (k - a[i+1]);
		}
		ans = min(ans, cur);
	}

	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 1024
s = list(input())
ans = []
for i in ['+', '-']:
    for j in ['+', '-']:
        for k in ['+', '-']:
            tmp = int(s[0])
            if i == '+':
                tmp += int(s[1])
            else:
                tmp -= int(s[1])
            if j == '+':
                tmp += int(s[2])
            else:
                tmp -= int(s[2])
            if k == '+':
                tmp += int(s[3])
            else:
                tmp -= int(s[3])
            if tmp == 7:
                ans = [s[0],i,s[1],j,s[2],k,s[3],'=7']
                break
print(''.join(map(str,ans)))

Measured memory_bytes: 61872
fun main() {
    val (n, m, x) = readLine()!!.split(" ").map {it.toInt()}
    val books = Array<Book>(n) { Book(0, emptyList())}
    for (i in 0 until n) {
        val list = readLine()!!.split(" ").map { it.toInt() }
        books[i] = Book(list[0], list.subList(1, list.size))
    }

    val plans = Array(2 shl n) { IntArray(m) to 0 }
    for (i in plans.indices) {
        var cost = 0
        for (k in 0 until n) {
            if (i and (1 shl k) != 0) {
                for (l in 0 until m) {
                    plans[i].first[l] += books[k].a[l]
                }
                cost += books[k].c
            }
        }
        plans[i] = plans[i].first to cost
    }

    var min = Int.MAX_VALUE
    for (plan in plans) {
        if (plan.first.all { it >= x }) {
            min = kotlin.math.min(min, plan.second)
        }
    }

    if (min == Int.MAX_VALUE) {
        println(-1)
    } else {
        println(min)
    }
}

data class Book(val c: Int, val a: List<Int>)


Measured memory_bytes: 39656
package main

import "fmt"

func main() {
	maxi := 100000 + 1
	var n, k int
	var a, b int
	fmt.Scan(&n, &k)
	bucket := make([]uint64, maxi)
	for i := 0; i < n; i++ {
		fmt.Scan(&a, &b)
		bucket[a] += uint64(b)
	}
	sum := uint64(0)
	for i := 1; i <= maxi; i++ {
		sum += bucket[i]
		if uint64(k) <= sum {
			fmt.Println(i)
			break
		}
	}
}


Measured memory_bytes: 5504
#include <stdio.h>

int digit( int n ) {

	int count = 1;

	while ( n / 10 != 0 ) {

		n /= 10;
		count++;

	}

	return count;

}

int main( void ) {

	int a, b;

	while ( scanf( "%d %d", &a, &b ) != EOF ) {

		printf( "%d\n", digit( a + b ) );

	}

	return 0;

}

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

#define fastread std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl '\n'
#define pb push_back
#define mp make_pair
#define print(a) for(auto x:a) cout<<x<<' ';cout<<endl;
#define printM(b) for(auto y:b) {print(y);}
#define printP(p) cout<<p.first<<' '<<p.second<<endl;

using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;

class knapsack
{
    public:
        ll w, val;
};

int main()
{
	fastread;
	
	ll n, w, i, j, k;

    cin>>n>>w;

    knapsack ks[n+1];

    for(i=1 ; i<=n ; ++i)
        cin>>ks[i].w>>ks[i].val;
    
    ll dp[n+1][w+1];
    ll mx = INT_MIN;

    for(i=0 ; i<=n ; ++i)
        for(j=0 ; j<=w ; ++j)
        {
            if(i==0 || j==0)
                dp[i][j] = 0;
            else if(j >= ks[i].w)
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-ks[i].w]+ks[i].val);
            else
                dp[i][j] = dp[i-1][j];
        }
    
    cout<<dp[n][w];
    
    return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  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;
  }
};

mint factorial(ll n) {
  mint answer = 1;
  while (n > 1) {
    answer *= n;
    n--;
  }
  return answer;
}

mint combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

mint permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

// setprecision(8) 桁数指定
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

bool compare_by_b(pair<ll, ll> a, pair<ll, ll> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

vector<ll> Eratosthenes(const ll N) {
  bool is_prime[1000000 + 1];
  vector<ll> P;
  for (ll i = 0; i <= N; i++) {
    is_prime[i] = true;
  }
  for (ll i = 2; i <= N; i++) {
    if (is_prime[i]) {
      for (ll j = 2 * i; j <= N; j += i) {
        is_prime[j] = false;
      }
      P.emplace_back(i);
    }
  }
  return P;
}

typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

int main() {
  int a, p;
  cin >> a >> p;
  int ans = (a * 3 + p) / 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import itertools
def op(x,y,i):
    if i=="+": return x+y
    elif i=="-": return x-y
    elif i=="*": return x*y

e0 = '((({0} {1} {2}) {3} {4}) {5} {6})'
e1 = '(({0} {1} {2}) {3} ({4} {5} {6}))'
def check(A, n):
    w,x,y,z = A
    S="+-*"
    for i in S:
        a = op(w,x,i)
        for j in S:
            b1,b2 = op(a,y,j),op(y,z,j)
            for k in S:
                if op(b1,z,k)==n: return e0.format(w,i,x,j,y,k,z)
                if op(a,b2,k)==n: return e1.format(w,i,x,k,y,j,z)
    return ""

n=10
while 1:
    x = map(int,raw_input().split())
    if x==[0,0,0,0]: break
    x =[map(int,list(e)) for e in itertools.permutations(x)]
    for e in x:
        s = check(e,n)
        if s!="": break
    else: s = "0"
    print s

Measured memory_bytes: 4408
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n,k,s;
	std::cin >> n >> k >> s;
	rep(i,k) {
		std::cout << s << ' ';
	}
	rep(i,n-k) {
		if(s!=1e9) std::cout << s+1 << ' ';
		else std::cout << 1 << ' ';
	}
	std::cout << ENDL;

	return 0;
}


Measured memory_bytes: 1280
h,w=map(int,input().split())
S=list(input() for _ in range(h))
ans=[[0]*(w+2) for _ in range(h+2)]
for i in range(1,h+1):
    for j in range(1,w+1):
        if S[i-1][j-1]=="#":
            ans[i-1][j-1] += 1
            ans[i-1][j] += 1
            ans[i-1][j+1] += 1
            ans[i][j-1] += 1
            ans[i][j+1] += 1
            ans[i+1][j-1] += 1
            ans[i+1][j] += 1
            ans[i+1][j+1] += 1
for i in range(h):
    for j in range(w):
        if S[i][j]=="#":
            ans[i+1][j+1]  = "#"
        print(ans[i+1][j+1],end="")
        if j==w-1 and i<h-1:print("")

Measured memory_bytes: 3444
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner scn=new Scanner(System.in);
    int x=scn.nextInt();
    int y=scn.nextInt();
    
    for(int i=0;i<=x;i++){
        if(i*2+(x-i)*4==y){
          System.out.println("Yes");
          return;
        }
    }
    System.out.println("No");
  }
}

Measured memory_bytes: 35880
#pragma region Header
#include <cstdint>
#include <cmath>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <iostream>
#include <iomanip>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    vector<int> cards(3 * n);
    rep(i, 3 * n)
    {
        cin >> cards[i];
        --cards[i];
    }

    vector dp1(n, vector(n, -1));
    auto dp2 = 0;
    vector dp3(n, -1);
    auto lazy = 0;
    stack<tuple<int, int, int>> up;
    {
        auto x = cards[0], y = cards[1];
        dp1[x][y] = dp1[y][x] = 0;
        dp3[x] = dp3[y] = 0;
    }
    FOR(i, 1, n - 1)
    {
        auto a = cards[3 * i - 1], b = cards[3 * i], c = cards[3 * i + 1];

        if (a == b and b == c)
        {
            ++lazy;
            continue;
        }

        auto solve = [&]() {
            up.emplace(b, c, max(1 + dp1[a][a], dp2));

            rep(x, n)
            {
                up.emplace(c, x, dp3[x]);
                if (a == b and dp1[a][x] >= 0)
                {
                    up.emplace(c, x, 1 + dp1[a][x]);
                }
            }
        };

        solve();
        swap(a, b);
        swap(b, c);
        solve();
        swap(a, b);
        swap(b, c);
        solve();

        while (not up.empty())
        {
            auto [x, y, d] = up.top();
            up.pop();

            chmax(dp1[x][y], d);
            chmax(dp1[y][x], d);
            chmax(dp2, d);
            chmax(dp3[x], d);
            chmax(dp3[y], d);
        }

#ifdef DEBUG
        clog << "dp1\n";
        for (auto &v : dp1)
        {
            for (auto d : v)
            {
                clog << ' ' << d;
            }
            clog << '\n';
        }
        clog << "lazy " << lazy << '\n';
#endif
    }

    auto a = cards[3 * n - 1];
    auto ans = lazy + max(dp2, 1 + dp1[a][a]);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 19504
n,w = list(map(int,input().strip().split()))

a = [[0] * 2 for i in [0] * n]

for i in range(n):
  a[i] = list(map(int,input().strip().split()))

weight_max = 0
for i in range(n):
  weight_max += a[i][0]

dp = [[0] * (w+1) for i in [0] * (n+1)]

for i in range(n):
  for sum_w in range(w+1):
    if sum_w >= a[i][0]:
      dp[i+1][sum_w] = max(dp[i+1][sum_w], dp[i][sum_w-a[i][0]]+a[i][1])
    dp[i+1][sum_w] = max(dp[i+1][sum_w],dp[i][sum_w])
print(dp[n][w])
                          
                   
    

Measured memory_bytes: 120812
####################
#  AC:     ms (PyPy)
####################

def main():
    MOD = 10**6+3
    # preprocess
    fac = [None] * (MOD+1)
    fac[0] = fac[1] = 1
    for i in range(2, MOD+1):
        fac[i] = (fac[i-1] * i) % MOD

    Q = int(input())
    for i in range(Q):
        x, d, n = map(int, input().split())

        if x == 0:
            print(0)
            continue

        if d == 0:
            print(pow(x, n, MOD))
            continue
        
        xd = (x * pow(d, MOD-2, MOD)) % MOD
        if xd + (n-1) >= MOD:
            print(0)
            continue

        print(pow(d, n, MOD) * fac[xd+(n-1)] * pow(fac[xd-1], MOD-2, MOD) % MOD)


if __name__ == "__main__":
    main()

Measured memory_bytes: 77000
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
vector < vector<int> > g;
vector < vector<int> > s;
vector<int> v;
vector<int> A;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	int res = 0;
	int a, b, ss;
	g.resize(N);
	s.resize(N);
	
	for (int i = 0; i < M; i++) {
		cin >> a >> b >> ss;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
		s[a].push_back(ss);
		s[b].push_back(ss);
	}
	int INF = (int)1 << 60;
	vector<int> mn(N, INF);
	vector<int> mx(N, INF);
	queue<int> qu;
	qu.push(0);
	mn[0] = 0;
	vector<int>inq(N, 0);
	inq[0] = 1;
	bool ok = true;
	while (qu.size()) {
		int a = qu.front(); qu.pop();
		inq[a] = 0;
		for (int i = 0; i < g[a].size(); i++) {
			if (mx[g[a][i]] == INF && mn[a] != INF ) {
				mx[g[a][i]] = s[a][i] - mn[a];
				if (inq[g[a][i]] == 0) {
					qu.push(g[a][i]);
					inq[g[a][i]] = 1;
				}
			}
			else if (mn[a]!= INF) {
				if (mx[g[a][i]] != s[a][i] - mn[a]) {
					ok = false;
					break;
				}
			}
			if (mn[g[a][i]]  == INF && mx[a] != INF) {
				mn[g[a][i]] = s[a][i] - mx[a];
				if (inq[g[a][i]] == 0) {
					qu.push(g[a][i]);
					inq[g[a][i]] = 1;
				}
			}
			else if (mx[a] != INF) {
				if (mn[g[a][i]] != s[a][i] - mx[a]) {
					ok = false;
					break;
				}
			}
		}
		if (!ok)break;
	}
	if (ok) {
		set<int> st;
		res = INF;
		for (int i = 0; i < N; i++) {
			//cerr << i << " " << mn[i] << " " << mx[i] << endl;
			//res = min(res, mx[i] - mn[i]);
			if (mn[i] != INF && mx[i] != INF) {
				st.insert(mx[i] - mn[i]);
			}
		}
		if ((int)st.size() > 1) {
			res = 0;
		}
		else if ((int)st.size() == 1) {
			int x = (*st.begin()) / 2;
			res = 1;
			for (int i = 0; i < N; i++) {
				if (mx[i] != INF && x >= mx[i])res = 0;
				if (mn[i] != INF && x <= -mn[i])res = 0;
			}
			//res = 1;
		}
		else {
			int tmx = INF;
			int tmn = 1;
			for (int i = 0; i < N; i++) {
				if (mx[i] != INF)tmx = min(tmx, mx[i] - 1);
				if (mn[i] != INF)tmn = max(tmn, -mn[i] + 1);
			}
			res = tmx - tmn + 1;
			res = max(res, (int)0);
		}
	}
	else {
		res = 0;
	}
	cout << res << endl;
}

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

using namespace std;

typedef long long int int64;

const int64 N = 1e3 + 10;
const int64 M = 1e4 + 10;
const int64 INF = 1e18;
int64 dp[N][M];

int main() {
	ios_base::sync_with_stdio(false);
  	cin.tie(0); cout.tie(0);
  	int64 h, n;
    cin >> h >> n;
    for(int i = 0; i <= n; i++)
    	for(int j = 0; j <= h; j++)
        	dp[i][j] = INF;
 	dp[0][0] = 0;
 	for(int i = 1; i <= n; i++) {
    	int aa, bb;
      	cin >> aa >> bb;
      	for(int j = 0; j <= h; j++) {
        	dp[i][j] = min(dp[i][j], dp[i-1][j]);
          	dp[i][j] = min(dp[i][j], dp[i][j-aa] + bb);
        }
    }
  	cout << dp[n][h] << "\n";
	return 0;
}


Measured memory_bytes: 78592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    vector<ll> a(n+1) ;
    for(ll i=1;i<=n;i++) cin>>a[i];
    map<ll,ll> taken;
    ll st=a[1];
    vector<ll> path;
    while(1){
        if(taken[st]){
            break;
        }
        path.push_back(st);
        taken[st]=1;
        st=a[st];
    }
    int ans=-1;
    for(int i=0;i<path.size();i++)
    {
        if(k==0) break;
        ans=path[i];
        k--;
        if(path[i]==st) break;
    }
    if(k==0){
        cout<<ans;
        return 0;
    }
    int ind=path.size()+1;
    for(int i=0;i<path.size();i++){
        if(path[i]==st){
            ind=i;
            break;
        }
    }
    vector<ll> dup;
    for(int i=ind;i<path.size();i++) dup.push_back(path[i]);
    ll sz=dup.size();
    cout<<dup[k%sz];
    return 0;
}

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

public class Main {


    public static void main(String[] args) throws Exception {

        FastReader fs = new FastReader();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        int n = fs.nextInt();
        int d = fs.nextInt();
        int ans = 0 ;
        for(int i =0 ; i<n ; i++){
            long x = fs.nextLong();
            long y = fs.nextLong();

            double dist = Math.sqrt(x*x + y*y);
            double dd = d;

           // out.println(dist+" "+dd);

            if(dist<=dd){
                ans++;
            }

        }

        out.println(ans);









        out.close();

    }

    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
}


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

ll gcd(ll x, ll y){
	if(y == 0){
		return x;
	}
	return gcd(y, x%y);
}

int main(){
	int N;
	cin >> N;
	vector<ll> A(N);
	rep(i,N){
		cin >> A.at(i);
	}
	
	vector<ll> R(N+1);
	vector<ll> L(N+1);
	
	L[0] = 0;
	R[N] = 0;
	
	rep(i,N){
		L[i+1] = gcd(L[i], A[i]);
	}
	
	for (int i = N-1; i >= 0 ; --i) {
		R[i] = gcd(R[i+1], A[i]);
	}
	
	ll ans = 0;
	
	rep(i,N){
		ans = max(ans, gcd(L[i], R[i+1]));
	}
	
	cout << ans << endl;
	
	
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
using namespace::std;



long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int x) {
	if (x < 0) {
		return -x;
	}
	return x;
}


int point,N;
int  H,W,c[11][11],A[200][200],ans;
string S,s;


int main() {
	cin >> H>>W;
	for (int i = 0; i <= 9; i++) {
		cin >> c[i][0]>>c[i][1] >> c[i][2] >> c[i][3] >> c[i][4] >> c[i][5] >> c[i][6] >> c[i][7] >> c[i][8] >> c[i][9];
	}
	for (int i = 0; i < H; i++) {
		for (int j =0 ; j < W; j++) {
			cin >> A[i][j];
		}
	}
	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (c[i][j] > c[i][k] + c[k][j]) {
					c[i][j] = c[i][k] + c[k][j];
				}
			}
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (A[i][j] > -1) {
				ans += c[A[i][j]][1];
			}
		}
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 384
// abc148_b
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int n;
  string s,t;
  cin>>n>>s>>t;
  rep(i,n){
    cout<<s[i]<<t[i];
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(300000)
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
A = LMI()
d = defaultdict(int)
ans = sum(A)
for a in A:
    d[a] += 1

Q = I()
for q in range(Q):
    B, C = MI()
    ans -= B * d[B]
    ans += C * d[B]
    d[C] += d[B]
    d[B] = 0
    print(ans)

Measured memory_bytes: 89644
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vi a(n);
	REP(i, n)cin >> a[i];
	reverse(ALL(a));
	vi b(n);
	REP(i, n) {
		if (i % 2 == 0)b[i / 2] = a[i];
		else b[n - 1 - i / 2] = a[i];
	}
	DUMP(b);
}


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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define vi vector<int>

typedef long long ll;

using namespace std;

void solve() {
  int n;
  cin >> n;
  vi a[n];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      int x;
      cin >> x;
      a[i].pb(x);
    }
  }
  vi dp[n];
  for (int i = 0; i < n; i++) {
    dp[i].resize(3);
  }
  for (int i = 0; i < 3; i++) dp[0][i] = a[0][i];
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      int x = -1e8;
      for (int k = 0; k < 3; k++) {
        if (j == k) continue;
        x = max(x, dp[i - 1][k] + a[i][j]);
      }
      dp[i][j] = x;
    }
  }
  int ans = -1;
  for (int x : dp[n - 1]) ans = max(ans, x);
  cout << ans;
}

int main() {
  ios::sync_with_stdio(false);
  srand (time(NULL));
  int t = 1;
  // cin >> t;
  while (t--) solve();
  return 0;
}

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

using namespace std;

vector <int> p, q, go;

int main() {
	int n, tr, sa1, sa2, cnt = 0;
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> tr;
		p.push_back(tr);
		go.push_back(i);
	}
	for (int i = 1; i <= n; ++i) {
		cin >> tr;
		q.push_back(tr);
	}
	do {
		++cnt;
		if (go == p)
			sa1 = cnt;
		if (go == q)
			sa2 = cnt;
	} while (next_permutation(go.begin(), go.end()));
	cout << abs(sa1 - sa2) << '\n';
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int K = sc.nextInt();
    int[] A = new int[M];
    int[] B = new int[M];
    for (int i = 0; i < M; i++) {
      A[i] = sc.nextInt();
      B[i] = sc.nextInt();
    }
    int[] C = new int[K];
    int[] D = new int[K];
    for (int i = 0; i < K; i++) {
      C[i] = sc.nextInt();
      D[i] = sc.nextInt();
    }
    sc.close();

    @SuppressWarnings("unchecked")
    List<Integer>[] f = new List[N + 1];
    int[] fc = new int[N + 1];
    for (int i = 0; i < M; i++) {
      int a = A[i];
      int b = B[i];
      if (f[a] == null) f[a] = new ArrayList<>();
      if (f[b] == null) f[b] = new ArrayList<>();
      f[a].add(b);
      f[b].add(a);
      fc[a]++;
      fc[b]++;
    }

    int[] gn = new int[N + 1];
    int[] gc = new int[N + 1];
    for (int i = 1; i < N + 1; i++) {
      Deque<Integer> q = new ArrayDeque<>();
      q.addLast(i);
      while (!q.isEmpty()) {
        int n = q.pollLast();
        if (gn[n] != 0) continue;
        gn[n] = i;
        gc[i]++;
        if (f[n] != null) q.addAll(f[n]);
      }
    }

    int[] bc = new int[N + 1];
    for (int i = 0; i < K; i++) {
      int c = C[i];
      int d = D[i];
      if (gn[c] == gn[d]) {
        bc[c]++;
        bc[d]++;
      }
    }

    int[] ans = new int[N + 1];
    for (int i = 1; i < N + 1; i++)
      ans[i] = gc[gn[i]] - 1 - fc[i] - bc[i];

    for (int i = 1; i < N + 1; i++)
      System.out.print(ans[i] + " ");
    System.out.println();
  }
}

Measured memory_bytes: 115308
#include<stdio.h>

static const int N = 1000;
void trace(int A[], int n){
  int i;
  for ( i = 1; i <= n; i++ ){
    if ( i > 1 ) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

void insertionSort(int A[], int n){
  int i,j,v;
  for(i=2;i<=n;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    trace(A,n);
  }
}
int main(){
  int i,j,n;
  int A[N+1];

  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d",&A[i]);

  trace(A,n);
  insertionSort(A,n);
  
  return 0;
}

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

using namespace std;

int main()
{
    int N, D;
    string X;
    cin >> N >> X >> D;
    vector<bool> used(N);
    for (int i = 0; D > 0 && i < N; i++) {
        if (X[i] == '0') {
            used[i] = 1;
            X[i] = '1';
            D--;
        }
    }
    
    for (int i = N - 1; D > 0 && i >= 0; i--) {
        if (X[i] == '1' && !used[i]) {
            X[i] = '0';
            D--;
        }
    }
    
    cout << X << endl;
    return 0;
}

Measured memory_bytes: 3204
'use strict'

/////////////////////////////////////
//コピペスペース//////////////////////

//定数
const INF  =  900719925474099 // Math.floor(Number.MAX_SAFE_INTEGER / 10);

//スペース区切りの数字列を数字の配列にして返す
function mapint(line){return line.split(' ').map((v)=>parseInt(v));}

function lower_bound(d,a,b,e){
    for(var c;1<b-a;)
        d[c=0|(a+b)/2]<e ? a=c : b=c;
    return d[a]<e?b:a
};

const MOD = 1000000007;
const N109 = 1000000000;

//コピペスペース//////////////////////
/////////////////////////////////////

function Main(input){
	let temp = input.trim().split('\n');
	let n = parseInt(temp[0]);
	let p = [0,...mapint(temp[1])];

	let swaped = false;
	for(let i=1;i<=n;i++){
		if(i!=p[i]){
			if(swaped){
				console.log('NO');
				return;
			}
			swaped = true;
			let j=p[i];
			p[i] = p[j];
			p[j] = j;
		}
	}
	console.log('YES');
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <iostream>
#include <cstdio>
#include <string>
#include <string.h>
#include <queue>
#include <math.h>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#include <list>
#include <ctype.h>
#include <cassert>
#include <stack>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <ctime>
#include <functional>
#include <ctime>
#include <limits>
#include <tuple>
#include <complex>
#include <numeric>
#include <future>

using namespace std;

#define snd second
#define fst first
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define left _left
#define right _right

const ld pi = acos(-1.0);

template<typename T>
T abs(T x) {
    return x > 0 ? x : -x;
}

template<typename T>
T sqr(T x) {
    return x * x;
}

template<typename T>
bool chmin(T &x, T y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}

template<typename T>
bool chmax(T &x, T y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}

template<typename U, typename V>
ostream &operator<<(ostream &s, const pair<U, V> &x) {
    s << "(" << x.fst << ", " << x.snd << ")";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const vector<U> &x) {
    s << "[";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "]";
    return s;
}

template<typename U>
ostream &operator<<(ostream &s, const set<U> &x) {
    s << "{";
    bool was = false;
    for (auto it : x) {
        if (was) {
            s << ", ";
        }
        was = true;
        s << it;
    }
    s << "}";
    return s;
}

template<int sz>
ostream operator<<(ostream &s, const bitset<sz> &x) {
    for (int i = 0; i < sz; i++) {
        s << x[i];
    }
    return s;
}


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

int main() {

    srand(time(NULL));

#ifdef LOCAL
    //gen();
    freopen("a.in", "r", stdin);
    //freopen("a.in", "w", stdout);
#else
    //freopen("brackets.in", "r", stdin);
    //freopen("brackets.out", "w", stdout);
#endif

    ll x;
    cin >> x;
    auto s = to_string(x);
    int ans = 0;
    int curr = 0;
    for (int i = 0; i < s.size(); i++) {
        int x = s[i] - '0';
        if (x) {
            chmax(ans, int(curr + x - 1 + 9 * (s.size() - 1 - i)));
        }
        curr += x;
    }
    chmax(ans, curr);
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision


#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;

#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const long long int INF = 1000000000; //<10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

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


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

  int n,m;
	cin >> n >> m;

	vector<int> num(n,-1);
	rep(i, m) {
	  int s, c;
		cin >> s >> c;
		if (num[n-s] == -1 || num[n-s] == c) num[n-s] = c;
		else {
			cout << -1 << endl;
			return 0;
		}
	}

	rep(i, 1000) {
		if(!(pow(10,n-1) <= i && i < pow(10,n)) && !(i == 0 && n == 1)) continue;
		bool e = true;
		string s = to_string(i);reverse(all(s));
		rep(d,n) {
		  e = e && (num[d] == (int) (s[d] - '0') || num[d] == -1);
		}
		if (e) {
			cout << i << endl;
			return 0;
		}
	}

	cout << -1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	int n;
	cin >> n;
	pll* ab = new pll[n];
	rep(i, n)cin >> ab[i].first >> ab[i].second;

	if (n & 1) {
		ll a, b;
		sort(ab, ab + n);
		a = ab[n / 2].first;
		sort(ab, ab + n, [](pll &x, pll &y) {
			return x.second > y.second;
			});
		b = ab[n / 2].second;

		cout << b - a + 1 << "\n";
	}else{
		ll a1, a2, b1, b2;
		sort(ab, ab + n);
		a1 = ab[n / 2-1].first;
		a2 = ab[n / 2].first;
		sort(ab, ab + n, [](pll &x, pll &y) {
			return x.second > y.second;
			});
		b1 = ab[n / 2-1].second;
		b2 = ab[n / 2].second;

		cout << (b1 + b2) - (a1 + a2) + 1 << "\n";
	}

	return 0;
}



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

int main(){
    string s;
    cin >> s;
    if(s=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}


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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

constexpr int dx[] = {0, -1, 1, 0, -1, 1, -1, 1};
constexpr int dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    int r, c, k;
    cin >> r >> c >> k;

    vector< string > gs(r + 1, string(c + 1, '#'));
    range(i, 1, r + 1) {
        gs[i] = '#' + input<string>();
    }
    
    auto dp = make_vector(r + 1, c + 1, 0);
    range(i, 0, r + 1) dp[i][0] = k;
    range(j, 0, c + 1) dp[0][j] = k;

    range(i, 1, r + 1) range(j, 1, c + 1) {
        dp[i][j] = min(dp[i - 1][j], dp[i][j - 1]) + 1;

        if (gs[i][j] == '.') {
            if (dp[i][j] == k + 1) {
                dp[i][j] = 0;
            }
        } else {
            chmin(dp[i][j], k);
        }
    }

    if (dp[r][c]) {
        cout << "Chieno" << endl;
    } else {
        cout << "Cacao" << endl;
    }
}

signed main(int argc, char *argv[]) {
    solver();
}



Measured memory_bytes: 8968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define all(v) v.begin(), v.end()

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  ll a,b,c;cin>>a>>b>>c;
  ll ans=0;
  if(a+b>=c){
    ans=b+c;
  }else if(a+b+1==c){
    ans=b+c;
  }else{
    ans=b+a+b+1;
  }
  cout<<ans<<endl;
  return 0;
}


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

ll n,m,a[100009],sum;

ll f(ll x){
    ll num=0,y=n-1;
    rep(i,n){
        while(y>=0&&a[i]+a[y]>=x){
            sum+=a[y]*(n-i);
            y--;
        }
        sum+=(n-y-1)*a[i];
        num+=n-y-1;
    }
    return num;
}

int main(){
    cin>>n>>m;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    ll l=0,r=1e18;
    while(l+1<r){
        ll mid=(l+r)/2;
        if(f(mid)<m)r=mid;
        else l=mid;
    }
    sum=0ll;
    cout<<l*(m-f(l))+sum<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;
const int INFTY = 1e7+1;

int main() {
  int n, w; cin >> n >> w;
  Graph G(n, vi(2));
  rep(i,n) rep(j,2) cin >> G[i][j];
  int w1 = G[0][0] - 1;
  rep(i,n) G[i][0] -= w1;
  vector<Graph> dp(n+1, Graph(4*n, vi(n+1, -INFTY)));
  dp[0][0][0] = 0;
  rep(i,n) {
    rep(j,4*(i+1)) {
      if (j < G[i][0]) {
        dp[i+1][j] = dp[i][j];
        continue;
      }
      rep(k,i+1) {
        dp[i+1][j][k+1] = max(dp[i][j][k+1], dp[i][j-G[i][0]][k] + G[i][1]);
      }
    }
  }
  int ans = 0;
  rep(k,n+1) {
    if (w1 * k > w) break;
    int accept = min(4*n, w+1-w1*k);
    rep(j,accept) ans = max(ans, dp[n][j][k]);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> cnt(m+1,0);
    rep(i,n){
        int k;
        cin>>k;
        rep(i,k){
            int a;
            cin>>a;
            cnt[a]++;
        }
    }

    int ans=0;
    for(int i=1;i<=m;i++){
        if(cnt[i]==n) ans++;
    }
    cout<<ans<<"\n";
    return 0;
}

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

int main(void)
{
	char string[10];
	int len = 0;
	int flag = 0;
	int i;

	scanf("%s", string);

	len = strlen(string);

	if (len % 2 == 1) printf("No\n");
	else {
		for (i = 0; i < len; i += 2) {
			if (string[i] == 'h' && string[i + 1] == 'i');
			else {
				flag++;
			}
		}
		if (flag == 0) printf("Yes\n");
		else printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0; i < (int)c; i++)
const int inf = 1000000000;

int main(){
 int n;
  cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  int L = x[0],R = x[0];
  rep(i,n){
    L = min(L,x[i]);
    R = max(R,x[i]);
  }
  int ans = inf ;
  for(int i=L;i<=R;i++){
    int cost =0;
    rep(j,n) cost += (x[j] - i)*(x[j] - i);
    ans = min(ans,cost);
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
int N;
  cin>>N;
  
  int sum=0, x=N;
  for(int i=0; i<9; i++){
   sum+=x%10;
    x/=10;
  }
  
  if(N%sum==0){cout<<"Yes";}
  else{cout<<"No";}
}

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

int main(){

    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    
    int minj = 0;
    int tmp;
    int cnt = 0;
    for(int i=0; i<n; i++){
        minj = i;
        for(int j=i; j<n; j++){
            if(a[j] < a[minj]){
                minj = j;
            }
        }
        if(minj != i){
            cnt++;
            tmp = a[i];
            a[i] = a[minj];
            a[minj] = tmp;
        }
    }

    for(int k=0; k<n; k++) {
        if(k != n-1){
            cout << a[k] << " ";
        }else{
            cout << a[k] << endl;
        }
    }
    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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; }

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

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

    int N;
    cin >> N;
    vector<pair<ll, pair<ll, ll>>> AAA;
    vec<ll> A(N), B(N);
    rep(i,N){
        cin >> A[i] >> B[i];
        AAA.push_back({A[i] + B[i], {A[i], B[i]}});
    }
    sort(all(AAA));
    reverse(all(AAA));
    ll ans = 0;

    rep(i,N){
        if(i&1)ans -= AAA[i].second.second;
        else ans += AAA[i].second.first;
    }
    cout << ans << endl;

}

Measured memory_bytes: 6516
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

ll solve(ll a1, ll a2, ll X, ll res = 0) {
	if ((a1 ^ a2) == X) return res;

	for (int i = 50; i > 0; --i) {
		if ((a1 ^ a2 ^ X) & (1LL << i)) {
			ll tmp1 = (a1 & ((1LL << i) - 1)) + 1;
			ll tmp2 = (1LL << i) - (a2 & ((1LL << i) - 1));
			ll rem = min(tmp1, tmp2);
			if (a1 - rem <= 0) return -1;
			return solve(a1 - rem, a2 + rem, X, res + rem);
		}
	}

	return -1;
}

int main(void) {
	int N; cin >> N;
	ll A1, A2, xor_else = 0;
	cin >> A1 >> A2;
	for (int i = 2; i < N; ++i) {
		ll Ai; cin >> Ai;
		xor_else ^= Ai;
	}
	cout << solve(A1, A2, xor_else) << endl;
	return 0;
}

Measured memory_bytes: 3592