akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int main() {
    int n;
    cin >> n;
    int s = 0;
    int x;
    for(int i = 0; i < n; ++i) {
        cin >> x;
        while(x % 2 == 0) {
            ++s;
            x /= 2;
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((abs(a - c) <= d) || (abs(a - b) <= d && abs(b - c) <= d)) { 
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);

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

struct edge{
    int to, rev;
    ll cap;
    edge(){}
    edge(int a, ll b, int c){
        to = a;
        cap = b;
        rev = c;
    }
};
using ve = vector<edge>;

void add_edge(int from, int to, ll cap, vector<ve> &G, bool directed = true){
    G[from].emplace_back(to, cap, (int)G[to].size());
    G[to].emplace_back(from, directed ? 0 : cap, (int)G[from].size() - 1);
}

void bfs(int s, vector<ve> &G, vector<int> &level){
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(edge &e : G[v]){
            if(e.cap > 0 && chmin(level[e.to], level[v] + 1)){
                que.push(e.to);
            }
        }
    }
}

ll dfs(int v, int t, ll f, vector<ve> &G, vector<int> &level, vector<int> &iter){
    if(v == t) return f;
    for(int &i = iter[v]; i < G[v].size(); ++i){
        edge &e = G[v][i];
        if(e.cap > 0 && level[v] < level[e.to]){
            ll d = dfs(e.to, t, min(f, e.cap), G, level, iter);
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

ll dinic(int s, int t, vector<ve> &G){
    ll res = 0;
    int sz = G.size();
    for( ; ; ){
        vector<int> level(sz, INT_MAX), iter(sz, 0);
        bfs(s, G, level);
        if(level[t] == INT_MAX) return res;
        ll f;
        while((f = dfs(s, t, INF, G, level, iter)) > 0) res += f;
    }
}

int main() {
    cin>>H>>W;
    vector<ve> G(H + W + 2, ve(0));
    rep(i, H){
        cin>>S;
        rep(j, W){
            if(S[j] == 'o'){
                add_edge(i, H + j, 1, G, false);
            }else if(S[j] != '.'){
                add_edge(i, H + W + (S[j] == 'T'), 400, G, false);
                add_edge(H + j, H + W + (S[j] == 'T'), 400, G, false);
            }
        }
    }
    ll ans = dinic(H + W, H + W + 1, G);
    cout<<(ans > 300 ? -1 : ans)<<endl;
}


Measured memory_bytes: 3920
#include<stdio.h>

int main(void){
  double n,k;
  double p[200001];
  int i,K;
  double x,y,a;
  
  scanf("%lf %lf\n",&n,&k);
  for(i=1;i<=n;i++){
    scanf("%lf ",&p[i]);
  }
  
  K=(int)k;
  x=0;
  for(i=1;i<=K;i++){
    x=x+p[i];
  }
  y=x;
  
  for(i=1;i<=n-K;i++){
    y=y-p[i]+p[i+K];
    if(x<y){
      x=y;
    }
    
  }
  
  a=(k+x)/2;
  
  printf("%lf",a);
  
  return 0;
}
  

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

const int N = 2e2 + 10;

int n, q;
int a[N], m[N];

//! 从输入值 m 中减去所选元素的递归函数
int solve(int i, int m)
{
    if(m == 0) return 1;
    if(i >= n) return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - a[i]);
    return res;
}

int main(void)
{
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    cin >> q;
    for(int i = 0; i < q; i++) cin >> m[i];
    for(int i = 0; i < q; i++)
    {
        if(solve(0, m[i]))
            printf("yes\n");
        else
            printf("no\n");
    }
    return 0;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(string, w);
  map<char, int> mp;
  each(x, w) {
    mp[x]++;
  }

  each(x, mp) {
    if (x.second % 2) {
      print("No");
      return;
    }
  }

  print("Yes");
}


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

using ll = long long;
using pll = pair<ll, ll>;

template <typename T> T gcd(T a, T b) {
	if (b == 0) return abs(a);
	T r; while ((r = a % b) != 0) a = b, b = r;
	return abs(b);
}

ll modpow(ll b, ll x, ll mod) {
    if (x == 0)
        return 1;
    if (x & 1) {
        return modpow(b*b % mod, x/2, mod) * b % mod;
    } else {
        return modpow(b*b % mod, x/2, mod);
    }
}

#define MOD 1000000007

#define D1(a) cerr<<#a<<":"<<a<<endl
#define D2(a,b) cerr<<#a<<":"<<a<<","<<#b<<":"<<b<<endl
#define D3(a,b,c) cerr<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cerr<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl
#define DH(c) do{rep(__i, c.size())cerr<<c[__i]<<(__i==c.size()-1?'\n':' ');}while(0)

// ifstream ifs("sub1_17.txt");
// #define cin ifs

int main()
{
    int N; cin >> N;
    vector<pll> AB(N);
    map<pll, int> cnt;
    for (auto& ab : AB) {
        cin >> ab.first >> ab.second;
        if (ab.first == 0 && ab.second == 0) {
            // そのまま
        } else if (ab.first == 0) {
            ab.second = -1;
        } else if (ab.second == 0) {
            ab.first = 1;
        } else {
            ll g = gcd(ab.first, ab.second);
            ab.first /= g;
            ab.second /= g;
            if (ab.first < 0) {
                ab.first = -ab.first;
                ab.second = -ab.second;
            }
        }
        cnt[ab]++;
    }

    ll ans = 1;

    map<pll, bool> done;

    for (const auto& kv : cnt) {
        const auto& ab = kv.first;
        const auto& c = kv.second;
        if (done[ab] || (ab.first==0 && ab.second==0)) continue;

        ll a = 1;
        pll abr = make_pair(abs(ab.second), ab.first);
        if (ab.second >= 0) abr.second = -abr.second;
        if (cnt.count(abr) > 0) {
            ll c_abr = cnt[abr];
            a = (modpow(2, c, MOD) + modpow(2, c_abr, MOD) - 1) % MOD; 
            done[abr] = true;
        } else {
            a = modpow(2, c, MOD);
        }
        ans = ans * a % MOD;
        done[ab] = true;
    }
    ans--;
    ans = (ans + cnt[make_pair(0LL, 0LL)]) % MOD;
    if (ans < 0) ans += MOD;

    cout << ans << endl;
}

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

dp = [0] * N

#Hの値Hiとそのインデックスiを取り出す
#dpの初期値は0なので1から始める
for i,Hi in enumerate(H[1:],1):
  #過去範囲の切り取り、リスト範囲をはみ出ないようにmaxが0になるように
  s = max(0,i-K)
  
  #K個分の範囲について、zip関数で各iについてコストを計算し、
  #最小値を計算
  dp[i] = min([t + abs(Hi - hl) for hl,t in zip(H[s:i], dp[s:i])])

#dpリストの最後尾
print(dp[N - 1])

Measured memory_bytes: 13980
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define ll long long
#define $1 first
#define $2 second
#pragma warning(disable : 4996)

using namespace std;

vector<pair<int, int> > v;

void solve_case();
int find_left(int idx);
int find_right(int idx);

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

	solve_case();

	return 0;
}

void solve_case() {
	int n, q, l, r, idx_l, idx_r;
	string s;

	cin >> n >> q;
	cin >> s;

	for (int i = 0; i + 1 < s.size(); i++) {
		if (s[i] == 'A' && s[i + 1] == 'C') {
			v.push_back({ i + 1, i + 2 });
		}
	}

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

	for (int qu = 0; qu < q; qu++) {
		cin >> l >> r;

		idx_l = find_left(l);
		idx_r = find_right(r);

		if (idx_l == -1 || idx_r == -1) {
			cout << "0\n";
			continue;
		}

		cout << idx_r - idx_l + 1 << "\n";
	}
}

int find_left(int idx) {
	int l = 0, r = (int)v.size() - 1;
	int pos = -1;

	while (l <= r) {
		int mid = (l + r) / 2;

		if (v[mid].$1 < idx) {
			l = mid + 1;
		}
		else {
			r = mid - 1;
			pos = mid;
		}
	}
	return pos;
}
int find_right(int idx) {
	int l = 0, r = (int)v.size() - 1;
	int pos = -1;

	while (l <= r) {
		int mid = (l + r) / 2;

		if (v[mid].$2 <= idx) {
			l = mid + 1;
			pos = mid;
		}
		else {
			r = mid - 1;
		}
	}
	return pos;
}

Measured memory_bytes: 1480
// ~/Remember,remember the 6th of March

#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-9;
const ll MOD = 1e9 + 7;
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    vector<int>arr(n),toSort(n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
        toSort[i]=arr[i];
    }
    sort(toSort.rbegin(),toSort.rend());
    for(int i=0;i<n;i++)
    {
        if(arr[i]==toSort[0])
            printf("%d\n",toSort[1]);
        else
            printf("%d\n",toSort[0]);
    }
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
    long int N,M;
    cin >> N >> M;

    vector <long int>    rst_num(M);
    vector <string> rst(M);

    rep(i,M){
        cin >> rst_num.at(i) >> rst.at(i);
    }

   // cout << N << "," << M << endl;

    map <long int,long int> test_map;
    map <long int,long int> test_map_NG;

    rep(i,N) {
        test_map[i+1] = 0;
        test_map_NG[i+1] = 0;
    }

//    for(auto x = test_map.begin(); x != test_map.end(); ++x){
//         cout << x->first << x->second << endl;
//     }

    long int cnt_OK = 0;
    rep(i,M){
        if(rst.at(i) == "AC" && test_map[rst_num.at(i)] == 0){
            test_map[rst_num.at(i)] = 1;
            cnt_OK++;
        }else if(rst.at(i) == "WA" && test_map[rst_num.at(i)] == 0){
            test_map_NG[rst_num.at(i)]++;
        }
    }

    long int cnt_NG = 0;
    rep(i,N){
        if(test_map[i+1] == 1){
            cnt_NG += test_map_NG[i+1];
        }
    }

    // long int tmp = 1;
    // for(auto x = test_map.begin(); x != test_map.end(); ++x){
    //     cout << tmp << ":" << test_map[tmp] << endl;
    //     tmp++;
    // }

    cout << cnt_OK << " " << cnt_NG << endl;
}

Measured memory_bytes: 19712
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		
		long ans = 0;
		long max = (long) Math.sqrt(n);
		for (long i = 1; i <= max; i++) {
			if (n % i == 0) ans = i;
		}
		
		System.out.println(ans + n / ans - 2);
	}
}

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

int main() {
  int K,S,X,Y,Z,total,count=0;

  cin >> K >> S;

  for (X=0; X<=K; X++) {
    for (Y=0; Y<=K; Y++) {
      Z = S - X - Y;
      if (0<=Z && Z<=K) count++;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 256
S=str(input())
l=len(S)-1
ans=0

M = 2#bit探査をしたい時はM=2
def dfs(A):
    global ans
    # 終端条件 --- l 重ループまで回したら処理して打ち切り
    if len(A) == l:
        memo=0
        for i in range(l):
            if A[i]==1:
                ans+=int(S[memo:i+1])
                memo=i+1
        ans+=int(S[memo:])
        return
    for v in range(M):
        A.append(v)
        dfs(A)
        A.pop() # これが結構ポイント

dfs([])
print(ans)

Measured memory_bytes: 67040
n = int(input())
a_list = list(map(int,input().split()))
q = int(input())
q_list = list(map(int,input().split()))
bits = 1

for a in a_list:
    bits |= bits << a

for q in q_list:
    if (bits>>q)&1:
        print('yes')
    else:
        print('no')


Measured memory_bytes: 5620
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

struct Node {
  int n;
  int w;
};

using Tree = vector<vector<Node>>;

void dfs(Tree &tree, vector<int> &painted, int current, int color) {
  if (painted.at(current) != -1) return;

  painted.at(current) = color;

  for (auto node : tree.at(current)) {
    if (painted.at(node.n) != -1) {
      continue;
    }

    if (node.w % 2 == 0) {
      dfs(tree, painted, node.n, color);
    } else {
      dfs(tree, painted, node.n, (color + 1) % 2);
    }
  }
}
int main() {
  int N;
  cin >> N;
  Tree tree(N);
  for (int i = 0; i < N - 1; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    tree.at(u - 1).push_back(Node{v - 1, w});
    tree.at(v - 1).push_back(Node{u - 1, w});
  }

  vector<int> painted(N, -1);

  dfs(tree, painted, 0, 0);

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

Measured memory_bytes: 10496
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;
const int mod = 1000000007;

int main(){
long long x;
cin>>x;
long long a=(x/11);
long long b=(x%11);
if(b==0){
    cout<<a*2<<endl;
}
else if(b<=6){
    cout<<a*2+1<<endl;
}
else{
    cout<<a*2+2<<endl;
}
}









Measured memory_bytes: 256
#include <bits/stdc++.h>
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;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    int A,B;
    cin >> A >> B;
    int ans;
    if(B%A==0){
        ans = A+B;
    }else{
        ans = B-A;
    }



    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int digit(int x) {
	if (x == 0) { return 1; }
	int ret = 0;
	while (x > 0) {
		++ret;
		x /= 10;
	}
	return ret;
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> v(N, -1);
	bool ok = true;
	for (int i = 0; i < M; ++i) {
		int s, c;
		cin >> s >> c;
		--s;
		if (v[s] >= 0 && v[s] != c) { ok = false; }
		v[s] = c;
	}
	if (!ok) {
		cout << -1 << endl;
		return 0;
	}
	
	for (int i = 0; i < 1000; ++i) {
		if (digit(i) != N) { continue; }
		ok = true;
		int x = i;
		for (int j = N - 1; j >= 0; --j) {
			if (v[j] >= 0 && x % 10 != v[j]) { ok = false; }
			x /= 10;
		}
		if (ok) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int N; cin>>N; string s; cin>>s;
	int no = 0;
	for(int x=0; x<N; x++){
		if(s[x]==')'){
			if(no==0){
				s = '('+s;
				x++;
				N++;
			} else {
				no--;
			}
		}
		if(s[x]=='(')
			no++;
	}
	s += string(no, ')');
	cout << s<< endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<int> L(N);
  rep(i,N)
  {
    cin >> L[i];
  }
  int M = 0;
  int sum = 0;
  rep(i,N)
  {
    sum += L[i];
    M = max(M,L[i]);
  }
  if(M>=sum-M)
  {
    cout << "No" << endl;
  }
  else
  {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import heapq
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x:x[0])
counter = 0
content = 0
ans = 0
h = []
heapq.heapify(h)
for i in range(m):
  while counter < n and ab[counter][0]==i+1:
    heapq.heappush(h,-ab[counter][1])
    counter+=1
    content+=1
  if content != 0:
    ans-=heapq.heappop(h)
    content-=1
print(ans)
  

Measured memory_bytes: 97592
#include <bits/stdc++.h>
#include <queue>
using namespace std;
int main(){
	int N; int K; string S; 
	cin >> N >> K >> S; 
	for(int i = 0; i < N; i++){
		if(i != K-1) cout << S.at(i); 
		else cout << (char) (S.at(i) + 'a' - 'A'); 
	}
	cout << endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll INF = 1e11;

int main() {
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> s(A);
    vector<ll> t(B);
    for(int i = 0; i < A; ++i)
        cin >> s[i];
    for(int i = 0; i < B; ++i)
        cin >> t[i];
    for(int i = 0; i < Q; ++i) {
        ll x;
        cin >> x;
        auto itr1 = upper_bound(s.begin(), s.end(), x);
        auto itr2 = upper_bound(t.begin(), t.end(), x);
        ll sclol, sclor, tclol, tclor, ans1, ans2, ans3, ans4;
        sclol = (itr1 != s.begin()) ? *(itr1 - 1) : -INF;
        sclor = (itr1 != s.end()) ? *itr1 : INF;
        tclol = (itr2 != t.begin()) ? *(itr2 - 1) : -INF;
        tclor = (itr2 != t.end()) ? *itr2 : INF;
        ans1 = x - min(sclol, tclol);
        ans2 = max(sclor, tclor) - x;
        ans3 = tclor - sclol + min(abs(tclor - x), abs(sclol - x));
        ans4 = sclor - tclol + min(abs(sclor - x), abs(tclol - x));
        cout << min(min(ans1, ans2), min(ans3, ans4)) << endl;
    }
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
const int N=20;
int n,a[N],b[N];
struct node
{
    int x,p;
    node(int x=0,int p=0):x(x),p(p){}
}c[N];
int d[N];
int solve(int x)
{
    for(int i=0;i<n;i++)
        if(x>>i&1)
            c[i+1]=node(b[i+1],1),d[i+1]=b[i+1];
        else
            c[i+1]=node(a[i+1],0),d[i+1]=a[i+1];
    sort(d+1,d+1+n);
    int ans=0;
    for(int i=n;i>=1;i--)
    {
        bool flag=false;
        for(int j=i;j>=1;j--)
            if(c[j].x==d[i]&&c[j].p==(i-j&1))
        {
            flag=true;
            ans+=i-j;
            for(int k=j;k<i;k++)
            {
                c[k+1].p^=1;
                swap(c[k],c[k+1]);
            }
            break;
        }
        if(!flag) return inf;
    }
    return ans;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++) scanf("%d",&b[i]);
    int ans=inf;
    for(int i=0;i<1<<n;i++)
        ans=min(ans,solve(i));
    if(ans==inf) ans=-1;
    printf("%d\n",ans);/////////////////
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
#define MOD 1000000007
using namespace std;

long n, m;
vector<vector<long> > zz;
vector<long> vis;

bool dfs( long bgn, long prev, long curr, long end ){
    vis[curr] = 1;
    long i;
    for(i=0; i<zz[curr].size(); i++) {
        long next = zz[curr][i];
        if( next==prev || next==end ) {
            continue;
        }
        if( next==bgn ) {
            return true;
        }
        if( !vis[next] ) {
            if(dfs(bgn, curr, next, end)) {
                return true;
            }
        }
    }
    return false;
}

int main(int argc, char* argv[])
{
    scanf("%ld%ld", &n, &m);
    zz.resize(n);
    vis.resize(n);
    long i;
    for(i=0; i<m; i++) {
        long a, b;
        scanf("%ld%ld", &a, &b);
        zz[a-1].push_back(b-1);
        zz[b-1].push_back(a-1);
    }

    for(i=0; i<n; i++) {
        if(zz[i].size()%2!=0) {
            printf("No\n"); return 0;
        }
    }

    for(i=0; i<n; i++) {
        if(zz[i].size()>=6) {
            printf("Yes\n"); return 0;
        }
    }

    long cnt=0;
    long a[2]={0};
    for(i=0; i<n; i++) {
        if(zz[i].size()==4) {
            cnt++;
            if(cnt==1) a[0]=i;
            if(cnt==2) a[1]=i;
        }
    }
    if(cnt<2) {
        printf("No\n"); return 0;
    }
    if(cnt==2) {
        if( !dfs( a[0], -1, a[0], a[1] ) ) {
            printf("No\n"); return 0;
        }
    }

    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;
    //vector<int> from(N,0);
    int from[N];

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();
        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            from[nv] = v;
            que.push(nv);
        }
    }

    // 結果出力 (各頂点の頂点 0 からの距離を見る)
  cout << "Yes" << endl;
    for (int v = 1; v < N; ++v) cout << from[v]+1 << endl;
}

Measured memory_bytes: 10716
#include <stdio.h>

int main() {
	int arr[3][3], bingo = 0;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			scanf("%d", &arr[i][j]);
		}
	}
	int n;
	scanf("%d", &n);
	while (n--) {
		int b, sumVert = 0, sumHor = 0, prim = 0, sec = 0;
		scanf("%d", &b);
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				arr[i][j] == b ? arr[i][j] = 0 : arr[i][j] = arr[i][j];
			}
		}
		for (int i = 0; i < 3; i++) {
			sumVert = sumHor = 0;
			for (int j = 0; j < 3; j++) {
				sumVert += arr[j][i];
				sumHor += arr[i][j];
			}
			bingo = sumVert == 0 || sumHor == 0 ? 1 : bingo;
		}
		for (int i = 0, j = 2; i < 3; i++, j--) {
			prim += arr[i][i];
			sec += arr[i][j];
		}
		bingo = prim == 0 || sec == 0 ? 1 : bingo;
	}
	bingo ? puts("Yes") : puts("No");
	return 0;
}

Measured memory_bytes: 1640
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int N;
  cin >> N;
  
  map<int, int> nagasa;
  int A;
  for( int i = 0; i < N; i++ ){
    cin >> A;
    if( nagasa.count(A) ) nagasa.at(A)++;
    else nagasa[A] = 1;
  }
  
  int hen1 = 0;
  int hen2 = 0;
  for( auto p : nagasa ){
    if( p.second > 1 ){
      hen2 = hen1;
      hen1 = p.first;
      if( p.second >= 4 ) hen2 = p.first;
    }
  }
  
  cout << hen1*hen2 << endl;
    
}



Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long int
using namespace std;

bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b) 
{ 
       return (a.first > b.first); 
}

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

    vector <ll> v(n);

    ll i;
    for(i = 0; i < n; i ++)
    {
    	cin >> v[i];
    }

    vector < pair <ll, ll> > cardsRep(m);
    for(i = 0; i < m; i ++)
    {
    	cin >> cardsRep[i].second;
    	cin >> cardsRep[i].first;
    }

    sort(v.begin(), v.end());
    sort(cardsRep.begin(), cardsRep.end(), comp);

    auto it = lower_bound(v.begin(), v.end(), cardsRep[0].first);
    ll index = it - v.begin();    

    ll curr = 0;
	for(i = 0; i < index; i ++)
	{
		if(cardsRep[curr].first <= v[i])
			break;
		else
		{
			v[i] = cardsRep[curr].first;
			cardsRep[curr].second --;
			if(cardsRep[curr].second == 0)
			{
				curr ++;
				if(curr >= m)
					break;
			}
		}
	}    

	ll sum = 0;
	for(i = 0; i < n; i ++)
	{
		sum = sum + v[i];
	}
	cout << sum << endl;

}

Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    string a, b, c, ans = "NO";
    cin >> a >> b >> c;
    if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) ans = "YES";
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
typedef pair<ll, ll> P;

int A, B, C, D;

int main(){
    cin >> A >> B >> C >> D;

    string ans;
    if(A+B > C + D) ans = "Left";
    else if(A + B < C + D) ans = "Right";
    else ans = "Balanced";

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x;
		int c = 0;
		while(true) {
			x = sc.nextInt();
			if(x==0)break;
			c++;
			System.out.println("Case "+c+": "+x);
		}
		sc.close();
	}
	
}


Measured memory_bytes: 41816
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main(){
    IOS;
    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i++){
        if(i%3!=0&&i%5!=0){
            ans+=i;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(){
	
int a,b,c,x,y,z;

scanf("%d%d%d",&a,&b,&c);

if(a>b){
x=a;
a=b;
b=x;
}

if(b>c){
y=b;
b=c;
c=y;
}

if(a>b){
z=a;
a=b;
b=z;
}

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

return 0;

}

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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int cnt = 0;
  for (int i = 0; i <= a; i++)
    for (int j = 0; j <= b; j++)
      for (int k = 0; k <= c; k++)
        if (500 * i + 100 * j + 50 * k == x) cnt++;
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
   int r, c;
   int x[101][101]={};
   cin>>r>>c;
   for(int i=0;i<r;i++){
       for(int j=0;j<c;j++){
           cin>>x[i][j];
           cout<<x[i][j]<<" ";
           x[r][j]+=x[i][j];
           x[i][c]+=x[i][j];
       }
       cout<<x[i][c]<<endl;
       x[r][c]+=x[i][c];
   }
   for(int j=0;j<c;j++){
       cout<<x[r][j]<<" ";
   }
   cout<<x[r][c]<<endl;
   
}



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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i=0;i<n;++i) cin >> a[i];
  
  int sum=0;
  for (int i=0;i<n;++i){
    sum+=a[i];
  }
  cout << sum-n << endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
ABC = list(map(int,read().split()))
A = ABC[::3]; B = ABC[1::3]; C = ABC[2::3]

class BIT():
    def __init__(self, max_n):
        self.size = max_n + 1
        self.tree = [0] * self.size
        
    def get_sum(self,i):
        s = 0
        while i:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i < self.size:
            self.tree[i] += x
            i += i & -i

def Inversion(seq):
    # seqは、1,2,...,Nの順列
    N = len(seq)
    bit = BIT(N)
    inv = N*(N-1)//2
    for x in seq:
        inv -= bit.get_sum(x)
        bit.add(x,1)
    return inv

def get_rank(seq):
    x_to_i = {x:i for i,x in enumerate(sorted(seq))}
    return [1+x_to_i[x] for x in seq]

def solve_x(A,B,C):
    M = (N*(N-1)//2+1)//2 # 必要な交点個数
    U = 2*10**8 + 100 # 交点の座標の上界
    left = -U # 交点の個数の合計が M 個に満たない
    right = U # 交点の個数の合計が M 個以上である
    # x = -inf における y の順序
    order = sorted(range(N),key = lambda i: A[i]/B[i])
    def test(x):
        y = [(C[i]-A[i]*x)/(B[i]) for i in order]
        seq = get_rank(y)
        return Inversion(seq) >= M
    
    for _ in range(60):
        mid = (left + right)/2
        if test(mid):
            right = mid
        else:
            left = mid
    return (left + right)/2

x = solve_x(A,B,C)
y = solve_x(B,A,C)
print(x,y)



Measured memory_bytes: 132908
while True:
	n = int(input())
	if n == 0:
		exit()
	taro = []
	for _ in range(0, n):
		taro.append(int(input()))
	hanako = []
	for i in range(1, 2 * n + 1):
		if i not in taro:
			hanako.append(i)
	taro.sort()
	#print(taro)
	#print(hanako)

	m = 0
	taro_flg = True
	while len(taro) != 0 and len(hanako) != 0:
		if taro_flg:
			for i in range(len(taro)):
				if taro[i] > m:
					m = taro[i]
					taro.remove(taro[i])
					break
				if i == len(taro)-1:
					m = 0
			taro_flg = False
		else:
			for i in range(len(hanako)):
				if hanako[i] > m:
					m = hanako[i]
					hanako.remove(hanako[i])
					break
				if i == len(hanako)-1:
					m = 0
			taro_flg = True

	#print(taro)
	#print(hanako)
	print(len(hanako))
	print(len(taro))



Measured memory_bytes: 5600
// Example program
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
    int K, T;
    cin >> K;
    cin >> T;
    int* a;
    a= (int*) malloc(sizeof(int)*T);
    // cout << "T = " << T << endl;
    int i=0;
    while ( i<T  ) {cin>>a[i]; i++;}
    
    // find max
    int max = 0;
    for (int i=0; i<T; i++) {
        if (a[i]>max) max=a[i];
    }
    
    int big = max;
    int used = 0;
    for (int i=0; i<T; i++) {
        if (a[i] != max || (a[i] == max && used) ) big -= a[i] ;
        if (a[i] == max) used++;
        //cout << big << endl;
    }
    if (big-1>0)  cout << big-1 << endl;
    else cout << 0 << endl;
    // cin >> K;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int k,a,b;
	cin>>k>>a>>b;int c=k;
	for(int i=1;i<=1000;i++)
	{
		k=c*i;
		if(a<=k&&k<=b)
		{
			cout<<"OK";exit(0);
		}
	}
	cout<<"NG";
}

Measured memory_bytes: 3656
def mod3(num):
    if num % 3 == 0:
        return True
    else:
        return False

cList = [list(map(int, input().split())) for _ in range(3)]
row = [sum(cList[0]), sum(cList[1]), sum(cList[2])]
col = [cList[0][i] + cList[1][i] + cList[2][i] for i in range(3)]
differenceRow = [row[i - 1] - row[i] for i in range(3)]
differenceCol = [col[i - 1] - col[i] for i in range(3)]
difference = [sum(row)] + differenceRow + differenceCol
if list(filter(mod3, difference)) != difference:
    print("No")
else:
    print("Yes")



Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    int n,m,x,y;
    cin>>n>>m;
    
    vector<int> adj[n+2] , topo;
    int inorder[n+2];
    
    memset(inorder,0,sizeof(inorder));
    
    for(int i=1;i < n+m ;i++) {
        cin>>x>>y;
        adj[x].push_back(y);
        inorder[y]++;
    }
    
    queue<int> q;
    int parent[n+2];
    
    for(int i=1; i<=n;i++) {
        if(inorder[i] == 0) q.push(i);
    }
    
    parent[q.front()] = 0;
    
    while(q.size() != 0) {
        int u = q.front();
        q.pop();
        topo.push_back(u);
        
        for(int v : adj[u]) {
            if(--inorder[v] == 0) {
                q.push(v);
                parent[v] = u;
            }
        }
    }
    
    for(int i=1;i<=n;i++) cout<<parent[i]<<"\n";
    return 0;
}

Measured memory_bytes: 7544
#include<iostream>
#include<vector>
#define ll long long
using namespace std;
const ll N=1e5+10;
ll n,c[N];vector<ll> E[N];
ll dfs(ll x,ll fr)
{
	if(E[x].size()==1) return c[x];
	ll s=0,mx=0,w;
	for(auto R:E[x]) if(R!=fr) w=dfs(R,x),mx=max(mx,w),s+=w;
	mx*2<=s?mx=s/2:mx=s-mx;
	if(c[x]>s||c[x]<s-mx) puts("NO"),exit(0);
	w=s-c[x];w=s-2*w;
	if(w<0) puts("NO"),exit(0);
	return w;
}
int main()
{
	cin>>n;for(ll i=1;i<=n;i++) cin>>c[i];
	if(n==2) c[1]==c[2]?puts("YES"):puts("NO"),exit(0);
	for(ll i=1,x,y;i<n;i++) cin>>x>>y,E[x].push_back(y),E[y].push_back(x);
	for(ll i=1;i<=n;i++) if(E[i].size()>1) dfs(i,0)?puts("NO"):puts("YES"),exit(0);
}


Measured memory_bytes: 11776
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) ->
      if x < y then Node (y, doit l, r)
      else Node (y, l, doit r) in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> f x; doit l; doit r in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> doit l; f x; doit r in
  doit t

let print t =
  inorder (fun e -> print_string " "; print_int e) t;
  print_newline ();
  preorder (fun e -> print_string " "; print_int e) t;
  print_newline ()

let find x t =
  let rec doit = function
    | Nil -> false
    | Node (y, _, _) when x = y -> true
    | Node (y, l, _) when x < y -> doit l
    | Node (_, _, r) -> doit r in
  doit t

let delete x t =
  let rec balance = function
    | Nil -> assert false
    | Node (x, Nil, r) -> (x, r)
    | Node (x, l, r) ->
      let (m, l) = balance l in
      (m, Node (x, l, r)) in
  let rec doit = function
    | Nil -> assert false
    | Node (y, l, r) ->
      if x = y then
        if l = Nil then r
        else if r = Nil then l
        else
          let (m, r) = balance r in
          Node (m, l, r)
      else if x < y then Node (y, doit l, r)
      else Node (y, l, doit r) in
  doit t

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let m = read_int () in
  let t = ref (create ()) in
  for _ = 0 to m - 1 do
    match read_line () |> split_on_char ' ' with
    | ["insert"; n] -> t := insert (int_of_string n) !t
    | ["find"; n] -> print_endline (if find (int_of_string n) !t then "yes" else "no")
    | ["delete"; n] -> t := delete (int_of_string n) !t
    | _ -> print !t
  done

Measured memory_bytes: 25288
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(2*n);
    for (int i = 1; i <= n; i++) cin >> a[i];

    vector<int> b;
    vector<int> c(2*n, 0);
    for (int i = n; i > 0; i--) {
        int s = 0;
        for (int j = 2*i; j <= n; j+=i) s += c[j];
        if (s % 2 != a[i]) {
            c[i]++;
            b.push_back(i);
        }
    }

    cout << b.size() << endl;
    for (int i:b) {
        cout << i << " ";        
    }
    cout << endl;
}

Measured memory_bytes: 4472
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
#define codejam cout<<"Case #"<<ii+1<<": ";
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=INT64_MAX;
const int32_t LOG=21;
const int MOD=MOD2;

int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      {

          int n,m;
          cin>>m>>n;;
          int a[n];
          rep(i,0,n)cin>>a[i];
          int sum=accumulate(a,a+n,0LL);
          int ans=max(m-sum,-1LL);
          cout<<ans<<endl;
      }


      return 0;                         
}

/*
 TIPS(FOR ME):
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/

Measured memory_bytes: 3736
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N, T; cin >> N >> T;
    vector<int>t(N);
    rep(i, N)cin >> t[i];
    long long ans = 0;
    REP(i, N)ans += min(t[i] - t[i - 1], T);
    cout << ans+T << endl;
}

Measured memory_bytes: 3964
#include <iostream>
using namespace std;
	
class Queue{
private:
	int fp;
	int rp;
	int d_num[100001];
	string d_name[100001];
	public:
		Queue(){
			fp = 0;
			rp = 0;
		}
		int next(int p){
			return (p+1)%100001;
		}
		bool isFull(){
			return (next(rp)==fp);
		}
		bool isEmpty(){
			return (rp==fp);
		}
		void enqueue(int d_i,string d_s){
			if(isFull()){
				return;
			}
			d_num[rp] = d_i;
			d_name[rp] = d_s;
			rp = next(rp);
		}
		int front_num(){
			if(isEmpty()){
				return -1;
			}
			return d_num[fp];
		}
		string front_name(){
			if(isEmpty()){
				return "-1";
			}
			return d_name[fp];
		}
		void dequeue(){
			if(isEmpty()){
				return;
			}
			fp = next(fp);
		}
};

int main(){
	int n,m;
	Queue A;
	cin >> n >> m;
	for(int i = 0;i < n;i++){
		string name;
		int num;
		cin >> name >> num;
		A.enqueue(num,name);
	}
	int time = 0;
	while(!A.isEmpty()){
		if(A.front_num() > m){
			time += m;
			A.enqueue(A.front_num() - m,A.front_name());
			A.dequeue();
		}else{
			time += A.front_num();
			cout << A.front_name() << ' ' << time << endl;
			A.dequeue();
		}
	}
	return 0;
}


Measured memory_bytes: 4720
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;


int main() {
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    if('A'<=s[k-1]&&s[k-1]<='Z')s[k-1]+='a'-'A';
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define ld long double
#define ull unsigned ll
#define pb push_back
#define popb pop_back
#define mt make_tuple
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair <int,int>
#define piii pair <pii,int>
#define piiii pair <pii,pii>
#define pll pair <ll,ll>
#define plll pair <pair <ll, ll>, ll>
#define rep0(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<=(ll)n;i++)
#define rep(i,x,y) for(ll i=(ll)x;i<=(ll)y;i++)
#define reprev(i,n) for(ll i=(ll)n;i>=0;i--)
#define all(c) c.begin(),c.end()
#define print(a) rep0(i,a.size()) cout << a[i] << " "
#define hi() cout << "\nHello, I am error. Can you find me? :):):)\n"
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_eppoch().count())
 
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>;

// FOR DEBUGGING
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}

void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", ";
	else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}

#ifndef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

const int mod = 1e9+7;
const long double pi = acos(-1);
const ll INF = 1e15;

ll power(ll x, ll y){
	x %= mod;
	ll ans = 1;
	while(y){
		if(y&1) ans = (ans*x)%mod;
		y /= 2;
		x = (x*x)%mod;
	}
	return ans;
}

void solve(){

	int a;
	cin >> a;
	cout << a + a*a + a*a*a;

	return;
}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	int TC = 1,t = 0;
	// cin >> TC;
	while(t++ < TC){
		// cout << "Case #" << t << ": ";
		solve();
		// cout << "\n";
	}

	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

	return 0; 
}

Measured memory_bytes: 3816
#include <algorithm>
#include <iostream>

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

  int sum = A + B;
  int sub = A - B;
  int mul = A * B;
  int cal[3] = { sum, sub, mul };
  std::sort(cal, cal + 3, std::greater<int>());
  std::cout << cal[0] << std::endl;

  return 0;
}


Measured memory_bytes: 256
//بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int x = 0, y = 0;
    for(char c : s){
        if(c == '1') x++;
        else y++;
    }
    cout << (min(x, y) * 2);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<endl
#define AA(i) cout<<i<<endl
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
  string S; cin >> S;
  bool f = true;

  for(int i=0; i<S.size()/2; i++){
     if(S[i] != S[S.size()-i-1]){
       f = false;
     }
  }
  for(int i=0; i<S.size()/4; i++){
     if(S[i] != S[S.size()/2-i-1]){
       f = false;
     }
  }
  if(f) AA("Yes");
  else AA("No");

  return 0;
}


Measured memory_bytes: 256
use proconio::input;
use std::cmp;

fn main() {
    input! {
        n: usize,
        k: usize,
        a: [usize; n],
    }

    let mut rmq = RMQ::new(300010, 0);

    let mut ans = 0;
    for &na in &a {
        let l = if na >= k { na - k } else { 0 };
        let r = cmp::min(na + k, 300000);
        let tmp = rmq.query(l, r + 1, 0, 0, rmq.get_n()) + 1;
        ans = cmp::max(ans, tmp);
        rmq.update(na, tmp);
    }

    println!("{}", ans);
}

struct RMQ {
    n: usize,
    dat: Vec<usize>,
    max: usize,
}

impl RMQ {
    fn new(_n: usize, max: usize) -> Self {
        let mut n = 1;
        while n < _n {
            n *= 2;
        }

        RMQ {
            n: n,
            dat: vec![max; 2 * n - 1],
            max: max,
        }
    }

    fn update(&mut self, mut k: usize, a: usize) {
        //kを0-indexedに
        k += self.n - 1;
        self.dat[k] = a;
        while k > 0 {
            k = (k - 1) / 2;
            self.dat[k] = cmp::max(self.dat[k * 2 + 1], self.dat[k * 2 + 2]);
        }
    }

    /// queryは[a, b)の最大値を返す
    ///外から呼ぶときはquery(a, b, 0, 0, n)と呼ぶ
    fn query(&self, a: usize, b: usize, k: usize, l: usize, r: usize) -> usize {
        if r <= a || b <= l {
            return self.max;
        }
        if a <= l && r <= b {
            return self.dat[k];
        } else {
            let vl = self.query(a, b, k * 2 + 1, l, (l + r) / 2);
            let vr = self.query(a, b, k * 2 + 2, (l + r) / 2, r);
            return cmp::max(vl, vr);
        }
    }

    ///queryを呼ぶときに使う
    fn get_n(&self) -> usize {
        self.n
    }
}


Measured memory_bytes: 11052
using System;

public class Program
{
    static void Main()
    {
        if(CalcCombination()) 
        {
            Console.WriteLine("1");
        }
        else
        {
            Console.WriteLine("0");
        }
    }

    /// <summary>
    /// 組み合わせ計算
    /// </summary>
    /// <returns></returns>
    private static bool CalcCombination()
    {
        double goukeiKingaku = double.Parse(Console.ReadLine().Trim());
        var hasuuKingaku = goukeiKingaku % 100;

        //100円のおにぎりのみで決まる場合は除外
        if (hasuuKingaku == 0) return true;

        //1個の場合は除外
        if (goukeiKingaku >= 100 && goukeiKingaku <= 105) return true;

        //全体の購入個数を仮決め
        //min:100*個数 = X、max:105*個数 = X
        for (int kosuu = (int)Math.Floor(goukeiKingaku / 100); kosuu >= Math.Floor(goukeiKingaku / 105); kosuu--) 
        {
            for (int i = kosuu; i >= 0; i--)
            {
                double sagaku = 3 * (kosuu - i) - hasuuKingaku;
                //103円のケーキを基準に+-2円の範囲で金額チェック
                if (sagaku > 0)
                {
                    if (CheckCombination((int)sagaku, kosuu - i)) return true;
                }
                else if (sagaku < 0)
                {
                    if (CheckCombination((int)Math.Abs(sagaku), kosuu - i)) return true;
                }
                else
                {
                    //103円のケーキのみで決まる
                    return true;
                }
            }

            //個数が減る場合は、+100円
            hasuuKingaku += 100;
        }
        return false;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sagaku"></param>
    /// <param name="kosuu"></param>
    /// <returns></returns>
    private static bool CheckCombination(int sagaku, int kosuu)
    {
        //1円の個数をx、2円の個数をyとする。
        //x + y = kosuu
        //x + 2y = sagaku
        //これをとくと、x = 2 * kosuu - sagaku,y = sagaku - kosuu

        if (2 * kosuu - sagaku >= 0 && sagaku - kosuu >= 0)
        {
            return true;
        }

        return false;
    }
}


Measured memory_bytes: 13140