akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;

//#define abs(N) ((N>0)?N:-1*N)
//#define min(A,B) ((A>B)?B:A)
//#define max(A,B) ((A<B)?B:A)
#define print(S) (cout << S)
#define println(S) (cout << S << endl)

#define M_PI 3.14159265358979

class Dice {
public:
	enum Dir{
		TOP=0,
		SOUTH=1,
		EAST=2,
		WEST=3,
		NORTH=4,
		BOTTOM=5,
	};

	Dice(int args[]){
		for (int i = 0; i < 6; ++i) {
			labels[i] = args[i];
		}
	}
	void move(char d){
		int tmp[6];
		for (int i = 0; i < 6; ++i) {
			tmp[i] = labels[i];
		}
//		print("==move : ");
//		println(d);
//		prt();
//		println("↓");
		switch(d){
		case 'N':
			labels[0] = tmp[1];
			labels[1] = tmp[5];
			labels[5] = tmp[4];
			labels[4] = tmp[0];
			break;
		case 'S':
			labels[1] = tmp[0];
			labels[5] = tmp[1];
			labels[4] = tmp[5];
			labels[0] = tmp[4];
			break;
		case 'E':
			labels[0] = tmp[3];
			labels[3] = tmp[5];
			labels[5] = tmp[2];
			labels[2] = tmp[0];
			break;
		case 'W':
			labels[3] = tmp[0];
			labels[5] = tmp[3];
			labels[2] = tmp[5];
			labels[0] = tmp[2];
			break;
		}
	}

	void prt(){
		for (int i = 0; i < 6; ++i) {
			cout << labels[i] << " ";
		}
		cout << endl;
	}

	int labels[6];
};

int main(){
	int labels[6];
	for (int i = 0; i < 6; ++i) {
		cin >> labels[i];
	}
	Dice d(labels);

	string str;
	cin >> str;
//	d.prt();
	for (int i = 0; i < str.size(); ++i) {
		char c;
		c = str[i];
		d.move(c);
//		d.prt();
	}
	println(d.labels[0]);

	return 0;
}



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

int main(){
	int n, k;
	string s;
	cin >> n >> k >> s;
	if (s[k - 1] == 'A') {
		s[k - 1] = 'a';
	}
	else if(s[k - 1] == 'B'){
		s[k - 1] = 'b';
	}
	else if (s[k - 1] == 'C') {
		s[k - 1] = 'c';
	}
	cout << s << endl;
}

Measured memory_bytes: 256
// Package main provides
//
// File:  mian.go
// Author: ymiyamoto
//
// Created on Mon Jan 28 11:31:12 2019
//
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)

	arr := make([]int, N)
	sorted := make([]int, N)
	for i := range arr {
		fmt.Scan(&arr[i])
		sorted[i] = arr[i]
	}
	sort.Ints(sorted)

	left := sorted[len(sorted)/2-1]
	right := sorted[len(sorted)/2]
	for i := range arr {
		if arr[i] <= left {
			fmt.Println(right)
		} else {
			fmt.Println(left)
		}
	}
}


Measured memory_bytes: 9728
import java.util.*;

public class Main {
	int [] vx = {-1,0,1,0};
	int [] vy = {0,1,0,-1};
	
	private void doit() {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			int [] x = new int[n];
			int [] y = new int[n];
			for(int i = 1; i < n; i++){
				int ni = sc.nextInt();
				int d = sc.nextInt();
				x[i] = x[ni] + vx[d];
				y[i] = y[ni] + vy[d];
			}
			int maxx= x[0],maxy = y[0],minx = x[0],miny = y[0];
			for(int i=1; i < n; i++ ){
				maxx = Math.max(maxx, x[i]);
				maxy = Math.max(maxy, y[i]);
				minx = Math.min(minx, x[i]);
				miny = Math.min(miny,y[i]);
			}
			System.out.println((maxx - minx + 1) + " " + (maxy - miny + 1));
		}
		
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

const long long INF = 1LL << 60;

unsigned long long dp[110][100010] = {INF};
int v[110];
unsigned long long w[110];

int main (){

    int N;
    unsigned long long W;
    cin >> N >> W;
    for (int i = 0; i < N; ++i){
        cin >> w[i] >> v[i];
    }

    for (int i = 0; i < 110; ++i){
        for (int j = 0; j < 100010; ++j){
            dp[i][j] = INF;
        }
    }

    for (int i = 0; i < 100010; ++i){
        if(i <= v[0]){
            dp[0][i] = w[0];
        }
    }

    dp[0][0] = 0;

    for(int i = 1; i < N; ++i){
        for (int v_sum=0; v_sum < 100010; ++v_sum ){
            if ((v_sum - v[i]) >= 0){
            //if (v_sum <= v[i]){
                chmin(dp[i][v_sum], dp[i-1][v_sum - v[i]] + w[i]);
            }
            chmin(dp[i][v_sum], dp[i-1][v_sum]);
        }
    }
    int ans = 0;
    for (int v_sum=0; v_sum < 100010; ++v_sum){
        if (dp[N-1][v_sum] <= W){
            chmax(ans,v_sum);
            //ans = v_sum;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 86144
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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; }
int main(){
    ios::sync_with_stdio(false);
    string s,t;
    cin >> s >> t;
    int n = s.size();
    map<char,vector<int>> m;
    rep(i,n) {
        m[s[i]].push_back(i);
    }
    ll ans = 0;
    int pre_idx = -1;
    rep(i, t.size()) {
        char c = t[i];
        if(m.count(c) == 0) {
            cout << -1 << endl;
            return 0;
        }
        auto idx_itr = lower_bound(m[c].begin(), m[c].end(), pre_idx+1);
        if(idx_itr != m[c].end()) {
            pre_idx = *idx_itr;
        } else {
            pre_idx = -1;
            ans += n;
            auto idx_itr2 = lower_bound(m[c].begin(), m[c].end(), pre_idx+1);
            pre_idx = *idx_itr2;
        }
    }
    ans += pre_idx+1;
    cout << ans << endl;
}


Measured memory_bytes: 4180
def main():
    N,M = map(int, input().split())
    s = [[int(x) for x in input().split()][1:] for _ in range(M)]
    p = [int(x) for x in input().split()]
    count=0
    for i in range(2**N):
        switch=[0]*N
        sw = bin(i)[2:]
        sw = "0"*(N-len(sw))+sw
        #print(sw)
        #for j in range(N):
            #switch[j] = int(sw[j])
        All=0   
        for j in range(M):
            Sum=0
            for k in s[j]:
                #if switch[k-1]==1:
                if int(sw[k-1])==1:
                    Sum+=1
            if Sum%2 == p[j]:
                All+=1
        if All==M:
            count+=1
    print(count)

main()

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

int main(){
  int a,b;
  double C,c;
  double S,L,h;
  
  cin >> a >> b >> C;
  double PI = acos(-1); //cos(PI rad) = -1 
  C = C * PI / 180;
  S = a * b * sin(C) / 2;
  c = sqrt( a*a + b*b - 2*a*b*cos(C) );
  L = a + b + c;
  h = b * sin(C);
  printf ("%lf\n%lf\n%lf",S,L,h);
  
  return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

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

    int N;
    cin >> N;

    int pre_t = 0, pre_x = 0, pre_y = 0;
    bool ok = true;
    rep(i, N) {
        int T, X, Y;
        cin >> T >> X >> Y;

        int diff_t = T - pre_t;
        int x = X - pre_x;
        int y = Y - pre_y;

        ok &= (x + y <= diff_t && (diff_t - (x + y))%2 == 0); 

        pre_t = T, pre_x = X, pre_y = Y;
    }
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
int n,a[110];
double cnt;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	cnt=a[1];
	for(int i=2;i<=n;i++) cnt=(double)(cnt+a[i])/2;
	cout<<cnt<<endl;
}

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

int main() {
  ll a,b,c; cin >> a >> b >> c;
  
  cout << max(c-(a-b), (ll)0) << endl;
}


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

typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define Hardmode usleep(1.5 * 1000000);
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    if(N == 1){
    	cout << "Hello World" << endl;
    	ED;
    }
    int a, b;
    cin >> a >> b;
    cout << a+b << endl;
}


Measured memory_bytes: 256
a1,b1=map(int,input().split())
a2,b2=map(int,input().split())
a3,b3=map(int,input().split())
a4,b4=map(int,input().split())
a5,b5=map(int,input().split())
a6,b6=map(int,input().split())
a7,b7=map(int,input().split())
print(a1-b1)
print(a2-b2)
print(a3-b3)
print(a4-b4)
print(a5-b5)
print(a6-b6)
print(a7-b7)


Measured memory_bytes: 5588
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int inf = 1e9;

int main(){
    int h,w;
    cin >> h >> w;
    int num[h][256];
    memset(num, 0, sizeof(num));

    for(int i=0; i<h; i++){
        string s;
        cin >> s;
        for(int j=0; j<(int)s.length(); j++){
            num[i][(int)s[j]]++;
        }
    }

    int ans = inf;
    for(int i=0; i<h-2; i++){
        for(int j=i+1; j<h-1; j++){
            int sub = 0;
            for(int k=0; k<h; k++){
                if(k<=i){
                    sub += w -num[k]['W'];
                }else if(k<=j){
                    sub += w -num[k]['B'];
                }else{
                    sub += w -num[k]['R'];
                }
            }
            ans = min(ans, sub);
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3192
use std::collections::VecDeque;
use std::io;

fn main() {
    let nk = parse_values::<usize>(2);
    let n = nk[0];
    let k = nk[1];
    let p = parse_values::<u16>(n);
    println!("{}", solve(n, k, p));
}

fn solve(n: usize, k: usize, p_vec: Vec<u16>) -> f64 {
    let mut p = p_vec.into_iter();
    let mut queue = VecDeque::with_capacity(k);
    for _ in 0..k {
        queue.push_back(p.next().unwrap());
    }

    let mut max_sum: usize = 0;
    for queue_item in &queue {
        max_sum += *queue_item as usize
    }
    //println!("{:?}", queue);
    //println!("{}", max_sum);
    let mut current_sum: usize = max_sum;
    for _ in 0..(n - k) {
        current_sum -= queue.pop_front().unwrap() as usize;
        let next = p.next().unwrap();
        queue.push_back(next);
        current_sum += next as usize;
        //println!("{:?}", queue);
        //println!("{}", current_sum);
        if current_sum > max_sum {
            max_sum = current_sum
        }
        //println!("{:?}", queue);
        //println!("{}", max_sum);
    }
    (max_sum + k) as f64 / 2.0
}

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

fn parse_values<T: std::str::FromStr>(n: usize) -> Vec<T> {
    let line = parse_line::<String>();
    let mut split = line.split_whitespace();
    let mut values = Vec::with_capacity(n);
    for _ in 0..n {
        let v = split.next().unwrap().parse::<T>().ok().unwrap();
        values.push(v);
    }
    values
}

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

int main(){
  int n;cin>>n;
  ll ans=0,tmp,now;
  cin>>tmp;
  now=tmp;
  REP(i,n-1){
    cin>>tmp;
    ans+=max((ll)0,now-tmp);
    now=max(now,tmp);
  }

  cout<<ans;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;
#define fori(i,a,b) for(ll i=(a);i<=(b);i++)
#define repi(i,n) fori(i,0,(n)-1)
#define forr(i,a,b) for(ll i=(b);i>=(a);i--)
#define repr(i,n) forr(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
#define fill(a,x) memset(a,x,sizeof(a))
#define vec vector<ll>
#define pb push_back
#define mp make_pair
#define pcnt __builtin_popcount
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}

#define N 333
ll n,cnt[3];
double dp[N][N][N];
double f(ll s,ll c1,ll c2, ll c3){
    if(c1==0&&c2==0&&c3==0)return 0;
    if(dp[c1][c2][c3]!=0)return dp[c1][c2][c3];
    double ret=(double)n/s;
    if(c1>0)ret+=f(s-1,c1-1,c2,c3)*c1/s;
    if(c2>0)ret+=f(s,c1+1,c2-1,c3)*c2/s;
    if(c3>0)ret+=f(s,c1,c2+1,c3-1)*c3/s;
    return dp[c1][c2][c3]=ret;
}
void solve(){
    cin>>n;
    repi(i,n){
        ll m;cin>>m;
        cnt[m-1]++;
    }
    cout.precision(10);
    cout<<f(n,cnt[0],cnt[1],cnt[2])<<endl;
}

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


Measured memory_bytes: 260224
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ll S; cin>>S;
  ll MAX=1000000000;
  ll Y3=S/MAX,X3=S%MAX;
  if(X3>0) {Y3++; X3=MAX-X3;}
  vector<ll> vec={0,0,MAX,1,X3,Y3};
  
  rep(i,6){
    if(i!=0) cout<<" ";
    cout<<vec[i];
  }
  cout<<endl;
  
  //cout<<MAX*Y3-1*X3<<endl;
  return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int64_t> a(N), b(N, 0);
    
    for (int i = 0; i < N; i++){
        cin >> a.at(i);
        b.at(a.at(i) - 1)++;
    }
    int64_t sum = 0;
    for (int i = 0; i < N; i++){
        if (b.at(i) >= 2) {
            sum += (b.at(i) - 1) * b.at(i) / 2;
        }
    }
    
    for (int i = 0; i < N; i++){
        cout << sum - b.at(a.at(i) - 1) + 1 << endl;
    }
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define endl '\n'

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;

const ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// head

void add(int& a, int b) {
    a += b;
    if(a >= mod) a -= mod;
}
void sub(int& a, int b) {
    a -= b;
    if(a < 0) a += mod;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;

    vector<int> dp(k + 1);

    dp[0] = 1; // there is only 1 way to distribute 0 candies xD

    rep(i,0,n) {
        int candiesLimit; cin >> candiesLimit; // this is the limit to how many candies we can distribute to this person
        vector<int> sum(k + 2);
        for(int j = k; j >= 0; j--) {
            add(sum[j + 1], dp[j]); // this is is saying that if we reach to j candies remaining, we add the # of ways we got here to the number of ways of the candies we get if we distribute some candies out of what we have remaining
            sub(sum[j + 1 + min(k - j, candiesLimit)], dp[j]);
        }
        rep(j,0,k+1) {
            add(sum[j+1], sum[j]);
            add(dp[j], sum[j]);
        }
    }
    cout << dp[k] << endl;

    return 0;
}


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

int main(void)
{
    int L, R, d;
    cin >> L >> R >> d;
    int count = 0;
    for (int i = L; i <= R; i++) {
        if (i % d == 0) {
            count++;
        }
    }
    cout << count << endl;
}


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

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main() {
    vector<int> num = {6,2,5,5,4,5,6,3,7,6};
    int N,M;
    cin >> N >> M;
    vector<int> A(M);
    for(int i=0;i<M;++i) {
        cin >> A[i];
    }
    sort(A.rbegin(),A.rend());

    vector<int> dp(N+1,-999);

    dp[0]=0;
    for(int i=1;i<=N;++i) {
        int max = 0;
        for(int j=0;j<M;++j) {
            if (i-num[A[j]]>=0&&i-num[A[j]]<=N)
                if (dp[i-num[A[j]]]>=0)
                    if (max < dp[i-num[A[j]]]+1)
                        max = dp[i-num[A[j]]]+1;
        }
        if (max > 0) dp[i] = max;
    }

    //cout << dp[N] << endl;
    int tmp=N;
    for (int i=0;i<dp[N];++i) {
        for (int j=0;j<M;++j) {
            if (tmp-num[A[j]]>=0 && dp[tmp-num[A[j]]]==dp[tmp]-1) {
                cout << A[j];
                tmp-=num[A[j]];
                break;
            }
        }
    }

    return 0;
}


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

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

    int n, ans=0, i,j,k;
    cin >> n;
    for (i=1;i<=n;i++) {
        for(j=1;j<=n;j++) {
            for(k=1;k<=n;k++) {
                ans += gcd(gcd(i, j), k);
            }
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;


int gcd(int p, int q) {
    while (q != 0) {
        int r = p % q;
        p = q;
        q = r;
    }
    return p;
}


int main() {
    long long k;
    cin >> k;

    long long ans = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            for (int c = 1; c <= k; c++) {
                ans += gcd(a, gcd(b, c));
            }
        }
    }

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


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y == NIL)
    root=z;
  else{
    if(z->key < y->key)
      y->left=z;
    else y->right=z;
  }
}

void inorder(Node u){
  if(u==NIL)
    return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)
    return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
    }
  }

  return 0;
}



Measured memory_bytes: 25164
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define MOD (1e9+7)

int main(void){
	int n,i;
	bool flag = true;
	ll a[12345],b[12345],save=0;
	cin >> n;
	for(i=0; i<n; i++){
		cin >> a[i];
	}
	for(i=0; i<n; i++){
		cin >> b[i];
	}
	for(i=0; i<n; i++){
		if(a[i] > b[i]){
			flag = false;
			save -= (a[i]-b[i])*2;
		}else{
			save += ((b[i]-a[i])/2)*2;
		}
	}
	if(flag){
		cout << "Yes" << endl;
		return 0;
	}else if(save >= 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		long num = sc.nextLong();
		long[] arrays = new long[(int) (num+1)];
		arrays[0] = 2;
		arrays[1] = 1;
		for (int i = 2; i < arrays.length; i++) {
			arrays[i] = arrays[i-1] + arrays[i-2];
		}
		System.out.println(arrays[(int) num]);
	}

}

Measured memory_bytes: 23764
program hrn;
 var
  s:string;
  l,a,b,i:longint;
 begin
  read(s);
  l:=length(s);
  for i:=1 to l do if s[i]='Z'then b:=i;
  for i:=l downto 1 do if s[i]='A'then a:=i;
  writeln(b-a+1);
 end.

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007
#define mp(a,b) make_pair(a,b)

ll N,Z,W;
ll a[2010];


int main() {
    cin >> N >> Z >> W;
    rep(i,N) cin >> a[i];
    if (N > 1){
        ll x = abs((a[N-1])-W);
        ll y = abs(a[N-2]-a[N-1]);
        cout << max(x,y) << endl;
    }
    else{
        cout << abs(a[N-1]-W) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
using namespace std;
using ll=long long;
#define chmax(x, y) { x = max(x, y); }
#define chmin(x, y) { x = min(x, y); }

int main(){
    ll x,k,d;
    cin>>x>>k>>d;

    if(x<0) x=-x;
    ll n=min(k,x/d);
    k-=n;
    x-=n*d;
    if(k%2==0) cout<<x<<endl;
    else cout<<abs(d-x)<<endl;

    return 0;
}

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

inline int read()
{
	int ret=0; char c=getchar();
	while(c<48||c>57)c=getchar();
	while(c>=48 && c<=57)ret=ret*10+c-48,c=getchar();
	return ret;
}

char s[5005];
int k,n,nn;
set<string>S;
string p;
int main()
{
	scanf("%s",s+1);
	k=read();
	n=strlen(s+1);//s0
	for(int i=1; i<=n; ++i)
	{
		nn=min(n,i+k-1);
		p=""; //.clear ????
		for(int j=i; j<=nn; ++j)
		{p+=s[j]; //p=p+j// o n //M???
		S.insert(p);//set
	}
	}
	for(int i=1;i<k; ++i)S.erase(S.begin());
	cout<<*(S.begin()); //()
}

Measured memory_bytes: 1664
#include <stdio.h>

int main() {
	int num[3];
	scanf("%d %d %d", &num[0], &num[1], &num[2]);

	int flag = 0;
	int temp = 0;
	while (flag == 0) {
		flag = 1;
		for (int i = 0; i < 2; i++) {
			if (num[i + 1] < num[i]) {
				temp = num[i + 1];
				num[i + 1] = num[i];
				num[i] = temp;
				flag = 0;
			}
		}
	}

	printf("%d %d %d\n", num[0], num[1], num[2]);
	return 0;
}

Measured memory_bytes: 1812
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
// #include <ext/rope>
// using namespace __gnu_cxx;
typedef long long int ll;
typedef long double ld;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define all(v) v.begin(), v.end()
#define pb push_back
#define mxe(v) *max_element(v.begin(), v.end())
#define mne(v) *min_element(v.begin(), v.end())
#define ve vector
#define lb lower_bound
#define ub upper_bound
#define bb break
#define cc continue
#define rem 1000000007
#define PI 3.141592653589793238462643383279502
ll power(ll x, ll y, ll p)
{
    ll res = 1; // Initialize result
    x = x % p;  // Update x if it is more than or
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1; // y = y/2
        x = (x * x) % p;
    }
    return res;
}
ll modInverse(ll n, ll p)
{
    return power(n, p - 2, p);
}
struct point
{
    ll x, y;
};
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    char x;
    cin>>x;
    if (x>'Z')
    {
        cout<<'a';
    }
    else
    {
        cout<<'A';
    }
}


Measured memory_bytes: 3660
sx, sy, tx, ty = map(int, input().split())

dx, dy = tx-sx, ty - sy

ans = ""
ans += "U" * dy
ans += "R" * dx
ans += "D" * dy
ans += "L" * dx

ans += "L"
ans += "U" * (dy+1)
ans += "R" * (dx+1)
ans += "DR"
ans += "D" * (dy+1)
ans += "L" * (dx+1)
ans += "U"

print(ans)

Measured memory_bytes: 38256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int N, W;
        cin >> N >> W;

        vector<vector<ll> > dp(N + 1, vector<ll>(W + 1, -1));
        dp[0][0] = 0;

        vector<ll> w(N), v(N);

        rep(i, 0, N) {
            cin >> w[i] >> v[i];
        }

        for (int i = 0; i < N; ++i) {
            int ni = i + 1;
            for (int j = 0; j <= W; ++j) {
                if (dp[i][j] != -1) {
                    ll nj = j + w[i];
                    if (ni <= N && nj <= W) {
                        chmax(dp[ni][nj], dp[i][j] + v[i]);
                    }
                    chmax(dp[ni][j], dp[i][j]);
                }
            }
        }

        ll ans = 0ll;
        for (int i = 0; i <= W; ++i) {
            chmax(ans, dp[N][i]);
        }

        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 80256
n=int(input())
lists=[]
for i in range(n):
  a=int(input())
  lists.append(a)
#Nこの連続した数の最大公約数、最小公倍数を求めるアルゴリズム
import math
import fractions

#最小公倍数
def union_lcm(lists):
    if len(lists)==1:
        return lists[0]
    elif len(lists)>1:
        num=lists[0]
        for i in range(1,len(lists)):
            num=num*lists[i]//fractions.gcd(num,lists[i])
        return num
P=union_lcm(lists)
print(P)

Measured memory_bytes: 5048
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>




using namespace std;
int main() {

	int n, a, b;
	cin >> n >> a >> b;
	if (abs(a - b) % 2)cout << "Borys" << endl;
	else cout << "Alice" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K;
string S,T;
//=============================
void input()
{
    cin>>N>>K;
}
//=============================
void func(){}
//=============================
void solve()
{
    cout<<(N%K ? "1" : "0") << endl;
}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
inf = float("inf")
N, M, L = map(int, input().split())
graph = np.zeros((N, N))
for _ in range(M):
    A, B, C = map(int, input().split())
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C
shortest_paths = dijkstra(csr_matrix(graph), directed=False)
graph = np.full((N, N), inf)
for i in range(N):
    for j in range(N):
        if shortest_paths[i][j] <= L:
            graph[i][j] = 1

Q = int(input())
def int_(num_str):
    return int(num_str) - 1

costs = dijkstra(csr_matrix(graph), directed=False)
for _ in range(Q):
    s, t = map(int_, input().split())
    print(int(costs[s][t])-1 if costs[s][t] != inf else -1)

Measured memory_bytes: 19528
int b[5];main(i,s,w) {while(1){for(s=i=0;i-5&&scanf("%d",b+i);s|=1<<--b[i++]);if(*b<0)return 0;for(i=0,w=s-5?s-6?0:1:2;printf("%d\n",(s-1&&s-2&&s-4&&s-7)?b[i]-w?2:1:3)&&++i-5;);}}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

void sort2vectors(vector<lint> &av, vector<lint> &bv) {
        lint n = av.size();
        vector<lint> p(n), av2(n), bv2(n);
        iota(p.begin(), p.end(), 0);
        sort(p.begin(), p.end(), [&](lint a, lint b) { return av[a] < av[b]; });
        for (int i = 0; i < n; i++) {
                av2[i] = av[p[i]];
                bv2[i] = bv[p[i]];
        }
        av = av2;
        bv = bv2;
}

int main(void){
    // input
    lint N;
    cin >> N;
    vector<lint> A(N);
    vector<lint> B(N);

    for (int i = 0; i < N; ++i) {
        cin >> A[i] >> B[i];
    }
    sort2vectors(B, A);
    vector<lint> cumsum_A(N);
    cumsum_A[0] = A[0];
    for (int i = 1; i < N; ++i) {
        cumsum_A[i] = A.at(i) + cumsum_A.at(i-1);
    }
    // Aの合計がBの最大値以下
    // dp[i]...i番目のタスクまでが実施可能かどうか
    int dp[N];
    dp[0] = (B[0] >= cumsum_A[0]);
    for (int i = 0; i < N-1; ++i) {
        
        // cout << "B[i] = " << B.at(i+1) << " ,";
        // cout << "A[i] = " << A.at(i+1) << " ,";
        // cout << "cumsum_A[i] = " << cumsum_A.at(i+1) << endl;

        dp[i+1] = ((dp[i]) && (B.at(i+1) >= cumsum_A.at(i+1)));
        // cout << dp[i+1] << endl;
    }
    
    string ans;
    if (dp[N-1]) ans = "Yes";
    else ans = "No";
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 8064
#include<cstdio>
#include<cassert>
#include<vector>
#include<algorithm>

using namespace std;

const long long inf=1e13;

struct RMQ{
	int N;
	long long dat[8192];
	void init(int N_){
		N=1;
		while(N<N_) N*=2;
		for(int i=1;i<=N*2-1;i++) dat[i]=-inf;
	}
	void update(int i,long long x){
		i+=N;
		while(i>0){
			dat[i]=max(dat[i],x);
			i/=2;
		}
	}
	long long get(int i){//[0,i)
		if(i==0) return -inf;
		int le=0,ri=N;
		int k=1;
		long long res=-inf;
		while(ri-le>1){
			int mid=(le+ri)/2;
			if(mid<=i){
				res=max(res,dat[k*2]);
				k=k*2+1;
				le=mid;
			}else{
				k=k*2;
				ri=mid;
			}
		}
		if(ri==i) res=max(res,dat[k]);
		return res;
	}
};


RMQ rmq;

long long sum[4040];
long long dp[4040][4040];

vector<long long> vals;

int N;
long long a[4040];

vector<int> C;

int main(){
	scanf("%lld",&N);
	for(int i=0;i<N;i++) scanf("%lld",a+i);
	sum[0]=a[0];
	for(int i=1;i<N;i++) sum[i]=sum[i-1]+a[i];
	for(int i=0;i<4040;i++) for(int j=0;j<4040;j++){
		dp[i][j]=inf;
	}
	for(int i=0;i<N;i++) dp[i][1]=sum[i];
	for(int k=2;k<=N;k++){
		vals.clear();
		for(int i=0;i<N;i++){
			if(dp[i][k-1]<inf) vals.push_back(dp[i][k-1]+sum[i]);
		}
		sort(vals.begin(),vals.end());
		vals.erase(unique(vals.begin(),vals.end()),vals.end());
		rmq.init(vals.size());
		for(int j=0;j<N;j++){
			int id=distance(vals.begin(),lower_bound(vals.begin(),vals.end(),sum[j]));
			long long ma=rmq.get(id);
			if(ma>-inf){
				dp[j][k]=min(dp[j][k],sum[j]-ma);
			}
			if(dp[j][k-1]<inf){
				id=distance(vals.begin(),lower_bound(vals.begin(),vals.end(),dp[j][k-1]+sum[j]));
				rmq.update(id,sum[j]);
			}
		}
	}
	int ans=0;
	for(int i=1;i<=N;i++){
		if(dp[N-1][i]<inf){
			ans=i;
		}
	}
	printf("%d\n",ans);
	int cur=N-1;
	for(int i=ans;i>=2;i--){
		bool flg=false;
		for(int j=cur-1;j>=0;j--){
			if(dp[j][i-1]<sum[cur]-sum[j]&&sum[cur]-sum[j]==dp[cur][i]){
				C.push_back(j+1);
				cur=j;
				flg=true;
				break;
			}
		}
		assert(flg);
	}
	reverse(C.begin(),C.end());
	for(int i=0;i<C.size();i++) printf("%d%c",C[i],i==C.size()-1?'\n':' ');
	if(C.size()==0) printf("\n");
//	assert(C.size()>=ans-1);
/*	long long prev=-inf;
	for(int i=0;i<(int)C.size();i++){
		int le=i==0?0:C[i-1];
		//int ri=i==C.size()-1?N-1:C[i+1]-1;
		int ri=C[i];
		long long sum=0;
		for(int j=le;j<ri;j++) sum+=a[j];
	//	assert(prev<sum);
		prev=sum;
	}
	long long xx=0;
	if(C.size()>0){
		for(int i=C[C.size()-1];i<N;i++) xx+=a[i];
	//	assert(prev<xx);
	}*/
	return 0;
}

Measured memory_bytes: 128760
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.1415;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

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

vector<vector<int>> bingo(3, vector<int>(3));
vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

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

struct UnionFind {
	vector<int>uf;

	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

ll getGcd(ll a, ll b) {
	if (a < b) {
		ll temp = b;
		b = a;
		a = temp;
	}

	ll r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

ll line[155];


int getNum(ll target) {

	int bottom = 0;
	int top = 151;
	while (1 < top - bottom) {
		int middle = (top + bottom) / 2;
		if (target < line[middle])top = middle;
		else bottom = middle;
	}
	return bottom;
}

int main() {

	for (ll i = 0; i <= 150;++i) {
		line[i] = i * i * i * i * i;
	}

	ll X; cin >> X;
	for (ll i = 0; i <= 150;++i) {
		bool isMinus = false;
		ll nokori = X - line[i];
		if (nokori < 0) {
			isMinus = true;
			nokori *= (-1);
		}
		int num = getNum(nokori);
		if (line[num] == nokori) {
			//成功
			if (isMinus) {
				cout << i << " " << ((ll)num) << endl;
			}
			else {
				cout << i << " " << -((ll)num) << endl;
			}
			return 0;
		}
	}
}




Measured memory_bytes: 5444
/*Read the problem carefully before starting to work on it*/
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

typedef long long ll;

//ll ncr(ll n,ll r){ll ans=1;r=min(r,n-r);for (int i=1;i<=r;i++){ans*=(n-r+i);ans/=i;}return ans;}

#define pb push_back
#define eb emplace_back
#define mp(x,y) make_pair(x,y)
#define mod 1000000007

double PI=3.1415926535897932384626;

//template<typename T> T power(T x,T y,ll m=mod){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ost;

#define fi first
#define se second

#define SSIZE 50

ll A[SSIZE];
ll B[SSIZE];
ll C[SSIZE];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	for(ll i=1;i<=n;i++)
	{
	    cin>>A[i];
	 }
	for(ll i=1;i<=n;i++)
	{
	    cin>>B[i];
	}
	for(ll i=1;i<n;i++)
	{
	    cin>>C[i];
	}
	ll ans=0;
	for(ll i=1;i<=n;i++)
	{
	    ans+=B[A[i]];
	   if(i>1)
	   {
	       if(A[i]==(A[i-1]+1))
	       {
	           ans+=C[A[i-1]];
	       }
	   }
	}
	cout<<ans;
    return 0;
}


//252908XL

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,s,n) for(int i = s; i < n; i++)
using Graph = vector<vector<int>>;
using ll = long long;
const ll INF = 1000000007;
int main(){ 
  int n;
  cin >> n;
  cout << (n ^1) << endl;
}


Measured memory_bytes: 3536
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
ll gcd(ll a,ll b){
    if(min(a,b)==0)return max(a,b);
    if(max(a,b)%min(a,b)==0)return min(a,b);
    return gcd(min(a,b),max(a,b)%min(a,b));
}
int main(){
    ll n;cin>>n;
    vector<ll>a(n);
    multiset<ll>st;
    rep(i,n){
        cin>>a[i];
        st.insert(a[i]);
    }
    sort(all(a));
    reverse(all(a));
    ll cnt=0;
    rep(i,n){
        if(!st.count(a[i]))continue;
        auto itr=st.lower_bound(a[i]);
        st.erase(itr);
        ll w=1;
        while(w<=a[i])w*=2;
        ll x=w-a[i];
        itr=st.lower_bound(x);
        if(*itr==x){
            cnt++;
            st.erase(itr);
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i > n; --i)
typedef long long ll;
#define mod 1000000007

int main() {
  int N; cin >> N;
  vector<string> s(N);
  rep(i, 0, N) cin >> s[i];
  int AB = 0;
  int aa = 0, bb = 0, ba = 0;
  rep(i, 0, N) {
    rep(j, 1, s[i].size()) {
      if(s[i][j-1] == 'A' && s[i][j] == 'B') AB++;
    }
  }
  rep(i, 0, N) {
    if(s[i][0] == 'B' && s[i].back() == 'A') ba++;
    else if(s[i][0] == 'B') bb++;
    else if(s[i].back() == 'A') aa++;
  }
  if(ba) {
    AB += ba - 1;
    if(aa) {
      aa--;
      AB++;
    }
    if(bb) {
      bb--;
      AB++;
    }
  }
  AB += min(aa, bb);
  cout << AB << endl;
  return 0;
}


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

#define ull unsigned long long int
#define ll long long int
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define MOD (ull)(double)(1e9 + 7)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vb vector<bool>
#define vll vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vs vector<string>
#define pull pair<ull, ull>
#define m_p make_pair
#define debug(x) cout << #x << " " << x << endl
#define printArr(a, start, end)for(int i=start ; i<end ; ++i)cout << a[i] << " ";
#define readArr(a, start, end)for(int i=start ; i<end ; ++i)cin >> a[i];
#define read2D(mat, n, m)for(int i=0 ; i<n ; ++i)for(int j=0 ; j<m ; ++j)cin >> mat[i][j];

const long double PI = 3.141592653589793238462643383279502884197169399;

// Find Set LSB = (x&(-x)), isPowerOfTwo = (x & (x-1))

void solve(){
	int n;
	cin >> n;
	
	vll a(n);
	map<ll, int> mp;
	for(ll& x : a){
		cin >> x;
		mp[x]++;
	}
	
	ll sum = accumulate(all(a), 0LL);
	
	int q;
	cin >> q;
	
	while(q--){
		int b, c;
		cin >> b >> c;
		
		if(mp.find(b) == mp.end())cout << sum << '\n';
		else{
			ll cnt = mp[b];
			mp.erase(mp.find(b));
			sum -= b * cnt;
			sum += c * cnt;
			mp[c] += cnt;
			
			cout << sum << '\n';
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int tt=1;
	//cin >> tt;
	
	while(tt--){
		solve();
	}
}


Measured memory_bytes: 7948
from sys import exit

X, Y, Z, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

ABC = []

for a in range(X):
    for b in range(Y):
        if (a + 1) * (b + 1) > K:
            break
        for c in range(Z):
            if (a + 1) * (b + 1) * (c + 1) > K:
                break
            ABC.append(A[a] + B[b] + C[c])

ABC.sort(reverse=True)

for i in range(K):
    print(ABC[i])


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

namespace Atcoder
{
    class AtCodeeeeeeeeeeeeeeeeeeeer
    {
        static void Main(string[] args)
        {
            int[] HW = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int H = HW[0];
            int W = HW[1];

            for (int i = 0; i < H+2; i++)
            {
                if (i == 0 || i == H+1)
                {
                    for (int j = 0; j < W+2; j++)
                    {
                        Console.Write("#");
                    }
                    Console.Write("\r\n");
                }
                else
                {
                    Console.WriteLine("#" + Console.ReadLine() + "#");
                }
            }
        }
    }
}


Measured memory_bytes: 11348
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
 
void Main() {
  int n;
  R n;
  n+=2;
  vector<int> a(n);
  rep(i,n) R a[i];
  pr(max(abs(a[1]-a[n-1]),abs(a[n-2]-a[n-1])));
}
 
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
/* sqrt を使わなくてもsqrt(a)*sqrt(a)=n を利用*/
int dig(long long x){
	int c = 0;
	while(x>0){x/=10;c++;}
	return c;
}

int main(void){
	long long n,i,j;
	scanf("%lld",&n);
	int c=dig(n);
	for(i=1;i*i<=n;i++){
		if(n%i==0){
			if(n/i>i)j=n/i;
			else j=i;
			int d = dig(j);
			if(d<c)c=d;
		}
	}
	
	printf("%d",c);
	return 0;
}

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

constexpr double EPS = 1e-9;

double cross(double x1, double y1, double x2, double y2) {
	return x1 * y2 - y1 * x2;
}

int ccw(double x1, double y1, double x2, double y2, double x3, double y3) {
	x2 -= x1;
	y2 -= y1;
	x3 -= x1;
	y3 -= y1;

	const double t = cross(x2, y2, x3, y3);
	if(t > EPS) return 1;
	if(t < -EPS) return -1;
	return 0;
}

int main() {
	double x[4];
	double y[4];

	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", x, y, x+1, y+1, x+2, y+2, x+3, y+3) == 8) {
		bool ok = true;
		const int t = ccw(x[0], y[0], x[2], y[2], x[1], y[1]);
		for(int i = 1; i < 4; ++i) {
			const int next = (i + 1) % 4;
			const int next2 = (i + 2) % 4;
			if(t != ccw(x[i], y[i], x[next2], y[next2], x[next], y[next])) {
				ok =false;
				break;
			}
		}

		puts((ok ? "YES" : "NO"));
	}


	return 0;
}

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

int main()
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    int res = 0;
    if (A + B > C*2)
    {
        int mi = min(X, Y);
        res += C * mi * 2;
        X -= mi;
        Y -= mi;
    }
    if (A > C * 2) {
        res += C * 2 * X;
        X = 0;
    }
    if ( B > C * 2) {
        res += C * 2 * Y;
        Y = 0;
    }
    res += X * A + Y * B;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n, m;
    int i, j;
    int A[100][100];
    int b[100];
    int c[100] = {0};
    scanf("%d %d",&n, &m);
    for(i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            scanf("%d", &A[i][j]);
        }
    }
    for(i = 0; i < m; i++){
        scanf("%d", &b[i]);
    }
    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            c[i] += (A[i][j] * b[j]);
        }
    }
    for(i = 0; i < n; i++){
        printf("%d\n", c[i]);
    }
    return 0;
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

template<typename T> void ckmin(T& a, const T& b) { a = min(a, b); }
template<typename T> void ckmax(T& a, const T& b) { a = max(a, b); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N, L;
    cin >> N >> L;

    int lo = L, hi = N + L - 1;

    int sum = 0;
    for (int v = lo; v <= hi; v++)
        sum += v;

    int ans = INT_MAX;
    for (int v = lo; v <= hi; v++)
        if (abs(v) < abs(ans))
            ans = v;

    cout << sum - ans << endl;

    return 0;
}



Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) throws IOException {
		//File fi=new File("file.txt");

		Scanner sc=new Scanner(System.in);
		for(;;){
			int n=sc.nextInt();
			int x=sc.nextInt();
			
			if(n==0&&x==0)break;
			else{int count=0;
				for(int a=1;a<n;a++){
					for(int b=a+1;b<n;b++){
						for(int c=b+1;c<=n;c++){
							if(a+b+c==x){
								if(a!=b&&a!=c&&b!=c)count++;
								
						}
					}
					}
				}System.out.println(count);
				
			}
		}
		sc.close();
		
	
	}}

Measured memory_bytes: 19620