akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

int n, N, bc[(1 << 18) + 5]; char str[37];
struct Hash{
	size_t operator () (const pair <ULL, int> &x) const{
		return hash <ULL> () (x.first) ^ hash <int> () (x.second);
	}
};
unordered_map <pair <ULL, int>, int, Hash> cnt;

int main(){
	int i, j; ULL h; LL ans = 0LL;
	scanf("%d%s", &n, str);
	N = 1 << n;
	for(i = 0; i < N; ++ i){
		h = 0ULL;
		bc[i] = bc[i >> 1] + (i & 1);
		for(j = n - 1; j >= 0; -- j)
			if((i & (1 << j)) == 0)
				h = h * 27 + (str[n + j] - 'a' + 1);
		for(j = 0; j < n; ++ j)
			if(i & (1 << j))
				h = h * 27 + (str[n + j] - 'a' + 1);
		++ cnt[make_pair(h, bc[i])];
	}
	for(i = 0; i < N; ++ i){
		h = 0ULL;
		for(j = 0; j < n; ++ j)
			if(i & (1 << j))
				h = h * 27 + (str[j] - 'a' + 1);
		for(j = n - 1; j >= 0; -- j)
			if((i & (1 << j)) == 0)
				h = h * 27 + (str[j] - 'a' + 1);
		ans += cnt[make_pair(h, n - bc[i])];
	} printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 38004
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int r = sc.nextInt();
		if (n >= 10){
			System.out.println(r);
		} else {
			System.out.println(r + (100 * (10 - n)));
		}
	}
}


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

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

const int MAX_N = 100;
int n, t = 0, flag[MAX_N] = {0}, d[MAX_N], f[MAX_N], G[MAX_N][MAX_N] = {0};

void dfs(int u) {
  int v;
  flag[u] = 1;
  d[u] = ++t;
  REP(v, n) {
    if (!G[u][v]) continue;
    if (!flag[v]) dfs(v);
  }
  flag[u] = 2;
  f[u] = ++t;
}

int main() {
  int u, v, k;
  cin >> n;
  REP(i, n) {
    cin >> u >> k;
    REP(j, k) {
      cin >> v;
      G[u - 1][v - 1] = 1;
    }
  }
  REP(i, n) if (!flag[i]) dfs(i);
  REP(i, n) cout << i + 1 << ' ' << d[i] << ' ' << f[i] << endl;
  return 0;
}

Measured memory_bytes: 3144
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <numeric>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define rrep()
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;

int main(){
    string s;
    cin>>s;
    Sort(s);
    if(s=="abc")cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import numpy as np
a = int(input())
b = int(input())
c = int(input())
x = int(input())

from itertools import product
alim = min(a, x // 500)
blim = min(b, x // 100)
clim = min(c, x //  50)

count = 0
for anum, bnum, cnum in product(np.arange(alim + 1), np.arange(blim + 1), np.arange(clim + 1)):
    value = anum * 500 + bnum * 100 + cnum * 50
    if value == x:
        count += 1
print(count)

Measured memory_bytes: 12492
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n;
    long k;
    scan(n, k);
    auto a = readln.split.to!(long[]);

    long ans;

    foreach (i ; 0 .. 50) {
        if (k & (1L << i)) {
            auto ks = k ^ (1L << i);
            auto mask = (1L << i) - 1;
            ks |= mask;

            auto res = solve(n, a, ks);

            debug {
                writefln("%08b", k);
                writefln("%08b", ks);
                writefln("res: %d", res);
            }
            ans = max(ans, solve(n, a, ks));
        }
    }

    ans = max(ans, solve(n, a, k));

    writeln(ans);
}

long solve(int n, long[] a, long k) {
    auto cnt = new int[](50);

    foreach (i ; 0 .. 50) {
        foreach (j ; 0 .. n) {
            if (a[j] & (1L << i)) {
                cnt[i]++;
            }
        }
    }

    long res;

    foreach (i ; 0 .. 50) {
        if (k & (1L << i)) {
            res += (1L << i) * max(cnt[i], n - cnt[i]);
        }
        else {
            res += (1L << i) * cnt[i];
        }
    }

    return res;
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

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

    if(x == 1 || x == 2*n-1){
        cout << "No" << endl;
        return 0;
    }

    if(n == 2){
        cout << "Yes" << endl;
        for(int i = 0;i < 3;i++){
            cout << i+1 << endl;
        }
        return 0;
    }

    deque<int> de;

    int st = 0;
    if(x > 2){
        de.push_back(x);
        de.push_front(x-1);
        de.push_back(x+1);
        de.push_back(x-2);
    }else{
        de.push_back(x);
        de.push_front(x-1);
        de.push_back(x+1);
        de.push_front(x+2);
        st++;
    }

    queue<int> que;
    for(int i = 1;i <= 2*n-1;i++){
        if(x > 2){
            if(i < x-2 || x+1 < i){
                que.push(i);
            }
        }else{
            if(i < x-1 || x+2 < i){
                que.push(i);
            }
        }
    }


    while(!que.empty()){
        if(st % 2 == 0){
            de.push_front(que.front());
        }else{
            de.push_back(que.front());
        }
        st++;
        que.pop();
    }

    cout << "Yes" << endl;
    for(int i = 0;i < 2*n-1;i++){
        cout << de[i] << endl;
    }

    return 0;
}





Measured memory_bytes: 2304
import collections
def main():
    s = list(input())
    tmp = len(set(s))
    c = collections.Counter(s)

    a_n = c['a']
    b_n = c['b']
    c_n = c['c']
    ans = []
    if len(s) == 1:
        print('YES')
        return
    if a_n >= b_n and a_n >= c_n:
        ans.append('a')
        a_n -= 1
        if b_n >= c_n:
            ans.append('b')
            b_n -= 1
        else:
            ans.append('c')
            c_n -= 1
    elif b_n >= a_n and b_n >= c_n:
        ans.append('b')
        b_n -= 1
        if a_n >= c_n:
            ans.append('a')
            a_n -= 1
        else:
            ans.append('c')
            c_n -= 1
    else:
        ans.append('c')
        c_n -= 1
        if b_n >= a_n:
            ans.append('b')
            b_n -= 1
        else:
            ans.append('a')
            a_n -= 1


    while True:
        if (ans[-1] == 'a' and ans[-2] == 'b') or (ans[-1] == 'b' and ans[-2] == 'a'):
            if c_n > 0 :
                c_n -= 1
                ans.append('c')
            else:
                if a_n == 0 and b_n == 0:
                    break
                print('NO')
                return
        elif (ans[-1] == 'c' and ans[-2] == 'b') or (ans[-1] == 'b' and ans[-2] == 'c'):
            if a_n > 0:
                a_n -= 1
                ans.append('a')
            else:
                if c_n == 0 and b_n == 0:
                    break
                print('NO')
                return
        else:
            if b_n > 0:
                b_n -= 1
                ans.append('b')
            else:
                if a_n == 0 and c_n == 0:
                    break
                print('NO')
                return
    print('YES')


if __name__ == '__main__':
    main()


Measured memory_bytes: 5028
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner stdIn=new Scanner(System.in);
		int n[]=new int[3],i,j,t;
		for(i=0;i<3;i++) n[i]=stdIn.nextInt();
		for(i=0;i<2;i++) {
			for(j=2;j>i;j--) {
				if(n[j-1]>n[j]) {
					t=n[j-1];
					n[j-1]=n[j];
					n[j]=t;
				}
			}
		}
		System.out.print(n[0]+n[1]==n[2]?"Yes":"No");
	}
}

Measured memory_bytes: 21584
import itertools

n = int(input())
p_list = list(map(int, input().split()))
q_list = list(map(int, input().split()))

cnt = 0
p_cnt = 0
q_cnt = 0

for a in itertools.permutations(range(n)): #順列を生成して、それらに対して処理
    cnt += 1
    for i in range(len(a)):
        if a[i]+1 != p_list[i]:
            break
        if i == len(a)-1:
            p_cnt = cnt
    for j in range(len(a)):
        if a[j]+1 != q_list[j]:
            break
        if j == len(a)-1:
            q_cnt = cnt

print(abs(p_cnt - q_cnt))


Measured memory_bytes: 9004
#include<iostream>
using namespace std;
int main() {
	string a;
	cin >> a;
	if (a=="Sunny") {
		cout << "Cloudy" << endl;
		return 0;
	}
	if (a=="Cloudy") {
		cout << "Rainy" << endl;
		return 0;
	}
	if (a=="Rainy") {
		cout << "Sunny" << endl;
		return 0;
	}
}

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

int main(){
    int x;cin>>x;
    int ans=0;
    int t=0;
    while(1){
        t+=x;
        ans++;
        if(t%360==0)break;
    }
    cout<<ans<<endl;
    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int main(void){
	int32 N, M, K;
	cin >> N;
	vector<double> a(N);
	double ave = 0;
	REP(i, N) cin >> a[i];
	REP(i, N) ave += a[i];
	ave /= (double)N;
	double sa = INF;
	int32 res = 0;
	REP(i, N){
		if(sa > abs(ave-a[i])){
			res = i;
			sa = abs(ave-a[i]);
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define int ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define mem(x,v) memset(x,v,sizeof(x))
#define gc getchar
#define pc putchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
#define pp(x,y) cout << "pp: " << x << " " << y << endl;
#define rank __RAnK
inline ll read(){
	register ll x=0,f=1;register char c=gc();
	for(;!isdigit(c);c=gc())if(c=='-')f=-1;
	for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
	return x*f;
}
#define rd read
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
const int maxn = 1e5+233;
vector<pair<int,int> > ans;
int d[maxn],w[maxn],a[maxn];
int del,n;
bool cmp(int x,int y){
	return d[x] < d[y];
}
int query(int l,int r,int need){
	int pos = -1;
	while(l<=r){
		int mid =(l+r)>>1;
		if(d[a[mid]] - del < need) l = mid + 1; else
		if(d[a[mid]] - del > need) r = mid - 1; else
		return a[mid];
	}
	return -1;
}
vector<int> edge[maxn];
int f[maxn],F[maxn],size[maxn];
void dfs(int u,int fa){
	f[u] = 0;
	size[u] = 1;
	for(auto v:edge[u]){
		if(v==fa) continue;
		dfs(v,u);
		size[u] += size[v];
		f[u] += f[v] + size[v];
	}
}
void DFS(int u,int fa){
	if(u==1) F[u]=f[u];
	for(auto v:edge[u]){
		if(v==fa) continue;
		F[v] = F[u] + (n - size[v]) - (size[v]);
		DFS(v,u);
	}
}
signed main(){
	n = rd();
	Rep(i,1,n) d[i] = rd();
	Rep(i,1,n) w[i] = 1;
	Rep(i,1,n) a[i] = i;
	sort(a+1,a+1+n,cmp);//从小到大排序 
	del = 0;
	Dep(i,n,2){
		/*当前是a[i] - del，权重为w[i]
		移动一步
		对于所有(n-w[i])个点，都要减少1*/
		ll need = d[a[i]] - del - (n - w[a[i]]) + w[a[i]]; 
		int pos = query(1,i-1,need);//找到标号
		if(pos == -1){
			puts("-1");
			return 0;
		}
		del += w[a[i]];
		w[pos] += w[a[i]];
		ans . push_back(pii(a[i],pos));
	}
	for(auto i:ans){
		int x = i.fi,y = i.se;
		edge[x]. push_back(y);
		edge[y]. push_back(x);
//		printf("(%lld %lld)\n",x,y);
	}
	dfs(1,0);
	DFS(1,0);
	sort(d+1,d+1+n);
	sort(F+1,F+1+n);
//	Rep(i,1,n){
//		debug(f[i]);
//	}
	Rep(i,1,n){
//		printf("[](%lld %lld)\n",F[i],d[i]);
		if(d[i] != F[i]){
			puts("-1");
			return 0;
		}
	}
	for(auto i:ans){
		printf("%lld %lld\n",i.fi,i.se);
	}
	return 0;
}

Measured memory_bytes: 17776
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int[] input = new int[N];
		for (int i = 0; i < input.length; i++) {
			input[i] = sc.nextInt();
		}
		int[] j = new int[N + 1];
		j[0] = 0;
		for (int i = 1; i < j.length; i++) {
			j[i] = j[i - 1] + input[i - 1];
		}
		int ans = 0;
		for (int i = 0; i < j.length; i++) {
			if (j[i] <= X)
				ans++;
		}
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 23124
using System;

class A4{
  public static void Main(){
    int n,q;
    n = int.Parse(Console.ReadLine());
    string[] S = new string[n];
    string[] str = Console.ReadLine().Split(' ');

    for(int i = 0;i < n;i++){
      S[i] = str[i];
    }

    q = int.Parse(Console.ReadLine());
    string[] T = new string[q];
    string[] str2 = Console.ReadLine().Split(' ');

    for(int i = 0;i < q;i++){
      T[i] = str2[i];
    }

    Console.WriteLine(Serach(S,T));

  }

  static int Serach(string[] S,string[] T){
    int count = 0,l = 0;
    bool flag = false;
    string[] memory = new string[S.Length];

    for(int i = 0;i < T.Length;i++){
      if(flag == true) l++;
      flag = false;
      for(int j = 0;j < S.Length;j++){
        if(flag == true && memory[l].CompareTo(S[j]) == 0){
          continue;
        }
        else if(S[j].CompareTo(T[i]) == 0){
          memory[l] = T[i];
          flag = true;
          count++;
          }
      }
    }
    return count;
  }
}


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

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) {
    if (!b) return a;
    return gcd(b, a % b);
}

int main() {
    int n;
    ll cur = 1;
    cin >> n;
    for (int i = 0; i < n; i++) {
        ll t; cin >> t;
        ll g = gcd(cur, t);
        cur = cur / g * t;
    }

    cout << cur;
}

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

string s;
int ok,i;

int main()
{
	cin>>s;
	for (i=0;i<=s.size()-1;i++)
	 if (s[i]=='C')
	 {
	 	ok=1;
	 	break;
	 }
	if (ok==0) 
	{
		puts("No");
		return 0;
	}
	for (i;i<=s.size()-1;i++)
	{
		if (s[i]=='F')
	 	{
	 		ok=2;
	 		break;
		}
	}
	if (ok==1) 
	{
		puts("No");
		return 0;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 998244353
mans = 998244353 ;ans = 0 ;count = 0 ;pro = 1
sys.setrecursionlimit(10**6)

n = int(input())
XD = [tuple(map(int,input().split())) for i in range(n)]
XD.append((-10**10,inf))
XD.sort()

now = 0
def dfs(node):
  global now
  pro = 1
  while now < n :
    if XD[now+1][0] < XD[node][0] + XD[node][1]:
      now += 1
      pro *= dfs(now)
      pro %= mod
    else:break
  return pro + 1
ans = dfs(0)
print((ans-1)%mod)


Measured memory_bytes: 202376
import networkx as nx

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

S = [list(input()) for _ in range(n)]
G = nx.DiGraph()

start = (n, m)
cnt = 0
goal = (n, m + 1)

for i in range(n):
    for j in range(m):
        if S[i][j] != "#":
            if S[i][j] == "o":
                cnt += 1
                G.add_edge(start, (i, j), capacity=1)
            if i + 1 < n:
                if S[i + 1][j] != "#":
                    G.add_edge((i, j), (i + 1, j), weight=-1)
            if j + 1 < m:
                if S[i][j + 1] != "#":
                    G.add_edge((i, j), (i, j + 1), weight=-1)
            G.add_edge((i, j), goal, capacity=1)
# G.add_node(start, demand=cnt)
# G.add_node(goal, demand=-cnt)
mincostflow = nx.max_flow_min_cost(G, start, goal)
ans = nx.cost_of_flow(G, mincostflow)
print(abs(ans))


Measured memory_bytes: 68712
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

/*** MOD CALCULATION ***/

const int MOD = 1e9+7;
const int MAX = 1'000'005;

ll addM(ll a, ll b){
	return ((a % MOD) + (b % MOD)) % MOD;
}

ll mulM(ll a, ll b){
	return ((a % MOD) * (b % MOD)) % MOD;
}

ll powM(ll a, ll b){
	if(b == 0) return 1;
  	else if(b == 1) return a % MOD;
  	else if(b%2==0) return mulM(powM(a, b/2), powM(a, b/2));
  	else return mulM(a, mulM(powM(a, (b-1)/2), powM(a, (b-1)/2)));
}

// b^{-1} = b^{p-2} (mod p)
// a/b = a*b^{p-2} (mod p)
ll divM(ll a, ll b){ 
  	return mulM(a, powM(b, MOD-2));
}

// n!, (n!)^{-1} のテーブル作成
ll fac[MAX], finv[MAX], inv[MAX];
void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep3(i,2,MAX-1){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COMB(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

/*** MOD CALCULATION ここまで ***/

void Main(){
    int n, m; cin >> n >> m;
    vi x(n-1), y(m-1);
    
    int now, past;
    rep(i, n){
        cin >> now;
        if(i != 0) x[i-1] = now - past;
        past = now;
    }
    
    rep(i, m){
        cin >> now;
        if(i != 0) y[i-1] = now - past;
        past = now;
    }
    
    int totx = 0;
    int toty = 0;
    
    rep(i, n-1){
        int coef = mulM(n-i-1, i+1);
        totx = addM(totx, mulM(coef, x[i]));
        // cout << coef << " " << x[i] << endl;
    }
    
    rep(i, m-1){
        int coef = mulM(m-i-1, i+1);
        toty = addM(toty, mulM(coef, y[i]));
        // cout << coef << " " << y[i] << endl;
    }
    
    // cout << totx << " " << toty << endl;
    int ans = mulM(totx, toty);
    cout << ans << endl;
    return;
}

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

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


dlist =[0]*(n-1)

for i in range(0,n-1):
    dlist[i] = (Alist[i+1] - Alist[i])*a

res = 0
for i in range(0,n-1):
    if dlist[i] > b:
        res += b
    else:
        res += dlist[i]

print(res)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int a[N],b[N],n,m;
int main() {
  int x,y;
  scanf("%d%d",&n,&m);
  for (int i = 1 ; i <= m ; ++ i) {
    scanf("%d%d",&x,&y);
    if (x > y) swap(x,y);
    if (y == n) b[x] = 1;
    if (x == 1) a[y] = 1;
  }
  for (int i = 1 ; i <= n ; ++ i)
    if (a[i] && b[i]) return 0 * printf("POSSIBLE\n");
  puts("IMPOSSIBLE");
  return 0;
}

Measured memory_bytes: 1792
n,a,b=map(int,input().split())
s=input()
y=0
fore=0
for i in s:
  if i == "a":
    if y<a+b:print("Yes");y+=1
    else:print("No")
  elif i == "b":
    if y<a+b and fore <b:print("Yes");fore+=1;y+=1
    else:print("No")
  else:print("No")

Measured memory_bytes: 4016
#include <cstdlib>
#include <iostream>
#include <algorithm>

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

    int a[10];
    int i=0;
    while (std::cin >> a[i]) {
        i++;
    }
    std::sort(a, a+10);
    for (i=9; i>6; i--){
        std::cout << a[i] << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3092
import java.util.*;
 
public class Main{
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    String[] S = sc.nextLine().split(" ");
    int count = 0;
    int now = 0;
    for(int i = 0; i < N; i++){
      int n = Integer.parseInt(S[i]);
      if(n > now){
        count += n-now;
        now = n;
      }else{
        now = n;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 23508
// C - 755

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int N;
int ans = 0;

bool is_753(ll k) {
	bool has7 = false, has5 = false, has3 = false;
	while(k > 0) {
		if (k % 10 == 7) has7 = true;
		if (k % 10 == 5) has5 = true;
		if (k % 10 == 3) has3 = true;

		k /= 10;
	}

	return has7 && has5 && has3;
}

void dfs(ll k) {
	if (k > N) return;
	if (is_753(k)) ans++;

	dfs(k*10 + 7);
	dfs(k*10 + 5);
	dfs(k*10 + 3);
}

int main() {
	cin >> N;

	dfs(0);

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr bool AUTOFLUSH = false;
    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))
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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

signed main() {
    SS(ll,a,b,m);
    ll amin=MOD,bmin=MOD;
    SV(ll,A,a);
    SV(ll,B,b);
    rep(i,a)chmin(amin,A[i]);
    rep(i,b)chmin(bmin,B[i]);
    ll ans=amin+bmin;
    rep(i,m){
        SS(ll,x,y,c);
        chmin(ans,A[x-1]+B[y-1]-c);
    }
    p(ans);
}

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//String s=sc.next();
		//String t= sc.next();
		int n = sc.nextInt();
		int m = sc.nextInt();
		//int k = sc.nextInt();
		long count=0;
		long count1=0;
		int[] array = new int[3];
		/*array[0]=n-m;
		array[1]=n*m;
		array[2]=n+m;*/
		Arrays.sort(array);

		/*for(int i=0;i<3;i++) {
			if(s.substring(i,i+1).equals(t.substring(i,i+1))) {
				count++;
			}
		}*/

		if(500*n>=m) {//SUN,MON,TUE,WED,THU,FRI,SAT
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

		//System.out.println(n*n);
	}
}




Measured memory_bytes: 21716
n,m,x = map(int,input().split())
CA = [list(map(int,input().split())) for i in range(n)]
com = []

import itertools
for i in range(1,n+1):
    c = list(itertools.combinations(CA,i))
    for j in c:
        com.append(j)
        
ans = 12*(10**5)+1
        
for i in com:
    res = [0]*(m+1)
    
    for j in range(len(i)):
        ca = i[j]
        
        for k in range(m+1):
            res[k] += ca[k]
            
    ok = 0        
    for j in res[1:]:
        if j >= x:
            ok += 1
            
        if ok == m:
            ans = min(ans,res[0])

if ans == 12*(10**5)+1:
    ans = -1
            
print(ans)

Measured memory_bytes: 85584
card ={'S': [0]*13,
        'H': [0]*13,
        'C': [0]*13,
        'D': [0]*13
}

n = int(input())

for i in range(1,n+1):
    m,num = input().split()
    num = int(num)
    card[m][num-1] =1

for c in ["S","H","C","D"]:
    for j in range(1,13+1):
        if (card[c][j-1]==0):
            print(c,str(j))



Measured memory_bytes: 5596
#include<stdio.h>
int main(void){
    int x, y, t;

    scanf("%d %d", &x, &y);
    if(x < y){
        t = x;
        x = y;
        y = t;
    }
    while(1){
        t = x % y;
        if(!t){
            printf("%d\n", y);
            break;
        }
        x = y;
        y = t;
    }
    return 0;
}


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

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

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

struct Card {char suit,value; };

void bubble(struct Card A[], int N){
	bool f=1;
	for(int i=0;f;i++){
		f = 0;
		for(int j = N-1; j>=i+1 ;j--){
			if(A[j].value<A[j-1].value){
				swap(A[j],A[j-1]);
				f=1;
			}
		}
	}
}
void select(struct Card A[],int N){
	for(int i=0;i<N;i++){
		int minj=i;
		for(int j=i;j<N;j++){
			if(A[j].value<A[minj].value){
				minj =j ;
			}
		}
		if(i != minj){
			swap(A[i],A[minj]);
		}
	}
}

int main() {
	int N;
	cin >>N;
	Card C1[N] , C2[N];
	for(int i=0 ; i<N ;i++){
		cin >>C1[i].suit>>C1[i].value;
		C2[i]=C1[i];
	}
	char ch;
	bubble(C1,N);
	for(int i=0;i<N;i++){
		if(i>0) cout << " ";
		cout <<C1[i].suit<<C1[i].value;
	}
	cout <<endl;
	cout <<"Stable"<<endl;
	select(C2,N);
	for(int i=0;i<N;i++){
		if(i>0) cout << " ";
		cout <<C2[i].suit<<C2[i].value;
	}
	cout <<endl;
	bool f=1;
	for(int i=0;i<N;i++){
		if(C1[i].suit!=C2[i].suit){
			f=0;
		}
	}
	if(f){
		cout <<"Stable"<<endl;
	}
	else{
		cout <<"Not stable"<<endl;
	}



}


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

int l[101][101] = {}, u[101][101] = {};

int main(){
    int n, m, d, ans = 0;
    char x;

    cin >> n >> m >> d;

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> x;
            if(x == '.'){
                u[i][j] = u[i-1][j]+1;
                l[i][j] = l[i][j-1]+1;
            }
            ans += (l[i][j] >= d) + (u[i][j] >= d);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3164
n,m = map(int,input().split())
judge = [True for i in range(n+1)]
for i in range(m):
    judge[int(input())] = False
dp = [0]*(n+1)
dp[0] = 1
for i in range(n):
    if i + 1 > n:continue
    if judge[i + 1]:dp[i+1] = (dp[i] +dp[i+1]) %1000000007
    if i + 2 > n:continue
    if judge[i + 2]:dp[i+2] = (dp[i] + dp[i+2]) %1000000007
print(dp[-1]%1000000007)

Measured memory_bytes: 45808
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

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

		// setOut();
		String str = sc.nextLine();
		System.out.println(help(str));

	}

	private static int help(String str) {
		// TODO Auto-generated method stub
		int s = 0;
		int f = str.length() - 1;
		int count = 0;
		char[] c = str.toCharArray();
		while (f > s) {
			if (c[f] == c[s]) {
				++s;
				--f;
			} else if (c[f] != 'x' && c[s] != 'x') {
				return -1;
			} else if (c[f] == 'x') {
				++count;
				--f;
			} else if (c[s] == 'x') {
				++count;
				++s;
			}

		}
		return count;
	}

}

Measured memory_bytes: 28228
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <list>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <ostream>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <cstdlib>
#include <sstream>
#include <fstream>
#include <iomanip>

#define N 45
#define INF (1 << 30)
#define NIL -1
const int mod = 1e9 + 7;
using namespace std;
int pre[N];
int in[N];
int post[N];
void rebuild(int preL, int inL, int postL, int n)
{
	if (n == 0)
		return;
	if (n == 1)
	{
		post[postL] = pre[preL];
		return;
	}
	post[postL + n - 1] = pre[preL];
	int i;
	for (i = 0; i < n; ++i)
	{
		if (in[i + inL] == pre[preL])
			break;
	}
	rebuild(preL + 1, inL, postL, i);
	rebuild(preL + i + 1, inL + i + 1, postL + i, n - i - 1);
}
int main()
{
	int T, n, k;
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> pre[i];
	for (int i = 0; i < n; ++i)
		cin >> in[i];
	rebuild(0, 0, 0, n);
	for (int i = 0; i < n - 1; ++i)
		cout << post[i] << ' ';
	cout << post[n - 1] << endl;
	return 0;
}

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

using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
	int a;
	cin >> a;
	cout << 48-a << "\n";	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <stdio.h>
#include <string.h>
int main(void){
    int a,b,n;
    std::cin>>n>>a>>b;
    if(n*a>b){
        std::cout<<b;
    }else{
        std::cout<<n*a;
    }
    return 0;
 }

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N, M;
    cin >> N >> M;
    cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
n,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
for i in range(n):
    x = x-a[i]
    if x < 0:
        print(i)
        break
    if i == n-1:
        if x == 0:
            print(n)
        else:
            print(n-1)


Measured memory_bytes: 9120
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int A[110];
    rep(i, N) cin >> A[i];
    int sum = 0;
    rep(i, N) sum += A[i];
    sort(A, A + N, greater<int>());
    rep(i, M) {
        if (sum > A[i] * 4 * M) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(void)
{
	int d,n;

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

	cin >> d >> n;

	long long int num = pow(100,d);

	if(n==100)
	{
		cout << num*n + num << '\n';
	}
	else
	{
		cout << num*n << '\n';
	}

	return 0;
}

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

int n, m, a, b;
std::map<int, int> v;
int main() {
    std::cin >> n >> m;
    for (int i = 0; i < m; i++) {
        std::cin >> a >> b;
        if (a == 1) {
            v[b]++;
        }
        if (b == n) {
            v[a] +=2;
        }
    }
    for (auto e: v) {
        if (e.second == 3) {
            std::cout << "POSSIBLE" << std::endl;
            return 0;
        }
    }
    std::cout << "IMPOSSIBLE" << std::endl;
}


Measured memory_bytes: 9600
def generate(n):
    if n == 1:
        for i in range(1, 10):
            yield [i]
    else:
        for A in generate(n - 1):
            for i in range(10):
                if abs(A[-1] - i) <= 1:
                    yield A + [i]


L = []
for n in range(1, 11):
    for A in generate(n):
        L.append(int(''.join([str(a) for a in A])))
k = int(input())
print(L[k - 1])


Measured memory_bytes: 17060
#include <stdio.h>
int main(){
int n;
  scanf("%d",&n);
  n %=10;
  if(n == 2 || n == 4 || n == 5 || n == 7||n == 9)
  printf("hon");
  else if(n == 0 || n == 1 || n == 6 || n == 8)
  printf("pon");
  else
  printf("bon");
}


Measured memory_bytes: 1732
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	string S;
	cin >> S;
    int bus=0;
    if(S.at(0) != S.at(1) || S.at(1) != S.at(2)){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
	return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>

void drawline(int width)
{
	int i;

	i = 0;
	while(i < width)
	{
		printf("#");
		i++;
	}
	printf("\n");
}

int main(void)
{
	int height, width;		//Value H, W.
	int i;

	while(1)
	{
		i = 0;
		scanf("%d %d", &height, &width);
		if(height == 0 && width == 0)
			return (0);

		while(i < height)
		{
			drawline(width);
			i++;
		}

		printf("\n");
	}

	return (0);
}



Measured memory_bytes: 2048
using System;

namespace ABC126_b
{
    class Program
    {
        static void Main(string[] args)
        {
            var aaa = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var s = Console.ReadLine();
            var s2 = s.ToCharArray();
            s2[aaa[1] - 1] = Char.ToLower(s2[aaa[1] - 1]);
            var s3 = new String(s2);
            Console.WriteLine(s3);

        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"

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

    long long x;
    cin >> x;
    long long a = 100;
    long long count = 0;
    while(true){
        if(a >= x)
            break;
        count++;
        a += a / 100;
        // cout << a << endl;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a + b == 15) {
        cout << "+" << endl;
    } else if (a * b == 15) {
        cout << "*" << endl;
    } else {
        cout << "x" << endl;
    }
}

Measured memory_bytes: 764
x,y=[int(s) for s in input().split()]
ans=0
if x<4:
  ans+=100000
if x<3:
  ans+=100000
if x<2:
  ans+=100000
if y<4:
  ans+=100000
if y<3:
  ans+=100000
if y<2:
  ans+=100000
if x*y==1:
  ans+=400000
print(ans)
  


Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define boost ios::sync_with_stdio(false); cin.tie(0)
#define ll              long long int
#define ld              long double
#define mk              make_pair
#define pb              push_back
#define f               first
#define s               second
#define fo(i,a,b)       for(i=a;i<b;i++)
#define foe(i,a,b)      for(i=a;i<=b;i++)
#define all(x)          x.begin(),x.end()
// #define vi               vector<int>
#define vl              vector <long long int>
// #define pii          pair <int,int>
#define pll             pair <long long int, long long int>
// #define vpii         vector< pair<int,int> >
#define vpll            vector < pair <long long int,long long int> >
#define MOD             1000000007
using namespace std;
const int inf = INT_MAX;
const ll inf64 = LLONG_MAX;


int main()
{
    boost;
    ll x;
    cin >> x;
    cout << !x;



    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main(void){
  double t1,t2;
  while(scanf("%lf %lf",&t1,&t2)!=EOF){
    if(t1<35.50&&t2<71.00)puts("AAA");
    else if(t1<37.50&&t2<77.00)puts("AA");
    else if(t1<40.00&&t2<83.00)puts("A");
    else if(t1<43.00&&t2<89.00)puts("B");
    else if(t1<50.00&&t2<105.00)puts("C");
    else if(t1<55.00&&t2<116.00)puts("D");
    else if(t1<70.00&&t2<148.00)puts("E");
    else puts("NA");
  }
  return 0;
}

Measured memory_bytes: 608
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
   
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] A = new int[9];
        for (int i = 0; i < A.length; i++) {
            A[i] = sc.nextInt();
        }
        int N = sc.nextInt();
        List<Integer> B = new ArrayList<>();
        for (int i = 0; i < N; i++) {
            B.add(sc.nextInt());
        }
        if ((B.contains(A[0] ) && B.contains(A[1]) && B.contains(A[2]))
         || (B.contains(A[0] ) && B.contains(A[4]) && B.contains(A[8]))
         || (B.contains(A[0] ) && B.contains(A[3]) && B.contains(A[6]))
         || (B.contains(A[1] ) && B.contains(A[4]) && B.contains(A[7]))
         || (B.contains(A[2] ) && B.contains(A[5]) && B.contains(A[8]))
         || (B.contains(A[2] ) && B.contains(A[4]) && B.contains(A[6]))
         || (B.contains(A[3] ) && B.contains(A[4]) && B.contains(A[5]))
         || (B.contains(A[6] ) && B.contains(A[7]) && B.contains(A[8]))) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
#55
import math
N,D = map(int,input().split())
x = []
dis = []
cnt = 0

for i in range(N):
    x.append(list(map(int,input().split())))
    
for i in range(N-1): 
    for j in range(i+1,N): 
        num = 0
        for m in range(D):
            num += (x[i][m]-x[j][m])*(x[i][m]-x[j][m])
        dis.append(num)
        
for i in dis:
    if int(math.sqrt(i)) == math.sqrt(i):
        cnt += 1
        
print(cnt)

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;

int main() {
   string s;
   cin >> s;
   vector<int> v(3);
   v[0] = count(s.begin(), s.end(), 'a');
   v[1] = count(s.begin(), s.end(), 'b');
   v[2] = count(s.begin(), s.end(), 'c');

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

   bool f = false;
   if (v[0] == v[1] && v[1] == v[2]) {
      f = true;
   }
   if (v[1] == v[2] && v[0]+1 == v[1]) {
      f = true;
   }
   if (v[0] == v[1] && v[1]+1 == v[2]) {
      f = true;
   }

   if (f) {
      puts("YES");
   } else {
      puts("NO");
   }

/*
   if (a == b && b == c) {
      puts("YES");
      return 0;
   }
   if (a == b && b == c+1) {
      puts("YES");
      return 0;
   }
   if (b == c) {
      if (a-1 == b) {
         puts("YES");
         return 0;
      }
   }
*/

   return 0;
}

Measured memory_bytes: 512
m,k=map(int,input().split())
if k>2**m-1:
  print(-1)
elif k==0:
  ans=[i for i in range(2**m)]
  ans=ans+ans[::-1]
  print(*ans)
else:
  if m==1:
    print(-1)
  else:
    ans=[]
    for i in range(2**m):
      if i==k:
        continue
      ans.append(i)
    ans=[k]+ans+[k]+ans[::-1]
    print(*ans)

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


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

    int ai, sumA=0;
    rep(i, M) {
        cin >> ai;
        sumA += ai;
    }

    if (N-sumA >= 0) cout << N - sumA << endl;
    else cout << -1 << endl;

    return 0;
}



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

using namespace std;

#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define Matrix vector<vector<int>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'

constexpr int INF = 2e18;
constexpr int MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 3;

// #define MULTIPLE_TEST_CASES
void solve() {
  int n;
  cin >> n;

  vector<int> arr(n);
  map<int, int> m;
  for (int &x : arr) {
    cin >> x;
    m[x]++;
  }

  int ans = accumulate(all(arr), 0ll);
  int q;
  cin >> q;
  while (q--) {
    int u, v;
    cin >> u >> v;

    ans -= m[u] * u;
    m[v] += m[u];
    ans += m[u] * v;
    m[u] = 0;
    cout << ans << endl;
  }
}

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int t = 1;

#ifdef MULTIPLE_TEST_CASES
  cin >> t;
#endif
  while (t--)
    solve();
}

Measured memory_bytes: 9944
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;

signed main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  for( int i = 0; i < N; i++ ) cin >> A.at(i);
  sort(A.begin(), A.end());
  cout << A.at(N/2) - A.at(N/2-1) << endl;

}


Measured memory_bytes: 1024
N = int(input())
A = [int(x) for x in input().split()]
W = [0]*(N+1)
p = 0
for i in range(1,N):
    if A[i-1] > A[i]:
        p = A[i-1]-A[i]
        A[i] = A[i] + p
        W[i] = p
print(sum(W))


Measured memory_bytes: 31996
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/rope>

using namespace __gnu_pbds; 
using namespace __gnu_cxx;
using namespace std;
using ll = long long;

#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define len(v) ((int)v.size())
#define all(v) v.begin(), v.end()
#define precision(n) fixed<<setprecision(n)

#ifdef LOCAL
    #include "debug.h"
#else
    #define debug(...) 42
#endif

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);    
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}

template<typename T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;
template<typename T> using MinPriorityQueue = priority_queue <T, vector <T>, greater <T> >;
template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);}


template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}

 

const int mod = 1e9;
const int N = 3e5 + 5;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937_64 mt(seed);

template <typename T>
long long myrand(T m) {
    long long mod = m;
    long long x = mt()%mod;

    return x;
}
int a[N];
vector<int> g[N];
int main() {
    io();
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++)
        cin >> a[i];

    for(int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;
        g[u].pb(v);
        g[v].pb(u);
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        int cnt = 0;
        for(int x : g[i]) {
            cnt = max(cnt, a[x]);
        }
        if(cnt == 0 || a[i] > cnt)
            ans++;
    }
    cout << ans;
}


Measured memory_bytes: 13828
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;
  
  int sum = 0;
  if(x >= y){
    if(c*2 < a+b){
      sum += c*2*y;
      x -= y;
      if(c*2 < a){
        sum += c*2*x;
      }
      else{
        sum += a*x;
      }
    }
    else{
      sum += a*x + b*y;
    }
  }
  else{
    if(c*2 < a+b){
      sum += c*2*x;
      y -= x;
      if(c*2 < b){
        sum += c*2*y;
      }
      else{
        sum += b*y;
      }
    }
    else{
      sum += a*x + b*y;
    }
  }

  cout << sum << endl;
}

  


Measured memory_bytes: 3540
def cash(a,N):
    ans = 0
    for i in reversed(range(len(a))):
        num = N//a[i]
        N -= a[i]*num
        ans += num
    return ans


N = int(input())

cash6 = []
cash9 = []
for i in range(1000):
    tmp = 6**i
    if tmp>N:
        break
    cash6.append(tmp)
for j in range(1000):
    tmp = 9**j
    if tmp>N:
        break
    cash9.append(tmp)

ans = 1e9
for i in range(N+1):
    ans = min(ans,cash(cash6,i)+cash(cash9,N-i))
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define ALL(a) (a).begin(), (a).end()
#define p(a, b) printf(a, b);
#define c(s) cout << (s) << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define cyn(c) cout << (c ? "Yes" : "No") << endl;
#define cYN(c) cout << (c ? "YES" : "NO") << endl;
#define pyn(c) printf("%s\n", c ? "Yes" : "No");
#define pYN(c) printf("%s\n", c ? "YES" : "NO");
#define INF 1e18
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> P;
template <class T>
bool contain(const std::string &s, const T &v)
{
  return s.find(v) != std::string::npos;
}
ULL mod = 1e9 + 7;

int main(){
  int n,v[21]={},c[21]={},ans=0;
  cin>>n;
  rep(i,n){
    cin>>v[i];
  }
  rep(i,n){
    cin>>c[i];
  }
  rep(i,n){
    if(v[i]-c[i]>0){
      ans += v[i]-c[i];
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//void chmin(ll &a,ll b){if(a>b) a = b ;}

int main(){
	ll n,k ;
	cin >> n >> k ;
	vll sum(n+1,0) ;
	for(int i=1;i<=n;i++){
		ll a ; cin >> a ;
		sum.at(i) = sum.at(i-1)+a ;
	}
	vector<bitset<40>> bit ;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			bit.emplace_back(sum.at(j)-sum.at(i-1)) ;
		}
	}
	vb ok(bit.size(),true) ;
	ll ans = 0 ;
	for(int i=39;i>=0;i--){
		ll cnt = 0 ;
		for(int j=0;j<bit.size();j++){
			if(ok.at(j)&&bit.at(j)[i]) cnt++ ;
		}
		if(cnt>=k){
			ans += (1LL<<i) ;
			for(int j=0;j<bit.size();j++){
				if(ok.at(j)&&!bit.at(j)[i]) ok.at(j) = false ;
			}
		}
	}
	cout << ans << endl ;
}


Measured memory_bytes: 7476