akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>

using namespace std;

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

const ll MOD = ll(1e9) + 7;
const ll INF = LLONG_MAX;
const ll MAX_N = 1 << 12;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

int n;
P p[200005];

int main() {
    cin >> n;
    REP(i, n) {
        ll a;
        cin >> a;
        p[i] = {a, 1};
    }
    REP(i, n) {
        ll b;
        cin >> b;
        p[i + n] = {b, 2};
    }
    sort(p, p + n * 2);
    ll t = 0, flag, ans = 1;
    REP(i, n * 2) {
        if (t == 0) {
            flag = p[i].second;
            t++;
        } else {
            if (p[i].second == flag) {
                t++;
            } else {
                ans = ans * t % MOD;
                t--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
/*
	Karya anak bangsa yang paling agung
	Author : Yohandi or... bukan..
*/

#define fs first
#define sc second
#define pb push_back
#define eb emplace_back

#define all(a) a.begin(),a.end()
#define lb(a,x) (lower_bound(all(a),x)-a.begin())
#define ub(a,x) (upper_bound(all(a),x)-a.begin())

#define rep(a,x,y) for(int a=(int)x;a<=(int)y;++a)
#define repd(a,x,y,d) for(int a=(int)x;a<=(int)y;a+=d)
#define res(a,x,y) for(int a=(int)x;a>=(int)y;--a)
#define resd(a,x,y,d) for(int a=(int)x;a>=(int)y;a-=d)

// Ordered Set, Ordered Multiset
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define o_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define o_multiset tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
// .order_of_key(x) -> Number of elements less than x
// * .find_by_order(k) -> Kth smallest element (0-based)
// .erase(x) -> Remove all elements equal to x

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using lint=long long;

mt19937 rng(time(NULL));

lint Power(lint A,lint B,lint C){
	if(!B) return 1LL;
	lint tmp=Power(A,B>>1,C);
	return tmp*tmp%C*(B&1?A:1)%C;
}

int T;

int main(){
//	ios_base::sync_with_stdio(0);
//	cin.tie(0); cout.tie(0);
	T=1;
//	cin>>T;
	rep(t,1,T){
		int A,B,C,K;
		int Ans=0;
		cin>>A>>B>>C>>K;
		int tmp=min(K,A);
		Ans+=tmp;
		K-=tmp;
		tmp=min(K,B);
		K-=tmp;
		tmp=min(K,C);
		Ans-=tmp;
		cout<<Ans<<endl;
	}
	return 0;
}




Measured memory_bytes: 3596
#include <iostream>
#include <cstring>
#include <vector>
#include <string>
#define LL long long
#define range(tmp,a,b) for(int tmp=a;tmp<=b;++tmp)
#define rerange(tmp,a,b) for(int tmp=a;tmp>=b;--tmp)
#define CLS(array) memset(array,0,sizeof(array))
using namespace std;
int n,t,MIN,MAX,ans;
vector<int>A;
void init(){
    cin>>n>>t;
    range(i,1,n){
        int tmp;
        cin>>tmp;
        A.push_back(tmp);
    }
    ans=1;
}
void solve(){
    MIN=A[0];MAX=0;
    range(i,1,n-1){
        ans+=(MAX==A[i]-MIN?1:0);
        if(A[i]-MIN>MAX){
            MAX=A[i]-MIN;
            ans=1;
        }
        MIN=min(MIN,A[i]);
    }
    cout<<ans<<endl;
}
int main(int argc, char *argv[]) {
    init();
    solve();
    return 0;
}

Measured memory_bytes: 892
import math
a = 0
b = 0
c = 0
d = 0
e = 0
ls = [a,b,c,d,e]
for i in range(len(ls)):
    ls[i] = int(input())
for i in ls:
    if i > 9:
        i = i//10
ans = 0
for i in ls:
    ans += math.ceil(i)

lsls = [0]
for i in range(len(ls)):
    ls_one = str(ls[i])
    if int(ls_one[-1]) > 0:
    	lsls.append(10-int(ls_one[-1]))
    
lsls.remove(max(lsls))
print(ans+sum(lsls))

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <random>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0)
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (lli i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

string s;
int main() {
  cin >> s;
  string y=s.substr(0,4), m=s.substr(5,2), d=s.substr(8,2);
  string yy="2019", mm="04", dd="30";
  bool b=false;
  if (y < yy || (y==yy && m<=mm)) b=true;
  cout << (b?"Heisei":"TBD") << '\n';
  return 0;
}


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

#define int long long
#define rep(i, a, n) for (int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort(ALL(c), greater<int>());
#define fi first
#define se second
int INF = 1e9 + 7;

typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> mat;

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

int a,b;

void solve() {
  cin>>a>>b;
  int c=a+b;
  int d=a-b;
  int e=a*b;
  cout<<max(c,max(d,e))<<endl;
}

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

  // cout << fixed << setprecision(10);

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INF 1000000000
#define MOD 1000000007
#define ll long long
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define bitget(a, b) (((a) >> (b)) & 1)
#define vint vector<int>
#define vvint vector<vector<int>>
#define vsort(x) sort(x.begin(), x.end())

using int32 = int_fast32_t;
using int64 = int_fast64_t;
using uint32 = uint_fast32_t;
using uint64 = uint_fast64_t;

using namespace std;

int main() {
	int n, k;
	scanf("%d", &n);
	scanf("%d", &k);
	int now = 1;
	rep(i, 0, n){
		if (now * 2 < now + k){
			now *= 2;
		}
		else{
			now += k;
		}
	}
	printf("%d", now);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define test(t) int t; cin>>t; while(t--)
#define p1(x) { cout << " [" << #x << ": " << x << "]\n"; }
#define p2(x) { cout << " [" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]\n"; }
#define pb push_back
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
 
 
void solve()
{
	int n, x, maxm=0;
	long long int ans=0;
	vector<int> a;
	cin>>n;
	F0R(i, n) {
		cin>>x;
		if(maxm>x) {
			ans+=(maxm-x);
		}
		else maxm=x;
	}
	cout<<ans<<endl;
}
 
int main() {
	// your code goes here
	// test(t)
		solve();
	return 0;
}
 

Measured memory_bytes: 3584
/*
2020/7/15
ロジックは組めるけど実装どうやるんだろ
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;

int main(){
    int N,K;
    cin >> N >> K ;
    vll a(N);
    for(int i=0;i<N;i++) cin >> a[i];
    ll ans=1e18;
    for(int i=0;i<(1<<N);i++){
        ll temp=i;
        int count=0;
        for(int j=0;j<N;j++){
            if(temp%2==1) count++;
            temp/=2;
        }
        if(count!=K) continue;
        vll building;
        ll temp2=i;
        for(int j=0;j<N;j++){
            if(temp2%2==1){
                building.push_back(j);
            }
            temp2/=2;
        }
        ll temp_ans=0;
        ll now_max=a[0];
        int j=0;
        for(int i=0;i<N;i++){
            if(now_max<a[i]) now_max=a[i];
            if(i==building[j]){
                if(now_max>=a[i]){
                    temp_ans+=now_max-a[i];
                    now_max++;
                    j++;
                }
            }
        }
        ans=min(ans,temp_ans);
    }
    cout << ans << endl;
    
}

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

long long int num2, num5;

long long int N;

long long int count2(long long int K) {

	long long int ret = 0;

	while (K > 0) {
		long long int tmp = K;

		while (tmp % 2 == 0) { ret++; tmp /= 2; }
		K -= 2;
	}

	return ret;
}

long long int count5(long long int K) {

	long long int ret = 0;

	while (K > 0) {
		long long int tmp = K;

		while (tmp % 5 == 0) { ret++; tmp /= 5; }
		K -= 2;
	}

	return ret;
}




int main(void) {

	cin >> N;
	long long int ans = 0;

	//cout << "count2= " << count2(N) << "  count5= " << count5(N) << endl;

	if (N % 2 == 1) { cout << 0 << endl; return 0; }


	long long int tmp = N;

/*	while (tmp > 0) {
		tmp /= 10;
		num5 += tmp / 10;
		if ((tmp % 10) >= 5) { num5++; }
	}
	*/
	/*tmp = N;
	while (tmp > 0) {
		ans += tmp / 10;
		tmp/= 10;
	}
	*/




	//cout << ans << endl;

	long long int Y = 5;

	tmp = N / 2;
	while (tmp >= Y) {
		num5 += tmp / Y;
		//cout << num5 << endl;
		Y *= 5;
	}
	cout << num5 << endl;

	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()

int main(){
  ll n,h,w; cin >> n >> h >> w;
  cout << max(n-h+1,0LL) * max(n-w+1,0LL) << endl;
}



Measured memory_bytes: 764
#include<bits/stdc++.h>
#include <numeric>
#define mod 1000000007
using namespace std;

int main(){
    int t;
    vector<string> vec;
    cin >> t;
    while(t--){
        string str;
        cin >> str;

        vec.push_back(str);
    }
    int ans = set<string>( vec.begin(), vec.end() ).size();
    cout << ans;
}


Measured memory_bytes: 25036
h, w, k = map(int, input().split())
L = [[0]*w for _ in range(h)]
now = 1
for i in range(h):
  s = input()
  for j in range(w):
    if s[j] == ".":
      L[i][j] = 0
    else:
      L[i][j] = now
      now += 1
for i in range(h):
  for j in range(w-1):
    if L[i][j+1] == 0:
      L[i][j+1] = L[i][j]
for i in range(h):
  for j in range(w-1):
    if L[i][w-2-j] == 0:
      L[i][w-2-j] = L[i][w-1-j]
for i in range(h-1):
  for j in range(w):
    if L[i+1][j] == 0:
      L[i+1][j] = L[i][j]
for i in range(h-1):
  for j in range(w):
    if L[h-2-i][j] == 0:
      L[h-2-i][j] = L[h-1-i][j]
for i in L:
  print(*i)

Measured memory_bytes: 7376
judge :: Bool -> (String,String) -> String
judge f (ts,fs) = case f of
  True -> ts
  False -> fs
 
isMultipleOf4 :: Int -> Int -> Bool
isMultipleOf4 x y = ((flip mod 4) $ x * 10 + y) == 0
 
main = do
  line <- getLine
  let 
    [_,g,b] = map read $ words line :: [Int]
    ret = isMultipleOf4 g b
  putStrLn $ judge ret ("YES","NO")


Measured memory_bytes: 508
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <iterator>
 
using namespace std;
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
 
#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)c.size())

typedef unsigned long long ull;

typedef complex<int> P;
int n;

bool Outside(P &p) {
return p.real() < 0 || p.real() >= n || p.imag() < 0 || p.imag() >= n; 
}

bool isWall(vector<string>& v,P &p){
	if(Outside(p)) return false;
	return v[p.imag()][p.real()] == '#';
}

int main(){
	int t; cin>>t;
	while(t--){
		cin>>n;
		vector<string> v(n,string(n,' '));

		P current(0,n-1),e(0,1);
		P d(0,-1);
		if(n == 1){
			v[0][0] = '#';
		} else{
			while(true){
				P next = current + d;
				if(isWall(v,next)) break;
				v[current.imag()][current.real()] = '#';
				bool ok = !Outside(next);
				if(ok){
					FOR(i,4){
						d *= e;
						P ne = next + d;
						if(ne == current) continue;
						if(isWall(v,ne))ok = false;
					}
				}

				if(!ok){
					d *= e;
				} else {
					current = next;
				}
			}
		}
		FOR(i,n) cout << v[i] << endl;

		if(t!=0)puts("");
	}

	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,b;
  cin>>n;
  int a[n*2];
  b=0;
  for(int i=0;i<n*2;i++){
    cin>>a[i];
  }
  sort(a,a+n*2);
  
  for(int j=0;j<n*2;j+=2){
    b+=a[j];
  }
  cout<<b<<endl;
}

Measured memory_bytes: 256
use std::cmp::min;
use std::io::{stdin, Read};

#[allow(unused_macros)]
macro_rules! parse {
    ($it: ident ) => {};
    ($it: ident, ) => {};
    ($it: ident, $var:ident : $t:tt $($r:tt)*) => {
        let $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
    ($it: ident, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = parse_val!($it, $t);
        parse!($it $($r)*);
    };
}

#[allow(unused_macros)]
macro_rules! parse_val {
    ($it: ident, [$t:tt; $len:expr]) => {
        (0..$len).map(|_| parse_val!($it, $t)).collect::<Vec<_>>();
    };
    ($it: ident, ($($t: ty),*)) => {
        ($(parse_val!($it, $t)),*)
    };
    ($it: ident, $t: ty) => {
        $it.next().unwrap().parse::<$t>().unwrap()
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    parse!(it, n: usize, a: [usize; n + 1]);
    let mut b = vec![0; n + 1];
    for i in 0..n {
        b[n - i - 1] = a[n - i] + b[n - i];
    }
    let mut s = 1;
    let mut ret = 0;
    for i in 0..(n + 1) {
        ret += s;
        if a[i] > s {
            println!("{}", -1);
            return;
        }
        let ns = min(2 * (s - a[i]), b[i]);
        if s - a[i] > ns {
            println!("{}", -1);
            return;
        }
        s = ns;
    }
    println!("{}", ret);
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 4528
N = int(input())
A = []
for i in range(N):
  A.append(int(input()))

if A[0] > 0:
  print(-1)
  exit(0)

cnt = 0
for i in range(1,N):
  if A[i-1] + 1 < A[i]:
    print(-1)
    exit(0)
  elif A[i-1] + 1 == A[i]:
    cnt += 1
  else:
    cnt += A[i]
    
print(cnt)

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i=0; i<N; ++i) cin >> a[i];

    int x = 0;
    for (int i=0; i<N; ++i) x ^= a[i];
    for (int i=0; i<N; ++i) {
        cout << (x ^ a[i]);
        if (i == N-1) cout << '\n';
        else cout << ' ';
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3972
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int x1,y1,x2,y2,x3,y3,x4,y4;
    cin>>x1>>y1>>x2>>y2;
    int posx=x2-x1,posy=y2-y1;
    x3=x2-posy,y3=y2+posx;
    x4=x1-posy,y4=y1+posx;
    cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;



int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll q; cin >> q;
    ll L = 0,R = 0;
    while(q--){
        ll p; char c; ll n; cin >> p >> c >> n;
        if(c == '(') L += n;
        else R += n;
        
        if(L == R) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}



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

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)
#define rrep(i,a,b) for(int (i)=int(a);(i)>=int(b);(i)--)

#define put(a) cout << (a) << endl
#define puts(a) cout << (a) << " "

#define llint long long int

#define INF (long long)(1e9+1)
#define MOD (long long)(1e9+7)
#define INF64 (long long)(1e18+1)

#define F first
#define S second

#define Pii  pair<int,int>
#define Pll  pair<long long,long long>
#define Piii pair<int,pair<int,int>>
#define Plll pair<long long,pair<long long,long long>>

#define Vll(a,b,c)    vector<vector<long long>> (a)((b),vector<long long>((c))
#define Vlll(a,b,c,d) vector<vector<vector<long long>>> (a)((b),vector<vector<long long>>((c),vector<long long>((d)))

#define MAX_N 1000000

int main (void)
{
  //INPUT
  llint N;
  cin >> N;
  string S;
  cin >> S;

  //SOLVE
  vector<llint> dp(N+1);
  dp[1] = 0;
  string bufs;
  llint bl;
  rep(i,1,N) {
    bufs = S.substr(i-dp[i],dp[i]+1);
    bl = S.find(bufs);
    // cout << bufs << endl;
    if (bl+dp[i]<i-dp[i]) {
      dp[i+1] = dp[i]+1;
    } else {
      dp[i+1] = dp[i];
    }
  }



  //OUTPUT
  cout << dp[N] << endl;

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	r := true
	for i := 0; i < n; i++ {
		ai := nextInt()
		if ai%2 == 0 && ai%3 != 0 && ai%5 != 0 {
			r = false
		}
	}
	if r {
		fmt.Println("APPROVED")
	} else {
		fmt.Println("DENIED")
	}
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


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

//#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

ll res = 0;
int k;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> k;

	forr(a, 1, k) forr(b, 1, k) forr(c, 1, k)
		res += __gcd(a, __gcd(b, c));
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll MOD = 1e9+7;
    ll H, W, K;
    cin >> H >> W >> K;
    K--; //0-indexedにする

    ll dp[H+1][W] = {};
    dp[0][0] = 1;

    rep(h, H) {
        for (int b = 0; b < (1<<(W-1)); b++) {
            // 横軸が隣り合っていないかチェック
            bool ok = true;
            rep(i, W-2) {
                // 末尾が11なら隣り合っている
                if ((b>>i) % 4 == 3) ok = false;
            }
            if(!ok) continue;

            // 各始点の終点を求める
            ll perm[W];
            rep(i, W) perm[i] = i;
            rep(i, W-1) {
                // あみだくじで位置をswap
                if ((b>>i) & 1) swap(perm[i], perm[i+1]);
            }

            // dp更新
            rep(i, W) {
                dp[h+1][perm[i]] += dp[h][i];
                dp[h+1][perm[i]] %= MOD;
            }
        }
    }
    cout << dp[H][K] << endl;
}

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


int main() {
    int N;
    cin>>N;
    int a =sqrt(N);
    cout<<(ll)pow(a,2)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
auto random_address = [] { char *p = new char; delete p; return uint64_t(p); };
const uint64_t SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll n;
bool c[1000001];
ll nrdivs[1000001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    c[1]=1;
    c[0]=1;
    for(ll i=1;i<=n;i++)
        nrdivs[i]=1;
    for(ll i=2;i<=n;i++)
        if(c[i]==0)
        {
            nrdivs[i]=2;
            for(ll j=i*2;j<=n;j+=i)
            {
                c[j]=1;
                ll prod=i;
                ll p=0;
                while(j%prod==0)
                {
                    p++;
                    prod*=i;
                }
                nrdivs[j]*=(p+1);
            }
        }
    ll ans=0;
    for(ll c=1;c<n;c++)
    {
        ll dif=n-c;
        ans+=nrdivs[dif];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 12440
#include <stdio.h>
int main(){
int a,b,c;
scanf ("%d%d%d",&a,&b,&c);
if (a==b){
printf ("%d",c);
}
  else if (b==c){
  printf ("%d",a);
  }
else {
printf ("%d",b);
}
return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define	rep(i,n)	for(int i=0;i<n;i++)
int main(){
  long long w,h,x,y;	cin >> w >> h >> x >> y;
  cout << (double)w*(double)h/2.0 << endl;
  if(x*2==w&&y*2==h)	cout << 1;
  else cout << 0;
}

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

int n,m,k;
int a[200005],b[200005];

int main(){

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

    cin>>n>>m>>k;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    long long tot=0;
    for(int i=1;i<=m;i++){
        cin>>b[i];
        tot+=b[i];
    }
    int ans=0;
    for(int ia=0,ib=m;ia<=n;ia++){
        tot+=a[ia];
        while(tot>k&&ib>0)tot-=b[ib--];
        if(tot>k)break;
        ans=max(ans,ia+ib);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 5212
/**
あなたの課題は、あるクラスの数学の成績を付けるプログラムを作成することです。

プログラムは複数の学生のテストの点数を読み込みます。

テストの点数は、中間試験の点数 m、期末試験の点数 f、再試験の点数 r で構成されています。

中間試験と期末試験は 50 点満点（m, f ? 50）、再試験は 100 点満点 （r ? 100）です。

試験を受けていない場合は点数を -1 とします。

以下の手順で成績が付けられます：
?中間試験、期末試験のいずれかを欠席した場合成績は F。
?中間試験と期末試験の合計点数が 80 以上ならば成績は A 。
?中間試験と期末試験の合計点数が 65 以上 80 未満ならば成績は B。
?中間試験と期末試験の合計点数が 50 以上 65 未満ならば成績は C。
?中間試験と期末試験の合計点数が 30 以上 50 未満ならば成績は D。 ただし、再試験の点数が 50 以上ならば成績は C。
?中間試験と期末試験の合計点数が 30 未満ならば成績は F。

 */

/*sucannerクラス使うためにインポート*/
import java.util.Scanner;

class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成
		Scanner sc = new Scanner(System.in);
		// 点数を受け取る変数を宣言
		int intM = 0;
		int intF = 0;
		int intR = 0;
		
		//breakされるまで処理をくりかえす
		while (true) {
			//数字を中間、期末、再試験の順にうけとる
			intM = sc.nextInt();
			intF = sc.nextInt();
			intR = sc.nextInt();

			//受け取った３つの数字がすべて-1だった場合breakして処理を終了する。
			if (intM == -1 && intF == -1 && intR == -1) {
				break;
			}
			//中間、期末にー1が入力された場合表示
			if (intM == -1 || intF == -1) {
				System.out.println("F");
			//中間、期末の合計が８０以上の場合表示
			} else if (intM + intF >= 80) {
				System.out.println("A");
			//中間、期末の合計が６５以上の場合表示
			} else if (intM + intF >= 65) {
				System.out.println("B");
				//中間、期末の合計が５０以上、または再試験の値が５０以上の場合表示
			} else if (intM + intF >= 50 || intR >= 50) {
				System.out.println("C");
			//中間、期末の合計が３０以上の場合表示
			} else if (intM + intF >= 30) {
				System.out.println("D");
			//それ以下のとき表示
			} else {
				System.out.println("F");
			}
		}
	}
}

Measured memory_bytes: 19108
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=1e5+2;
int n,m;
struct Edge{
	int to,nxt;
};
Edge edge[maxn<<1];
int cnt,head[maxn];
void addedge(int u,int v){
	cnt++;
	edge[cnt].to=v;
	edge[cnt].nxt=head[u];
	head[u]=cnt;
}
bool odd=false;
int col[3],vis[maxn];
void dfs(int u,int color){
	if (vis[u]){
		if (vis[u]!=color) odd=true;
		return;
	}
	vis[u]=color;
	col[color]++;
	for (int i=head[u];~i;i=edge[i].nxt){
		int v=edge[i].to;
		dfs(v,3-color);
	}
}
void init(){
	cnt=0;
	memset(head,-1,sizeof(head));
}
int main(){
	init();
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
	}
	dfs(1,1);
	if (odd) printf("%lld\n",1LL*n*(n-1)/2-m);
	else printf("%lld\n",1LL*col[1]*col[2]-m);
	return 0;
}

Measured memory_bytes: 3328
import java.io.*;
import java.util.*;

public class Main {

	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
	public static List<Integer>[] edges;
	public static long[] fac,inv;
	public static int mod = (int) (1e9+7),MAX = (int) (1e5+1);
	public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc = new FastReader();
	
	
		int n = sc.nextInt();
		edges = new ArrayList[n+1];
		for(int i=0;i<=n;++i) edges[i] = new ArrayList<>();
		int k = 0;
		List<Pair> list = new ArrayList<>();
		for(int i=1;i<n;++i) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			edges[u].add(v);
			edges[v].add(u);
			list.add(new Pair(u,v));
			k = Math.max(k, Math.max(edges[u].size(), edges[v].size()));
		}
	
		int[] col = bfs(n);
		out.println(k);
		for(int i=0;i<list.size();++i) out.println(col[list.get(i).v]);
		
        out.close();
		
	}
	
	private static int[] bfs(int n) {
		int[] col = new int[n+1];
		Queue<Integer> q = new ArrayDeque<>();
		q.add(1);
		boolean[] vis = new boolean[col.length];
		vis[1] = true;
		while(q.size() > 0) {
			int node = q.poll();
			int c = 1;
			for(int v : edges[node]) {
				if(!vis[v]) {
					if(c == col[node]) ++c;
					col[v] = c++;
					vis[v] = true;
					q.add(v);
					
				}
			}
		}
		
		return col;
	}
	
	static class Pair implements Comparable<Pair>{
		int u;
		int v;
		int c;
		Pair(int u,int v){
			this.u = u;
			this.v = v;
		}
		@Override
		public int compareTo(Pair arg0) {
			// TODO Auto-generated method stub
			return this.u - arg0.u;
		}
	}
	
}


Measured memory_bytes: 54236
N, K = map(int, input().split())
H = list(map(int, input().split())) + [0]
dp = [[10**12]*(K+2) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
  for j in range(min(i+1, K) + 1):
    for k in range(j + 1):
      dp[i+1][j] = min(dp[i+1][j], dp[i-k][j-k] + max(H[i] - H[i-k-1], 0))
ans = min(dp[-1])
for i in range(K+1):
  ans = min(ans, dp[N-i][K-i])
print(ans)


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

int main() {
  int N, T, Max=0;
  map<int, int> A;
  cin >> N;
  rep(i, N){
  cin >> T;
  A[T]++;
  A[T-1]++;
  A[T+1]++;
  }
  for(auto x:A) if(x.second>Max) Max=x.second;
  cout << Max << endl;
}

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

int main() {
	int	x=0;
  cin>>x;
  bool ok=false;
  if(x==0)
    cout<<"No";
    else{
  for(int i=1; i<10;i++){
  if(x/i<10 && x%i==0){
    ok=true;
    break;}
  
  }
  if(ok)
    cout<<"Yes";
  else
    cout<<"No";
    }
	return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
#define mp            make_pair
template<class T, class S> inline bool minup(T& m, const S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, const S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 2000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-10;

int N, n, m;
int A[111];
int B[111];
int c[111];
int v;

inline void rotate(int m)
{
  int t = A[0];
  rep(i, m - 1) A[i] = A[i + 1];
  A[m - 1] = t;
}

int main(int argc, char *argv[])
{
  cin >> N;
  rep(i, N) cin >> A[i];
  rep(i, N) if(A[i] < 100) c[A[i]] += 1;
  rep(i, N) if(A[i] > 4) m += 1;
  
  sort(A, A + N, [&](const int& x, const int& y){
      if(x == 0){
        if(y == 0) return false;
        if(y == 1) return true;
        return false;
      }
      if(x == 1){
        if(y == 1) return false;
        if(y == 0) return false;
        return false;
      }
      if(y <= 1) return true;
      return x < y;
    });
  
  rep(i, N - 1) if(A[i] != A[i + 1]) v += 1;
  
  bool ok = true;
  if(c[2]){
    if(c[3] == 1 && (c[4] == 0 && m == 0 && (!(c[0] & 1) || c[1]))){
      swap(A[c[2]], A[c[2] - 1]);
      ok = false;
    }
    else if(c[3] == 1 && (c[4] == 0 && m == 0 && (!(c[0] & 1) || c[2] >= 2))){
      swap(A[c[2]], A[c[2] - 1]);
      //if(c[0] == 1) ok = false;
    }
    else if(c[3] == 1 && c[4] + m == 1 && (c[0] & 1)){
      swap(A[c[2]], A[c[2] - 1]);
      ok = false;
    }
    else if(c[3] == 2 && c[4] + m == 0 && ((c[0] & 1) && !c[1])){
      swap(A[c[2] + 1], A[c[2] - 1]);
      ok = false;
    }
  }
  
  else if(c[2] == 1 && !c[3]){
    if(c[4] == 1 && m == 0 && (c[0] & 1)){
      swap(A[c[2]], A[c[2] - 1]);  
        ok = false;
    }
  }
    
  if((c[0] & 1) && c[1]){
    rev(i, N - 1) if(A[i + 1] == 1 && A[i] == 0){
      swap(A[i + 1], A[i]);
      break;
    }
  }
  
  else if(ok && (c[0] == 1)){
    rotate(N - c[0]);
    //    swap(A[0], A[N - c[0] - 1]);
  }

  else if(ok && (c[0] >= 3 && (c[0] & 1))){
    rotate(N - c[0]);
    swap(A[N - c[0] - 1], A[N - 2]);
  }
  
  rep(i, N) cout << A[i] << endl;

  
  return 0;
}

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


using namespace std;

string reverse(string &s){
	int l=s.length();
	string ret="";
	for (int i = l-1; i >= 0; --i)
	{
		ret+=s[i];
	}
	return ret;

}


int main() {
	string s;
	cin >> s;
	string s1="",s2="";
	for(int i=0;i<s.length();i++){
		if(s[i]!='x')
			s1+=s[i];
	}
	int count=0;
	s2=reverse(s1);
	if(s1!=s2){
		cout << -1;
	}else{
		int indf=0, indb = s.length()-1;
		for(int i=0;i<(s.length()+count)/2;i++){
			if(s[indf]==s[indb]){
				indf++;
				indb--;
			}else if(s[indf]=='x'){
				count++;
				indf++;
			}else{
				count++;
				indb--;
			}
		}
		cout << count;
	}
}

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

string s;

int main(){
    cin >> s;
    if(s.size() & 1){
        cout << "No" << endl;
        return 0;
    }
    int k = s.size()/2;
    string t;
    while(k --){
        t += "hi";
    }
    if(s != t){
        cout << "No" << endl;
        return 0;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}


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

using namespace std;

int main() {
	string s, t;
	cin >> s >> t;

	vector<vector<int>> chars(26);

	for (int i = 0; i < s.size(); i++) {
		chars[s[i] - 'a'].emplace_back(i);
	}

	int s_times = 0;
	int s_idx = -1;
	for (auto c: t) {
		int c_idx = c - 'a';
		if (chars[c_idx].empty()) {
			cout << -1 << endl;
			return 0;
		}

		auto it = upper_bound(chars[c_idx].begin(), chars[c_idx].end(), s_idx);
		if (it == chars[c_idx].end()) {
			s_times++;
			it = upper_bound(chars[c_idx].begin(), chars[c_idx].end(), -1);
		}

		s_idx = *it;
	}

	long long ans = 1LL * s_times * s.size() + s_idx + 1;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1216
H, W = map(int, input().split())
S = [list(input()) for i in range(H)]

check_pat = [(1, 0), (-1, 0), (0, -1), (0, 1)]
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            continue

        if H == 1:
            if W == 1:
                check_pat = []
            elif j == W-1:
                check_pat = [(0, -1)]
            else:
                check_pat = [(0, -1), (0, 1)]
        elif i == 0:
            if W == 1:
                check_pat = [(1, 0)]
            elif j == W-1:
                check_pat = [(1, 0), (0, -1)]
            else:
                check_pat = [(1, 0), (0, -1), (0, 1)]
        elif i == H-1:
            if W == 1:
                check_pat = [(-1, 0)]
            elif j == W-1:
                check_pat = [(-1, 0), (0, -1)]
            else:
                check_pat = [(-1, 0), (0, -1), (0, 1)]
        else:
            if W == 1:
                check_pat = [(-1, 0), (1, 0)]
            elif j == W-1:
                check_pat = [(-1, 0), (1, 0), (0, -1)]
            else:
                check_pat = [(-1, 0), (1, 0), (0, -1), (0, 1)]

        ng_flg = 1
        for pat in check_pat:
            if S[i+pat[0]][j+pat[1]] == "#":
                ng_flg = 0
                break
        if ng_flg == 1:
            print("No")
            exit()

print("Yes")

Measured memory_bytes: 3192
import java.io.*;
import java.util.*;

class Main {
	static FastScanner sc = new FastScanner();
	static PrintWriter out = new PrintWriter(System.out);

	public void solve() {
		int N = sc.nextInt();
		int[] T = new int[N];
		for (int i = 0; i < N; i++) {
			T[i] = sc.nextInt();
		}
		int M = sc.nextInt();
		int[] P = new int[M];
		int[] X = new int[M];
		for (int i = 0; i < M; i++) {
			P[i] = sc.nextInt();
			X[i] = sc.nextInt();
		}
		
		for (int i = 0; i < M; i++) {
			int[] t = T.clone();
			t[P[i]-1] = X[i];
			out.println(Arrays.stream(t).sum());
		}		
	}
	
	

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

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 27860
#include<bits/stdc++.h>
#define rep(i,x,y) for(int i=x,i##end=y;i<=i##end;++i)
#define _rep(i,x,y) for(int i=x,i##end=y;i>=i##end;--i)
#define ll long long 
#define N 100005
typedef std::pair<int,int> pii;


int main(){
	std::ios::sync_with_stdio(0);
	std::cin.tie(0),std::cout.tie(0);
	int d,t,s;
	std::cin>>d>>t>>s;
	if((double)d/t<=s) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3708
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A.sort()
B.sort()
C.sort()

def is_ok(mid, array, n):  return array[mid] > n

def binary_search(left, right, array, n):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid, array, n):  right = mid
        else:  left = mid
    return right

ans = 0
BtoC = []
for i in range(N):
    ret = binary_search(-1, N, C, B[i])
    if ret != N:
        BtoC.append(N - ret)
    else:
        BtoC.append(0)
for i in range(1, N):  BtoC[-i - 1] += BtoC[-i]
for i in range(N):  
    ret = binary_search(-1, N, B, A[i])
    if ret != N:  ans += BtoC[binary_search(-1, N, B, A[i])]
print(ans)

Measured memory_bytes: 105172
import java.io.FileNotFoundException;
import java.util.LinkedHashMap;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	int N = sc.nextInt();
    	long sum = 0;
		LinkedHashMap<Integer, Integer> map = new LinkedHashMap<Integer, Integer>();
		for (int i=0;i<N;i++) {
			int A = sc.nextInt();
			sum += A;
		    if (map.containsKey(A)) {
		        map.put(A, map.get(A) + 1);
		    } else {
		        map.put(A, 1);
		    }
		}

		int Q = sc.nextInt();
		for(int i=0;i<Q;i++) {
			int B = sc.nextInt();
			int C = sc.nextInt();
			if(map.containsKey(B)) {
				int num = map.get(B);
				map.put(B,0);
				if(map.containsKey(C)) {
					map.put(C,map.get(C)+num);
				} else {
					map.put(C, num);
				}
				sum = sum + (C-B) * num;
				System.out.println(sum);
			} else {
				System.out.println(sum);
			}
		}
    }
}


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

using namespace std;
using namespace __gnu_pbds;

typedef unsigned long long ll;
typedef pair<ll, ll> pii;
#define X first
#define Y second
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
// change type to pair & use counter for multi-set
typedef tree<
    int,
    null_type,
    less<int>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;

void fastInOut();
const double EPS = 1e-8;
const int MOD = 1e9 + 7;
const int N = 10000 + 5;

string k;
int d;
int dp[N][105][2]; // idx, mod sum, is_flipped

int solve(int i=0, int sum=0, bool flip=0)
{
    if(i == k.size()) return (sum == 0);
    int &res = dp[i][sum][flip];
    if(~res) return res;
    res = 0;
    if(flip) {
        for(int j=0; j<10; ++j)
            res = (res + solve(i+1, (sum+j)%d, true)) % MOD;
    } else {
        res += solve(i+1, (sum+k[i]-'0')%d, false);
        for(int j=0; j<(k[i]-'0'); ++j)
            res = (res + solve(i+1, (sum+j)%d, true)) % MOD;
    }
    return res;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    fastInOut();
    memset(dp, -1, sizeof(dp));
    cin >> k >> d;
    cout << (solve()-1+MOD)%MOD << '\n';
    return 0;
}

void fastInOut() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}


Measured memory_bytes: 9216
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
string A;
int ap[26] = {};
 
signed main() {
    cin >> A;
    for (int i = 0; i < A.length(); i++) {
        ap[A[i] - 'a']++;
    }
    int ans = 0;
    for (int i = 0; i < 26; i++) {
        ans += ap[i] * (A.length() - ap[i]);
    }
    cout << ans / 2 + 1 << endl;
    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int ans = A-2*B;
		if(ans>=0) {
			System.out.println(ans);
		}else {
			System.out.println(0);
		}
	}

}



Measured memory_bytes: 24276
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
#include <algorithm>
//#include <vector> 

int main(int argc, char* argv[])
{
	long a, b, c;
    scanf("%ld %ld %ld", &a, &b, &c);

    long max = a;
    if(max<b)
        max = b;
    if(max<c)
        max = c;

    printf("%d\n", max*9+a+b+c);


    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    int N;
    cin >> N;
    VLL A(N);
    rep(i,N){
        cin >> A[i];
        A[i]=A[i]-(i+1);
    }
    sort(all(A));
    ll key=0;
    ll sum=0;
    key=A[N/2];
    rep(i,N){
        sum+=abs(A[i]-key);
    }
    cout << sum << endl;
} 

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1LL<<60;

int ans = 0;

int bubbleSort(vector<int> A, int N){
  bool flag = true;
  while (flag) {
    flag = false;
    for (int j = N-1; j > 0; j--) {
      if (A[j] < A[j-1]) {
        swap(A[j], A[j-1]);
        ans ++;
        flag = true;
      }
    }
  }
  rep(k, N) {
    if (k != N-1)cout << A[k] << " ";
    else cout<< A[k];
  }
  cout<< endl;
  return 0;
}

int main() {
  int N;cin>>N;
  vector<int> A(N);
  rep(i, N) cin>>A[i];

  bubbleSort(A, N);

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



Measured memory_bytes: 3156
import numpy as np

n = int(input())
num_list = np.array(input().split(), dtype = np.int64)
mod = 10**9 + 7

ans = 0
for i in range(60):
    b = np.count_nonzero(num_list >> i & 1)
    if i==0:
        pow_two = 1
    else:
        pow_two = pow_two * 2 % mod
    ans += pow_two * b * (n-b) % mod
    ans %= mod
    
print(ans)

Measured memory_bytes: 62768
#include <bits/stdc++.h>
using namespace std;
int q, n, m;
int main() {
	cin >> q;
	while(q--) {
		cin >> n >> m;
		if(n % 2 == 1) cout << (n - 1) * 127 + m << endl;
		else cout << n * 127 - m << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 1000400
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl '\n'
#define sp ' '
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
ll power(ll x,ll y){
    ll ret=1;
    while(y>0){
        if(y&1)
            ret=(ret*x);
        y/=2;
        x=(x*x);
    }
    return ret;
}
ll get(ll n){
	ll ret=0;
	while(n){
		ret+=n%10;
		n/=10;
	}
	return ret;
}
void solve(){
	ll n;
	cin>>n;
	ll sm=get(n);
	if(n%sm==0){
		cout<<"Yes\n";
	}else{
		cout<<"No\n";
	}
}	
int main(){
	gear_change;
	ll test=1;
	// in(test);
	while(test--){
		solve();
	}
}	


Measured memory_bytes: 256