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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

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

string find_same(string s, string t)
{
    string ans = "";
    int sl,tl;
    sl = s.length();
    tl = t.length();
    int sindex = 0;
    int tindex = 0;
    while(sindex<sl && tindex <tl)
    {
        if(s[sindex]==t[tindex])
        {
            ans.push_back(s[sindex]);
            sindex++; tindex++;
        }else
        {
            if(s[sindex]<t[tindex])
            {
                sindex++;
            }else
            {
                tindex++;
            }
        }
    }
    return ans;
}

int main()
{
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n)
    {
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
    }
    string temp = s[0];
    rep(i,n)
    {
        temp = find_same(temp, s[i]);
    }
    cout << temp << endl;


}

Measured memory_bytes: 256
// Created by proofbycontradiction on 2019-03-03 23:41.
#include <bits/stdc++.h>
#ifndef LOCAL
#define debug(...) 42
#endif
using namespace std;

#define int long long
#define endl '\n'
#define all(x) (x).begin(), (x).end()

using ii = pair<int, int>;
using vb = vector<bool>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvii = vector<vii>;

int32_t main() {
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n; cin >> n;
  vi h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }
  vi ans(n, std::numeric_limits<int>::max());
  ans[0] = 0;
  for (int i = 1; i < n; i++) {
    ans[i] = min(ans[i], ans[i-1] + abs(h[i] - h[i-1]));
    if (i > 1) {
      ans[i] = min(ans[i], ans[i-2] + abs(h[i] - h[i-2]));
    }
  }
  cout << ans[n-1] << endl;
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
}


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

int main(){
  int H, W;
  cin >> H >> W;

  vector<string> a(H);
  for(int i = 0; i < H; i++){
    cin >> a[i];
  }

  vector<bool> row(H, false); // row: 行
  vector<bool> column(W, false); // colimn: 列
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(a[i][j] == '#'){
        row[i] = true;
        column[j] = true;
      }
    }
  }

  int flag = 0;
  for(int i = 0; i < H; i++){
    flag = 0;
    for(int j = 0; j < W; j++){
      if(row[i] && column[j]){
        cout << a[i][j];
        flag = 1;
      }
    }
    if(flag){
      cout << endl;
    }
  }

  return 0;

}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
    def sum(self, i):  # 区間 [1, i]の和
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    def add(self, i, x):  # iにxを加算
        while i <= self.size:
            self.tree[i] += x
            i += i & -i  
    def pos(self, idx):  # idxの値を取得
        return self.sum(idx) - self.sum(idx-1)
    def lower_bound(self, w):  # w以上の値を持つ最小のidxを検索
        if w <= 0:
            return 0
        idx = 0
        k = 1
        while k*2 <= self.size:
            k *= 2
        while k > 0:
            if idx+k <= self.size and self.tree[idx+k] < w:
                w -= self.tree[idx+k]
                idx += k
            k //= 2
        return idx+1

S = input()
N = len(S)
b = Bit(N)
x = [1 if s == "W" else 2 for s in S]
ans = 0
for i in range(N):
	ans += i-b.sum(x[i])
	b.add(x[i], 1)
print(ans)


Measured memory_bytes: 76124
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    char s[8];
    while (atoi(fgets(s,8,stdin))) {
        *strchr(s,'\n')=0;
        int res=0;
        while (strcmp(s,"6174")) {
            sort(s, s+4);
            int S=atoi(s);
            reverse(s, s+4);
            int L=atoi(s);
            if (S==L) { res=-1; break; }
            res++;
            sprintf(s,"%04d",L-S);
        }
        if (res<0) puts("NA");
        else printf("%d\n",res);
    }
    return 0;
}

Measured memory_bytes: 1004
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
const ll bg = 1000000007;
#define ff(i,n) for(i=0;i<n;i++)
#define vv vector<vector<ll> >
vector<vector<ll> >master [31]; 
int main() 
{
	ll t;
	t=1;
	while(t--)
	{
		 ll x;
		 cin>>x;
		 if(x>=30)
		    cout<<"Yes";
		else
		    cout<<"No";		
	}
    return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  if(n<=111){
    printf("111\n");
  }else if(n<=222){
    printf("222\n");
  }else if(n<=333){
    printf("333\n");
  }else if(n<=444){
    printf("444\n");
  }else if(n<=555){
    printf("555\n");
  }else if(n<=666){
    printf("666\n");
  }else if(n<=777){
    printf("777\n");
  }else if(n<=888){
    printf("888\n");
  }else if(n<=999){
    printf("999\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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 main() {
  ll N, K, Q;
  cin >> N >> K >> Q;
  vector<ll> A(Q);
  vector<ll> seikai(N);
  rep(i, Q) {
    cin >> A[i];
    A[i]--;
    seikai[A[i]]++;
  }

  rep(i, N) {
    if (Q - seikai[i] < K)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
void PDF(vector < string >M)
{
    int c=0,k=0,s=0,t=0;
    for(int i=0;i<M.size();i++)
    {
        if(M[i] == "AC")
        {
            c++;
        }
        else if(M[i] == "WA")
        {
            k++;
        }
        else if(M[i] == "TLE")
        {
            s++;
        }
        else if(M[i]== "RE")
        {
            t++;
        }
    }
    printf("AC x %d\n",c);
    printf("WA x %d\n",k);
    printf("TLE x %d\n",s);
    printf("RE x %d\n",t);
}
int main()
{
    int n,i,j,l;
    string s;
    vector < string > M;
    cin >>n;
    for (i=0;i<n;i++)
    {
        cin >> s ;
        M.push_back(s);

    }
    PDF(M);
    return 0;
}


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



int main() {
    int H,A;
    cin>>H>>A;
    cout<<(H-1)/A+1<<endl;
    return 0;
}

Measured memory_bytes: 256
import fractions
from functools import reduce
import numpy as np
import sys

N, M = map(int, input().split())
an = list(map(int, input().split()))


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)


def listdivide(list):
    numpy = np.array(list)
    numpy = numpy//2
    return numpy.tolist()


def divide2(x):
    res = 0
    while x % 2 == 0:
        x /= 2
        res += 1
    return res


# while gcd_list(an) % 2 == 0:
#     print(gcd_list(an))
an = listdivide(an)

t = divide2(an[0])
for i in range(1, N):
    if divide2(an[i]) != t:
        print(0)
        sys.exit()

for i in range(t):
    an = listdivide(an)
    M = M // 2

LCM = lcm_list(an)

if LCM > M == 0:
    print(0)
else:
    print(-(-(M // LCM)//2))


Measured memory_bytes: 24216
#include <stdio.h>

int main(void)
{
	int i,x,y;
	int data[10];
	for(i=0;i<5;i++){
		scanf("%d",&data[i]);
	}
	x=data[0]*data[4];
	if(data[2]>=data[4]){
		y=data[1];
	}else{
		y=(data[4]-data[2])*data[3]+data[1];
	}
	if(x<=y){
		printf("%d\n",x);
	}else{
		printf("%d\n",y);
	}
	return 0;
}

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


int main()
{
   int k;
   cin >> k;
   if(k % 2 == 0)
   {
       cout << k/2 * k/2 << endl;
       return (0);
   }
   else
   {
       cout << (k-1)/2 * ((k-1)/2+1) << endl;
       return (0);
   }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 114514810;
const ll MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

struct union_find
{
	vector<int> par;
	union_find(int n) :par(n, -1) {}
	int find(int x) { return par[x] < 0 ? x : par[x] = find(par[x]); }
	void unite(int x, int y)
	{
		x = find(x); y = find(y);
		if (x == y) return;
		if (par[y] < par[x]) swap(x, y);
		if (par[x] == par[y]) par[x]--;
		par[y] = x;
		if (find(x) != find(y)) par[find(y)] = x;
	}
	bool same(int x, int y) { return find(x) == find(y); };
	int count()
	{
		int cnt = 0;
		REP(i, par.size()) if (par[i] < 0) cnt++;
		return cnt;
	}
};

int main()
{
	int h, w;
	while (cin >> h >> w, h)
	{
		union_find uft(h*w);
		vs fld(h);
		REP(i, h) cin >> fld[i];
		REP(i, h)REP(j, w)
		{
			REP(k, 4)
			{
				int nx = i + dx[k];
				int ny = j + dy[k];
				if (valid(nx, ny, h, w) && fld[i][j] == fld[nx][ny])
				{
					uft.unite(i*w + j, nx*w + ny);
				}
			}
		}
		cout << uft.count() << endl;
	}
	return 0;
}

Measured memory_bytes: 1268
# coding: utf-8

def showBuilding(buildings):
    for i, tou in enumerate(buildings):
        for wow in tou:
            for room in wow:
                print(' ' + str(room), end='')
            print()
        if i != 3:
            print('####################')


if __name__ == '__main__':
    
    buildings = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
    
    for _ in range(int(input())):
    
        b, f, r, v = map(int, input().split())
    
        if buildings[b - 1][f - 1][r - 1] + v >= 9:
            buildings[b - 1][f - 1][r - 1] = 9
        elif buildings[b - 1][f - 1][r - 1] + v < 0:
            buildings[b - 1][f - 1][r - 1] = 0
        else:
            buildings[b - 1][f - 1][r - 1] += v
    
    showBuilding(buildings)


Measured memory_bytes: 5632
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int ary[] = new int[n];        

        for (int i = 0; i < ary.length; i++) {
            ary[i] = sc.nextInt();
        }
        
        int i, j, tmp = 0;
        long sum = 0;
        // ソート
        for (i = 0; i < ary.length; i++) {
            for (j = i + 1; j < ary.length; j++) {
                
                if (ary[i] > ary[j]) {
                    tmp = ary[i];
                    ary[i] = ary[j];
                    ary[j] = tmp; // ary[i] をary[j]に入れる
                }                
            }
            sum += ary[i];
        }
        
        System.out.printf("%d %d %d%n", ary[0], ary[n-1],sum);
        
        

        sc.close();

    }


}


Measured memory_bytes: 42536
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


s = S()
n = len(s)

for i in range(n):
    if i % 2 == 0 and not s[i] in "RUD":
        print("No")
        exit()
    elif i % 2 == 1 and not s[i] in "LUD":
        print("No")
        exit()

print("Yes")

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

int main(){
  int n,k,ans=0;cin>>n>>k;
  vector<int> x(n,0);
  REP(i,n) cin>>x.at(i);
  sort(x.begin(),x.end(),greater<int>());
  REP(i,k) ans+=x.at(i);
  cout<<ans;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var k, s, count int
	fmt.Scan(&k, &s)

	for x := 0; x <= k; x++ {
		for y := 0; y <= k; y++ {
			z := s - x - y

			if z >= 0 && z <= k {
				count++
			}
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iostream>
#include <string>
#include <set>
#define X first
#define Y second
#define sqr(x) (x)*(x)
using namespace std;
const double PI = acos(-1.0);
map<int,int>::iterator it;
typedef long long LL ;
#pragma comment(linker,"/STACK:102400000,102400000")

const int N = 1005;
const int M = 20000006;
struct edge
{
    int u,v,pre;
} E1[M],E2[M];
int head[N],hd[N],nedge,cnt,dfn[N],low[N],instack[N],belong[N];
int n,m,tsp,qlen;
vector<int> qlt[N];
stack<int> S;

void init()
{
    for(int i=0; i<N; ++i)qlt[i].clear();
    memset(hd,-1,sizeof(hd));
    memset(head,-1,sizeof(head));
    memset(dfn,-1,sizeof(dfn));
    memset(instack,0,sizeof(instack));
    nedge=0;
    cnt=0;
    tsp=0;
    qlen=0;
    while(!S.empty())S.pop();
}
void add_edge(int u,int v)
{
    E1[nedge].u=u;
    E1[nedge].v=v;
    E1[nedge].pre=head[u];
    head[u]=nedge++;
}
void add_edge2(int u,int v)
{
    E2[cnt].u=u;
    E2[cnt].v=v;
    E2[cnt].pre=hd[u];
    hd[u]=cnt++;
}
void dfs(int u)
{
    //printf("u=%d\n",u);
    dfn[u]=low[u]=++tsp;
    S.push(u);
    instack[u]=1;
    //puts("ok");
    for(int e=head[u]; ~e; e=E1[e].pre)
    {
        //printf("e=%d\n",e);
        int v = E1[e].v;
        //printf("v=%d\n",v);
        if(dfn[v]==-1)
        {
            dfs(v);
            low[u]=min(low[v],low[u]);
        }
        else if(instack[v])
        {
            low[u]=min(low[u],dfn[v]);
        }
    }
    //printf("u=%d\n",u);
    if(dfn[u]==low[u])
    {
        int p = u;
        while(S.top()!=p)
        {
            qlt[qlen].push_back(S.top());
            belong[S.top()]=qlen;
            instack[S.top()]=0;
            S.pop();
        }
        qlt[qlen].push_back(p);
        belong[p]=qlen++;
        instack[p]=0;
        S.pop();
    }
}
LL dp[N];
int ind[N];
bool vis[N];
LL res;
LL mod = 1000000007LL;
void dfs2(int u)
{
    bool dfsed=false;
    dp[u]=1;
    for(int e=hd[u]; ~e; e=E2[e].pre)
    {
        int v = E2[e].v;
        dfs2(v);
        dp[u]*=dp[v];
        dp[u]%=mod;
        dfsed=true;
    }
    ++dp[u];
}
void gao()
{
    memset(vis,0,sizeof(vis));
    memset(dp,0,sizeof(dp));
    memset(ind,0,sizeof(ind));
    for(int i=0; i<nedge; ++i)
    {
        if(belong[ E1[i].u ]!=belong[ E1[i].v ])
        {
            ind[ belong[ E1[i].u ] ]++;
            add_edge2(belong[ E1[i].v ],belong[ E1[i].u ]);
        }
    }
    res=1;
    for(int i=0; i<qlen; ++i)
    {
        if(ind[i]==0)
        {
            dfs2(i);
            res *= dp[i];
            res %= mod;
        }
    }
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        init();
        for(int i=0; i<m; ++i)
        {
            int u,v;
            scanf("%d%d",&u,&v);
            add_edge(u,v);
        }
        for(int i=1; i<=n; ++i)if(dfn[i]==-1)dfs(i);
        gao();
        //for(int i=0; i<qlen; ++i)printf("%d: %lld %lld\n",i,dp[i][0],dp[i][1]);

        printf("%lld\n",res);
    }
    return 0;
}

Measured memory_bytes: 3360
while True:
    n = int(raw_input())
    if n == 0:
        break
    a=[]
    for i in range(n):
        a.append(int(raw_input()))
    max = -1e10
    for i in range(len(a)):
        sum = 0
        for j in range(i,len(a)):
            sum += a[j]
            if sum > max:
                max = sum
    print max

Measured memory_bytes: 4496
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N, K;  cin >> N >> K;
  int d[K];
  int a;
  int sunuke_flag[100]={0};
  int answer = 0;
  for(int i = 0; i < K; i++){
    cin >> d[i];
    for(int j = 0; j < d[i]; j++){
      cin >> a;
      sunuke_flag[a-1]=1;
    }
  }
  for(int i = 0; i < N; i++){
    if(sunuke_flag[i] == 0)	answer++;
  }
  cout << answer << endl;
}

Measured memory_bytes: 3192
#include<iostream>
#include<vector>
#include<math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;

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

    vector<pair<int, int>> a(m);
    rep(i, m) cin >> a[i].first >> a[i].second;
    rep(i, m) a[i].first--;

    vector<int> res(n, 0);
    bool exist = true;

    rep(i, m){
        if (n != 1 && a[i].first == 0 && a[i].second == 0) exist = false;
        if (res[a[i].first] != 0 && res[a[i].first] != a[i].second) exist = false;
        res[a[i].first] = a[i].second;
    }
    int ans = 0;
    if (n != 1 && res[0] == 0) res[0] = 1;
    rep(i, n){
        // cout << res[i] << endl;
        ans += res[i] * pow(10, n-i-1);
    }

    if(exist) cout << ans << endl;
    else cout << -1 << endl;

    return 0;
}

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

int main() {
  char a, b;
  cin >> a >> b;
  if(a == b)
    cout << '=' << endl;
  if(a > b)
    cout << '>' << endl;
  if(a < b)
    cout << '<' << endl;
  
  //cout << (  ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>

using namespace std;

#define mp make_pair
#define pb push_back
#define st first
#define nd second

typedef long long ll;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef pair<ll,ll> pll;

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ans = (k % 2 == 0) ? a - b : b - a;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int K = 3;
			
			long[][] benefits = new long[N][K];
			for(int i = 0; i < N; i++) {
				for(int j = 0; j < K; j++) {
					benefits[i][j] = sc.nextLong();
				}
			}
			
			final long[][] DP = new long[N][3];
			for(int j = 0; j < K; j++) {
				DP[0][j] = benefits[0][j];
			}
			
			for(int i = 1; i < N; i++) {
				for(int j = 0; j < K; j++) {
					for(int k = 0; k < K; k++) {
						if(j == k) { continue; }
						
						DP[i][j] = Math.max(DP[i][j], DP[i - 1][k] + benefits[i][j]);
					}
				}
			}
			
			System.out.println(Arrays.stream(DP[N - 1]).max().getAsLong());
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

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

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

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 53704
#include <bits/stdc++.h>
 
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------

int main(){
 ll n,m,sum=0,ans=0;
 cin>>n>>m;
 vll a(n);
 rep(i,n){
     cin>>a.at(i);
     sum+=a.at(i);
 }
 double bar = sum/(4.0*m);
 rep(i,n){
     
     if(a.at(i)>=bar)ans++;
 }
 if(ans>=m)cout<<"Yes"<<endl;
 else cout<<"No"<<endl;
 
}
   



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



#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)

using namespace std;

template <class T>
using vec = std::vector<T>;
typedef long long ll;
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; }

const long long INF = 1LL<<60;

const double PI = acos(-1.0);

int lcm(int a,int b){
    //最小公倍数
    return a/__gcd(a,b) * b;
}

struct edge{int from, to,cost;};

// int型の2次元配列(3×4要素の)の宣言
// vector<vector<int>> data(3, vector<int>(4));

long  double a,b;
ll res;

int main()
{
    cin>>a>>b;
    res=floor(a*b);
    cout<<res<<endl;
    return 0;

}




Measured memory_bytes: 3728
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, S: str):
    seq = []
    if(S[0] == '0'): seq.append(0)
    f = S[0]
    c = 1
    for i in range(1, N):
        if(S[i] == f):
            c += 1
        else:
            seq.append(c)
            f = S[i]
            c = 1
    seq.append(c)
    
    rseq = [0] * (len(seq)+1)
    for i in range(1,len(seq)+1):
        rseq[i] = rseq[i-1] + seq[i-1]

    ans = 0
    # cumulative sum
    for i in range(len(rseq)):
        # print(ans, rseq[min(len(rseq)-1,i*2+2*K+2)], rseq[min(len(rseq)-1, i*2)])
        ans = max(ans, rseq[min(len(rseq)-1,i*2+2*K+1)] - rseq[min(len(rseq)-1, i*2)])


    # naive
    # for i in range(len(seq)):
    #     for j in range(K):
    #         # print(seq[i*2:i*2+2*K+1])
    #         ans = max(ans, sum(seq[i*2:i*2+2*K+1]))

    print(ans)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    S = str(next(tokens))  # type: str
    solve(N, K, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 8180
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int N=2e6+1000;
const LL P=1e9+7;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(int x){
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
inline int gcd(int a,int b) {
    int r;
    while(b>0) {
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int n,m;
int a[N];
int p[N];
vector<int> v;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		scanf("%d",&a[i]);
	}
	for(LL i=2;i<=1000000;++i){
		if(p[i]==0){
			v.push_back(i);
			for(LL j=i*i;j<=1000000;j+=i){
				p[j]=1;
			}
		}
	}
	int x,y,flag=1;
	for(int i=1;i<=n&&flag;++i){
		x=a[i];y=0;
		while(v[y]<=sqrt(x)){
			if(x%v[y]==0){
				p[v[y]]++;
				if(p[v[y]]>1) {
					//cout<<v[y]<<endl;
					flag=0;
				}
				while(x%v[y]==0){
					x=x/v[y];
				}
			}
			else ++y;
		}
		if(x>1){
			++p[x];
			if(p[x]>1) {
				flag=0;
				//cout<<x<<endl;
			}
		}
	}
	if(flag==1){
		cout<<"pairwise coprime"<<endl;
		return 0; 
	}
	int ans=a[1];
	for(int i=2;i<=n;++i) ans=gcd(ans,a[i]);
	if(ans>1) cout<<"not coprime"<<endl;
	else cout<<"setwise coprime"<<endl;
	return 0;
}

Measured memory_bytes: 11724
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>

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

using namespace std;
using ll = long long int;

int main(void) {
    int n; cin >> n;
    map<string, int> mp;
    REP(i, n) {
        string s; cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for (auto i = mp.begin(); i != mp.end(); i++) {
        mx = max(mx, i->second);
    }
    for (auto i = mp.begin(); i != mp.end(); i++) {
        if (i->second == mx) cout << i->first << endl;
    }
}

Measured memory_bytes: 25216
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}

int32_t main()
{
    IOS
    
      

    int m,d;
    cin>>m>>d;
    int count=0;
    for(int i=1;i<=m;++i)
    {
        for(int j=10;j<=d;++j)
        {
            int x=j%10,y=j/10;
            if(x*y==i and x>=2 and y>=2)
                count++;
        }
    }
    cout<<count;

}

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

int main(){
  int n;
  cin >> n ;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }

  vector<int> b(n);

  b = a;

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

  for(int i = 0; i < n; i++){
    if(b.at(i) == a.at(n - 1)){
      cout << a.at(n - 2) << endl;
    }
    else{
      cout << a.at(n - 1) << endl;
    }
  }

}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using P = pair<int, int>;
void prp(P& p) {cout << p.first << " " << p.second << endl;}
int n, m;
int ans;
arr<int> G;
vector<bool> seen;
void dfs(int k, int len, vector<bool> see){
    see[k] = true;
    if(len==n) {ans++; return;}

    for(int i: G[k]){
        if(see[i]) continue;
        dfs(i, len+1, see);
    }
}   
int main()
{
    cin >> n >> m;
    G.resize(n);
    rep(i, m){
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    ans = 0;
    seen.assign(n, false);
    vector<bool> see(n, false);
    dfs(0, 1, see);
    pr(ans);
    return 0;}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;

int n,num;
unsigned long long ans=0;
int fa[100010];
struct zhk1{int f,t,val;}b[200010];
struct nancy{int id,x,y;}a[100010];

inline int get_num()
{
	int now=0;int fh=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')fh=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){now=(now<<3)+(now<<1)+ch-'0';ch=getchar();}
	return now*fh;
}

inline bool cmp(zhk1 a,zhk1 b){return a.val<b.val;}
inline bool cmp1(nancy a,nancy b){return a.x<b.x;}
inline bool cmp2(nancy a,nancy b){return a.y<b.y;}

inline int find(int x)
{
	if(fa[x]==x)return x;
	return fa[x]=find(fa[x]);
}

inline void merge(int x,int y)
{
	int fx=find(x);
	int fy=find(y);
	fa[fy]=fx;
}

int main()
{
	n=get_num();
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=n;i++)
	{
		a[i].x=get_num();
		a[i].y=get_num();
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmp1);
	for(int i=2;i<=n;i++)
	{
		b[++num].f=a[i-1].id;
		b[num].t=a[i].id;
		b[num].val=abs(a[i].x-a[i-1].x);
	}
	sort(a+1,a+n+1,cmp2);
	for(int i=2;i<=n;i++)
	{
		b[++num].f=a[i-1].id;
		b[num].t=a[i].id;
		b[num].val=abs(a[i].y-a[i-1].y);
	}
	sort(b+1,b+num+1,cmp);
	for(int i=1;i<=num;i++)
	{
		if(find(b[i].f)!=find(b[i].t))
		{
			merge(b[i].f,b[i].t);
			ans+=b[i].val;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 4096
using System;
class Program
{
	static void Main(string[] args)
	{
	   string[] DeerPenkiS = Console.ReadLine().Split(' ');
	   int[] DeerPenkiI = new int[DeerPenkiS.Length];
	   for(int i = 0; i < DeerPenkiS.Length; i++)
	   {
	      DeerPenkiI[i] = int.Parse(DeerPenkiS[i]);
	   }
	   int result = 0;
	   int[] Penki = new int[101];
	   for(int i = 0; i < DeerPenkiI.Length; i++)
	   {
	      int dpi = DeerPenkiI[i];
	      if(Penki[dpi] == 0)
	      {
	         result++;
	         Penki[dpi] = dpi;
	      }
	   }
	   Console.WriteLine(result);
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FOR(i) for(cin>>i;i>0;i--)
#define elif else if
#define pb push_back
#define ll long long
#define mp make_pair
#define all(x) x.begin(),x.end()
#define re(x) {cout<<x<<endl;return 0;}
//#define x first
//#define y second

using namespace std;
int n,k=0;
double d;
int main()
{
	cin>>n>>d;
	rep(i,n)
	{
		double a,b;
		cin>>a>>b;
		if(sqrt(a*a+b*b)<=d) k++;
	}
	re(k)
	return 0;}

Measured memory_bytes: 3796
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll N = 5;

    ll a;
    ll ans;
    rep(i, N){
        sll(a);
        if(a==0){
            ans = i + 1;
        }
    }

    cout << ans <<endl;

}

int main(){
    Main();
}

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { -1,  0, 1, 0,  1, -1,  1, -1};
static const int dy[8] = {0,  1, 0,  -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
//const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;

int N,M;
int maxd;
int ans;
int G[10][10];
vector<int> st;
vector<int> rest;
vector<pii> match;


bool get_input(){
    scanf("%d",&N);
    if(N == 0) return false;
    MEM(G,0);
    scanf("%d",&M);
    st.clear();
    rest.clear();
    match.clear();
    _for(i,0,N){
        rest.PB(N-1);
        st.PB(0);
    }

    _for(i,0,M){
        int x,y;
        scanf("%d %d",&x,&y);
        x--;y--;
        G[x][y] = (G[y][x] = 1);
        rest[x]--;rest[y]--;
        st[x]++;st[y]--;
    }
    _for(i,0,N){
        _for(j,i+1,N){
            if(!G[i][j]){
                match.PB(MP(i,j));
            }
        }
    }
    maxd = match.size();
    ans = 0;

    return true;
}

bool ok(int a){
    int k = abs(st[a]);
    if(rest[a] < k) return false;
    return true;
}

bool can(){
    _for(i,0,N){ if(st[i]) return false;}
    return true;

}

void searching(int d){
    //cout << rest <<endl;
    //cout << st << endl;
    if(d == maxd){
        if(can())++ans;
        return;
    }

    pii m = match[d];
    int a = m.fst;
    int b = m.scd;
    rest[a]--;rest[b]--;
    st[a]++;st[b]--;
    if(ok(a) && ok(b)){
        searching(d+1);
    }

    st[a]-=2;st[b]+=2;
    if(ok(a) && ok(b)){
        searching(d+1);
    }
    rest[a]++; rest[b]++;
    st[a]++;st[b]--;
}


int main()
{
    //freopen("out.txt","w",stdout);
    while(get_input()){
        searching(0);
        cout << ans << endl;


    }
    return 0;
}



Measured memory_bytes: 3220
#include <stdio.h>
int main(void){
    // Your code here!
    int a, N, max = 0, min = 1000000000;
    scanf("%d",&N);
    for(int i = 0; i < N; i++)
    {
        scanf("%d",&a);
        if(a > max) max = a;
        if(a < min) min = a;
    }
    printf("%d\n",max - min);
}


Measured memory_bytes: 128
abm=list(map(int, input().split())) 
a=list(map(int, input().split())) 
b=list(map(int, input().split())) 
answer=min(a)+min(b)
for i in range(abm[2]):
    xyc=list(map(int, input().split())) 
    answer00=a[xyc[0]-1]+b[xyc[1]-1]-xyc[2]
    if answer00<answer:
        answer=answer00
print(answer)

Measured memory_bytes: 18736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void start(){
std::ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
}
int main(){
     start();
     ll n;
     cin>>n;
    vector<ll>v(n),ans;
    for(ll &c : v)cin>>c;
    for(int i = -100 ; i <= 100 ; i++){
        ll sum = 0;
        for(int j = 0 ; j < n ; j++){
            sum+= ( v[j] - i ) * ( v[j] - i ) ;
        }
        ans.push_back(sum);
    }
    sort(ans.begin(),ans.end());
    cout<<ans[0]<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Solve{
    public Solve(){}
    public static int Main(){
        new Solve().Calc();
        return 0;
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        long E = long.Parse(str[1]);
        long T = long.Parse(str[2]);
        long[] x = new long[N];
        str = Console.ReadLine().Split(' ');
        for(int i=0;i<N;i++){
            x[i] = long.Parse(str[i]);
        }
        long[] dp = new long[N];
        long m = -2 * x[0];
        int p = -1;
        for(int i=0;i<N;i++){
            while(2 * x[p+1] + T < 2 * x[i]){
                p++;
                if(p != 0){
                    m = m > dp[p-1] - 2 * x[p] ? dp[p-1] - 2 * x[p] : m;
                }
            }
            if(p == -1){
                dp[i] = T;
            }
            else{
                dp[i] = T + dp[p] < 2 * x[i] + m ? T + dp[p] : 2 * x[i] + m;
            }
        }
        Console.WriteLine(E+dp[N-1]);
    }    
}

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

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

  int a[3*n];

  for (int i=0; i<3*n; i++) {
    cin >> a[i];
  }

  sort(a, a+3*n, greater<int>());

  long long sum=0;
  for (int i=1; i<2*n; i+=2) {
    sum += a[i];
  }

  cout << sum << endl;

}


Measured memory_bytes: 1408
N = int(input())
A = [int(input()) for i in range(N)]
A.sort(reverse=True)
count = 0

for i in range(N):
    for j in range(i+1,N):
        if A[i] == A[j] and A[i]!=0:
            A[j] = 0
            count += 1
        
print(len(A)-count)


Measured memory_bytes: 3060
package main

import "fmt"

func main() {
	var x int
	fmt.Scan(&x)
	ans := 0
	switch {
	case 400 <= x && x <= 599:
		ans = 8
	case 600 <= x && x <= 799:
		ans = 7
	case 800 <= x && x <= 999:
		ans = 6
	case 1000 <= x && x <= 1199:
		ans = 5
	case 1200 <= x && x <= 1399:
		ans = 4
	case 1400 <= x && x <= 1599:
		ans = 3
	case 1600 <= x && x <= 1799:
		ans = 2
	case 1800 <= x && x <= 1999:
		ans = 1
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1768
#include <stdio.h>

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

	int a,b;
	char op;

	while(1) {

		scanf("%d %c %d", &a, &op, &b);

		if( op == '?' ) break;

		switch (op) {
		case '+':
			printf("%d\n", a+b);
			break;
		case '-':
			printf("%d\n", a-b);
			break;
		case '*':
			printf("%d\n", a*b);
			break;
		case '/':
			printf("%d\n", a/b);
			break;
		}
	}

	return 0;

}

Measured memory_bytes: 600
# include <iostream>
using namespace std; 
int main(){
 long long int n,i,temp,a,t,b;
  long long int sum; 
 long long int mod=1e5;
  cin>>n; 
  int ar[n];
  int arr[mod+1]={0};
  sum=0;
  for(i=0;i<n;i++){
    cin>>ar[i];
    sum=sum+ar[i];
    arr[ar[i]]++;
  }
  cin>>t; 
  while(t--){
    cin>>a>>b; 
    if(arr[a]>0){
      temp=(b-a);
      sum=sum+((arr[a])*temp); 
      arr[b]+=arr[a];
      arr[a]=0;
    }
    cout<<sum; 
    cout<<"\n";
  }
  return 0;
}

Measured memory_bytes: 4392
#include<iostream>
#include<queue>
using namespace std;
const int maxx=105;
static const int INFTY = (1<<21);
#define WHITE 0
#define GRAY 1
#define BLACK 2
int graph[maxx][maxx];
int color[maxx];
int n;

int d[maxx];//通过距离管理访问状态
 
void bfs(int u)
{
	queue<int> q;
	q.push(u);
	
	int s;
	 
	for(int i=0;i<n;i++)
	{
		d[i]=INFTY;
	}
	d[u]=0; 
	while(!q.empty())
	{
		s=q.front();
		q.pop();
		for(int v=0;v<n;v++)
		{
			if(graph[s][v]==0)
				continue;
			if(d[v]!=INFTY)
				continue;
			d[v]=d[s]+1;
			q.push(v);
		}
	}
	for(int i=0;i<n;i++)
	{
		cout<<i+1<<" "<<(d[i]==INFTY?(-1):d[i])<<endl;
	}	
}
int main()
{
	cin>>n;
	int i,j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
			graph[i][j]=0;
	}
	for(i=0;i<n;i++)
	{
		int index,nn;
		cin>>index>>nn;
		for(j=0;j<nn;j++)
		{
			int ee;
			cin>>ee;
			graph[index-1][ee-1]=1;
		}
	}
	bfs(0);
	return 0;
}


Measured memory_bytes: 3136
#include <stdio.h>
int n,ans;
char s[30000];
int pos[10][30000],size[10];
bool ok(int i,int j,int k){
    if(size[i]==0||size[j]==0||size[k]==0) return false;
    int pivot=-1;
    for(int a=0;a<size[j];a++){
        if(pos[j][a]>pos[i][0]){
            pivot=pos[j][a];
            break;
        }
    }
    if(pivot==-1) return false;
    for(int b=0;b<size[k];b++){
        if(pos[k][b]>pivot){
            return true;
        }
    }
    return false;
}
int main(){
    for(int i=0;i<=9;i++){
        size[i]=0;
    }
    scanf("%d",&n);
    scanf("%s",&s);
    for(int i=0;i<n;i++){
        int num=s[i]-'0';
        pos[num][size[num]]=i;
        size[num]++;
    }
    for(int i=0;i<=9;i++){
        for(int j=0;j<=9;j++){
            for(int k=0;k<=9;k++){
                if(ok(i,j,k)) ans++;
            }
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 1876
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int x,n;
  cin >> x >> n;
  vi d(102);
  rep(i,n) {
    int p;
    cin >> p;
    d.at(p) = 1;
  }
  int ans = 100000;
  int mn = 100000;
  drep(i,102) {
    if(d.at(i) == 1) continue;
    if(abs(x-i) <= mn) {
      ans = i;
      mn = abs(x-i);
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
const int N = 1e5+10;
int mypow(int p, int q) {
	int ret = 1;
	while (q > 0) {
		if (q%2) ret = (1ll*ret*p) % MOD;
		p = (1ll*p*p) % MOD;
		q /= 2;
	}
	return ret;
}
int inv(int p) {
	return mypow(p,MOD-2);
}
int fact(int x) {
	int ret = 1;
	for (int i=1;i<=x;i++) ret = (1ll * ret * i) % MOD;
	return ret; 
}
int main() {
	int h,w,a,b;
	scanf("%d %d %d %d",&h,&w,&a,&b);
	int t = 1ll * (1ll * fact(w+h-a-2) * inv(fact(h-a-1)) % MOD) * inv(fact(w-1)) % MOD;
	int u = 1;
	int ans = 0;
	for (int i=0;i<w-b;i++) {
		//printf("%d %d\n",t,u);
		ans = (1ll*ans + (1ll*t * u) % MOD) % MOD;
		u = 1ll*(1ll*u*(a+i) % MOD) * inv(i+1) % MOD;
		t = 1ll*((1ll*t*inv(w+h-a-2-i)%MOD)*(w-1-i))%MOD;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
N,M,K = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = [0]
d = [0]

a.each do |x|
  c << c[-1] + x
end

b.each do |x|
  d << d[-1] + x
end

ans = 0

c.each_with_index do |x,i|
  break if x > K
  while d[M] > K - x
    M -= 1
  end
  ans = [ans,i + M].max
end

puts ans

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

using namespace std;

int main(){
  int N,K,Only1;
  cin >> N >> K ;
  if ( N == 1 ){
    cin >> Only1;
    cout << Only1 << endl;
  }else{ 
  
  vector<int> nedan(N);
  for (int i = 0; i < N; i++){
    cin >> nedan.at(i);
  }
  
  sort(nedan.begin(),nedan.end());
  
  int goukei = 0;
  for (int i = 0; i < K; i++){
    goukei = goukei + nedan.at(i);
  }
  
  cout << goukei << endl;
  }
}


Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<pi> vpi;

#define debugone(x) cerr << #x << " " << x << endl;
#define debugtwo(x) cerr << #x << "-------------" << endl;for(auto &it: x) cerr << it << " ";cerr << endl;
#define debugthree(x, i, j) cerr << #x << "------------" << endl;cerr << "from " << i << " to " << j << endl;for(int k=i; k<=j; k++) cerr << x[k] << " ";cout << endl;

typedef tuple<ll, ll, ll> triple;


ll g(ll n){
	switch (n % 4){
		case 0 : return n;
		case 1 : return 1;
		case 2 : return n + 1;
		default : return 0;
	}
}

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	ll a, b;
	cin >> a >> b;
	cout << (g(b) ^ g(max(a - 1, 0LL))) << endl;
}		

Measured memory_bytes: 256