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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

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

const int mod = 1e9+7;

int H, W;
string B[1111];
int dp[1111][1111];

signed main() {
  cin >> H >> W;
  rep (i, H) {
    cin >> B[i];
  }
  
  dp[0][0] = 1;
  for (int yi = 0; yi < H; yi++) {
    for (int xi = 0; xi < W; xi++) {
      if (B[yi][xi] == '#') continue;
      if (yi > 0) {
        dp[yi][xi] += dp[yi-1][xi];
      }
      if (xi > 0) {
        dp[yi][xi] += dp[yi][xi-1];
      }
      dp[yi][xi] %= mod;
    }
  }

  cout << dp[H-1][W-1] << endl;
  // print2(dp, H, W);

  return 0;
}

Measured memory_bytes: 9984
//                               //
    // author : samars_diary //
    // 18-09-2020 │ 22:08:56 //
//                               //

#include <iostream>
using namespace std;

void solve(){
    long long int a ; cin>>a ;
    if(a%10==0 || a%10==1 || a%10==6 || a%10==8){
        cout<<"pon"<<'\n';
    }else if (a%10==3){
        cout<<"bon"<<'\n';
    }else{
        cout<<"hon"<<'\n';
    }
}

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

    //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    //#endif

    int t = 1;
    while(t--){
        solve();
    }

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(false);
	int x, a,b;
	cin >> x >> a >> b;
	if(abs(x-a) > abs(x-b)) cout << "B" << endl;
	else cout << 'A' << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
queue<pair<ll,ll>> A{};
int main() {
  ll N;
  cin >> N;
  ll x = floor(sqrt(N));
  while(true){
    ll y = N / x;
    if(x*y==N){
      cout << x + y - 2 << endl;
      return 0;
    }
    x--;
  }
}

Measured memory_bytes: 256
use std::io::Read;
use std::str::FromStr;

fn f(s:&str) -> i64{
    let l = s.len();
    if l == 0 {
        return 0;
    }
    (1..l)
        .map(|x| i64::from_str(&s[..x]).unwrap() * (1<<(l-1-x)) + f(&s[x..]))
        .sum::<i64>()
    + i64::from_str(&s).unwrap()
}

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let s:&str = iter.next().unwrap();

    println!("{}",f(s));
}


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

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

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    repd(i, k, n + 2) {
        ll num_min = (1 + i) * i / 2;
        ll num_max = i * (2 * n - i + 3) / 2;
        ll num = (num_max - num_min + 1) % mod;
        ans += num;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
	int x, y;
	while(1){
		scanf("%d%d", &x, &y);
		if(x==0){
			if(y==0){
				break;
			}
		}
		if(x<y){
			printf("%d %d\n", x, y);
		}else{
			printf("%d %d\n", y, x);
		}
	}
	return 0;
}

Measured memory_bytes: 600
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next(),t = sc.next();
    char[] sch = s.toCharArray();
    char[] tch = t.toCharArray();
    Arrays.sort(sch);
    Arrays.sort(tch);
    int slen = s.length(),tlen = t.length();
    s = "";t = "";
    for(int i = 0;i<slen;i++){
      s = s + sch[i] ;
    }
    for(int i = 0;i<tlen;i++){
      t = tch[i] + t;
    }
    if(t.compareTo(s) > 0){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }


  }
}


Measured memory_bytes: 23124
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<algorithm>
using namespace std;
long long mod=1000000007;
int main(){
	long long i,n,k,ans=0;
	scanf("%lld%lld",&n,&k);
	for(i=k;i<=n;i++){
		ans+=(2*n-i+1)*i/2-(i-1)*i/2+1;
		ans%=mod;
	}
	printf("%lld\n",(ans+1)%mod);
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  while(A>0,C>0){
   C=C-B;
    if(C<=0){
      break;
    }
   A=A-D;
    if(A<=0){
      break;
    }
  }
  
  if(A<=0){
    cout << "No" << endl;
  }
  else{ 
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3540
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;

signed main(){
    int n;
    cin >> n;
    int a[100010];
    rep(i,n)cin >> a[i];
    multiset<int> c;
    int maxi = 0;
    int mini = 0;
    int s = 0;
    rep(i,n){
        if(c.size() == 0){
            c.insert(a[i]);
            maxi = a[i];
            mini = a[i];
        }else{
            auto itr = c.lower_bound(a[i]);
            if(itr == c.begin())c.insert(a[i]);
            else{
                itr--;
                c.erase(itr);
                c.insert(a[i]);
            }
        }
    }
    cout << c.size() << endl;

    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc134.contest.atcoder.jp/tasks/abc134_b

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;
const long long inf = 100000000000LL;

int main() {
  ll a, b, q;
  cin >> a >> b >> q;
  vll s(a), t(b);
  rep(i,a) cin >> s[i];
  rep(i,b) cin >> t[i];
  vll ret;
  rep(i,q) {
    ll x;
    cin >> x;
    ll sl, sr, tl, tr;
    sl = sr = tl = tr = 0LL;
    if(x < s[0]) {
      sr = s[0];
      sl = -inf;
    }
    if(x > s[a-1]) {
      sr = inf;
      sl = s[a-1];
    }
    if(x < t[0]) {
      tr = t[0];
      tl = -inf;
    }
    if(x > t[b-1]) {
      tr = inf;
      tl = t[b-1];
    }
    if(sr == 0LL) sr = s[upper_bound(s.begin(),s.end(),x)-s.begin()];
    if(sl == 0LL) sl = s[upper_bound(s.begin(),s.end(),x)-s.begin()-1];
    if(tr == 0LL) tr = t[upper_bound(t.begin(),t.end(),x)-t.begin()];
    if(tl == 0LL) tl = t[upper_bound(t.begin(),t.end(),x)-t.begin()-1];
    ll ans = 100000000000LL;
    ans = min(ans,min((x-sl)+(tr-sl),(tr-x)+(tr-sl)));
    ans = min(ans,min((x-tl)+(sr-tl),(sr-x)+(sr-tl)));
    ans = min(ans,max((sr-x),(tr-x)));
    ans = min(ans,max((x-sl),(x-tl)));
    ret.push_back(ans);
  }
  rep(i,ret.size()) cout << ret[i] << endl;
  return 0;
}

Measured memory_bytes: 3828
s = input()
len_s = len(s)
for count in range(1, len_s+1):
  sub_s = s[:-count]
  if len(sub_s) % 2 == 0:
    half_len_sub = int(len(sub_s) / 2)
    if sub_s[:half_len_sub] == sub_s[half_len_sub:]:
      print(len_s - count)
      exit()
      

Measured memory_bytes: 2940
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    long n,a,b;
    scanf("%ld %ld %ld", &n, &a, &b);
    if(a > b){
        swap(a,b);
    }
    if( ( a + b ) % 2 == 0){
        printf("%ld", (b - a) / 2);
    } else {
        if(a + b >= n + 1){
            printf("%ld", n-b+1+(b-a-1)/2);
        } else {
            printf("%ld", a+(b-a-1)/2);
        }
    }
    
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N=pow(10,9)+7;

ll pow_mod(ll n, ll k){
    if(k==0) return 1;
    else{
        ll a=(pow_mod(n, k/2)*pow_mod(n, k/2))%N;
        if(k%2==0){
            return a;
        }
        else{
            return (a*n) % N;
        }
    }
}
/*
ll combi(ll n, ll k){
    ll up=1,down=1;
    for(int i=0; i<k; i++){
        up=(up*(n-i))%N;
        down=(down*(i+1))%N;
    }
    return (up*pow_mod(down,N-2))%N;
}*/
int main(){
    ll n,m;
    cin >> n >> m;
    vector<ll> c(n+1,1),p1(n+1,1),p2(n+1,1);
    for(int i=1; i<=n; i++){
        p1.at(i)=(p1.at(i-1)*(m-i+1))%N;
        p2.at(n-i)=(p2.at(n-i+1)*(m-n+i))%N;
    }
    for(ll i=1; i<=n; i++){
        c.at(i) = (c.at(i-1)*(n-i+1))%N;
        c.at(i) *= pow_mod(i, N-2);
        c.at(i) %= N; 
    }
    ll ans=0;
    for(int k=0; k<=n; k++){
        ll cnt=(c.at(k)*p1.at(k))%N;
        cnt = (cnt*pow_mod(p2.at(k),2))%N;
        if(k%2==0) ans += cnt;
        else ans -= cnt;
        ans%=N;
        if(ans<0) ans+=N;
    }
    cout << ans << endl;
}

Measured memory_bytes: 14768
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    int n;
    long ga, sa, ba;
    long gb, sb, bb;
    ArrayList<P> pab = new ArrayList<>();
    ArrayList<P> pba = new ArrayList<>();

    void run() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        ga = sc.nextLong();
        sa = sc.nextLong();
        ba = sc.nextLong();
        gb = sc.nextLong();
        sb = sc.nextLong();
        bb = sc.nextLong();

        if (ga < gb) {
            pab.add(new P(ga, gb));
        } else {
            pba.add(new P(ga, gb));
        }

        if (sa < sb) {
            pab.add(new P(sa, sb));
        } else {
            pba.add(new P(sa, sb));
        }

        if (ba < bb) {
            pab.add(new P(ba, bb));
        } else {
            pba.add(new P(ba, bb));
        }

        if (pab.size() == 3) {
            long max = n;
            max = getMax(max, ga, gb, sa, sb, ba, bb);

            System.out.println(max);
        } else if (pab.size() == 2) {
            long max = getMax(n, pab.get(0).a, pab.get(0).b, pab.get(1).a, pab.get(1).b);

            System.out.println(max + (max / pba.get(0).b) * (pba.get(0).a - pba.get(0).b));
        } else if (pab.size() == 1) {
            long max = n + (n / pab.get(0).a) * (pab.get(0).b - pab.get(0).a);

            System.out.println(getMax(max, pba.get(0).b, pba.get(0).a, pba.get(1).b, pba.get(1).a));
        } else {
            long max = n;
            max = getMax(max, gb, ga, sb, sa, bb, ba);

            System.out.println(max);
        }
    }

    private long getMax(long max, long a1, long b1, long a2, long b2) {
        long ret = max;
        for (long c1 = 0; c1 <= max; c1++) {
            long c2 = max - c1;
            long d1 = c1 + (c1 / a1) * (b1 - a1);
            long d2 = c2 + (c2 / a2) * (b2 - a2);
            ret = Math.max(ret, d1 + d2);
        }
        return ret;
    }

    private long getMax(long max, long gb, long ga, long sb, long sa, long bb, long ba) {
        for (long gcnt = 0; gcnt <= n; gcnt++) for (long scnt = 0; scnt <= n - gcnt; scnt++) {
            long bcnt = n - gcnt - scnt;
            long gd = gcnt  + (gcnt / gb) * (ga - gb);
            long sd = scnt  + (scnt / sb) * (sa - sb);
            long bd = bcnt  + (bcnt / bb) * (ba - bb);
            max = Math.max(max, gd + sd + bd);
        }
        return max;
    }

    class P implements Comparable<P> {
        long a, b, d;
        P(long a, long b) {
            this.a = a;
            this.b = b;
            d = b - a;
        }

        @Override
        public int compareTo(P o) {
            return (o.d - d) > 0 ? 1 : -1;
        }

        @Override
        public String toString() {
            return a + " " + b;
        }
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 23764
import sys
input=sys.stdin.readline
m=0
a=0
r=0
c=0
h=0

n=int(input())
for i in range(n):
    p=input()
    if p[0]=="M":
        m+=1
    elif p[0]=="A":
        a+=1
    elif p[0]=="R":
        r+=1
    elif p[0]=="C":
        c+=1
    elif p[0]=="H":
        h+=1

ans=0
ans+=m*a*r
ans+=m*a*c
ans+=m*a*h
ans+=m*r*c
ans+=m*r*h
ans+=m*c*h
ans+=a*r*c
ans+=a*r*h
ans+=a*c*h
ans+=r*c*h
print(ans)

Measured memory_bytes: 73820
N = int(input())
A = list(map(int, input().split()))
A.sort()
A_max = A[N-1]

boo = [1 for _ in range(A_max +1)]
tmp = A[0] 
kosuu = 2
while tmp * kosuu <= A_max:
    boo[tmp * kosuu] = 0
    kosuu += 1
pre = tmp
for i in range(1,N):
    tmp = A[i]
    if tmp == pre:
        boo[tmp] = 0
    else:
        kosuu = 2
        while tmp * kosuu <= A_max:
            boo[tmp * kosuu] = 0
            kosuu += 1
        pre = tmp
        
total = 0
for x in A:
    total += boo[x]
print(total)

Measured memory_bytes: 32296
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args) throws Exception{
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] cmd=br.readLine().split(" ");
		int n=Integer.valueOf(cmd[0]);
		int[][] arr=new int[n][2];
		for(int i=0;i<n;i++)
		{
			StringBuilder s=new StringBuilder(br.readLine());
			Stack<Character> st=new Stack<>();
			int cnt=0;
			for(int j=0;j<s.length();j++)
			{
				if(s.charAt(j)=='(')
					st.push('(');
				else
				{
					if(st.empty())
						cnt++;
					else
						st.pop();
				}
			}
			arr[i][1]=st.size();
			arr[i][0]=cnt;
		}
		StringBuilder f=new StringBuilder("");
		for(int i=0;i<n;i++)
		{
			if(arr[i][0]==0)
			{
				for(int j=0;j<arr[i][1];j++)
				{
					f=f.append("(");
				}
			}
		}
		ArrayList<int[]> ar1=new ArrayList<>();
		ArrayList<int[]> ar2=new ArrayList<>();
		for(int i=0;i<n;i++)
		{
			if(arr[i][1]!=0 && arr[i][0]!=0 & arr[i][1]>=arr[i][0])
				ar1.add(new int[] {arr[i][0],arr[i][1]});
			else if(arr[i][1]!=0 && arr[i][0]!=0 & arr[i][1]<arr[i][0])
				ar2.add(new int[] {arr[i][0],arr[i][1]});
		}
		ar1.sort(new Comparator<int[]>() {
			public int compare(int[]a,int[]b)
			{
				if(a[0]>b[0])
					return 1;
				else if(a[0]<b[0])
					return -1;
				return 0;
			}
		});
		ar2.sort(new Comparator<int[]>() {
			public int compare(int[]a,int[]b)
			{
				if(a[1]>b[1])
					return -1;
				else if(a[1]<b[1])
					return 1;
				return 0;
			}
		});
		for(int i=0;i<ar1.size();i++)
		{
			for(int j=0;j<ar1.get(i)[0];j++)
			{
				f=f.append(")");
			}
			for(int j=0;j<ar1.get(i)[1];j++)
			{
				f=f.append("(");
			}
		}
		for(int i=0;i<ar2.size();i++)
		{
			for(int j=0;j<ar2.get(i)[0];j++)
			{
				f=f.append(")");
			}
			for(int j=0;j<ar2.get(i)[1];j++)
			{
				f=f.append("(");
			}
		}
		for(int i=0;i<n;i++)
		{
			if(arr[i][1]==0)
			{
				for(int j=0;j<arr[i][0];j++)
				{
					f.append(")");
				}
			}
		}
		Stack<Character> st=new Stack<>();
		int b=0;
		for(int i=0;i<f.length();i++)
		{
			if(f.charAt(i)=='(')
				st.push('(');
			else
			{
				if(st.empty())
				{
					b=1;
					break;
				}
				else
					st.pop();
			}
		}
		if(b==1 || st.size()!=0)
			System.out.println("No");
		else
			System.out.println("Yes");
	}
}


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

using namespace std;

#ifndef ONLINE_JUDGE
  #define pr_vars(...) do { cerr << "DEBUG: line "<< __LINE__ << ": " << __PRETTY_FUNCTION__ << ":  "; \
                            pr_var(split(#__VA_ARGS__, ',').begin(), __VA_ARGS__); } while(0)
#else
  __attribute__ ((constructor)) static void fast_cin() { ios_base::sync_with_stdio(false); cin.tie(0); }
  #define pr_vars(...) do { } while(0)
#endif /* ONLINE_JUDGE */

using ll = int64_t;
using ull = uint64_t;
using mp = pair<ll, ll>;
using mt = tuple<ll, ll, ll>;    // unpack: tie(ll, ll, ll) = mt;

template<typename T, typename R>
istream &operator>> (istream &fin, pair<T, R> &p) { fin >> p.first >> p.second; return fin; }

template<typename T, typename R>
ostream &operator<< (ostream &fout, const pair<T, R> &p)
{ fout << "{" << p.first << ", " << p.second << "} "; return fout; }

template<typename T> ostream &operator<< (ostream &fout, const vector<T> &vec)
{ for (size_t i = 0; i < vec.size(); i++) fout << vec[i] << ' '; return fout; }

template<typename T> ostream &operator<< (ostream &fout, const deque<T> &vec)
{ for (size_t i = 0; i < vec.size(); i++) fout << vec[i] << ' '; return fout; }

template<typename T> ostream &operator<< (ostream &fout, const list<T> &vec)
{ for (auto i: vec) fout << i << ' '; return fout; }

template<typename T> istream &operator>> (istream &fin, vector<T> &vec)
{ for (size_t i = 0; i < vec.size(); i++) fin >> vec[i]; return fin; }

vector<string> split(const string &s, char c) { vector<string> v; ull st = 0, fn = 0, lvl = 0;
for ( ; fn < s.size(); fn++ ) { if (s[fn] == c && lvl == 0) { v.push_back(s.substr(st, fn - st)); st = fn + 1; }
if (s[fn] == '(') { lvl++; } if (s[fn] == ')') { lvl--; } } v.push_back(s.substr(st, fn - st)); return v; }

void pr_var(vector<string>::iterator it) { (void) it; cerr << endl; }
template<typename T, typename... Args> void pr_var(vector<string>::iterator it, T a, Args... args)
{ cerr << *it << "=" << a << "  "; pr_var(++it, args...); }

ll div_ceil(ll n, ll d) { ll res = n / d; if (res >= 0) res += n % d ? 1 : 0; return res; }
ll gcd(ll a, ll b) { a = llabs(a); b = llabs(b); while (a && b) a > b ? a %= b : b %= a; return a + b; }
ll lcm(ll a, ll b) { ll c = gcd(a, b); return c == 0 ? 0 : llabs(a / c * b); }

#define setp(a) fixed << setprecision(a)
const double PI = acos(-1.0);
constexpr double EPS = 1e-6;
constexpr ll INF = numeric_limits<ll>::max();
constexpr ll MOD = 1e9 + 7;

#define FOR(i, n) for (ll i = 0; i < (n); i++)
int main()
{
    ll n; cin >> n;
    vector<ll> a(n); cin >> a;
    vector<mp> b;
    for (ll i = 0; i < n; i++) {
        if (a[i] != i + 1)
            b.push_back(mp(i + 1, a[i]));
    }
    if (b.size() > 2) { cout << "NO" << endl; exit(0); }
    else if (b.size() == 2) {
        pr_vars(b[0].first, b[1].second);
        if (b[0].first != b[1].second) { cout << "NO" << endl; exit(0); }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int x,i,s;
	s = 0;
	while(1){
		scanf("%d",&x);
		if(x==0){
			break;
		}else{
			i = s + 1;
			s = i;
			printf("Case %d: %d\n",i,x);
		}


	}


	return 0;
}

Measured memory_bytes: 1028
import sys

sys.path.append("/home/contestant/.local/lib/python3.8/site-packages")

import networkx as nx

N, K = [int(x) for x in input().split()]
A = [[int(x) for x in input().split()] for i in range(N)]


graph = nx.DiGraph()

SOURCE = 2 * N
SINK = SOURCE + 1

graph.add_node(SOURCE, demand=-K * N)
for i in range(N):
    graph.add_node(i)  # row
    graph.add_node(i + N)  # col
graph.add_node(SINK, demand=K * N)


for r in range(N):
    graph.add_edge(SOURCE, r, capacity=K, weight=0)
for r in range(N):
    for c in range(N):
        graph.add_edge(r, c + N, capacity=1, weight=-A[r][c])  # neg to maximize
for r in range(N):
    graph.add_edge(r + N, SINK, capacity=K, weight=0)

graph.add_edge(SOURCE, SINK, capacity=N * K, weight=0)  # slack


flowDict = nx.algorithms.flow.min_cost_flow(graph)
total = 0
grid = [["." for c in range(N)] for r in range(N)]
for r in range(N):
    for c in range(N):
        if flowDict[r][c + N]:
            grid[r][c] = "X"
            total += A[r][c]

print(total)
for row in grid:
    print("".join(row))


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

int main(){
  int n;
  cin >> n;
  int ans=0;
  vector<int>a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  for(int i=0;i<n;i++){
    while(a.at(i)%2==0){
      ans++;
      a.at(i)/=2;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3680
s = input()
ans = 0
for i in range(len(s)):
    count = i
    acgt = 0
    while count<=len(s)-1:
        if s[count]=="A" or s[count]=="C" or s[count]=="G" or s[count]=="T":
            acgt+=1
        else:
            break
        ans = max(ans,acgt)
        count+=1
print(ans)

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll n;
vvll res;

void rec(ll l, ll r, ll v){
  if(r-l<=1) return;
  
  ll mid=(l+r)/2;
  rec(l,mid,v+1);
  rec(mid,r,v+1);
  
  irep(i,l,mid){
    irep(j,mid,r){
      res[i][j]=v;
    }
  }
  
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  cin>>n;
  res.assign(n,vll(n,1));
  rec(0,n,1);
  
  rep(i,n){
    irep(j,i+1,n){
      cout<<res[i][j]<<' ';
    }
    cout<<endl;
  }
  
}

Measured memory_bytes: 5156
#include <stdio.h>

int main(int argc, char*argv[]){

    int N,L,M;
    
    scanf("%3d",&N);

    L = N%100;
    M = N%10;

    if(M == 2|| M == 4|| M == 5|| M == 7|| M == 9){
        printf("hon");
        return 0;

    }else if(M == 0|| M == 1|| M == 6|| M == 8){
        printf("pon");
        return 0;

    }else{
        printf("bon");
        return 0;
    }

}

Measured memory_bytes: 1696
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)

int x,a,b;

int main()
{
    cin >> x >> a >> b;
    x -= a;
    x %= b;

    cout << x << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int count(int x) {
    unordered_map<int, int> m;
    int t = 2;
    while (x != 1) {
        if (x % t == 0) {
            x /= t;
            m[t]++;
        } else {
            t++;
        }
    }
    int res = 1;
    for (auto p: m) {
        res *= p.second + 1;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i += 2) {
        if (count(i) == 8) {
            ans++;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

#define REP(i, x) for(int i=0;i<(int)(x);i++)
#define REPS(i, x) for(int i=1;i<=(int)(x);i++)
#define RREP(i, x) for(int i=(int)(x)-1;i>=0;i--)
#define RREPS(i, x) for(int i=(int)(x);i>0;i--)
#define FOR(i, x) for(auto it=x.begin();it!=x.end();++it)
typedef long long ll;
typedef vector<int> vi;

int n, p[300000];

int c(int x){
        return p[max(x-1, 0)];
}

int main(){
        for(int i=2;i<300000;i++){
                if(!p[i]){
                        for(ll j=(ll)i*i;j<300000;j+=i) p[j]=1;
                }
                p[i] = !p[i];
        }
        REP(i, 300000) p[i+1] += p[i];
        while(cin >> n, n){
                cout << c(2*n+1) - c(n+1) << endl;
        }
        return 0;
}

Measured memory_bytes: 2332
//
//  ALDS1_1_A.cpp
//  
//
//  Created by mk on 2015/11/23.
//
//

#include <stdio.h>
#include <iostream>
using namespace::std;

void printArray(int* A, int N){
    for (int i = 0; i < N; i++) {
        cout << A[i];
        if(i != N-1){
            cout << " ";
        }
    }
    cout << endl;
}

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


int main(int argc, const char * argv[]) {
    int n;
    int A[100];
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    insertionSort(A, n);
    

    return 0;
}

Measured memory_bytes: 1244
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
	int n;
	std::cin >> n;
	std::vector<int> vec(n);
	for (auto &v : vec) std::cin >> v;
	int q; std::cin >> q;
	for (auto i = 0; i < q; ++i) {
		int k;
		std::cin >> k;
		std::cout << std::lower_bound(vec.begin(), vec.end(), k) - vec.begin() << std::endl;
	}
}


Measured memory_bytes: 3096
while True:
    try:
        s = input()
    except:
        break

    alphabet = 'abcdefghijklmnopqrstuvwxyz'

    for i in range(26):
        decoded_s = ''
        for j in range(len(s)):
            if s[j] not in alphabet:
                decoded_s += s[j]
                continue

            decoded_s += alphabet[alphabet.index(s[j]) - i]

        if 'the' in decoded_s or 'this' in decoded_s or 'that' in decoded_s:
            break

    print(decoded_s)

Measured memory_bytes: 5564
#include <iostream>
#include <set>

using namespace std;

int main(void) {
    int n, a;
    set<int> s;
    cin >> n;
    for (int i=0;i<n;i++) {
        cin >> a;
        s.insert(a);
    }
    cout << s.size() << endl;
    return 0;
}


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

int n;  int frq[10][10];

string s;

int main()
{
	
	cin>>n; long long sum=0;
	
	for( int i=1;i<=n;i++)
	{
		s= to_string(i);
		int l= s.size();
		
		if( s[l-1]!='0') //if last is zero first should be zero..but 01 is 1..so discard it
		{  
			int x= s[0]   - '0';
			int y= s[l-1] - '0';
			
			 // cout<<x<<" "<<y <<" 1st"<<endl;
			
			frq[x][y]++ ;  //to store first digit ans last digit occurence
		}
		
	}
	
	/* cout<<"freqarray"<<endl;
		
		for( int i=1;i<=9;i++)
		{   
		    cout<<"row"<<i<<"--> ";
			for( int j=1;j<=9;j++)
			cout<< frq[i][j]<<" ";
			cout<<endl;
		}
		
		*/
	
		//multiply a[i][j]*a[j][i] ...for i ,j how many element occurs
		
		for( int i=1;i<=9;i++)
		{
			for( int j=1;j<=9;j++)
			sum= sum + frq[i][j]*frq[j][i];  //total element
		}
		
		cout<<sum<<endl;
	}


Measured memory_bytes: 3708
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

	int n, k;
	string s;
	cin >> n >> k >> s;
	k--;
	s[k] -= 'A';
	s[k] += 'a';
	cout << s << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
main()
{
	long long int i, x;
	cin >> x;
	for(i=0;i<=1000;i++)
	{
		long long int pip = pow(i, 5), pin = pow(-i, 5);
		for(long long int j=0;j<=1000;j++)
		{
			long long int pjp = pow(j, 5), pjn = pow(-j, 5);
			if(pjp-pip == x)
			{
				cout << j << " " << i; 
				return 0;
			}
			if(pip-pjp == x)
			{
				cout << i << " " << j; 
				return 0;
			}
			if(pip-pjn == x)
			{
				cout << i << " " << (-j); 
				return 0;
			}
			if(pjn - pip == x)
			{
				cout << (-j) << " " << i; 
				return 0;
			}
			if(pin-pjp == x)
			{
				cout << (-i) << " " << j; 
				return 0;
			}
			if(pjp - pin == x)
			{
				cout << j << " " << (-i); 
				return 0;
			}
			
			
		}
	}
	
  	return 0;
}

Measured memory_bytes: 4064
#include <bits/stdc++.h>
 
using namespace std;
 
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define ll	long long
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell 1000000007
#define PI 3.141592653589793

int main() 
{	
	int t = 1;
	//cin>>t;
	while (t--) {
		int k;
		cin>>k;
		string s;
		cin>>s;
		int l = sz(s);
		if (l <= k) cout<<s;
		else {
			for (int i = 0; i < k; i++) {
				cout<<s[i];
			}
			cout<<"...";
		}
		cout<<"\n";
	}
    return 0; 
} 


Measured memory_bytes: 3628
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

double heron(double a, double b, double c) {
	const double s = (a + b + c) / 2.0;
	return sqrt(s * (s - a) * (s - b) * (s - c));
}

int main() {
	for(int a, l, x; scanf("%d %d %d", &a, &l, &x) == 3;) {
		const double half = (l + x) / 2.0;
		const double ans = heron(a, l, l) + 2.0 * heron(l, half, half);
		printf("%.10lf\n", ans);
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1068
#include<iostream>
using namespace std;
int main(){
  int n,m;
  int i,j,k;
  int mat[100][100]={{}};
  int ve[100]={};
  cin >> n >> m;
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      cin >> mat[i][j];
    }
  }
  for(j=0;j<m;j++) cin >> ve[j];
  for(i=0;i<n;i++){
    int x=0;
    for(j=0;j<m;j++) x+=mat[i][j]*ve[j];
    cout << x << endl;		       
  }
  
  return 0;
}



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

// type {{{
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int,int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<ll>>;
// }}}


// macro {{{
#define REP(i,n) for (int i=0; i<(n); ++i)
#define RREP(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define FOR(i,a,n) for (int i=(a); i<(n); ++i)
#define RFOR(i,a,n) for (int i=(int)(n)-1; i>=(a); --i)

#define SZ(x) ((int)(x).size())
#define all(x) begin(x),end(x)
// }}}


// debug {{{
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    REP (i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << "(" << p.first << " " << p.second << ")";
}
// }}}


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


// constants {{{
#define inf(T) (numeric_limits<T>::max() / 2)
const ll MOD = 1e9+7;
const ld EPS = 1e-9;
// }}}


using State = string::const_iterator;
class ParseError {};

vector<int> val;

int formula(State& begin) {
    if (*begin == '-') {
        ++begin;
        int ret = formula(begin);
        if (ret == 0) return 2;
        if (ret == 1) return 1;
        if (ret == 2) return 0;
        throw ParseError();
    }
    if (*begin == '(') {
        ++begin;
        int lhs = formula(begin);
        char op = *begin;
        ++begin;
        int rhs = formula(begin);
        if (*begin != ')') throw ParseError();
        ++begin;
        if (op == '*') return min(lhs, rhs);
        if (op == '+') return max(lhs, rhs);
        throw ParseError();
    }
    if ('0' <= *begin and *begin <= '2') {
        int ret = *begin - '0';
        ++begin;
        return ret;
    }
    if ('P' <= *begin and *begin <= 'R') {
        int ret = val[*begin - 'P'];
        ++begin;
        return ret;
    }
    throw ParseError();
}

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

    for (;;) {
        string s; cin >> s;
        if (s == ".") break;

        int ans = 0;

        val.assign(4, 0);

        while (!val[3]) {
            State begin = s.begin();

            int ret = formula(begin);
            if (ret == 2) ++ans;

            for (int i = 0; ++val[i] == 3; ++i) val[i] = 0;
        }

        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3184
R = 6378.1
PI = Math.acos(-1)


class Numeric
  def to_rad; self * PI / 180 end
  def to_deg; self * 180 / PI end
end

class Point
  attr_accessor :x, :y, :z
  def initialize(x = 0, y = 0, z = 0); @x = x; @y = y; @z = z; end
  def abs; (@x**2 + @y**2 + @z**2)**0.5; end
  def +(other); Point.new( @x + other.x, @y + other.y, @z + other.z ); end
  def -(other); Point.new( @x - other.x, @y - other.y, @z - other.z ); end
  def self.ll_to_p(h, l) # h and l is rad
    y = Math.sin(h) * R
    r = Math.cos(h) * R
    x = r * Math.cos(l)
    z = r * Math.sin(l)
    Point.new(x, y, z)
  end
end


loop do
  h1, l1, h2, l2 = gets.split(" ").map(&:to_f)
  break if h1 == -1
  
  p1 = Point.ll_to_p(h1.to_rad, l1.to_rad)
  p2 = Point.ll_to_p(h2.to_rad, l2.to_rad)

  d = (p1 - p2).abs

  ang = Math.acos(1.0 - d**2 / R**2 / 2)

  puts (ang * R).round
end

Measured memory_bytes: 2524
#include <iostream>
using namespace std;
int main() {
    long long n, d;
    cin >> n >> d;
    int cnt = 0;
    long long x, y;
    for (int i=0; i<n; i++) {
        cin >> x >> y;
        if (x*x + y*y <= d*d) {
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3632
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s) {
		map<char, ll> h;
		REP(i, s.size()) h[s[i]]=1;
		ll ans=h['S']==h['N']&&h['W']==h['E'];
		cout<<YN(ans)<<endl;
	}
	
	return 0;
}


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

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop0(i,n) for(int i=0; i<(n); i++)
#define loop1(i,n) for(int i=1; i<=(n); i++)
#define fori(a,b,i) for(int i=(a); i<=(b); i++)
#define ford(a,b,i) for(int i=(a); i>=(b); i--)
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ign cin.ignore(numeric_limits<streamsize>::max(),'\n')

#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef map<int,int> MCI;
typedef unordered_map<int,int> UMII;
typedef unordered_map<char,int> UMCI;
typedef set<int> SI;
typedef long long int llint;


int main() {
    fast_io;
	llint n;
	cin >> n;
	vector<llint> v(n);
	unordered_map<llint, llint> m; 
	for(auto &i : v) cin >> i;
  llint sum=0;
	for (llint i = 0; i < n; i++) m[v[i]]++,sum+=v[i];
	llint q;
	cin >> q;
	
	for(llint i = 0; i < q; i++){
		llint a,b;
		cin >> a >> b ;
		
		sum -= (1LL*a*m[a]);
        sum+=(1LL*b*m[a]);
		
		m[b] += m[a];
		
		m[a] = 0;

		cout << sum << endl;		
	}
	
}


Measured memory_bytes: 7912
#include <iostream>
#include <queue>
#include <set>
#include <list>
#include <deque>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <iterator>
#define ll long long
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define powr(x,n,p) for(int axy=0 ; axy<p ; axy++){x=x*n;}
#define YES printf("YES\n")
#define Yes printf("Yes\n")
#define yes printf("yes\n")
#define NO printf("NO\n")
#define No printf("No\n")
#define no printf("no\n")
#define nl printf("\n")
#define fr0(n,q) for(q=0 ; q<n ; q++)
#define fr1(n,q) for(q=1 ; q<=n ; q++)
#define mp make_pair
#define scl(x) scanf("%lld",&x)
#define sci(x) scanf("%d",&x)
#define lst(x) x[x.size()-1]
#define llst(x) x[x.size()-2]
#define md 1000000007
#define check(x,y) (x&(1<<y))
#define set(x,y) x=x|(1<<y)
using namespace std;
int dp[100005];
int arr[100005];
int n,k;
int solve(int x){
	if(x>=n) return 0;
	if(dp[x]!=-1) return dp[x];
	int ret=(1<<30);
	for(int i=1 ; i<=k && x+i<=n ; i++){
		ret=min(ret, abs(arr[x+i]-arr[x])+solve(x+i));
	}
	return dp[x]=ret;
}
int main()
{
	int i;
	cin>>n>>k;
	for(i=0 ; i<100005 ; i++) dp[i]=-1;
	for(i=1 ; i<=n ; i++) cin>>arr[i];
	cout<<solve(1);
	nl;
	return 0;
}


Measured memory_bytes: 10616
#include <stdio.h>

int main()
{
	int N;
	scanf("%d", &N);
	int a[N];
	int i, j, k;
	for (i = 0; i < N; i++) {
		scanf("%d", &a[i]);
	}

	int count_2 = 0, count_4 = 0;
	for (i = 0; i < N; i++) {
		if (a[i] % 4 == 0) {
			count_4++;
		} else if (a[i] % 2 == 0) {
			count_2++;
		}
	}

	if (count_2 > 0) {
		if (N - count_2 - count_4 <= count_4) {
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	} else if (count_2 == 0) {
		if (N - count_2 - count_4 <= count_4 + 1) {
			printf("Yes\n");
		} else {
			printf("No\n");
		}
	}

	return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

typedef long long ll;

/////////////         modの計算
constexpr ll mod = 1000000007;

class modlong {
public:
	modlong(ll num) { x = num; }
	inline operator ll() const { return x; }
	inline void operator = (ll num) { x = num; }
	inline void operator += (ll num) { x += num; }
	inline void operator *= (ll num) { x = adjust(x * num); }
	inline modlong operator * (ll num) { modlong m(adjust(x * num)); return m; }
	inline ll adjust(ll a) {
		if (a >= mod) { return a % mod; }
		return a;
	}
	ll x;
};

constexpr int K = 16;

constexpr ll v_e[] = { 0, 765144583, 346175634, 347662323, 5655049, 184117322, 927321758, 444014759, 542573865, 237315285, 417297686, 471090892, 183023413, 660103155, 727008098, 869418286 };
constexpr ll v_o[] = { 539588932, 729548371, 700407153, 404391958, 962779130, 184117322, 927321758, 444014759, 542573865, 237315285, 417297686, 471090892, 183023413, 660103155, 727008098, 869418286 };

int main() {
	int T; scanf("%d", &T);
	for (int _t = 0; _t < T; _t++) {
		ll N; scanf("%ld", &N);
		modlong ans = 0;
		modlong x = 1;

		if (N & 1) {// odd
			for (int i = 0; i < K; i++) {
				ans += x * v_o[i];
				x *= N;
			}
		}
		else {// even
			for (int i = 0; i < K; i++) {
				ans += x * v_e[i];
				x *= N;
			}
		}
		printf("%ld\n", ans.x % mod);
	}

	return 0;
}


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

int main(){
  int n,d,k,chd,chk,o;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>d>>k;
    chd=0;
    chk=0;
    if(d%100!=0)chd=1;
    if(k%30!=0)chk=1;
    o=0;
    o=d/100+(k/30*5);
    if(chd==0&&chk==0){
      cout<<o<<endl;
    }else if(chd==0&&chk==1){
      cout<<o<<" "<<o+5<<endl;
    }else if(chd==1&&chk==0){
      cout<<o<<" "<<o+1<<endl;
    }else if(chd==1&&chk==1){
      cout<<o<<" "<<o+1<<" "<<o+5<<" "<<o+6<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
int prime[100001],isprime[100001],sum[100001];
void Euler_sieve(int n)
{
	int i,j,total=0;
	memset(isprime,0,sizeof(isprime));
	isprime[0]=isprime[1]=1;
	prime[0]=0;
	for(i=2;i<=n;i++)
	{
		if(!isprime[i])
		{
			prime[++prime[0]]=i;
			if(!isprime[(i+1)/2])
			{
				total++;
			}
		}
		sum[i]=total;
		for(j=1;j<=prime[0]&&i*prime[j]<=n;j++)
		{
			isprime[i*prime[j]]=1;
			if(i%prime[j]==0)
				break;
		}
	}
}
int main()
{
	int q,i,a,b;
	scanf("%d",&q);
	Euler_sieve(100000);
	for(i=0;i<q;i++)
	{
		scanf("%d%d",&a,&b);
		printf("%d\n",sum[b]-sum[a-1]);
	}
	return 0;
}

Measured memory_bytes: 1408
#n = int(input()) #入力
#a, b = (int(x) for x in input().split())
#a, b = map(int, input().split())

#G = [input() for i in range(0, H)] #文字列を複数行に渡って

#a = [int(x) for x in input().split()]
#a = list(map(int, input().split()))
#a = [list(map(int,input().split(" "))) for i in range(N)]   #2次元


#a.sort() # C++ の sort(a.begin(), a.end());
#a.append(3) # C++ の a.push_back(3);


#exit(0) # return 0 的な。終了できる。
## 整数の切り捨て除算は // (ダブルスラッシュ)


#a[始まりの位置: 終わりの位置: スライスの増分] # (a は配列)


#import numpy as np  #importに100 ms 程度かかる。
import math
import copy
import string
#math.gcd(a, b) で、gcd 計算できる。
#math.pi は円周率。

INF = int(10**18) #べき乗 C++ の pow(10, 18) or 1e18;
pi = math.pi

MOD = 1000000007
#MOD = 1000000009
#MOD = 998244353




#繰り返し2乗法
#N^aの、Mで割った余りを求める。
def my_pow(N, a, M):
    if(a == 0):
        return 1
    else:
        if(a % 2 == 0):
            tempo = my_pow(N, a/2, M)
            return (tempo * tempo) % M
        else:
            tempo = my_pow(N, a - 1, M)
            return (tempo * N) % M




#N_C_a を M で割った余り
def my_combination(N, a, M):
    res = 1

    for i in range(0, a):
        res *= N - i
        res %= M

    for i in range(0, a):
        res *= my_pow(i + 1, M - 2, M)
        res %= M

    return res




#N_C_i を M で割った余りを、v[i] に代入する。
def my_combination_table(N, M, v):
    if(len(v) < N + 1):
        l = N + 1 - len(v)
        tempo = [1] * l
        v.extend(tempo)

    for i in range(1, N + 1):
        v[i] = v[i - 1] * (N - (i - 1))
        v[i] %= M

        v[i] *= my_pow(i, M - 2, M)
        v[i] %= M

    return




#math.factorial で階乗は計算できる。
#math.gcd で gcd は計算できる。
#np.gcd.reduce(A) #(Aは配列) で、Aの全ての要素の gcd が計算できる。


N = int(input())
L =[int(x) for x in input().split()]

res = 0
for i in range(0, N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            #print(L[i], L[j], L[k])
            tempo = [L[i], L[j], L[k]]
            tempo.sort()
            
            #print(tempo[0], tempo[1], tempo[2])
            if(tempo[0] + tempo[1] > tempo[2] and tempo[0] < tempo[1] and tempo[1] < tempo[2]): 
                res += 1
                #print(i, j, k)
print(res)

















Measured memory_bytes: 10156
n = int(input())
block = [int(x) for x in input().split()]
s = 1
c = 0
for i in range(n):
  if block[i] == s:
    s += 1
  else:
    c += 1
if block == [1]:
  print(c)
elif s == 1:
  print(-1)
else:
  print(c)

Measured memory_bytes: 25768