akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <list>
#include <bitset>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long int64;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define FST first
#define SND second

signed main(){
    int n, k;
    cin >> n>>k;
    cout << n-k+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int>vi;
#define pb push_back
#define sc(n) scanf("%d",&n)
#define lsc(n) scanf("%lld",&n)
#define all(x) x.begin(),x.end()
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define rev1(i,n) for(i=n;i>0;i--)
#define in insert
#define IT ::iterator
#define pr(n) printf("%d\n",n)
#define lpr(n) printf("%lld\n",n);


int main()
{
	long double a,b,x;
	cin >> a >> b >> x;
	long double ans;
	if(((a*a*b)/2)<=x)
	{
		ans=atan((2*(a*a*b-x))/(a*a*a));
	}
	else
	{
		ans=(acos(-1)/2)-atan(2*x/(a*b*b));
	}
	ans=(ans*180.0)/(acos(-1));
	cout << fixed << setprecision(12) << ans << endl;
    return 0;
}


Measured memory_bytes: 3772
#include <stdio.h>

int main(void)
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(0>=a&&b>=0||a>=0&&0>=b)puts("Zero");
	else if(0>a&&0>b&&(a-b)%2==0)puts("Negative");
	else puts("Positive");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int A, B, C;
	
	cin>>A>>B>>C;
	
	A -= B;
	cout<<max(C-A,0ll)<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
///#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,abm,mmx,popcnt,avx,avx2,tune=native")

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

/*
    zet:
        find_by_order(k): k-stat [k > 0]
        order_of_key(k) : {el < k}

    gp_hash_table<key, val, custom_hash>

    rope<T>:
        iterators: mutable_begin, ..
        methods  : erase, insert, substr, ..
*/

#define all(x) (x).begin(), (x).end()
#define size(x) (int)((x).size())
#define em_back emplace_back

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

mt19937 eng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 4;

ll res = 0;
ll n, a, b, x[N];

void solve() {
    cin >> n >> a >> b;
    for (int i = 1; i <= n; ++i) {
        cin >> x[i];
    }

    ll res = 0;
    for (int i = 1; i < n; ++i) {
        res += min(b, (x[i + 1] - x[i]) * a);
    }
    cout << res << "\n";
}

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

    int z = 1;
    /// cin >> z;

    while (z--) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 4368
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){


  while(1){
    int n,a,b,c,x,y[110];
    cin >> n >> a >> b >> c >> x;
    if(n==0 && a == 0) break;
    rep(i,n) cin >> y[i];

    int i,in=0;
    for(i=0;i<10001;++i,x = (a*x + b) % c){
      if(y[in] == x){
	if(in == n-1){
	  cout << i << endl;
	  break;
	}
	in++;
      }
    }
    if(i == 10001) cout << "-1\n";
  }

}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int main() {
    int N;
    string S;
    ll ans = 0;
    cin >> N >> S;
    vector<ll> r(N, 0), g(N, 0), b(N, 0);
    r[0] = (S[0] == 'R');
    g[0] = (S[0] == 'G');
    b[0] = (S[0] == 'B');
    for (int i = 1; i < N; i++) {
        r[i] = r[i - 1] + (S[i] == 'R');
        g[i] = g[i - 1] + (S[i] == 'G');
        b[i] = b[i - 1] + (S[i] == 'B');
    }
    for (int j = 1; j < N; j++)
        for (int k = j + 1; k < N; k++) {
            if (S[j] == S[k]) continue;
            if (S[j] != 'R' && S[k] != 'R') {
                ans += r[j - 1];
                if (j - (k - j) >= 0 && S[j - (k - j)] == 'R') ans--;
            } else if (S[j] != 'B' && S[k] != 'B') {
                ans += b[j - 1];
                if (j - (k - j) >= 0 && S[j - (k - j)] == 'B') ans--;
            } else if (S[j] != 'G' && S[k] != 'G') {
                ans += g[j - 1];
                if (j - (k - j) >= 0 && S[j - (k - j)] == 'G') ans--;
            }
        }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3740
#include <iostream>
#include <stack>
#include <algorithm>
#include <cmath>
using namespace std;

int M[101][101], cond[101], st[101], en[101], n, t;
stack<int> S;

void setAdj()
{
	int u, k, v;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v;
			M[u][v] = 1;
		}
	}
}

void dfs(int x)
{
	S.push(x);
	cond[x] = -1; //?¨???????
	st[x] = ++t;

	int i, j;
	while (!S.empty()) {
		int u = S.top();
		for (i = 1; i <= n; i++) {
			if (M[u][i] == 1 && cond[i] == 0) {
				break;
			}
		}
		if (i == n + 1) {
			cond[u] = 1;
			en[u] = ++t;
			S.pop();
		}
		else {
			S.push(i);
			cond[i] = -1;
			st[i] = ++t;	
		}
	}
}

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

	cin >> n;
	t = 0;
	setAdj();
	
	for (int i = 1; i <= n; i++)
		if (cond[i] == 0) dfs(i);

	for (int i = 1; i <= n; i++) {
		cout << i << " " << st[i] << " " << en[i] << endl;
	}
	return 0;
}

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

#define mod 1000000007
#define ll long long int


int main()
{

  int n;
  cin>>n;
  ll arr[n];
  for(int i=0;i<n;i++)cin>>arr[i];
  vector<ll >v;
  for(int i=0;i<n;i++)if(arr[i]%2==0)v.push_back(arr[i]);
  int len=v.size();
  ll ans=0;
  for(int i=0;i<len;i++)
  {
      while(v[i]%2==0 && v[i]>0)
      {
          ans++;
          v[i]/=2;
      }
  }
  cout<<ans;
}




Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
int main(){
    ll yen = 100, x, res = 0;
    scanf("%lld", &x);
    while (yen < x){
        yen = yen + yen / 100;
        res++;
    }
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 3824
n = int(input())
a, b = map(int, input().split())
p = list(map(int,input().split()))

problem_set = [0] * 3

for i in p:
    if i <= a:
        problem_set[0] += 1
    elif a < i <= b:
        problem_set[1] += 1
    else:
        problem_set[2] += 1

print(min(problem_set))

Measured memory_bytes: 3064
n = int(input())
a = [int(input()) for _ in range(n)]

if a[0] != 0:
	print(-1)
else:
	ans = 0
	muri = 0

	for i in range(1, n):
		if a[i] > a[i-1] + 1:
			muri = 1
		elif a[i] < a[i-1] + 1:
			ans += a[i-1]
			if i == n - 1:
				ans += a[i]
		elif i == n - 1:
			ans += a[i]

	if muri:
		print(-1)
	else:
		print(ans)

Measured memory_bytes: 11052
#include <iostream>
#include <string>
using namespace std;
int main(){
 
  string s;
  cin >> s;
  int count=0;
  if (s[0] == '1') ++count;
  if (s[1] == '1') ++count;
  if (s[2] == '1') ++count;
  cout << count << endl;
  
  
  
return 0;
}

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

int main() {
    double N;
    cin >> N;
    if (int(N)%2 == 0) cout << 0.5 << endl;
    else {
        double ans = int(N/2+1)/N;
        cout << setprecision(10) << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int a, b;
	cin>>a>>b;
	cout<<max(0, a-2*b)<<endl;
    return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(long long i=j;i<(n);++i)
#define bk(i,j,n)   for(long long i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define srt(x) sort(x.begin(),x.end());
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>

typedef long long ll;
ll modpower(ll a,ll b,ll c)
{
	ll res=1;
	while(b)
	{
		if(b&1LL)
			res=(res*a)%c;
		a=(a*a)%c;
		b>>=1;
	}
	return res;
}

ll n,k;
ll a[200005];
//[15],c[15];


int main()
{
   // run;
    cin>>n>>k;
    fr(i,0,n)
    {
        cin>>a[i];
        a[i]--;

    }

    ll vis[n];
    memset(vis,-1ll,sizeof vis);
    if(1)
    {
        ll j=0;
        ll prev=j;
        ll cnt=0;
        while(vis[j]==-1ll && cnt<k)
        {
            cnt++;
            vis[j]=cnt;
            prev=j;
            j=a[j];
           // cout<<j<<" "<<vis[j]<<endl;


        }
        if(cnt==k)
        {
            cout<<j+1;
            return 0;
        }
        ll st_cnt=vis[j];
        ll en_cnt=vis[prev];
        k-=(st_cnt-1);
        ll o=en_cnt-st_cnt;
        o++;
       // cout<<o<<" "<<k<<endl;
        k+=o;
        k%=o;
       /* if(k)
        k--;*/
        prev=j;
       // cout<<k<<endl;
        while(k)
        {
            prev=j;
            j=a[j];
            k--;
        }

        cout<<j+1<<endl;
        return 0;




    }


}


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

int main(void){
    int n;
    cin >> n;
    map<string, int> index;
    vector<int> t(n);
    rep(i,n){
        string s;
        cin >> s >> t[i];
        index[s] = i+1;
    }
    string x;
    cin >> x;
    int sum = 0;
    for (int i = index[x]; i < n; i++) {
        sum += t[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
using namespace std;
const int N=1e2+10;
void swap(int &a,int &b){
    int temp=a;
    a=b;
    b=temp;
    return ;
}
int main(){
    int n,f[N],a[N],w,l,d;
    bool first=true;
    string c[N];
    while(true){
        scanf("%d",&n);
        if(n==0)return 0;
        if(first)first=false;
        else printf("\n");
        for(int i=0;i<n;i++){
            cin>>c[i];
            f[i]=i;
            scanf("%d%d%d",&w,&l,&d);
            a[i]=w*3+d;
        }
        for(int i=0;i<n;i++)for(int j=1;j<n;j++)if(a[f[j-1]]<a[f[j]])swap(f[j],f[j-1]);
        for(int i=0;i<n;i++)cout<<c[f[i]]<<","<<a[f[i]]<<endl;
    }
}


Measured memory_bytes: 3176
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int isPrime(int);

int main(){
  int i, n, *A;
  int primen=0;

  scanf("%d", &n);
  A = (int *)malloc(n*sizeof(int));

  for(i=0; i<n; i++) scanf("%d",A+i);

  for(i=0; i<n; i++){
    if (isPrime(A[i])==1) primen++;
  }
  printf("%d\n",primen);

  return 0;
}

int isPrime(int x){
  int i;

  if (x == 2) return 1;

  if (x<2 || x%2==0) return -1;

  i = 3;
  while (i <= sqrt(x)){
    if (x%i==0) return -1;
    i = i + 2;
  }
  return 1;
}

Measured memory_bytes: 628
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////


int main() {

	ll N, M;
	cin >> N >> M;

	vector<ll> a(N + 1), b(N + 1), c(M + 1), d(M + 1);

	repn(i, N) cin >> a[i] >> b[i];
	repn(i, M) cin >> c[i] >> d[i];

	repn(i, N) {
		ll m = INF;
		ll ans = 0;
		
		repn(j, M) {
			ll di = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if (di < m) { ans = j; m = di; }
		}

		cout << ans << endl;
	}
	
	system("PAUSE");
}


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

using namespace std;
using ll = long long;

int main() {
    string s;
    cin>>s;
    reverse(s.rbegin(),s.rend());
    ll sum=0;
    int qi=-1;
    for(int i = 1;i <= 11;++i) {
        if(s[i]!='?') {
            sum+=(s[i]-'0')*(i<=6?i+1:i-5);
        }
        else qi=i;
    }
    if(qi==-1) {
        int ans = sum%11;
        if(ans<=1)ans=0;
        else ans=11-ans;
        cout<<ans<<endl;
    }
    else {
        int cd=s[0]-'0';
        vector<int> ans;
        for(int i = 0;i < 10;++i) {
            int ts=sum+i*(qi<=6?qi+1:qi-5);
            if(11-(ts)%11==cd||((ts)%11<=1&&cd==0))ans.emplace_back(i);
        }
        if(ans.size()==1)cout<<ans[0]<<endl;
        else cout<<"MULTIPLE"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3224
import sys
import numpy as np
from collections import deque
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
H, W = [int(x) for x in input().strip().split()]
G = np.zeros((H, W), dtype=int)
pre = np.ones(W, dtype=int) * -1
NH = H
for h in range(H):
    s = np.array([1 if s == '#' else 0 for s in input().strip()])
    if np.all(s == pre):
        NH -= 1
    else:
        G[h, :] = s
        pre = s

H = NH
C = [[float('inf') for _ in range(W)] for _ in range(H)]
pre = ''
def dfs(r, c, cost):
    # print(' -- dfs --')
    C[r][c] = cost
    ret = deque([])
    q = deque([(r, c)])
    while q:
        cr, cc = q.popleft()
        # print('    cr = {}, cc = {}'.format(cr, cc))
        for i, j in [(0, 1), (1, 0)]:
            if not(0 <= cr + i < H and 0 <= cc + j < W):
                continue
            if C[cr+i][cc+j] != float('inf'):
                continue
            if G[r][c] == G[cr+i][cc+j]:
                C[cr+i][cc+j] = cost
                q.append((cr+i, cc+j))
                if cr+i == H-1 and cc+j == W-1:
                    return ret
            else:
                ret.append((cr+i, cc+j))
    # print(ret)
    return ret
q = deque([(0, 0)])
cost = 0
while True:
    # print('q = {}'.format(q))
    nq = deque([])
    if G[q[0][0]][q[0][1]] == 1:
        cost += 1
    for r, c in q:
        # print('  r = {}, c = {}'.format(r, c))
        if C[r][c] != float('inf'):
            continue
        nq.extend(dfs(r, c, cost))
    q = nq
    # print(C)
    # print('nq = {}'.format(nq))
    if C[H-1][W-1] != float('inf'):
        print(C[H-1][W-1])
        exit()

Measured memory_bytes: 12560
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = l()
co = 0
for i in range(n):
    if i+1 == a[a[i]-1]:
        co += 1
print(co//2)

Measured memory_bytes: 85260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n;
	scanf("%lld",&n);
	vector<int> x;
	ll sum = 0;
	int CT = 0;
	for (int i = 1; i < 13; i++){
		ll cur = 1;
		for (int j = 0; j < i; j++) cur *= 26;
		if (sum+cur < n){
			sum += cur;
		}
		else{
            CT = i;
			n -= sum+1; break;
		}
	}
	while (n){
		x.push_back(n%26);
		n /= 26;
	}
	while (x.size() < CT) x.push_back(0);
	reverse(x.begin(),x.end());
	for (auto X : x){
		//printf("%d ",X);
		printf("%c",(char)(X+'a'));
	}
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
#define COUT(x) cout << #x << " = " << (x) << ", "
typedef long long ll;
using namespace std;
static const ll MOD = 1000000007;

int main(){
  ll X,Y,A,B,C;
  cin >> X >> Y >> A >> B >> C;
  vector<ll> p(A);
  vector<ll> q(B);
  vector<ll> r(C);
  for(int i = 0; i < A; i++){
    cin >> p[i];
  }
  for(int i = 0; i < B; i++){
    cin >> q[i];
  }
  for(int i = 0; i < C; i++){
    cin >> r[i];
  }
  sort(p.begin(), p.end());
  sort(q.begin(), q.end());
  sort(r.begin(), r.end());
  ll res = 0;
  int idxA = A - X;
  int idxB = B - Y;
  int idxC = C - 1;
  bool flagA = true;
  bool flagB = true;
  bool flagC = true;
  for(int i = 0; i < X + Y; i++){
    if(flagC == false){
      if(flagA == false){
	res += q[idxB];
	idxB++;
	continue;
      }
      if(flagB == false){
	res += p[idxA];
	idxA++;
	continue;
      }
      if(p[idxA] < q[idxB]){
	res += q[idxB];
	idxB++;
	if(idxB == B){
	  flagB = false;
	}
	continue;
      }else{
	res += p[idxA];
	idxA++;
	if(idxA == A){
	  flagA = false;
	}
	continue;
      }
    }
    if(flagA == false){
      if(r[idxC] > q[idxB]){
	res += r[idxC];
	idxC--;
	idxB++;
	if(idxC == -1){
	  flagC = false;
	}
      }else{
	res += q[idxB];
	idxB++;
      }
      continue;
    }
    if(flagB == false){
      if(r[idxC] > p[idxA]){
	res += r[idxC];
	idxC--;
	idxA++;
	if(idxC == -1){
	  flagC = false;
	}
      }else{
	res += p[idxA];
	idxA++;
      }
      continue;
    }
    if(p[idxA] < q[idxB]){
      if(p[idxA] < r[idxC]){
	res += r[idxC];
	idxC--;
	idxA++;
	if(idxA == A){
	  flagA = false;
	}
	if(idxC == -1){
	  flagC = false;
	}
      }else{
	res += p[idxA];
	idxA++;
	if(idxA == A){
	  flagA = false;
	}
      }
    }else{
      if(q[idxB] < r[idxC]){
	res += r[idxC];
	idxC--;
	idxB++;
	if(idxB == B){
	  flagB = false;
	}
	if(idxC == -1){
	  flagC = false;
	}
      }else{
	res += q[idxB];
	idxB++;
	if(idxB == B){
	  flagB = false;
	}
      }
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include "iomanip"

using namespace std;

#include <cstdio>
#include <cstring>


int main() {
    string s, t = "CODEFESTIVAL2016";
    cin >> s;
    int count = 0;
    for (int i = 0; i < s.length(); ++i) {
        if (t[i] != s[i]) {
            count++;
        }
    }
    cout << count << endl;

}

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


// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N,a;
  scanf("%lld",&N);
  std::vector<long long> A(N);
  std::vector<long long> tab(N);
  vector<long long> result;
  A[0] = 0;
  tab[0]++;
  for(int i = 1 ; i < N ; i++){
    scanf("%lld",&A[i]);
    tab[A[i]]++;
  }

  for(int i = 0; i < (N-1); i++){
    cout << tab[(i+1)] << endl;
  }
  cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 6452
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
class Main{
  public static void main(String args[]) throws IOException{
   int n,m;
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   String line = br.readLine(); 
   String[] token = line.split(" ");
   n = Integer.parseInt(token[0]);
   m = Integer.parseInt(token[1]);
   int[][] matrixA = new int[n][m];
   int[] matrixB = new int[m];
   int[] matrixanswer = new int[n]; 
 
   for(int i = 0; i < n ;i++){
     String line2 = br.readLine(); 
     String[] token2 = line2.split(" ");
     for(int j = 0; j < m ;j++){
        matrixA[i][j] = Integer.parseInt(token2[j]);
         
     }//for  
   }//for
 
   for(int i = 0; i < m ;i++){
      matrixB[i] = Integer.parseInt(br.readLine());
   }
 
   for(int i = 0; i < n ;i++){
      matrixanswer[i] = 0;
   }   
 
  for(int i = 0; i < n ;i++){
      for(int j = 0; j < m ;j++){
        matrixanswer[i] += matrixA[i][j]*matrixB[j];
      }
   }
 
    for(int j = 0; j < n ;j++){
       System.out.println(matrixanswer[j]);
    }
 
 
  }
}

Measured memory_bytes: 27484
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define in insert
#define pb push_back
#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl "\n"
inline ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
inline ll power(ll a, ll n, ll m)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2, m);
    p = (p * p) % m;
    if (n % 2)
        return (p * a) % m;
    else
        return p;
}
const ll mod = 1e9 + 7;
const int N = int(3e5) + 999;
#define int long long int
#define inf 1e18

int n;
vector<int> g[100005];
int vis[100005];
int dp[100005][2];

void dfs(int node, int par)
{
    vis[node] = 1;
    dp[node][0] = dp[node][1] = 1;
    for (auto child : g[node])
    {
        if (child == par)
            continue;
        if (vis[child] == 0)
        {
            dfs(child, node);
        }
        int wh = dp[child][0];
        int bl = dp[child][1];
        dp[node][0] = (dp[node][0] * (wh + bl)) % mod;
        dp[node][1] = (dp[node][1] * wh) % mod;
    }
}

int32_t main()
{
    IOS;
    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        g[a].pb(b);
        g[b].pb(a);
    }
    dfs(1, -1);
    cout << (dp[1][0] + dp[1][1]) % mod;
    return 0;
}

Measured memory_bytes: 14976
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;
  ll x[N];
  for (int i = 0; i < N; i++) cin >> x[i];

  ll ans = 10000000000;
  for (int i = 0; i < N; i++) {
    if (i + K > N) break;
    ll sum, l = x[i], r = x[i + K - 1];
    sum = min(abs(l) + abs(r - l), abs(r) + abs(r - l));
    ans = min(sum, ans);
  }

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

Measured memory_bytes: 1024
import sys
input = lambda: sys.stdin.readline().rstrip('\r\n')

N, D = map(int, input().split())
r = 0
for _ in range(N):
	x, y = map(int, input().split())
	if x ** 2 + y ** 2 <= D ** 2:
		r += 1
print(r)


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

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



Measured memory_bytes: 3076
N = int(input())
S = []
for i in range(N):
    s = input()
    S.append(s)

M = int(input())
T = []
for i in range(M):
    t = input()
    T.append(t)

ans = -1
x = 0
for i in S:
    x = S.count(i) - T.count(i)
    ans = max(ans, x)

if ans < 0:
    ans = 0

print(ans)


Measured memory_bytes: 9188
package main

import "fmt"

func main() {
	var n, x int
	fmt.Scan(&n, &x)
	list := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&list[i])
	}

	count := 1
	d := 0
	for i := 0; i < n; i++ {
		if (d + list[i]) <= x {
			count++
		}
		d = d + list[i]
	}
	fmt.Println(count)

}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include<vector>
#include <queue>
using namespace std;
int main()
{
	int a, b;
	int ans = 0;
	cin >> a >> b;
	for (int i = a; i <= b; i++) {
		if (i % 10 == i / 10000 && (i % 100)/10 == (i / 1000)%10)ans++;
	
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {

    public static void main (String [] args) {

        Scanner sc = new Scanner(System.in);

        while(true) {
        
            int n = sc.nextInt();
            int m = sc.nextInt();
            int p = sc.nextInt();

            if (n == 0 && m == 0 && p == 0) break;

            int [] bets = new int[n];
            int total = 0;

            for(int i = 0; i < n; i++) {
                bets[i] = sc.nextInt();
                total += bets[i];
            }

            if (bets[m-1] == 0) {
                System.out.println("0");
            } else {
                total = total * (100 - p);
                System.out.println(total / bets[m-1]);
            }

        }

    }
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
    using namespace std;
    
    #define ll long long
    #define pb push_back
    #define printV(v) for(int i=0;i<v.size();i++){cout << v[i]<< " ";} cout << endl
    #define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
    #define sortV(v) sort(v.begin(),v.end())
    #define revV(v) reverse(v.begin(),v.end())
    #define FOR(i,from,n) for(int i=from;i<n;i++)
    #define FOL(i,from,n) for(int i=from;i >= n;i--)

        ll a,b,c,d,e,f,g,n,m,k,t,x,h,w,p,q,y;
        string str = "";
        ll mod = 1e9 + 7;

        ll pow(ll base, ll q, ll mod){
            ll answer = 1;
            while(q > 0){
                if(q & 1LL)
                    answer = (answer * base) % mod;

                q = q >> 1LL;
                base = (base*base) % mod;
            }
            return answer % mod;
        }

        ll factorial(ll n, ll mod){
            ll answer = 1;
            for(int i=2; i<=n; i++){
                answer = (answer * i) % mod;
            }
            return answer % mod;
        }

        ll inverse(ll base, ll mod){
            return pow(base, mod-2, mod) % mod;
        }

        /*ll C(ll n, ll m, ll mod){
            return (factorial(n, mod) * inverse(factorial(m,mod) * factorial(n-m, mod)%mod, mod) ) % mod;
        } */  

        

        void solve(){
            cin >> n >> m;
            if(m%2 || 4*n < m || 2*n > m) cout << "No\n";
            else cout << "Yes\n";
        }

       
    


        int main(){
            ios_base::sync_with_stdio(false);

            

            

            int cases = 1;
            //cin >> cases;

            while(cases--) solve();
            return 0;

        }

Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
    int d,n;
    cin>>d>>n;
    int ans=(int)pow(100,d);
    if(n==100)n++;
    ans*=n;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
//
// Created by watemus on 08.09.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define FF first
#define SS second

using ll = long long;
using ld = long double;

#define int ll

template<typename T>
using vec = std::vector<T>;

template<typename T>
using uset = std::unordered_set<T>;

template<typename T1, typename T2>
using umap = std::unordered_map<T1, T2>;

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;
const ld PI = acos(-1);

#ifdef LOCAL
std::mt19937 rnd(228);
#else
std::mt19937 rnd(std::chrono::steady_clock::now().time_since_epoch().count());
#endif

vec<pair<int, int>> DD = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
/*
template<class... Args>
auto Vec(size_t n, Args&&... args) {
  if constexpr(sizeof...(args) == 1)
    return vector(n, args...);
  else
    return vector(n, Vec(args...));
}*/

#ifdef LOCAL
#else
#endif

void run() {
    int n;
    cin >> n;
    if (n % 2 == 0 || n % 5 == 0) {
        cout << "-1\n";
        return;
    }
    int cur = 0;
    for (int i = 1; i < 1e7; i++){
        cur = ((cur * 10) + 7) % n;
        if (cur == 0) {
            cout << i << '\n';
            return;
        }
    }
    cout << "-1\n";
}

signed main() {
#ifdef LOCAL
  std::freopen("input.txt", "r", stdin);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
#endif
  int t = 1;
  //cin >> t;
  while (t--) {
    run();
  }
  return 0;
}




Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long int
#define N 1000
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
using namespace std;
/**
        * @author :: Sawlani
        *
        */
int main()
{
    ll x,y,z;
    cin >>  x >> y >> z;

    swap(x,y);
    swap(x,z);

    cout << x << " " << y << " " <<  z;
}

Measured memory_bytes: 384
(let* ((a (read))
       (b (read))
       (c (read))
       (k (read))
       (x (if (< (log (/ a b) 2) 0)
              0
              (1+ (floor (log (/ a b) 2)))))
       (d (* b (expt 2 x)))
       (y (if (< (log (/ d c) 2) 0)
              0
              (1+ (floor (log (/ d c) 2))))))
  (if (>= k (+ x y))
      (format t "Yes~%")
      (format t "No~%")))


Measured memory_bytes: 23564
num,total = map(int,input().split())
for i in range(num+1):
    for j in range(num+1-i):
        if i*10000 + j*5000 + (num-i-j)*1000 == total:
            print(i,j,num-i-j)
            exit()
print("-1 -1 -1")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
string s;
int f[129]={0},cnt=0;
int main(){
	cin>>s;
	for(int i=0;i<s.size();i++){
		f[s[i]]++;
	}
	for(int i=1;i<=127;i++){
		if(f[i]!=0){
			cnt++;
		}
	}
	if(cnt==2){
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
	return 0;
} 

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

#define INF 1e9
using namespace std;

int main() {

    int H, W; cin >> H >> W;

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

    //黒いマスのある行、列を記録していく
    vector<bool> row(H, false);
    vector<bool> col(W, false);
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (a[i][j] == '#') {
                row[i] = true;
                col[j] = true;
            }
        }
    }

    //黒いマスのある行、列を表示する
    for (int i = 0; i < H; ++i) {
        if (row[i]) {
            for (int j = 0; j < W; ++j) {
                if (col[j]) {
                    cout << a[i][j];
                }
            }

            cout << endl;
        }
    }
}

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

int main()
{
  int a,b,c,d;
  cin >>a>>b>>c>>d;
  
  if (a+b > c+d){
    cout << "Left" << endl;
  }else if (a+b < c+d){
    cout << "Right" << endl;
  }else{
    cout << "Balanced" << endl;
  }
  
    
    return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <numeric>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

int main(void){
  int s;
  cin >> s;
  map<int,int> m;
  int i=1;
  while(true) {
    if (s%2 == 0) {
      if (m.count(s)==0) {
        m[s] = 1;
      }else {
        cout << i;
        break;
      }
      s = s/2;
    } else {
      if (m.count(s)==0) {
        m[s] = 1;
      }else {
        cout << i;
        break;
      }
      s = 3*s+1;
    }
    i++;
  }
  return 0;
}


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

int main() {
  int a = 0, b = 0;
  
  cin >> a >> b;
  if ( (a & 1) && (b & 1) ) {
    cout << "Odd" << endl;
  } else {
    cout << "Even" << endl;
  }
}


Measured memory_bytes: 256
import sys
from heapq import heappush, heappop
from collections import defaultdict, deque
sys.setrecursionlimit(10**9)


def solve(n, a, b, c, d):
    MAX = n * max(a, b, c, d) + 1
    memo = defaultdict(lambda: MAX)

    def dfs(m, cost):
        if memo[m] <= cost:
            return
        memo[m] = cost

        if m > 0:
            dfs(m // 2, cost + (m % 2) * d + a)
            dfs(m // 3, cost + (m % 3) * d + b)
            dfs(m // 5, cost + (m % 5) * d + c)

            dfs((m + (2 - m % 2)) // 2, cost + (2 - m % 2) * d + a)
            dfs((m + (3 - m % 3)) // 3, cost + (3 - m % 3) * d + b)
            dfs((m + (5 - m % 5)) // 5, cost + (5 - m % 5) * d + c)

            dfs(0, cost + m * d)

    dfs(n, 0)
    return memo[0]


t = int(input())
for _ in range(t):
    n, a, b, c, d = map(int, input().split())
    ans = solve(n, a, b, c, d)
    print(ans)


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

int main () {
  int a, b, c, ans = 0;
  cin >> a >> b >> c;
  
  for (int i=a; i<=b; i++) {
    if (i%c==0) {
      ans ++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main() {
    int n;
    ll a, b;
    cin >> n >> a >> b;
    vector<ll>x(n);
    rep(i, 0, n){
        cin >> x[i];
    }
    ll ans;
    rep(i, 0, n-1){
        ans += min((x[i+1]-x[i])*a, b);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	int n;
	cin >> n;
	while(n--)
	{
		int x;
		cin >> x;
		if(x % 2)
			continue;
		if(x % 3 == 0 || x % 5 == 0)
			continue;
		cout << "DENIED";
		return 0;
	}
	cout << "APPROVED";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)

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

    if((n-1)%(k-1)==0){
        cout<<(n-1)/(k-1)<<endl;
    }else{
        cout<<(n-1)/(k-1)+1<<endl;
    }    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int M,N,S;
  cin >> N >> M;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  S = 0;
  for(int i=0; i<N; i++){
    S += A.at(i);
  }
  sort(A.begin(), A.end());
  if(A.at(N-M)*4*M < S){
    cout << "No" << endl;
  }
  else{
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

// Union-Find
class UnionFind {
private:
	// parents[i] >= 0 なら i の親
	// parents[i] < 0 で、根。abs(parents[i])がその木に属する頂点数
	vector<int> parents;
	int n_root;

public:
	UnionFind();
	UnionFind(int n) {
		parents.assign(n, -1);
		n_root = n;
	}
	~UnionFind() {
		parents.clear();
	};

	int find(int x) {
		if (parents[x] < 0) {
			return x;
		} else {
			return parents[x] = find(parents[x]);
		}
	}

	void unite(int x, int y) {
		x = find(x);
		y = find(y);

		if (x == y) {
			return;
		}

		if (size(x) < size(y)) {
			swap(x, y);
		}

		parents[x] += parents[y];
		parents[y] = x;
		n_root--;
		return ;
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// xが属する集団のサイズ
	int size(int x) {
		return -parents[find(x)];
	}

	// いくつの集団があるか
	int get_n_root() {
		return n_root;
	}
};

int main() {
	long long n, m;
	cin >> n >> m;

	vector<int> a(m), b(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}

	vector<long long> ans(m + 1, -1);
	ans[m] = n * (n - 1) / 2;

	UnionFind uf(n);

	for (int i = m - 1; i >= 0; i--) {
		if (uf.same(a[i], b[i])) {
			ans[i] = ans[i + 1];
		} else {
			int x = uf.size(a[i]);
			int y = uf.size(b[i]);
			uf.unite(a[i], b[i]);
			ans[i] = ans[i + 1] - 1LL * x * y;
		}
	}

	for (int i = 1; i <= m; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3328
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
	int n,v=0,s=0;
	char a[150];
	scanf("%d",&n);
	scanf("%s",a);
	for (int i=0;i<n;i++)
	{
		if (a[i]=='I')s++;
		if (a[i]=='D')s--;
		v=max(v,s);
	}
	printf("%d\n",v);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll inf=1000000000000000000;
ll dat[800010];
ll u;
void seginit(ll n){
  for(int i=0;;i++){
    ll y=pow(2,i);
    if(y>=n){
      u=y;
      break;
    }
  }
  fill(dat,dat+2*u,inf);
}
void add(ll n,ll x){
  ll i=n+u-1;
  dat[i]=x;
  while(i>0){
    i=(i-1)/2;
    dat[i]=min(dat[2*i+1],dat[i*2+2]);
  }
}
ll que(ll a,ll b,ll k,ll l,ll r){
  if(a>=r||b<=l)return inf;
  if(a<=l&&b>=r)return dat[k];
  ll m1=que(a,b,2*k+1,l,(l+r)/2);
  ll m2=que(a,b,2*k+2,(l+r)/2,r);
  return min(m1,m2);
}

int main(){
  ll n,q;cin>>n>>q;
  seginit(2*n);
  ll a[2*n],b[2*n];
  for(int i=0;i<2*n;i++)cin>>a[i];
  ll sum=0;
  ll c=0;
  ll z=0;
  for(int i=0;i<2*n;i++){
    cin>>b[i];
    if(i==0||i==2*n-1){
      sum+=a[i];
    }
    else{
      if(a[i]>=b[i]){
        sum+=a[i];
        add(i,a[i]-b[i]);
        if(a[i]==b[i])z++;
      }
      else{
        c=(c+1)%2;
        sum+=b[i];
        add(i,b[i]-a[i]);
      }
    }
  }
  for(int i=0;i<q;i++){
    ll p,x,y;cin>>p>>x>>y;
    p--;
    if(p==0||p==2*n-1){
      sum+=-a[p]+x;
      a[p]=x;
      b[p]=y;
      ll g=0;
      if(c==1){
        g=que(1,2*n-1,0,0,2*n);
      }
      cout<<sum-g<<endl;
      continue;
    }
    if(((a[p]-b[p])>=0&&x<y)||((a[p]-b[p])<0&&x>=y)){
      c=(c+1)%2;
    }
    //cout<<c<<endl;
    sum+=-max(a[p],b[p])+max(x,y);
    add(p,abs(x-y));
    if(a[p]==b[p])z--;
    if(x==y)z++;
    a[p]=x;
    b[p]=y;
    if(z>0){
      cout<<sum<<endl;
      c=0;
      continue;
    }
    ll f=0;
    if(c==1){
      f=que(1,2*n-1,0,0,2*n);
    }
    cout<<sum-f<<endl;
  }
}
        
  


Measured memory_bytes: 11008
// ---------- BEG ../defs.hpp BEG ----------
#ifndef atcoder_defs_hpp
#define atcoder_defs_hpp
#include <cstdio>
#include <cstdint>
#include <cinttypes>
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;
using i8t = std::int64_t;
using u8t = std::uint64_t;
using vi8t = std::vector<i8t>;
using vvi8t = std::vector<std::vector<i8t>>;
using vu8t = std::vector<u8t>;
#include <limits>
static const i8t i8t_max=numeric_limits<i8t>::max();
static const i8t i8t_min=numeric_limits<i8t>::min();
#include <unordered_map>
#include <unordered_set>
template<typename Key,typename Value> using map_t=std::unordered_map<Key, Value>;
template<typename Key> using set_t=std::unordered_set<Key>;
#define F3(i,i0,iN,step) for(i8t i=i0,i##_N=iN;i<i##_N;i+=step)
#define F2(i,i0,iN) F3(i,i0,iN,1)
#define F(i,N) F3(i,0,N,1)
#define FR(i,N) for(i8t i=N;i--;)
#define R(V) i8t V;std::cin>>V;
#define RV(V,N) std::vector<i8t> V;F(_i,N){R(_x)V.push_back(_x);}
#define RL1(line) std::getline(std::cin,line);
#define RL(line) std::string line;RL1(line)
#define RM(V,L,C) std::vector<char> V;F(_i,L){RL(_l)F(_j,C)V.push_back(_l[_j]);}
#define P(X) std::cout<<(X)<<std::endl;
template<typename T> T umax(T& ans,T const& value) {if(value>ans)ans=value;return ans;}
template<typename T> T umin(T& ans,T const& value) {if(value<ans)ans=value;return ans;}
template<typename T> struct identity { using type = T; };
#endif
// ---------- END ../defs.hpp END ----------

int main() {
  RL(S)R(Q);
  i8t hanten=0;
  std::string C;

  std::string ffix[2];
  F(i,Q){
    R(T);
    if(T==1)
      hanten^=1;
    else{
      R(F);std::cin>>C;
      ffix[(F==2)^hanten] += C;
    }
  }

  std::reverse(ffix[0].begin(),ffix[0].end());
  std::string ans = ffix[0] + S + ffix[1];
  if(hanten)std::reverse(ans.begin(),ans.end());
  P(ans);
  return 0;
}


Measured memory_bytes: 1348
#include <stdio.h>
#define N 25

typedef struct{
  int parent;
  int left;
  int right;
}Node;

Node node[N];

void preorder(int);
void inorder(int);
void postorder(int);

int main(){
  int i, j, n, id, child, sub;
  scanf("%d", &n);
  for(i = 0;i < n;i++){
    node[i].parent = node[i].left = node[i].right = -1;
  }
  for(i = 0;i < n;i++){
    scanf("%d", &id);
    for(j = 0;j < 2;j++){
      scanf("%d", &child);
      if(child != -1){
        node[child].parent = id;
        if(j == 0){
          node[id].left = child;
        }
        else{
          node[id].right = child;
        }
      }
    }
  }
  for(i = 0;i < n;i++){
    if(node[i].parent == -1){
      sub = i;
      break;
    }
  }
  printf("Preorder\n");
  preorder(sub);
  printf("\nInorder\n");
  inorder(sub);
  printf("\nPostorder\n");
  postorder(sub);
  printf("\n");
  return 0;
}
void preorder(int root){
  int i, j;
  printf(" %d", root);
  if(node[root].left != -1){
    i = node[root].left;
    preorder(i);
    if(node[root].right != -1){
      j = node[root].right;
      preorder(j);
    }
  }
  else{
    if(node[root].right != -1){
      j = node[root].right;
      preorder(j);
    }
  }
}

void inorder(int root){
  int i, j;
  if(node[root].left != -1){
    i = node[root].left;
    inorder(i);
    printf(" %d", root);
    if(node[root].right != -1){
      j = node[root].right;
      inorder(j);
    }
  }
  else{
    if(node[root].right != -1){
      printf(" %d", root);
      j = node[root].right;
      inorder(j);
    }
    else{
      printf(" %d", root);
    }
  }
}

void postorder(int root){
  int i, j;
  if(node[root].left != -1){
    i = node[root].left;
    postorder(i);
    if(node[root].right != -1){
      j = node[root].right;
      postorder(j);
    }
    printf(" %d", root);
  }
  else{
    if(node[root].right != -1){
      j = node[root].right;
      postorder(j);
      printf(" %d", root);
    }
    else{
      printf(" %d", root);
    }
  }
}

Measured memory_bytes: 616
n, m = map(int,input().split())
a = []
e = []
for i in range(n):
    b = list(map(int,input().split()))
    a += b
for i in range(m):
    d = int(input())
    e.append(d)
for i in range(0,len(a),m):
    g = 0
    for j in range(m):
        f = a[i+j]*e[j]
        g += f
    print(g)


Measured memory_bytes: 6012
#include<stdio.h>
#define MAX 44

int FN[MAX+1];

int main() {
    int i, n;
    FN[0] = FN[1] = 1;

    scanf("%d", &n);
    for (i=2; i<=n; i++) {
        FN[i] = FN[i-1] + FN[i-2];
    }

    printf("%d\n", FN[n]);

    return 0;
}


Measured memory_bytes: 2720
let (a,b,c,k) = cin.quadro
let s = min(a,k) - min(max(k-a-b, 0), c)
print(s)

// MARK: #### 以下、ライブラリ ####

import Foundation
#if os(Linux)
    import Glibc
#else
    import Darwin.C
#endif

enum cin {
    // 123
    static var int: Int { Int(readLine()!)! }
    // 12 23
    static var pair: (Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!) }
    // 12 23 34
    static var triple: (Int, Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!, Int(line[2])!) }
    static var quadro: (Int, Int, Int, Int) { let line = readLine()!.components(separatedBy: " "); return (Int(line[0])!, Int(line[1])!, Int(line[2])!, Int(line[3])!) }
    // AtCoder
    static var str: String { readLine()! }
    // At Coder
    static var arrayStr: [String] { str.components(separatedBy: " ") }
    // 1 2 3 4
    static var array: [Int] { str.components(separatedBy: " ").map { Int($0)! } }
    // 1
    // 2
    // 3
    static func v_array(count: Int) -> [Int] { (0..<count).map { _ in int } }
}

extension Int {
    // 123 -> [1, 2, 3]
    var digits: [Int] { Array(String(self)).map { Int(String($0))! } }
}

extension Array where Element == Int {
    // [2, 1, 3, 2] -> 8
    var sum: Int { self.reduce(0, +) }
    // [2, 1, 3, 2] -> [1, 2, 2, 3]
    var orderBy: [Int] { sorted() }
    // [2, 1, 3, 2] -> [3, 2, 2, 1]
    var orderByDesc: [Int] { sorted(by: { $0 > $1 }) }
    // [2, 1, 3, 2] -> [2, 1, 3]
    var distinct: [Int] { Array(Set(self)) }
}

precedencegroup PowerPrecedence { higherThan: MultiplicationPrecedence }
infix operator ^^ : PowerPrecedence
func ^^ (radix: Int, power: Int) -> Int {
    return Int(pow(Double(radix), Double(power)))
}

extension String {
    // e.g. cin.line.regex(match: "^(dream|dreamer|erase|eraser)*$")
    func regex(match pattern: String) -> Bool {
        let regex = try! NSRegularExpression(pattern: pattern)
        return regex.firstMatch(in: self, range: NSRange(location: 0, length: self.count)) != nil
    }
    // "ABC"[1] -> "B"
    subscript(i: Int) -> Character {
        get {
            self[index(at: i)]
        }
        set(char) {
            var characters = Array(self)
            characters[i] = char
            self = String(characters)
        }
    }
    func index(at offset: Int) -> String.Index { index(startIndex, offsetBy: offset) }
    // "ABC".swapAt(0, 1) -> "BAC"
    mutating func swapAt(_ index1: Int, _ index2: Int) {
        var characters = Array(self)
        characters.swapAt(index1, index2)
        self = String(characters)
    }
}


Measured memory_bytes: 14132
N = int(input())
pret = prex = prey = 0
res = True
for _ in range(N):
    t,x,y = map(int,input().split())
    dt,dx,dy = t-pret,x-prex,y-prey
    pret,prex,prey = t,x,y
    r = dt-abs(dx)-abs(dy)
    if r<0 or r%2!=0:res = False
print('Yes' if res else 'No')

Measured memory_bytes: 3064