akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
#include <set>
#include <random>
using namespace std;

int main() {
  int X, Y;
  cin >> X >> Y;
  int ans = max(4 - X, 0) + max(4 - Y, 0);
  ans += 4 * (ans == 6);
  cout << ans * 100000 << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main 
{
  public static void main(String[] args) 
  {
    Scanner input=new Scanner(System.in);
    int a=input.nextInt();
    int b=input.nextInt();
    int c=input.nextInt();
    if(b>=1 && b<=1000 && c>=1 && c<=1000 && a>=(b+c) && a<=10000)
    {
     a=a-b;
     int temp=a%c;
     System.out.println(temp);
    }
  }
}

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

int main(){
  ll A,B,K;
  cin >> A >> B >> K;
  if(A + B <= K){
    cout << 0 << " " << 0 << endl;
  }else if(A <= K){
    cout << 0 << " " << A + B - K << endl;
  }else{
    cout << A - K << " " << B << endl;
  }
}


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

using namespace std;

int mil()
{
	int y,m,d;
	y=1000;
	m=1;
	d=1;
		int day=(y-1)*(20*5+19*5);
		day+=(y-1)/3*5;

		day+=(m-1)/2*19+(m)/2*20;
		if(y%3==0)
			day+=(m-1)/2;

		day+=d;
	return day;	
}

int main()
{
	int n;
	cin >> n;
	while(n--)
	{
		int y,m,d;
		cin >> y >> m >> d;

		int day=(y-1)*(20*5+19*5);
		day+=(y-1)/3*5;

		day+=(m-1)/2*19+(m)/2*20;
		if(y%3==0)
			day+=(m-1)/2;

		day+=d;
		
		cout << mil()-day << endl;
		
	}
}



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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main()
{
    ll n,m,ans=0;
    cin>>n>>m;
    if(n>m) swap(n,m);
    if(n==1)
    {
        if(m==1) ans=1;
        else ans=m-2;
    }
    else if(n==2)
    {
        ans=0;
    }
    else
    {
        ans=(n-2)*(m-2);
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
double ABS(double a){return max(a,-a);}
int main(){
	int T,D,ta,tb,da,db;
	scanf("%d%d%d%d%d%d",&T,&D,&ta,&tb,&da,&db);
	double ret=999999999;
	for(int i=0;i<=D;i+=da){
		for(int j=0;i+j<=D;j+=db){
			if(i+j==0)continue;
			double S=(double)(ta*i+tb*j)/(i+j);
			ret=min(ret,ABS(T-S));
		}
	}
	printf("%.12f\n",ret);
}

Measured memory_bytes: 1064
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define NODE_MAX 100001
int par[NODE_MAX],rk[NODE_MAX];
void init(){
  for(int i=0;i<NODE_MAX;i++){
    par[i]=i;
    rk[i]=0;
  }
}
int root(int x){
  if(x==par[x]) return x;
  return par[x]=root(par[x]);
}
void unite(int x,int y){
  x = root(x);
  y = root(y);
  if(x==y) return;

  if(rk[x]<rk[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(rk[x]==rk[y]) rk[x]++;
  }
}
bool same(int x,int y){
  return root(x)==root(y);
}
int main(){
  ll n,sum=0,tmp;
  cin >> n;
  ll x[n],y[n];
  P vx[n],vy[n];
  vector<P> xy;
  init();
  priority_queue<pair<ll,P>,vector<pair<ll,P>>,greater<pair<ll,P>>> que;
  for(ll i=0;i<n;i++){
    cin >> x[i] >> y[i];
    vx[i]=P(x[i],i);
    vy[i]=P(y[i],i);
    xy.push_back(P(x[i],y[i]));
  }
  sort(vx,vx+n);
  sort(vy,vy+n);
  for(int i=1;i<n;i++){
    tmp = min(vx[i].first-vx[i-1].first,
        abs(y[vx[i].second]-y[vx[i-1].second]));
    que.push(make_pair(tmp,P(vx[i].second,vx[i-1].second)));

    tmp = min(vy[i].first-vy[i-1].first,
        abs(x[vy[i].second]-x[vy[i-1].second]));
    que.push(make_pair(tmp,P(vy[i].second,vy[i-1].second)));
  }
  while(!que.empty()){
    pair<ll,P> e = que.top(); que.pop();
    if(!same(e.second.first,e.second.second)){
      unite(e.second.first,e.second.second);
      sum+=e.first;
    }
  }
  cout <<sum<<endl;
}


Measured memory_bytes: 17004
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

N,R = imn()

if N >= 10:
    print(R)
else:
    print(R+100*(10-N))

Measured memory_bytes: 66156
#include<bits/stdc++.h>                          
using namespace std;
int a,b,i=1,f;
double x,y;
int main(){
    int a,b;
    cin>>a>>b;
    for(int i=1;i<=20050;i++)
	{
        x=i*0.08;
        y=i*0.1;
        if((int)x==a&&(int)y==b) {cout<<i<<endl;return 0;}
    }
    cout<<-1;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    ll L[N], R[N];
    rep(i, N) cin >> L[i] >> R[i];
    sort(L, L+N, greater<ll>());
    sort(R, R+N);
    int i = 0;
    ll sum = 0;
    while(L[i] > R[i]){sum += L[i]-R[i]; i++;}
    ll ans = sum;
    if(i >= 1){
        ans = max(ans, sum-L[i-1]);
        ans = max(ans, sum+R[i-1]);
    }
    if(i*2 != N){
        ans = max(ans, sum+L[i]);
        ans = max(ans, sum-R[i]);
    }
    cout << ans*2 << endl;
}

Measured memory_bytes: 1792
def read_input():
    n = int(input())
    k = int(input())
    x = int(input())
    y = int(input())

    return n, k, x, y


def submit():
    n, k, x, y = read_input()

    c_x = min(n, k)
    c_y = max(0, n - k)

    print(c_x * x + c_y * y)

if __name__ == '__main__':
    submit()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,m;
    int br1,br2;
    cin>>n>>m;
    
    vector <int> toshi(n+1,0);
    for(int i=0;i<m;i++){
        cin>>br1>>br2;
        for(int j=1;j<=n;j++){
            if(j==br1) toshi[j]++;
            else if(j==br2) toshi[j]++;
        }
    }
    
    for(int i=1;i<=n;i++){
        cout<<toshi[i]<<endl;
    }
}


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

int main() {
	int n;
  	string s;
  	cin >> n >> s;
  
  	vector<int> prefix;
  	int now = 0;
  	s = '#' + s;
  	prefix.push_back(0);
  	for(int i=1;i<=n;i++) {
    	if(s[i] == 'W') {
        	now++;
        }
      	prefix.push_back(now);
    }
  
  	int ans = n - prefix[n];
  	ans = min(ans , prefix[n]);
  
  	for(int i=1;i<=n;i++) {
    	int numR = i - prefix[i];
      	int numW = prefix[i];
      	
      	int numW1 = prefix[n] - prefix[i];
      
      	int numR1 = n - (numR+numW+numW1);
      
      	// white and red exchange.
      	// remaining color the rest
      
      	int itne = min(numW,numR1);
      	
      	int rest = numW + numR1 - 2*itne;
      
      	ans = min(ans , itne + rest);
      
    }
  
  	cout << ans << endl;
  
  	return 0;
}


Measured memory_bytes: 4648
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

n = ni()
a = na()

st = []
ans = 0
gans = 0
for i in range(n):
    v = a[i]
    l = 0
    bst = []
    while len(st) > 0 and st[-1][1] < v:
        h = st.pop(-1)
        ans -= h[1] * h[2]
        if h[0] < v:
            h[0], h[1] = v, h[0]
        else:
            h[1] = v
        ans += h[1]*h[2]

        if len(bst) > 0 and bst[-1][0] == h[0] and bst[-1][1] == h[1]:
            bst[-1][2] += h[2]
        else:
            bst.append(h)
    st.extend(bst[::-1])
    st.append([v, 0, 1])
    gans += ans

print(gans)


Measured memory_bytes: 60252
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define pi 3.14159265359
#define ll long long

using namespace std;

int main()
{
    double r;
    cin >> r;
    double c = 2 * pi * r;
    cout << c << endl;
}

Measured memory_bytes: 3784
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

    public String next() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

    public long nextLong() {
      return Long.parseLong(next());
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

    public long[] nextLongArray(int n) {
      long[] a = new long[n];
      for (int i = 0; i < n; i++)
        a[i] = nextLong();
      return a;
    }
  }

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] a = sc.nextIntArray(m);
    int sum = 0;
    for (int ai : a) {
      sum += ai;
    }
    System.out.println(n >= sum ? n - sum : -1);
  }
}

Measured memory_bytes: 33904
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi 3.1415926535897932
int main()
{
ios_base::sync_with_stdio(false);
  cin.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
#endif

   double a,b,c,d;
  cin>>a>>b>>c>>d;

   double angle=(11*d/2)-30*c;

   double ans=sqrt(a*a+b*b-2*a*b*cos(angle*pi/180));
  cout<<fixed<<setprecision(10)<<ans<<endl;

  return 0;
}

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

#define endl '\n'

using namespace std;

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

	int n, x, ans;
	while(cin >> n >> x && n){
		ans = 0;
		for(int i = 1 ; i <= n ; i++){
			for(int j = i + 1, k ; j <= n ; j++){
				k = x - i - j;
				if(k > j && k <= n)
					ans++;
			}
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3216
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll memo[2020];
ll rec(ll rest){
    if(rest == 0) return 1;
    if(memo[rest] != -1) return memo[rest];
    ll res = 0;
    if(rest - 3 >= 0) res += rec(rest - 1);
    res %= MOD;
    if(rest - 3 >= 0) res += rec(rest - 3);
    res %= MOD;
    return memo[rest] = res;
    
}
int main(void){
    ll s;
    cin >> s;
    rep(i, 2020) memo[i] = -1;

    cout << rec(s) << endl;
}


Measured memory_bytes: 3520
#include <iostream>
using namespace std;
 
int main(){
 
    int a[26]={0},i=0;
    char s;
 
    while(i<1200&& cin >> s)
    {
               if('a'<=s && s<='z'){
            a[s-'a']++;
        }
        else if('A'<=s && s<='Z'){
            a[s-'A']++;
        }
 i++;
    }
 
    for(int i=0; i<26; i++){
        cout << (char)(i+'a') << " : " << a[i] << endl; 
  
       	 
   }
   return 0;
}

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

long long min(long long l, long long r){
    return l > r ? r : l;
}


int main(void){
    long long sum = 0, mi;
    int n;
    cin>>n;
    vector<long long> a(n);
    rep(i,n){
        cin>>a[i];
        sum += a[i];
    }
    long long l = a[0];
    mi = 1e10;
    rep(i,n-1){
        //cout<<a[i]<<" "<<sum-l<<" "<<l<<" "<<abs(sum - l - l)<<endl;
        mi = min(mi, abs(sum - l - l));
        l += a[i+1];
    }
    cout<<mi<<endl;

}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  int X[100] = {0};
  for (int i = 0; i <= N; i++) {
    string str = to_string(i);
    int a = str[0] - 48;
    int b = str[str.size() - 1] - 48;
    X[(10 * a) + b]++;
  }
  int ans = 0;
  for (int i = 0; i < 100; i++) {
    if (i % 10 == 0) {
      continue;
    }
    if (i < 10) {
      continue;
    }
    int e = ((i % 10) * 10) + ((i - i % 10) / 10);
    ans += X[i] * X[e];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

N = int(input())
X, Y, H = [0] * N, [0] * N, [0] * N

notzero = -1
for i in range(N):
    X[i], Y[i], H[i] = map(int, input().split())
    if H[i] != 0:
        notzero = i

def solve():
    for x in range(101):
        for y in range(101):
            cx, cy = x, y
            h = H[notzero] + abs(X[notzero] - cx) + abs(Y[notzero] - cy)
            ok = True
            for i in range(N):
                ok &= max(0, h - abs(X[i] - cx) - abs(Y[i] - cy)) == H[i]
            if ok:
                return cx, cy, h

print(*solve())

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

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

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

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

    int ans = 0;
    while (true) {
        if (A % 2 != 0 || B % 2 != 0 || C % 2 != 0) {
            std::cout << ans << std::endl;
            return 0;
        }

        const int a = B / 2 + C / 2; 
        const int b = C / 2 + A / 2; 
        const int c = A / 2 + B / 2; 
        ++ans;

        if (a == A && b == B && c == C) {
            std::cout << -1 << std::endl;
            return 0;
        }

        A = a;
        B = b;
        C = c;
    }


    return 0;
}


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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace
#define fi first
#define se second

#define all(n) (n).begin(), (n).end()
#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);	
    //cout << setprecision(15);
    ll n, k;
    cin >> n >> k;
    vll h(n);
    FOR(i, n) cin >> h[i];
    ll c = 0;
    FOR(i, n) c += h[i] >= k;
    cout << c << '\n';
}



Measured memory_bytes: 1024
import collections
 
 
def main():
    range = xrange
    input = raw_input
    from sys import stdin, stdout
 
    def read():
        return stdin.readline().rstrip('\n')
 
    def read_array(sep=None, maxsplit=-1):
        return read().split(sep, maxsplit)
 
    def read_int():
        return int(read())
 
    def read_int_array(sep=None, maxsplit=-1):
        return [int(a) for a in read_array(sep, maxsplit)]
 
    def write(*args, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in args) + end)
 
    def write_array(array, **kwargs):
        sep = kwargs.get('sep', ' ')
        end = kwargs.get('end', '\n')
        stdout.write(sep.join(str(a) for a in array) + end)
 
    N, Q = [int(x) for x in input().split()]
    updates1 = []
    updates2 = []
    for i in range(N):
        S, T, X = [int(x) for x in input().split()]
        updates1.append((S - X, X))
        updates2.append((T - X, X))
 
    active = []
    to_delete = collections.defaultdict(int)
    import heapq
    heapq.heapify(updates1)
    heapq.heapify(updates2)
    for _ in range(Q):
        x = int(input())
        while updates1 and updates1[0][0] <= x:
            coord, val = heapq.heappop(updates1)
            heapq.heappush(active, val)
 
        while updates2 and updates2[0][0] <= x:
            coord, val = heapq.heappop(updates2)
            to_delete[val] += 1
 
        while active and to_delete[active[0]] > 0:
            to_delete[active[0]] -= 1
            heapq.heappop(active)
        write(active[0] if active else -1)
 
main()


Measured memory_bytes: 120896
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cinttypes>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

static const long kMod = 1000000007;

int main()
{
    long n;
    cin >> n;

    vector<long> an(n);
    for(long& a : an){
        cin >> a;
    }

    long m0 = 0;
    for(int i = 0 ; i < n; i++){
        if(i % 2 == 0){
            m0 += an[i];
        } else {
            m0 -= an[i];
        }
    }

    cout << m0;
    long m_prev = m0;
    for(int i = 0 ; i < n - 1 ; i++){
        long m_next = 2 * an[i] - m_prev;
        cout << " " << m_next;
        m_prev = m_next;
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 2048
n = int(input())
a = []
for i in range(n-1):
	c,s,f = map(int, input().split())
	a.append([c,s,f])
ans = 0
while len(a) > 0:
	ans = 0
	for i, j, k in a:
		ans = max(ans, j)
		if ans%k != 0:
			ans += k - (ans%k)
		ans += i
	print (ans)
	a.pop(0)
print (0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}

const int INF = 100000; 

int main(){
    string a, b, c;
    cin >> a >> b >> c;

    if(a[a.size()- 1] == b[0] && b[b.size()- 1] == c[0]){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
n = int(input())
ll = [list(map(int,input().split())) for _ in range(n)]
import itertools as it
c,d = 0,0
for t in it.permutations(range(n)):
  c += 1
  for i in range(len(t)-1):
    d += ((ll[t[i+1]][1]-ll[t[i]][1])**2+(ll[t[i+1]][0]-ll[t[i]][0])**2)**.5
print(d/c)

Measured memory_bytes: 3188
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#define N_ 201000
#define SZ 262144
using namespace std;
int n, par[N_][20], Dep[N_], Num[N_], cnt, ReNum[N_], Ed[N_];
long long D[N_][2], Mod = 1000000007, po[N_];
vector<int>E[N_], V[N_], G[N_];
void DFS(int a, int d) {
	Num[a] = ++cnt;
	V[d].push_back(cnt);
	ReNum[cnt] = a;
	Dep[a] = d;
	int i;
	for (i = 0; i < 19; i++)par[a][i + 1] = par[par[a][i]][i];
	for (auto &t : E[a]) {
		par[t][0] = a;
		DFS(t, d + 1);
	}
	Ed[a] = cnt;
}
int LCA(int a, int b) {
	if (Dep[a] < Dep[b])return LCA(b, a);
	int d = Dep[a] - Dep[b], i = 0;
	while (d) {
		if (d & 1)a = par[a][i];
		d >>= 1; i++;
	}
	for (i = 18; i >= 0; i--) {
		if (par[a][i] != par[b][i])a = par[a][i], b = par[b][i];
	}
	if (a != b)a = par[a][0];
	return a;
}
int IT[SZ + SZ];
void Put(int b, int e, int x) {
	b += SZ, e += SZ;
	while (b <= e) {
		IT[b] = x;
		IT[e] = x;
		b = (b + 1) >> 1, e = (e - 1) >> 1;
	}
}
int Get(int x) {
	x += SZ;
	int r = 0;
	while (x) {
		r = max(r, IT[x]);
		x >>= 1;
	}
	return r;
}
int pp[N_], rt;
void Do(int a) {
	int p = Get(Num[a]);
	if (!p)rt = a;
	else G[ReNum[p]].push_back(a);
	Put(Num[a], Ed[a], Num[a]);
}
void Del(int a) {
	G[a].clear();
	Put(Num[a], Ed[a], 0);
}
void Go(int a) {
	if (G[a].empty()) {
		D[a][0] = D[a][1] = 1;
		return;
	}
	long long c[2] = { 1,0 }, s = 1;
	for (auto &x : G[a]) {
		Go(x);
		s = s * (D[x][0] + D[x][1]) % Mod;
		c[1] = (c[1] * D[x][0] + c[0] * D[x][1]) % Mod;
		c[0] = c[0] * D[x][0] % Mod;
	}
	D[a][0] = (s-c[1]+Mod)%Mod, D[a][1] = c[1];
}
int main() {
	int i, a, j;
	scanf("%d", &n);
	n++;
	po[0] = 1;
	for (i = 1; i <= n; i++)po[i] = po[i - 1] * 2 % Mod;
	for (i = 2; i <= n; i++) {
		scanf("%d", &a);
		E[a+1].push_back(i);
	}
	DFS(1, 0);
	long long res = 0;
	for (i = 0; i <= n; i++) {
		if (V[i].empty())continue;
		sort(V[i].begin(), V[i].end());
		set<int>P;
		for (auto &t : V[i])P.insert(t);
		for (j = 0; j < V[i].size() - 1; j++) {
			P.insert(Num[LCA(ReNum[V[i][j]], ReNum[V[i][j + 1]])]);
		}
		for (auto &t : P) {
			Do(ReNum[t]);
		}
		Go(rt);
		res = (res + po[n - V[i].size()] * D[rt][1]) % Mod;
		for (auto &t : P) {
			Del(ReNum[t]);
		}
	}
	printf("%lld\n", res);
}

Measured memory_bytes: 61568
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

template<typename T>
class BIT {
private:
  vector<T> bit;
  int n;
public:
  BIT(int _n) : n(_n) {
    bit = vector<T>(n+1, 0);
  }
  void add(int v, T a){ //0-indexed
    for(int x=v+1; x<=n; x += x&(-x)) bit[x] += a;
  }
  T sum(int v){ //0-indexed
    T ret=0;
    for(int x=v+1; x>0; x -= x&(-x)) ret += bit[x];
    return ret;
  }
  int lower_bound(T w){ //wテ、ツサツ・テ、ツクツ甘」ツ?ィテ」ツ?ェテ」ツつ凝ヲツ慊?・ツーツ湘」ツ?ョsumテ」ツ?ョテ、ツスツ催ァツスツョ(0-indexed)
    if(w<=0) return 0;
    int x=0, d=0;
    while(n > (1<<d)) d++;
    for(int k=(1<<(d-1)); k>0; k/=2){
      if(x+k<=n && bit[x+k]<w){
        w -= bit[x+k];
        x += k;
      }
    }
    return x;
  }
};

vector<int> ans;

long ask(int l, int r){
  cout << "? " << l << " " << r << endl;
  if(ans.size()>0){
    l--;
    long ret = 0;
    rep(i,l,r)rep(j,l,i) if(ans[j] > ans[i]) ret++;
    return ret;
  } else {
    long d;
    cin>>d;
    return d;
  }
}

int main(int argc, char* argv[]){
  if(argc>2){
    rep(i,1,argc) ans.pb(atoi(argv[i]));
    dbg(ans);
  }

  int n;
  cin>>n;

  vector<long> acc(n);
  acc[0] = 0;
  rep(i,1,n){
    acc[i] = ask(1,i+1);
  }
  vector<long> val(n);
  val[0] = 0;
  rep(i,1,n) val[i] = acc[i] - acc[i-1];

  BIT<int> bit(n+1);
  rep(i,n) bit.add(i+1,1);

  vector<int> res(n);
  for(int i=n-1; i>=0; i--){//dbg(i,val[i]);
    int idx = bit.lower_bound(i+1-val[i]);
    res[i] = idx;
    bit.add(idx, -1);
  }

  cout << "!";
  rep(i,n) cout << " " << res[i];
  cout<<endl;

  return 0;
}

Measured memory_bytes: 288896
import sys
input = sys.stdin.readline

N,M,V,P=map(int,input().split())
A=list(map(int,input().split()))

A.sort()

OK=N-P
NG=-1

while OK-NG>1:
    
    mid=(OK+NG)//2
    #print(OK,NG,mid)

    if (P-1)+mid+1>=V:
        if A[-P]<=A[mid]+M:
            OK=mid
        else:
            NG=mid

    else:
        V2=V-(P-1)-mid
        A2=A[mid:N-P+1]

        #print(V2,A2)

        BASE=A2[0]+M
        k=0

        if BASE<A2[-1]:
            NG=mid
            continue
            
        for a in A2[1:]:
            k+=(BASE-a)

        #print(k)

        if k<M*(V2-1):
            NG=mid
        else:
            OK=mid


print(N-NG-1)


Measured memory_bytes: 66200
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let n: usize = read(&mut stdin_lock, &mut buf, b'\n');

    let mut lv = vec![0u64; n + 1];
    lv[0] = 2;
    lv[1] = 1;
    for i in 2..n + 1 {
        lv[i] = lv[i - 1] + lv[i - 2];
    }
    println!("{}", lv[n]);
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

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

using namespace std;

int main() {
    vector<int> vec(5);
    vector<int> dif(5);
    for (int i = 0; i < 5; i++)
    {
        cin >> vec[i];
        int val = 10 - (vec[i] % 10);
        if (val == 10)
        {
            val = 0;
        }
        dif[i] = val;
    }

    int index = distance(dif.begin(), max_element(dif.begin(), dif.end()));
    //cout << index << endl;

    int ans = 0;
    for (int i = 0; i < 5; i++)
    {
        if (i == index)
        {
            ans += vec[i];
        }
        else
        {
            ans += vec[i] + dif[i];
        }
    }

    cout << ans << endl;
}

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

long gcd(long n, long m) {
	if (n == 0)return m;
	if (n < m)swap(n, m);
	return gcd(n % m, m);
}

int main() {
	int N; cin >> N;
	int w[110];
	int sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> w[i];
		sum += w[i];
	}
	int su2 = 0;
	int i = 0;
	while (su2+w[i] <= sum / 2) {
		su2 += w[i];
		i++;
	}
	int su3 = su2 + w[i];
	cout << min(su3 * 2 - sum, sum - 2 * su2);
}

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

using namespace std;
using ll = long long;

int main() {
  int k;
  cin >> k;
  if (1 <= k && k <= 9) {
    cout << k;
    return 0;
  }
  queue<ll> que;
  rep(i, 9) { que.push(i + 1); }
  ll cnt = 9;
  while (1) {
    ll x = que.front();
    if (x % 10 != 0) {
      que.push(10 * x + (x % 10) - 1);
      cnt++;
      if (cnt == k) {
        break;
      }
    }
    que.push(10 * x + (x % 10));
    cnt++;
    if (cnt == k) {
      break;
    }
    if (x % 10 != 9) {
      que.push(10 * x + (x % 10) + 1);
      cnt++;
      if (cnt == k) {
        break;
      }
    }
    que.pop();
  }
  cout << que.back() << endl;
  return 0;
}

Measured memory_bytes: 4144
import bisect

n = int(input())
aa = list(sorted(map(int, input().split())))
bb = list(sorted(map(int, input().split())))
cc = list(sorted(map(int, input().split())))

ans = 0
for b in bb:
    ax = bisect.bisect_left(aa, b)
    ci = bisect.bisect(cc, b)
    cx = len(cc) - ci
    ans += ax * cx
print(ans)


Measured memory_bytes: 29256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

const int N = 1e+5+5;
const int mo = 1e+9+7;

int a[N],m;
int f[N];

int dec(int x,int y){return x>=y?x-y:x+mo-y;}

int quickmi(LL x,int tim){LL ans=1;for(;tim;tim/=2,x=x*x%mo)if (tim&1)ans=ans*x%mo;return ans;}

int add(int x,int y){return x+y>=mo?x+y-mo:x+y;}

int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	fo(i,1,sqrt(n))
	if (n%i==0){
		a[++m]=i;
		if (n/i!=i)a[++m]=n/i;
	}
	sort(a+1,a+1+m);
	f[1]=k;
	fo(i,2,m){
		f[i]=quickmi(k,(a[i]+1)/2);
		fo(j,1,i-1)
		if (a[i]%a[j]==0)f[i]=dec(f[i],f[j]);
	}
	int ans=0;
	fo(i,1,m)
	if (a[i]&1)ans=add(ans,1ll*f[i]*a[i]%mo);
	else ans=add(ans,1ll*f[i]*a[i]/2%mo);
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  int n;
  cin >> n;
  vii a(3, vi(n));
  rep (i, n) {
    cin >> a[0][i] >> a[1][i] >> a[2][i];
  }
  vll dp(n + 1, vl(3, -INF));
  dp[0][0] = dp[0][1] = dp[0][2] = 0;
  rep (i, n) {
    rep (j, 3) {
      dp[i + 1][j] = max(dp[i][(j + 1) % 3], dp[i][(j + 2) % 3]) + a[j][i];
    }
  }
  cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
}
  


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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S; cin >> S;
    int D; cin >> D;
    S = '0' + S;
    int lenS = S.length();
    ll dp[lenS][D][2]{};
    dp[0][0][0] = 1;
    for(int i = 0; i < lenS-1; i++){
        int keta = S[i+1]-'0';
        for(int j = 0; j < D; j++){
            for(int smaller = 0; smaller <= 1; smaller++){
                for(int d = 0; d <= (smaller ? 9 : keta); d++){
                    dp[i+1][(j+d) % D][smaller || d<keta] += dp[i][j][smaller];
                    dp[i+1][(j+d) % D][smaller || d<keta] %= mod;
                }
            }
        }
    }
    ll ans = dp[lenS-1][0][0] + dp[lenS-1][0][1] - 1;
    if(ans < 0) ans += mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16000
#include <stdio.h>
#include <string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){
    if (ch == 'A') return 1;
    else if (ch == 'B') return 2;
    else if (ch == 'C') return 3;
    else if (ch == 'T') return 4;
    else return 0;
}

long long getKey(char str[]){
    long long sum = 0, p = 1, i;
    for(i=0;i<strlen(str);i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[]){
    long long key, i, h;
    key = getKey(str);
    for(i=0;;i++){
        h = (h1(key) + i*h2(key)) % M;
        if(strcmp(H[h], str)==0 ) return 1;
        else if (strlen(H[h]) == 0 ) return 0;
    }
    return 0;
}

int insert(char str[]){
    long long key, i, h;
    key = getKey(str);
    for(i=0;;i++){
        h = (h1(key) + i*h2(key)) % M;
        if(strcmp(H[h], str)==0 ) return 1;
        else if (strlen(H[h]) == 0 ) {
            strcpy(H[h],str);
            return 0;
        }
    }
    return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for(i=0;i<M;i++) H[i][0] = '\0';
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%s %s", com, str);
        if(com[0]=='i'){
            insert(str);
        }else{
            if(find(str)){
                printf("yes\n");
            }else{
                printf("no\n");
            }
        }
    }
    return 0;
}


Measured memory_bytes: 16056
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define RREP(i,n) for(int i = n - 1; i >= 0; i--)

#define ALL(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

#define UNIQUE(v) do{sort(v.begin(), v.end()); v.erase( unique(v.begin(), v.end()), v.end() );} while(0)


#define y0 y3487465
#define y1 y8687969

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

string S;

int main(){
  cin >> S;
  int ct = 0;
  int k = S.size();
  REP(i, k) {
    if(S[i] == 'o') {
      ct++;
    } 
  }
  if(15 - k + ct >= 8) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
// template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
// template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-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;
}



int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    unordered_map<ll,ll> m;
    ll sum=0;
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        m[A[i]]++;
        sum+=A[i];
    }

    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> B(Q);
    std::vector<long long> C(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
        ll b=B[i];
        ll c=C[i];
        m[c] += m[b];
        sum = sum - m[b]*b + m[b]*c;
        cout << sum << endl;
        m[b] = 0;
    }

    return 0;
}


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

using namespace std;

int K, N, S;
long long dp[105][64000];
long long MOD = 1e9+7;

long long add(long long a, long long b){
    return (a+b)%MOD;
}

long long mult(long long a, long long b){
    return (a*b)%MOD;
}

long long val(long long k){
    return max(K/(2*S-k+1), S*1LL) - max((K)/(2*S-k+2), S*1LL);
}

int main(){
    cin >> K >> N;
    S = (int) sqrt(K);
    for(int i = 1; i<=2*S; i++){
        if(i <= S){
            dp[1][i] = 1 + dp[1][i-1];
        }
        /*
        else if(i == S+1){
            if(K/S == S){
                dp[i][i] = 0;
            }
            else{
                dp[i][i] = mult(dp[1][i-1], val(i));
            }
        }
        */
        else{
            dp[1][i] = val(i) + dp[1][i-1];
        }
    }
    for(int i = 2; i<=N; i++){
        for(int l = 1, r = 2*S; l<=2*S; l++, r--){
            if(l <= S){
                dp[i][l] = dp[i-1][r];
            }
            /*
            else if(l == S+1){
                if(K/S == S){
                    dp[i][l] = 0;
                }
                else{
                    dp[i][l] = mult(dp[i-1][r], val(l));
                }
            }
            */
            else{
                dp[i][l] = mult(dp[i-1][r],  val(l));
            }
            dp[i][l] = add(dp[i][l-1], dp[i][l]);
        }
    }
    cout << dp[N][2*S] << endl;
}


Measured memory_bytes: 50944
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#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 FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
#define input(N) cin >> N ;

signed main() {
string S,T;
int a=0;
cin >> S >> T;
REP(i,S.size()){
    if(S.at(i)!=T.at(i)) a++;
}
answer(a);
return 0;
}


Measured memory_bytes: 3920
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  string s;
  cin >> n >> s;
 
  int num=0;
  if(n%2==0){
    for(int i=0; i<n/2; i++){
    if(s[i]==s[i+n/2]){
     num++;
    }
  }
     if(num==n/2){
       cout << "Yes" << endl;
     }
       else{
         cout << "No" << endl; 
       }
  }
  else{
    cout << "No" << endl;
  }
  
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

int main () {
  int n;
  cin >> n;
  vector<pll> ba(n);
  rep (i, n) {
    cin >> ba[i].second >> ba[i].first;
  }
  sort(all(ba));
  //  DEBUG_VEC(ba);
  ll now = 0;
  rep (i, n) {
    now += ba[i].second;
    if (now > ba[i].first) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3328
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

debug = True
#debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)

def solve():
    a, b = LI()
    c = max(a, b)
    d = min(a, b)

    if (c - d) % 2 == 1:
        print("IMPOSSIBLE")
        return

    print((c+d)//2)

solve()

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

int main(){
  string S;
  cin >> S;
  int len = S.size();
  int cnt = 0;
  for(int i = 0; i < len/2; i++){
    if(S[i] != S[len-1-i]){
      cnt++;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int pos(const string& s, const string& t, const vector<bool>& dir, int i) {
  int q = t.size();
  REP(j,q) {
    if (s[i] == t[j]) {
      if (dir[j]) {
        --i;
      } else {
        ++i;
      }
    }
  }
  return i;
}

int main()
{
  int n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  string t;
  vector<bool> dir(q);
  REP(i,q) {
    string c;
    string d;
    cin>>c>>d;
    t.push_back(c[0]);
    dir[i] = d[0] == 'L';
  }
  s = "$" + s + "$";
  int lo = 0;
  int hi = n+1;
  while (hi-lo > 1) {
    int mid = (hi+lo) / 2;
    if (pos(s, t, dir, mid) == 0) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  int left = lo;
  lo = 0;
  hi = n+1;
  while (hi-lo > 1) {
    int mid = (hi+lo) / 2;
    if (pos(s, t, dir, mid) == n+1) {
      hi = mid;
    } else {
      lo = mid;
    }
  }
  int right = n+1 - hi;
  cout << (n - left - right) << endl;
  return 0;
}


Measured memory_bytes: 1032