akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (ll i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (ll i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (ll i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (ll i = x.size()-1; i >= 0; i--)
#define REPITR(itr,x) for (auto itr = (x).begin(); itr != (x).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define debug(x) cerr<<__LINE__<<": "<<(#x)<<" = "<<(x)<<endl;
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define e1 first
#define e2 second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

class UnionFindTree {
public:
    vector<int> rank, p, nakama;

    UnionFindTree() {}

    UnionFindTree(int size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        nakama.resize(size, 0);
        for (int i = 0; i < size; ++i) {
            makeSet(i);
        }
    }

    void makeSet(int x)
    {
        p[x] = x;
        rank[x] = 0;
        nakama[x] = 1;
    }

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

    void unite(int x, int y)
    {
        link(findSet(x), findSet(y));
    }

    void link(int x, int y)
    {
        if (x == y)
            return;

        if (rank[x] > rank[y]) {
            p[y] = x;
            nakama[x] += nakama[y];
        } else {
            p[x] = y;
            nakama[y] += nakama[x];
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }

    int findSet(int x)
    {
        if (x != p[x]) {
            p[x] = findSet(p[x]);
        }
        return p[x];
    }

    int maxUnion()
    {
        int size = p.size();
        int r = 0;
        REP(i,size) {
            r = max(r, (int)count(p.begin(), p.end(), i));
        }
        return r;
    }
};

int n, m, k;
VVI f, b;

int main()
{
    cin>>n>>m>>k;
    UnionFindTree r(n);
    f.resize(n); b.resize(n);
    REP(i,m) {
        int a, b;
        cin>>a>>b;
        r.unite(a-1, b-1);
        f[a-1].push_back(b-1);
        f[b-1].push_back(a-1);
    }
    REP(i,k) {
        int c, d;
        cin>>c>>d;
        b[c-1].push_back(d-1);
        b[d-1].push_back(c-1);
    }

    REP(i,n) {
        int t_ans = r.nakama[r.findSet(i)] - f[i].size() - 1;
        //debug(t_ans);
        REPALL(j,b[i]) {
            if (r.findSet(i) == r.findSet(b[i][j]))
                t_ans--;
        }
        cout<<t_ans;
        if (i != n-1)
            cout<<" ";
    }
    nextline;

    return 0;
}


Measured memory_bytes: 13048
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };



int main() {
	int D, N;
	scanf("%d%d", &D,&N);

	if (D == 0) {
		if (N != 100) {
			printf("%d", N);
		}
		else printf("101");
	}
	else if (D == 1) {
		if (N != 100) {
			printf("%d", 100 * N);
		}
		else printf("10100");
	}
	else if (D == 2) {
		if (N != 100) {
			printf("%d", 10000 * (N));
		}
		else printf("1010000");
	}
}





/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
・文字列の＜＜スペル＞＞は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
using namespace std;
typedef pair<int, int>p;
p mov[200005];
long long mod = 1e9 + 7;
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
char reverse(char c) {
	if (c == 'E')return 'S';
	else return 'E';
}
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	string s[303];
	string b[303];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		b[i] = "";
		for (int z = 0; z < n; z++) {
			b[i] += s[i][z];
		}
	}
	int ans = 0;
	for (int z = 0; z < n; z++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				b[i][j] = s[i][(j + z)%n];
			}
		}
		int judge = 0;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if(b[i][j]!=b[j][i])judge=1;
			}
		}
		if (judge == 0)ans += n;
	}
	cout << ans;
}

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

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

  int n;
  cin >> n;
  int m = 101;
  int s = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    s += a;
    if (a % 10) m = min(m, a);
  }
  int ans;
  if (s % 10) ans = s;
  else if (m == 101) ans = 0;
  else ans = s - m;
  cout << ans << '\n';
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> a (n);
    ll ans = 0;
    for(int i=0; i<n; i++){
        ll x = 0;
        cin >> x;
        ll d = 0;
        while(1){
            if(x%2 == 1 || x == 0) break;
            x /= 2;
            d++;
        }
        ans += d;
    }
    cout << ans << endl;
}

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

int main()
{
	int a,b;
	string opt;
	cin>>a>>opt>>b;
	if(opt=="+")
	{
		cout<<a+b<<endl;
	}
	else
	{
		cout<<a-b<<endl;
	}
	return 0;
}
 

Measured memory_bytes: 256
/*
[abc148] D - Brick Break
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 200000;

int N;
int a[MAX_N];
bool has[MAX_N + 1];

ll solve() {
    int len = 0;

    has[0] = true;
    for (int i = 0; i < N; i++) {
        if (has[a[i] - 1]) {
            len = max(len, a[i]);
            has[a[i]] = true;
        }
    }

    int ans = (len == 0) ? -1 : N - len;

    return ans;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 1280
N,M=map(int,raw_input().split())

upper=M/N
def factorize(n):
    fct = []
    b, e = 2, 0
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct
def divisorize(fct):
    b, e = fct.pop()
    pre_div = divisorize(fct) if fct else [[]]
    suf_div = [[(b, k)] for k in range(e + 1)]
    return [pre + suf for pre in pre_div for suf in suf_div]
def num(fct):
    a = 1
    for base, exponent in fct:
        a = a * base**exponent
    return a

fct = factorize(M)
if fct==[]:
    print 1
    exit()

Ans=1
for div in divisorize(fct):
    if num(div)<=upper:
        Ans=max(Ans,num(div))
   
print Ans

Measured memory_bytes: 2696
import sys

S = input()
K = int(input())

N = len(S)

if(K >= len(S)):
    ans_set = set()
    for i in range(len(S)):
        for j in range(1, K + 1):
            if(i + j > N):
                break
            ans_set.add(S[i:i + j])
    ans = sorted(list(ans_set))
    print(ans[K - 1])
    sys.exit()

alpha = [chr(i) for i in range(97, 97 + 26)]
min_dic = 25
ans_set = set()
for i in range(0, N):
    if(min_dic < alpha.index(S[i:i + 1])):
        continue
    else:
        min_dic = alpha.index(S[i:i + 1])

    for j in range(1, K + 1):
        if(i + j > N):
            break
        ans_set.add(S[i:i + j])

ans = sorted(list(ans_set))
print(ans[K - 1])

Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>

using namespace std;

long long N, W, w[100], v[100];

void input(){
  scanf("%lld %lld", &N, &W);
  for(int i=0; i<N; i++){
    scanf("%lld %lld", &w[i], &v[i]);
  }
}

int main(){
  input();
  long long DP[100001] = {0};
  for(int i=0; i<N; i++){
    for(int j=W; j>=w[i]; j--){
      DP[j] = max(DP[j], DP[j-w[i]] + v[i]);
    }
  }
  printf("%lld", DP[W]);
}

Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    long x = Long.parseLong(str[0]);
    long y = Long.parseLong(str[1]);
    
    int len = 0;
    long cur = x;
    while(cur <= y) {
      len++;
      cur = cur * 2;
     }
    
    System.out.println(len);
  }
}

Measured memory_bytes: 32624
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::cmp::Ordering;

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut switches: Vec<(usize, bool)> = Vec::new();
    for val in a {
        switches.push((val, false));
    }

    let mut ans = 0;
    let mut now = 0;
    loop {
        let switch = switches[now]; 
        if switch.1 {
            println!("-1");
            return;
        }
        if switch.0 == 2 {
            println!("{}", ans + 1);
            return;
        }
        switches[now].1 = true;
        now = switches[now].0 - 1;
        ans += 1;
    }
} 


Measured memory_bytes: 8444
n = int(input())
c = input()

def alter(c,n):
    number = 0
    i = 0
    j = n-1
    while(i<j):
        if c[j] == 'R':
            j -= 1
            while (c[i] == 'R'):
                i += 1
                if i >= j:
                    return number
            number += 1
            i += 1
        else:
            j -= 1
    return number
    

    
print(alter(c,n))

Measured memory_bytes: 9240
#include <iostream>
using namespace std;
 
char chess(int h, int w){
    if((h+w)%2 == 0){
        return '#';
    }
    return '.';
}
 
int main(void){
    int H,W;
    while(true){
    cin >> H >> W;
    if(H == 0 && W == 0){
        break;
    }
    for(int j = 0; j < H; j++){
        for(int i = 0; i < W; i++){
            cout << chess(i,j) ;
        }
        cout << endl;
    }
    cout << endl;
    }
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define ll long long
#define INF LLONG_MAX 
#define dd double 
#define fi first
#define se second
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define dll deque<long long>
#define qll queue<long long>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define vvll vector<vector<ll>>
#define vpll vector<pair<long long,long long>>
#define vpcl vector<pair<char,long long>>
#define vpsl vector<pair<string,long long>>
#define stll stack<long long>
#define stc stack<char>
#define mll map<long long,long long>
#define pll pair<long long,long long>
#define psl pair<string,long long>
#define mcl map<char,long long>
#define msl map<string,long long>
#define pcl pair<char,long long>
#define mmll multimap<long long,long long> 
#define mmcl multimap<char,long long>
#define mmsl multimap<string,long long>
#define sll set<long long>
#define sc  set<char>
#define ss  set<string>
#define msll multiset<long long>
#define msc  multiset<char>
#define mss  multiset<string>
#define lb lower_bound
#define up upper_bound
#define lt length
#define clr clear
#define ap append
#define sz size
#define sub substr
#define ull unsigned long long int
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
//#include <boost/multiprecision/cpp_int.hpp> 
//using boost::multiprecision::cpp_int; 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

ll modexp(ll x,ll n,ll p){    //modular exponential function
  if(n==0){return 1;}
  ll u = modexp(x,n/2,p);
  u = u*u%p;
  if(n%2==1){u=(u*x)%p;}
  return u;
}

ll gcd (ll a, ll b) {     //Eulers algorithm
    if (b == 0)
        return a;
    else
        return gcd (b, a % b);
}

ll dp[401][401];
ll arr[401];
ll sum[401];
ll f(ll i,ll j){
    if(i==j){return 0;}
    if(i+1==j){return arr[i]+arr[j];}
    if(dp[i][j]!=-1){return dp[i][j];}
    ll ans = 100000000000000000;
    if(i==0){
    rep(k,i,j-1){
      ans = min(ans,sum[j]+f(i,k)+f(k+1,j));
    }
    }
    else{
      rep(k,i,j-1){
      ans = min(ans,sum[j]-sum[i-1]+f(i,k)+f(k+1,j));
    }
    }
    dp[i][j] = ans;
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n; cin>>n;
    rep(i,0,n-1){cin>>arr[i];}
    sum[0]=arr[0];
    rep(i,1,n-1){sum[i] = arr[i] + sum[i-1];}
    memset(dp,-1,sizeof(dp));
    cout<<f(0,n-1);
}


Measured memory_bytes: 4804
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	string a, b, c, x;
	int ans;
	cin >> a >> b >> c;
	
	x = a + b + c;
	ans = stoi(x);
	
	if (ans % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;

	}

}

Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())
s = str(input())

if c>d: #ABDC
  if s[b-2:d+1].find("...")!=-1 and s[a-1:c].find("##")==-1:
    print("Yes")
  else:
    print("No")
elif s[a-1:c].find("##")==-1 and s[b-1:d].find("##")==-1:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <list>
#include <math.h>

using namespace std;

int tenup(int input) {
	int ans;
	if (input % 10 != 0) {
		int tmp= input / 10;
		ans = (int)tmp * 10 + 10;
	}
	else {
		ans = int(input);
	}
		return (int)ans;
}


int main()
{
/*	int a, b, c, d, e;
	std::cin >> a >> b >> c >> d >> e;
	*/

	int time[5];
	for (int i = 0; i < 5; i++) {
		std::cin >> time[i];
	}

	int one[5];

	for (int i = 0; i < 5; i++) {
		one[i] = time[i] % 10;
	}
	int one_min = 10;
	int one_min_index = 100;
	for (int i = 0; i < 5; i++) {
		if (one[i] != 0 && one[i] < one_min) {
			one_min = one[i];
			one_min_index = i;
		}
	}

	int alltime=0;
	for (int i = 0; i < 5; i++) {
		if (i != one_min_index) {
			alltime = alltime + tenup(time[i]);
		}
		else {
			alltime = alltime + time[i];
		}
	}

//	std::cout << one_min << endl;
	std::cout << alltime << endl;

}

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

int main() {
    int n;
    vector<string> s;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string c;
        cin >> c;
        s.push_back(c);
    }

    int cnt = 0;
    int ba = 0, b = 0, a = 0;
    for (int i = 0; i < n; i++) {
        string t = s[i];
        for (int j = 0; j < t.size(); j++) {
            if (t[j] == 'A' && t[j + 1] == 'B') cnt++; //ABの数をカウント
        }

        //端がAまたはB、または両方含まれているかカウント
        if (t[0] == 'B' && t[t.size() - 1] == 'A') ba++; //BOOOA
        else if (t[0] == 'B') b++; //BOOOO
        else if (t[t.size() - 1] == 'A') a++; //OOOOA
    }

    if (ba == 0) cnt += min(b, a);
    else {
        if (b + a > 0) cnt += ba + min(b, a);
        else cnt += ba - 1;
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 768
import sys

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()

    print((int((n / 2)) + (n % 2)) / n)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}


int main(void){
    int a, b;
    scanf("%d %d", &a, &b);
    if ((b != 1 && a > b) || (a == 1 && b != 1)){
        printf("Alice\n");
        return 0;
    }else if ((a != 1 && b > a) || (b == 1 && a!= 1)){
        printf("Bob\n");
        return 0;
    }else{
        printf("Draw\n");
        return 0;
    }

}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

int main(){
    char a[10], b[10];
    for(int i = 0; i < 3; i++){
        cin >> a;
        cin >> b;
    }
    if(a[0] == b[2] && a[1] == b[1] && a[2] == b[0]){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;

}

Measured memory_bytes: 256
// Problem : C - Divide the Problems
// Contest : AtCoder - AtCoder Beginner Contest 132
// URL : https://atcoder.jp/contests/abc132/tasks/abc132_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*when the going gets tough the tough gets going  */
/*we are what we repeatedly do , Excellence then is not an act but a habit  - aristotle */
/*The best way to predict the future is to create it - abraham lincoln*/
/*First think , second believe , third dream and finally dare - walt disney*/
/*It is during our darkest moments that we must focus to see the light */
/*Nothing is impossible the word itself says "i'm fucking possible man just try me again and again till i seem impossible "*/
/*Dont judge each day by the harvest you reap but by the seeds you plant */
/*Do not dwell in the past, do not dream of the future, concentrate the mind on the present moment*/
/*Success is not final failure is not fatal : it is the courage to continue that counts */ 
/*the future belongs to those who believe in the beauty of their dreams */
/*The pessimist complains about the wind , the optimist waits for it to change; the realist adjusts the sails  */
/*Believe you can and you are half way there */
/*Everything has beauty but not everyone sees it */
/*Life is not about finding yourself , life is about creating yourself*/
/*You are the average of the 5 people you spend the most time with .........*/
/*Everything is hard before it is easy see for example now the list of examples is very long hahahahahaha...... ......*/
/*I believe in miracles .......*/
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<bitset>
#include<set>
#include<climits>
#include<math.h>
#include<stdlib.h>
#define lli long long int 
#define pb push_back
#define mp make_pair
#define pii pair<int , int > 
#define pll pair<lli , lli >
#define wht while (t--)
#define fu( i , a  , n ) for ( int i = (int)a ; i <=(int)n ; i++  )
#define fd( i , n , a ) for (int i = (int)n ; i >=(int)a ;i--)
#define rep(i,n) for ( int i = 0 ; i < (int)n;  i++)
#define fst  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sz size()
#define ln length()
#define ps printf(" ") 
#define pn printf("\n")
#define pi(n) printf("%d" , n ) 
#define pl(n) printf("%lld" , n )
#define ii(n) scanf("%d" , &n)
#define il(n) scanf("%lld" , &n )
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define ALL(V) V.begin(), V.end()
#define ic(n) cin>>n
#define pr printf
#define inf 99999999
using namespace std ;
 
int main()
{
	fst;
	  int n ;
    cin >> n; 
    int arr[n];
    for(int i = 0 ; i < n ;i++ )
    {
      cin>> arr[i];
    }
    int ans = 0;
  sort(arr , arr + n );
  for (int i = 1 ; i <= 100004; i++ )
  {
    int ind = lower_bound(arr, arr + n , i)- arr;
    // if (i ==5 || i == 6 )
    // {
    	// cout << ind << " ";
    // }
    if ((n - ind) == (ind  ) ) 
      ans++;
  }
  cout << ans;
      
 
} 

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  if (N % 1000 == 0) {
    cout << 0 << endl;
  } else {
    cout << 1000 - N % 1000 << endl;
  }
  return 0;
}


Measured memory_bytes: 3176
eval"N,K,*A="+`dd`.split*?,
s=eval A*?+
1.upto(3e4){|j|s%j<1&&$*<<j<<s/j}
p$*.max_by{|h|t=0
A.map{|x|x%h}.sort.count{|x|K<t+=x}>t/h ?0:h}

Measured memory_bytes: 12032
#include <iostream>
#include <map>

int main() {
    long n, a, res=0;
    std::map< long, long > mp;
    std::cin >> n;

    for (long i=0; i<n; ++i) {
        std::cin >> a;
        if ( mp.find( a ) != mp.end() ) {
            ++mp[ a ];
        } else {
            mp[ a ] = 1;
        }
    }
    std::map< long, long >::iterator itr = mp.begin();
    while( itr != mp.end() ) {
        if ( itr->second % 2 ) ++res;
        ++itr;
    }
    std::cout << res << std::endl;

    return 0;
}


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

int main() {
  string s; cin >> s;
  int alice = 753;
  int ans = 1e9;
  for (int i=0; i<s.size()-2; ++i) {
    int tmp = abs(alice - stoi(s.substr(i, 3)));
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

    vector<int> s(m), c(m);
    REP(i, m) cin >> s[i] >> c[i];

    REP(i, 1000) {
        int x = i / 10;
        vector<int> d(1, i % 10);
        while (x) {
            d.push_back(x % 10);
            x /= 10;
        }
        reverse(d.begin(), d.end());
        if (d.size() != n) continue ;

        bool ok = true;
        REP(i, m) if (d[s[i] - 1] != c[i]) ok = false;
        if (ok) {
            cout << i << '\n';
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll m = 998244353;
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector <pair<ll, ll>> v;
    vector <ll> sum(n+1, 0);
    sum[0] = 0;
    sum[1] = 1;
    vector <ll> ans(n + 1, 0);
    ans[0] = 0;
    ans[1] = 1;
    while(k--){
        int a, b; cin >> a >> b;
        v.pb({a, b});
    }
    for(int i = 1; i <= n; i++){
        for(auto p: v){
            ll r = max(0LL, i - p.f), l = max(0LL, i - p.sc);
            //if(i == 5) cout << l << " " << r << "\n";
            ll s = sum[r];
            if(l > 0) s -= sum[l - 1];
            s%=m;
            if(s < 0) s+=m;
            ans[i] +=s;
            ans[i] %= m;
        }
        sum[i]= ans[i] + sum[i-1];;
        sum[i]%=m;
    }
    cout << ans[n] << "\n";
}


Measured memory_bytes: 6364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
vector<int>v[N];
int b[N];
int dfs(int x)
{
    int i,ans=0;
    for(int i:v[x])
    if(!b[i])
    {
        b[i]=1;
        ans^=dfs(i)+1;
    }
    return ans;
}
int main()
{
    int i,n;
    cin>>n;
    memset(b,0,sizeof b);
    for(i=0;i<n-1;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        v[x].push_back(y);
        v[y].push_back(x);
    }
    b[1]=1;
    if(dfs(1))printf("Alice");
    else printf("Bob");
    return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define mp          make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vb          vector<bool>
// #define vc          vector<char>
#define vii         vector<pii>
//#define mi          map<int,int>
//#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
// #define ub(x)       upper_bound(x)
// #define lb(x)       lower_bound(x)
#define endl        '\n'
#define file        freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
#define fastio      ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
// #define N            1e5+5
#define PRIME           998244353
#define MAX         10001
#define mem0(a)     memset(a,0,sizeof(a))
#define prec        cout<<std::setprecision(9)<<std::fixed
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define pi          3.14159265358979323
int i,j,k;


void Anon_mouS(){
    int n,W;
    cin>>n>>W;
    vector<pair<int,int>> a;
    for(i=0;i<n;i++){
        int x,y;
        cin>>x>>y;
        a.pb(mp(x,y));
    }
    //weight value/
    int k[n+1][W+1];
    for(i=0;i<=n;i++){
        for(int w=0;w<=W;w++){
            if(i==0 or w==0)k[i][w]=0;
            else if(a[i-1].F<=w)
                k[i][w]=max(a[i-1].S+k[i-1][w-a[i-1].F],k[i-1][w]);
            else k[i][w]=k[i-1][w];
        }
    }
    cout<<k[n][W];
}

 
int32_t main(){
    fastio;
    int q=1;
    // cin>>q;
    while(q--){
        Anon_mouS();
    }
    return 0;   
}

Measured memory_bytes: 79232
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;

int A, B, K;

int main() {
    cin >> A >> B >> K;
    int cnt = 0;
    for (int i = min(A, B); i > 0; --i) {
        if (A % i == 0 && B % i == 0) {
            cnt++;
        }
        if (cnt == K) {
            cout << i << endl;
            return 0;
        }
    }
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int x, n;
	cin >> x >> n;
	int a[n];
	map<int, int>mt;
	zip(i, 0, n)
	{
		cin >> a[i];
		mt[a[i]]++;

	}
	int ans = 1e9;
	vii v;
	for (int i = -1000; i <= 1000; i++)
	{
		if (mt[i] == 0)
		{
			int y = abs(i - x);
			v.pb({y, i});
		}
	}
	sort(all(v));
	cout << v[0].ss << en;


	return 0;
}



Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (b>a) { 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; }
const long long INF = 2LL << 60;
using ll = long long;
using P = pair<string, ll>;



int main(int argc, char const *argv[]) {
    ll n, k, cnt=0;
    cin >> n >> k;
    while(n!=0){
        n/=k;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main() {
    int N, C, K;
    cin >> N >> C >> K;
    vector<int> T(N);
    for (int i = 0; i < N; ++i) cin >> T[i];
    
    sort(T.begin(), T.end());
    vector<bool> searched(N, false);
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        if (searched[i]) continue;
        ++cnt;
        int n = 1;
        int j = i + 1;
        while (j < N && n < C) {
            if (T[j] <= T[i] + K) {
                searched[j] = true;
                ++n;
            }
            else break;
            ++j;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

const string res[3] = {"Vacant", "Male", "Female"};


bool listen(ll out, vll& c){
  string s;
  cout << out << endl;
  cin >> s;
  REP(i, 3){
    if(res[i] == s){
      if(i == 0)
        return true;
      else if(i == 1)
        c[out] = 1;
      else
        c[out] = -1;
    }
  }

  return false;
}


bool check(vll& c, ll x){
  ll valid;
  if(x%2 == 0)
    valid = c[0];
  else
    valid = c[0]*-1;

  return c[x] == valid;
}


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

  ll n;
  cin >> n;
  //man:1, woman:-1
  vll c(n, 0);

  if(listen(0, c))
    return 0;
  ll ok = 1;
  ll ng = n;
  while(abs(ok-ng) > 1){
    ll mid = (ok+ng)/2;
    if(listen(mid, c))
      return 0;
    if(check(c, mid))
      ok = mid;
    else
      ng = mid;
  }

  if(listen(ok, c))
    return 0;
}


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

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

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

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

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

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

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

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

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}
	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

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



int main() {
	ll A, B, C, K;
	cin >> A >> B >> C >> K;

	ll ans;
	if (K <= A) { ans = K; }
	else if (K <= A+B) { ans = A; }
	else { ans = A - (K - A - B); }
	cout << ans << endl;

	system("PAUSE");

}

Measured memory_bytes: 3688
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;


class Solution{

private:
    long long INF = 1000000000000000000ll;

public:
    long long minNum(const vector<pair<int, int>>& v){

        long long cura = v[0].first, curb = v[0].second;
        for(int i = 1; i < v.size(); i ++){
            long long k = binary_search(v[i].first, v[i].second, cura, curb);
            cura = k * v[i].first, curb = k * v[i].second;
        }
        return cura + curb;
    }

private:
    long long binary_search(int r1, int r2, long long a, long long b){

        long long l = 1ll, r = min(INF / r1, INF / r2);
        while(l < r){
            long long mid = l + (r - l) / 2;
            if(mid * r1 >= a && mid * r2 >= b) r = mid;
            else l = mid + 1;
        }
        return l;
    }
};

int main() {

    int N;
    scanf("%d", &N);

    vector<pair<int, int>> v(N);
    for(int i = 0; i < N; i ++)
        scanf("%d%d", &v[i].first, &v[i].second);
    printf("%lld\n", Solution().minNum(v));

    return 0;
}


Measured memory_bytes: 3172
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  string N;
  cin >> N;
  int M = N.size();
  vector<vector<int>> answer(M+1, vector<int>(2));
  answer[M][0] = 0;
  answer[M][1] = 1;
  for (int i = M - 1; i >= 0; --i) {
    int num = (N[i] - '0');
    answer[i][0] = min(answer[i+1][0] + num, answer[i+1][1] + (10 - num));
    answer[i][1]  = min(answer[i+1][0] + num + 1, answer[i+1][1] + (10 - num - 1));
  }
  cout << answer[0][0] << endl;
  return 0;
}


Measured memory_bytes: 58956
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <assert.h>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <math.h>
#include <stack>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define db double
#define ldb long double
#define MOD 1000000007
#define Fi first
#define Se second
#define INF INT_MAX
#define NINF INT_MIN
#define L_INF LLONG_MAX
#define L_NINF LLONG_MIN
#define gc getchar
#define sz(x) (int)(x).size()
#define pii pair<int,int>
#define pll pair<ll,ll>

void fsscan(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

void scani(int &x)
{
    register int c = gc();x = 0;int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

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

int main()
{
    fsscan();
    ll a,p;
    cin>>a>>p;
    ll s=a*3+p;
    cout<<s/2;
    return 0;
}


Measured memory_bytes: 256
# 169A
# A × B を整数として出力せよ


# 1. 入力をプログラムで扱えるように受け取ること
a,b=map(int,input().split())
#print(a,b)

# 2. 受け取った入力値を使って、適切に処理（計算）をすること
answer=a*b

# 3. 計算した結果を出力すること
print(answer)

Measured memory_bytes: 9064
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <string.h>
#include <iomanip>
#include <limits>
using namespace std;

const int MAX_N=10000;
string s;

int main(){
	cin >> s;
	
	for(int i=0;i<s.size();i+=2) cout << s[i];
	
	cout << endl;
	return 0;
}


Measured memory_bytes: 512
"""
import numpy as np
from collections import Counter

n = map(int,input().split())
a = list(map(int,input().split()))
Q = int(input())
a_count = dict(Counter(a))



def change_dict_key(d, old_key, new_key, default_value=None):
    d[new_key] = d.pop(old_key, default_value)


#change_dict_key(a_count, 1, 5)

#print(a_count)



for q in range(Q):
    num = list(map(int,input().split()))
    
    if(num[0] not in a_count):
        print(np.dot( np.array(list(a_count.keys())) , np.array(list(a_count.values()) ) ) )
        continue

    if(num[1] not in a_count):
        change_dict_key(a_count,num[0],num[1])

    else :
        a_count[num[1]] += a_count[num[0]] 
        del a_count[num[0]] 
    
    #print(a_count.values())

    print(np.dot( np.array(list(a_count.keys())) , np.array(list(a_count.values()) ) ) )
    #print((sum(list_a))  )
"""
N = int(input())
A = list(map(int, input().split()))
Q = int(input())

B, C = [0]*Q, [0]*Q
for i in range(Q):
    B[i], C[i] = list(map(int, input().split()))

bucket = [0]*100001
for i in A:
    bucket[i] += 1

sum = sum(A)

for i in range(Q):
    sum += (C[i] - B[i]) * bucket[B[i]]
    bucket[C[i]] += bucket[B[i]]
    bucket[B[i]] = 0
    print(sum)





Measured memory_bytes: 22068
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main() {
  int a[5];
  cin >>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
  vector<pair<int,int>> sa(5);
  rep(i,5){
    sa[i].first=a[i]%10;
    if(sa[i].first==0){
      sa[i].first=sa[i].first;
    }else{
      sa[i].first=10-sa[i].first;
    }
    sa[i].second=a[i]/10;
  }
  sort(all(sa));
  int sum=0;
  rep(i,4){
    if(sa[i].first==0){
      sum+=sa[i].second*10;
    }else{
      sum+=sa[i].second*10+10;
    }
    //cout<<sum<<" ";
  }
  if(sa[4].first==0){
    sum+=sa[4].first+sa[4].second*10;
  }else{
    sum+=10-sa[4].first+sa[4].second*10;
  }
  cout <<sum<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m;
char s[55][55];
int dirx[4]={0,-1,0,1};
int diry[4]={-1,0,1,0};
bool check(int x,int y)
{
    for(int i=0;i<4;i++)
    {
        int tmpx=x+dirx[i],tmpy=y+diry[i];
        if(tmpx>=0&&tmpx<n&&tmpy>=0&&tmpy<m)
        {
            if(s[tmpx][tmpy]=='#') return true;
        }
    }
    return false;
}
int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
    }
    bool flag=true;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(s[i][j]=='#')
            {
                if(!check(i,j))
                {
                    flag=false;
                }
            }
        }
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;

const int MAX_N = 105;
int g[MAX_N][MAX_N];
int d[MAX_N];
bool used[MAX_N];
int n;

void dijkstra(int s){
    fill(d,d+n,inf);
    fill(used,used+n,false);
    d[s] = 0;

    while(true){
        int v = -1;
        for(int u = 0; u < n; u++){
            if(!used[u] && (v == -1 || d[u] < d[v])){
                // 1番最小のd[u]となるuを、v = u　として保存
                // ループを抜けた後に、vを介して[u]を更新
                v = u;
            }
        }
        //　この時点でd[u]が最小となるuは決定されている。
        if(v == -1) break;
        used[v] = true;
        for(int u = 0; u < n; u++){
            d[u] = min(d[u],d[v] + g[v][u]);
        }
    }
}

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            g[i][j] = inf;
        }
    }
    for(int i = 0; i < n; i++){
        int u,k;cin >> u >> k;
        for(int j = 0; j < k ;j++){
            int v,c; cin >> v >> c;
            g[u][v] = c;
        }
    }
    dijkstra(0);
    for(int i = 0; i < n; i++){
        cout << i << ' ' << d[i] << endl;
    }
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1LL<<55LL
#define MAX_V 21111
struct edge {
  int to,cap,rev;
  edge(){}
  edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
};

vector<edge> G[MAX_V];
int level[MAX_V];
int iter[MAX_V];


void add_edge(int from,int to,int cap){
  //cout<<from<<" "<<to<<" "<<cap<<endl;
  G[from].push_back(edge(to,cap,G[to].size()));
  // directed
  G[to].push_back(edge(from,0,G[from].size()-1));
}

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

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

int max_flow(int s,int t,int lim){
  int flow=0;
  for(;;){
    bfs(s);
    //cout<<level[t]<<" "<<lim<<endl;
    if(level[t]<0||lim==0) return flow;
    memset(iter,0,sizeof(iter));
    int f;
    while((f=dfs(s,t,lim))>0){
      flow+=f;
      lim-=f;
    }
  }
}
int max_flow(int s,int t){
  return max_flow(s,t,INF);
}
typedef pair<int,int> P;
signed main(){
  int h,w;
  cin>>h>>w;
  string a[h];
  for(int i=0;i<h;i++) cin>>a[i];
  int s,t;
  int cnt=0;
  map<P,int> m;
  int sx,sy,tx,ty;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(a[i][j]=='o') m[P(i,j)]=cnt++;
      if(a[i][j]=='S') s=m[P(i,j)]=cnt++,sy=i,sx=j;
      if(a[i][j]=='T') t=m[P(i,j)]=cnt++,ty=i,tx=j;
    }
  }
  
  //for(auto p:m) cout<<p.first.first<<" "<<p.first.second<<endl;
  
  if(sx==tx||sy==ty){
    cout<<-1<<endl;
    return 0;
  }
  for(int i=0;i<h;i++){
    int j=0;
    while(j<w&&a[i][j]=='.') j++;
    vector<int> v(1,j++);
    while(1){
      while(j<w&&a[i][j]=='.') j++;
      if(j>=w) break;
      v.push_back(j++);
    }
    for(int x=0;x<(int)v.size();x++)
      for(int y=0;y<(int)v.size();y++)
	if(x!=y) add_edge(m[P(i,v[x])]+cnt,m[P(i,v[y])],1LL);
  }
  for(int j=0;j<w;j++){
    int i=0;
    while(i<h&&a[i][j]=='.') i++;
    vector<int> v(1,i++);
    while(1){
      while(i<h&&a[i][j]=='.') i++;
      if(i>=h) break;
      v.push_back(i++);
    }
    for(int x=0;x<(int)v.size();x++)
      for(int y=0;y<(int)v.size();y++)
	if(x!=y) add_edge(m[P(v[x],j)]+cnt,m[P(v[y],j)],1LL);
  }
  for(int i=0;i<cnt;i++){
    if(i==s||i==t) add_edge(i,i+cnt,INF);
    else add_edge(i,i+cnt,1LL);
  }
  //cout<<s<<" "<<t+cnt<<endl;
  cout<<max_flow(s,t+cnt)<<endl;
  return 0;
}


Measured memory_bytes: 122880
l = []
while True:
  A = input().split()
  if A[1] == '?':
     break
  elif A[1] == '+' :
    i = int(A[0]) + int(A[2])
    l.append(i)
  elif A[1] == '*' :
    i = int(A[0]) * int(A[2])
    l.append(i)
  elif A[1] == '/':
    i = int(A[0]) // int(A[2])
    l.append(i)
  elif A[1] == '-':
    i = int(A[0]) - int(A[2])
    l.append(i)
    
for k in l:
  print(k)




Measured memory_bytes: 5596
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define MAX_N 100001
typedef long long ll;
ll a[MAX_N], b[MAX_N], c[MAX_N], order[MAX_N], n;
int main(){
    cin >> n;
    for(ll i=0; i<n; i++){
        cin >> a[i];
    }
    ll nd = 0, ne = 0;
    for(ll i=0; i<n; i++){
        cin >> b[i];
        c[i] = a[i] - b[i];
    }
    sort(c, c+n);
    ll sum=0;
    for(int i=0; i<n; i++){
        sum += c[i];
        // cout << c[i] << endl;
    }
    if(sum < 0){
        cout << -1 << endl;
        return 0;
    }

    int i=0, j=n-1;
    ll tmp_cj = c[j];
    while(c[j]>0 && c[i]<0){
        if(c[j] > -c[i]){
            c[j] += c[i];
            c[i] = 0;
            i++;
        }else{
            c[i] += c[j];
            c[j] = 0;
            j--;
            tmp_cj = c[j];
        }
        // for(int i=0; i<n; i++){
        //     cout << c[i] << " ";
        // }
        // cout << endl;
    }
    if(tmp_cj == c[j]) cout << i + (n - 1 - j) << endl;
    else cout << i + (n - 1 - j) + 1 << endl;
    return 0;
}

Measured memory_bytes: 2560
package main

import (
	"fmt"
	"sort"
)

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

	arr := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&arr[i])
	}

	sort.Ints(arr)
	fmt.Println(arr[n-1] - arr[0])
}


Measured memory_bytes: 512