akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    p = LI()
    q = LI()
    a = 0
    b = 0
    k = 1
    for pe in permutations(range(1,n+1)):
        if list(pe) == p:
            a = k
        if list(pe) == q:
            b = k
        if a&b:
            break
        k += 1
    print(abs(a-b))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 41200
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <tuple>
#include <stdlib.h>
using namespace std;
typedef long long int ll;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
int  enum_div(long long int n)
{
	int ret = 1;
	long long int a = n;
	for (long long int i = 2; i*i <= n; ++i)
	{
		bool flag = true;
		if (n%i == 0)++ret;
		while (n%i == 0)
		{
			n /= i;
		}
	}
	if (n != 1)++ret;
	return ret;
}

int main()
{
	long long int A, B;
	cin >> A >> B;
	long long int g = gcd(A, B);
	int ans = enum_div(g);
	cout << ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a;
int ans;
int main(){
	cin>>a;
	for(int i=0;i<a.size();i++)
		ans+=a[i]-'0';
	if(ans%9==0)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3688
let N = stdin.ReadLine() |> int
let A = stdin.ReadLine().Split() |> Array.map int64

let rec solver money i =
    if i = N - 1 then money
    elif A.[i] < A.[i + 1] then
        let stocks = money / A.[i]
        solver (money + (A.[i + 1] - A.[i]) * stocks) (i + 1)
    else solver money (i + 1)

solver 1000L 0 |> stdout.WriteLine


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

typedef long long ll;

int main()
{
    string S;
    ll Q;
    cin >> S;
    cin >> Q;
    bool Rev = false;
    for (int i = 0; i < Q; ++i)
    {
        int T;
        cin >> T;

        if (T == 1)
        {
            Rev = !Rev;
        }
        else
        {
            int F;
            cin >> F;
            if (F == 1 xor Rev)
            {

                string C;
                cin >> C;
                S.insert(0, C);
            }
            else
            {

                char C;
                cin >> C;
                S.insert(S.end(), C);
            }
        }
    }
    if (!Rev)
    {
        cout << S << endl;
    }
    else
    {
        reverse(S.begin(), S.end());
        cout << S << endl;
    }
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
#define mp make_pair
#define fr front()
#define s second
#define f first
using namespace std;
string s;
map<string,bool>d,odw;
void dp(string s)
{
if(odw[s])return;
for(int i=1;i<s.size()-1;i++)
    {
    if(s[i-1]!=s[i+1])
        {
        string s2=s.substr(0,i);s2+=s.substr(i+1,s.size()-i-1);
        dp(s2);
        //fcout<<s2<<' '<<d[s2]<<'\n';
        if(d[s2]==0)
            {
            d[s]=1;
            break;
            }
        }
    }
odw[s]=1;
}
int main()
{
cin>>s;
if(s.size()<=10)
    {
    dp(s);
    if(d[s]==1)cout<<"First";
    else cout<<"Second";
    return 0;
    }
if(s.size()%2==0)
    {
    if(s[0]==s[s.size()-1]&&s.size()>2)cout<<"First";
    else cout<<"Second";
    }
else
    {
    if(s[0]==s[s.size()-1])cout<<"Second";
    else cout<<"First";
    }
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int[] s=new int[n];
		int l1;
		int l2;
		for(int i=1;i<n;i++){
			for(int j=i+1;j<n+1;j++){
				l1=j-i;
				int ix;
				int jy;
				if(x>=i){
					ix=x-i;
				}else{
					ix=i-x;
				}
				if(y>=j){
					jy=y-j;
				}else{
					jy=j-y;
				}
				l2=ix+jy+1;
				if(l1<l2){
					s[l1]++;
				}else{
					s[l2]++;
				}
			}
		}
		for(int i=1;i<n;i++){
			System.out.println(s[i]);
		}
	}
}


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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    int n,m;
    cin >> n >> m;
    int ans = 0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            ans++;
        }
    }
    for(int i=1;i<=m;i++){
        for(int j=i+1;j<=m;j++){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

template <typename T>
struct edge
{
    int src, to;
    T cost;
    edge(int to, T cost) : src(-1), to(to), cost(cost) {}
    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
    edge &operator=(const int &x)
    {
        to = x;
        return *this;
    }
    operator int() const { return to; }
};

template <typename T>
using Edges = vector<edge<T>>;

template <typename T>
using WeightedGraph = vector<Edges<T>>;

template <typename T>
using UnweightedGraph = vector<vector<T>>;

template <typename T>
using Matrix = vector<vector<T>>;

template <typename T>
pair<T, int> dfs(const WeightedGraph<T> &G, int v, int par)
{
    pair<T, int> res = {0, v};
    for (auto &e : G[v])
    {
        if (e.to == par)
            continue;
        auto dist = dfs(G, e.to, v);
        dist.first += e.cost;
        res = max(res, dist);
    }
    return res;
}

template <typename T>
T tree_diameter(const WeightedGraph<T> &G)
{
    auto p = dfs(G, 0, -1);
    auto q = dfs(G, p.second, -1);
    return q.first;
}

int main()
{
    int N;
    cin >> N;
    WeightedGraph<int> G(N);
    for (int i = 0; i + 1 < N; i++)
    {
        int x, y;
        cin >> x >> y;
        x--, y--;
        G[x].emplace_back(y, 1);
        G[y].emplace_back(x, 1);
    }
    cout << (tree_diameter(G) % 3 != 1 ? "First" : "Second") << "\n";
}

Measured memory_bytes: 26752
#include<bits/stdc++.h>
#include<map>
#include<vector>
#include<algorithm>
#include<set>
#include<ctime>
#include<cstdlib>
using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define c(n) cout << n << " ";
#define ci(n) cin >> n;
#define cn cout << "\n";
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define sc(a, n) int a[n]; for(int i = 0; i < n; i++) cin >> a[i];
#define scl(a, n) ll a[n]; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
using namespace std;

main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ic(n)
    vector<int> a(n);
    f(n) cin >> a[i];
    vector<int> ans;
    while(a.size() > 0)
    {
        bool flg = false;
        for(int i = a.size() - 1; i >= 0; i--)
        {
            if(a[i] == i + 1)
            {
                ans.pb(a[i]);
                a.erase(a.begin() + i);
                flg = true;
                break;
            }
        }
        if(flg == false)
        {
            cout << -1;
            return 0;
        }
    }
    for(int i = ans.size() - 1; i >= 0; i--) cout << ans[i] << " ";

}


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

int main(){
	long long H, W, x, y;
	cin >> W >> H >> x >> y;

	cout << setprecision(8) << ((double)(H * W) * 1.0 / 2) << " ";

	if (W == 0 || H == 0) cout << "1";
	else if (x * 2 == W && y * 2 == H) cout << "1";
	else cout << "0";

	return 0;
}


Measured memory_bytes: 256
def divisor(x):
  ret=[]
  for i in range(1,int(x**0.5)+1):
    if x%i==0:
      ret.append(i)
      if x//i==i:continue
      ret.append(x//i)  
  return set(ret)

a,b,k=map(int,input().split())
al=divisor(a)
bl=divisor(b)
cl=list(al & bl)
cl.sort(reverse=True)
print(cl[k-1])

Measured memory_bytes: 3064
#!/usr/bin/env python

import sys
import argparse
import logging
#import math

logging.basicConfig(filename='logger.log', level=logging.DEBUG)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)


def f(n: int, l_list: list, i: int = None, j: int = None, k: int = None) -> int:
    '''
    >>> f(0, [])
    0
    >>> f(1, [1])
    0
    >>> f(2, [1, 1])
    0
    >>> f(3, [1, 1, 1])
    0
    >>> f(3, [1, 1, 2])
    0
    >>> f(3, [1, 2, 2])
    0
    >>> f(3, [1, 2, 3])
    0
    >>> f(3, [1, 2, 4])
    0
    >>> f(3, [1, 3, 4])
    0
    >>> f(3, [2, 3, 4])
    1
    >>> f(5, [4, 4, 9, 7, 5])
    5
    >>> f(6, [4, 5, 4, 3, 3, 5])
    8
    >>> f(10, [9, 4, 6, 1, 9, 6, 10, 6, 6, 8])
    39
    '''
    if n <= 2:
        return 0
    result = 0
    for i in range(0, n-2):
        li = l_list[i]
        for j in range(i+1, n-1):
            lj = l_list[j]
            if li == lj:
                continue
            for k in range(j+1, n):
                lk = l_list[k]
                if li == lk or lj == lk:
                    continue
                #logger.debug("(n, i,j,k)=(%d, %d,%d,%d)" % (n, i, j, k))
                l_ijk = sorted([l_list[i], l_list[j], l_list[k]])
                if l_ijk[0] + l_ijk[1] > l_ijk[2]:
                    #logger.debug("yes")
                    result += 1
    return result


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument(
            '--doctest', action='store_true', default=False)
    args = parser.parse_args()
    if args.doctest:
        import doctest
        doctest.testmod(verbose=True)
        sys.exit()

    n = int(sys.stdin.readline().rstrip())
    l_list = list(map(lambda x: int(x), sys.stdin.readline().rstrip().split()))
    print(f(n, l_list))


Measured memory_bytes: 11912
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
	int n, x;
	cin >> n >> x;
	int cnt = 1, d = 0;

	for (int i = 0; i < n; ++i) {
		int l;
		cin >> l;
		d = d + l;

		if (d <= x) {
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<queue>
#define INF -1000000
#define F first
#define S second
using namespace std;

int N,imap[100010],MINE;
int dp[100010];
bool Init(){
  cin >> N;
  if(N == 0)return false;
  for(int i=0;i<N;i++){
    cin >> imap[i];
    dp[i] = 1<<29;
  }
  for(int i=N;i<100010;i++)dp[i] = 1<<29;
  MINE = 1<<29;
  return true;
}

int main(){
  //while(true){
  //if(!Init())break;
  Init();

  deque<int> que;
  que.push_front(0);
  dp[0] = 0;

  while(!que.empty()){
    int p = que.front();que.pop_front();
   
    if(p >= N-1){
      cout << dp[p] << endl;
      break;
    }
    if(imap[p] != 0){
      int np = p + imap[p];
      if(dp[np] <= dp[p])continue;
      dp[np] = dp[p];
      que.push_front(np);//飛ばされてきた場合を優先する
      continue;
    }
    for(int i=1;i<=6;i++){
      int np = p+i;
      if(dp[np] <= dp[p]+1)continue;
      dp[np] = dp[p]+1;
      que.push_back(np);
    }
  }
  //for(int i=1;i<N;i++)cout << "dp["<< i << "] = "  << dp[i] << endl;


  
  //}
  return 0;
}

Measured memory_bytes: 2000
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
	x=0;static char ch;static bool flag;flag = false;
	while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
	while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
#define rg register int
#define rep(i,a,b) for(rg i=(a);i<=(b);++i)
#define per(i,a,b) for(rg i=(a);i>=(b);--i)
const int maxn = 100010;
struct Edge{
	int to,next;
}G[maxn<<1];
int head[maxn],cnt;
void add(int u,int v){
	G[++cnt].to = v;
	G[cnt].next = head[u];
	head[u] = cnt;
}
int fa[maxn],g[maxn];
void dfs(int u){
	g[u] = 0;
	for(rg i = head[u],v;i;i=G[i].next){
		v = G[i].to;if(v == fa[u]) continue;
		fa[v] = u;dfs(v);
		g[u] ^= (g[v] + 1);
	}
}
int main(){
	int n;read(n);
	int u,v;
	rep(i,2,n){
		read(u);read(v);
		add(u,v);add(v,u);
	}dfs(1);
	puts(g[1] == 0 ? "Bob" : "Alice");
	return 0;
}


Measured memory_bytes: 7552
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const int INF = INT_MAX / 2;

int main()
{
    for(;;){
        int n, m;
        cin >> n >> m;
        if(n == 0)
            return 0;

        vector<int> a(n);
        for(int i=0; i<n; ++i)
            cin >> a[i];

        vector<int> x(1<<n, 0);
        for(int i=0; i<(1<<n); ++i){
            bitset<10> bs(i);
            for(int j=0; j<n; ++j){
                if(bs[j])
                    x[i] += a[j];
            }
        }

        vector<int> dp(m+1, INF);
        dp[0] = 0;

        for(int i=0; i<m; ++i){
            for(int j=0; j<(1<<n); ++j){
                int y = i + x[j];
                if(y <= m)
                    dp[y] = min(dp[y], dp[i] + 1);
            }
        }

        cout << dp[m] << endl;
    }
}

Measured memory_bytes: 1592
#include<iostream>

using namespace std;
char ans[205];
int main(){
    long long  N, R, m=0, now;
    long long  num  = 0;
    cin>>N>>R;
    	while(N){
		now = N % R;
		if(now <= 9){
			ans[m++] = '0' + now;    //ASCll表的运用
		}else{
			ans[m++] = 'A' + now - 10;
		}
		
		N /= R;
		
	}
	
	
	if(m == 0)
		cout<<0;
	
	for(int i=m-1; i>=0; i--)    //利用for循环把反序输出成正序
		num++;
		
		cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define M 1000000007
#define all(a) (a).begin(),(a).end()
#define rep(i,n) reps(i,0,n)
#define reps(i,m,n) for(int i=(m);i<(n);i++)
int main(){
  ll n;string s;cin>>n>>s;
  ll a=0LL;
  a+=(s[0]-'0')*100;a+=(s[2]-'0')*10;a+=(s[3]-'0');
  n*=a;n/=100;
  cout<<n;
}

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

using namespace std;

using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
ll n,k;

template <typename T>
T zero_sum_ranges(vector<T> A) {
    T n = A.size();
    T sum[n + 1] = {};
    sum[1] = A[0];
    map<T, T> mp;
    for(size_t i = 0; i < n; i++) {
        sum[i + 1] = (sum[i] + A[i]) % k;
    }
    T ret = 0;
    for(size_t i = 0; i <= n; i++) {
        if(mp.count(sum[i])) ret += mp[sum[i]];
        mp[sum[i]]++;
        if(i>=k-1){
            mp[sum[i-k+1]]--;
        }
    }
    return ret;
}

int main() {
    ll m, i, j;
    cin >> n >> k;
    vector<ll> A(n);
    for(i=0;i<n;i++){
        cin >> A[i];
        A[i]--;
    }
    cout << zero_sum_ranges(A) << endl;
    return 0;
}


Measured memory_bytes: 17408
S = input()
count1 = 0
count2 = 0
for i in range(len(S)):
    if i%2:
        if S[i] == '0':
            count1 += 1
        else:
            count2 += 1
    else:
        if S[i] == '1':
            count1 += 1
        else:
            count2 += 1
print(min(count1, count2))

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>

#include <cstdio>

using namespace std;

bool check(vector<int> const& covered_coord)
{
	int lim = covered_coord[0]+1;
	for(int i = 1; i < covered_coord.size() && i <= lim; i++){
		lim = max(lim, covered_coord[i]+1);
	}

	return lim == covered_coord.size();
}

int main(void)
{
	int n ,w, h;
	cin >> n >> w >> h;
	vector<int> x_covered(w, -1), y_covered(h, -1);

	for(int i = 0; i < n; i++){
		int x, y, koto;
		scanf("%d %d %d", &x, &y, &koto);

		int min_coord = max(0, -koto+x), max_coord = min(w-1, koto-1+x);
		x_covered[min_coord] = max(x_covered[min_coord], max_coord);

		min_coord = max(0, -koto+y), max_coord = min(h-1, koto-1+y);
		y_covered[min_coord] = max(y_covered[min_coord], max_coord);
	}

	cout << (check(x_covered) || check(y_covered) ? "Yes" : "No" ) << endl;

	return 0;
}

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	string a, b, c;
	cin >> a >> b >> c;

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


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a,b,c,n,i;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a,&b,&c);
		if(a*a+b*b==c*c || a*a+c*c==b*b || c*c+b*b==a*a)
			printf("YES\n");
		else
			printf("NO\n");

	}
	return 0;
}

Measured memory_bytes: 576
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
#include <cmath>
using namespace std;
#define MAXA 1001
#define MAXB 1001
#define MAXH 1000000001
#define MAXW 405
#define INF 5000
#define MAXN 51
#define MAXM 200001
#define MAXK 200002
#define MAXP 1000001
#define MOD 1000000007
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
ll N;
ll A[MAXN];


int main(){
    int n;
    cin >> n;
    string s[MAXN];
    for(int i = 0;i < n;i++){
        cin >> s[i];
    }
    map<char, int> m[MAXN];
    for(int i = 0;i < n;i++){
        for(int j = 0;j < s[i].length();j++){
            m[i][s[i][j]]++;
        }
    }
    map<char, int> ans;
    int res = 0;
    string best = "";
    for(char c = 'a';c <= 'z';c++){
        ans[c] = INF;
        for(int i = 0;i < n;i++){
            if(ans[c] > m[i][c]) ans[c] = m[i][c];
        }
        res += ans[c];
        for(int i = 0;i < ans[c];i++){
            best += c;
        }
    }
    cout << best << endl;

    
    return 0;
}

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

using namespace std;

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

	string ans = "No";
	for (int i = 1; i <= 5; i++) {
		t += "hi";
		if (s == t) {
			ans = "Yes";
			break;
		}
	}

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
//#include <iostream>
//#include <vector>
//#include <string>
using namespace std;
#define setc cin.tie(0);ios::sync_with_stdio(0)
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define contain(q) !q.empty()
#define cont(q) !q.empty()
//#define qpop(q, a, b) a=q.back().first;b=q.back().second;q.pop()
//#define pqpop(p, a, b) a=q.top().first;b=q.top().second;q.pop()
#define el "\n"
#define sp " "
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#define wildcard(T) numeric_limits<T>::min()

#define pb push_back
#define pq priority_queue
#define np next_permutation

#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
const unsigned int bf0 = (1 << 0);
const unsigned int bf1 = (1 << 1);
const unsigned int bf2 = (1 << 2);
const unsigned int bf3 = (1 << 3);
const unsigned int bf4 = (1 << 4);
const unsigned int bf5 = (1 << 5);
const unsigned int bf6 = (1 << 6);
const unsigned int bf7 = (1 << 7);

typedef long long lint;
typedef vector<int> ivec; typedef vector<string> svec;
typedef vector<vector<int>> ivvec;
typedef pair<int, int> P;

const int
	dx8[8] = { 0,1,1,1,0,-1,-1,-1 },
	dy8[8] = { 1,1,0,-1,-1,-1,0,1 },
	dx4[4] = { 0,1,0,-1 },
	dy4[4] = { 1,0,-1,0 };

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

vector<P> e;

bool cmp(P a, P b) {
	return a.first < b.first;
}

int main() {
	setc;

	lint n, m; cin >> n >> m;

	lint ain, bin;
	
	rep(i, m) {
		cin >> ain >> bin;
		e.pb({ ain,bin });
		e.pb({ bin,ain });
	}

	ivec a;//[0]から[n-2]までに、2からnまでが入っている
	repi_(i, 2, n)a.push_back(i);
	lint ans = 0;
	sort(all(e));

	bool f;
	do {
		f = 1;
		if (!binary_search(all(e), P(1, a[0])))f = 0;
		repi_(i, 1, n - 2)if (!binary_search(all(e), P(a[i - 1], a[i]))) {
			f = 0; break; }
		ans += f;
	} while (np(all(a)));
	co(ans);
	gc();
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
Aabs=list(map(abs,A))

fu=0
for i in range(N):
  if A[i]<0:
    fu+=1
if fu % 2 == 0:
  print(sum(Aabs))
else:
  print(sum(Aabs)-2*min(Aabs))

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

using namespace std;

#define mp make_pair
#define fi first
#define se second
typedef long long LL;

const int MAXN = 200000;
const int MAXQ = 200000;
int n, q;
int pos[MAXN + 5];

LL pre[MAXN + 5];
void fillPre() {
    pre[0] = 0;
    for (int i = 1; i < q + 2; ++i) {
        pre[i] = pre[i - 1] + abs(pos[i] - pos[i - 1]);
    }
}

const int treesize = 4 * MAXN;
pair<LL, LL> tree[treesize + 5];
const LL INF = 1000000000000LL;
void buildTree(int l, int r, int idx) {
    tree[idx] = mp(INF, INF);
    if (l == r) return;
    int mid = (l + r) >> 1;
    buildTree(l, mid, idx << 1);
    buildTree(mid + 1, r, (idx << 1) | 1);
}

void buildTree() {
    buildTree(1, n, 1);
}

pair<LL, LL> combine(pair<LL, LL> lVal, pair<LL, LL> rVal) {
    return mp(min(lVal.fi, rVal.fi), min(lVal.se, rVal.se));
}

void update(int l, int r, int idx, int pos, pair<LL, LL> val) {
    if (l == r) {
        assert(l == pos);
        tree[idx] = combine(tree[idx], val);
        return;
    }

    int mid = (l + r) >> 1;
    if (pos <= mid) {
        update(l, mid, idx << 1, pos, val);
    } else {
        update(mid + 1, r, (idx << 1) | 1, pos, val);
    }

    tree[idx] = combine(tree[idx << 1], tree[(idx << 1) | 1]);
}

void update(int pos, pair<LL, LL> val) {
    update(1, n, 1, pos, val);
}

// type == 0, first val
// type == 1, second val
LL query(int type, int l, int r, int idx, int queryL, int queryR) {
    if (queryL <= l && r <= queryR) {
        if (type == 0) {
            return tree[idx].fi;
        } else {
            return tree[idx].se;
        }
    }

    if (queryL > r || queryR < l) {
        return INF;
    }

    int mid = (l + r) >> 1;
    return min(query(type, l, mid, idx << 1, queryL, queryR),
        query(type, mid + 1, r, (idx << 1) | 1, queryL, queryR));
}

LL query(int type, int queryL, int queryR) {
    return query(type, 1, n, 1, queryL, queryR);
}

LL dp[MAXQ + 5];
LL findAns() {
    dp[q + 2] = 0;
    for (int i = q + 1; i >= 1; --i) {
        int a = i - 1;
        int b = i;
        dp[i] = pre[q + 1] - pre[b];
        dp[i] = min(dp[i], query(0, pos[a], n) - pre[b] - pos[a]);
        dp[i] = min(dp[i], query(1, 1, pos[a]) - pre[b] + pos[a]);
        update(pos[b], mp(dp[b] + pre[b - 1] + pos[b], dp[b] + pre[b - 1] - pos[b]));
    }

    return dp[1];
}

LL solve() {
    fillPre();
    buildTree();
    return findAns();
}

long long minimum_time(int N, int Q, int A, int B, vector<int> X) {
    n = N;
    q = Q;
    pos[0] = A;
    pos[1] = B;
    for (int i = 2; i < q + 2; ++i) {
        pos[i] = X[i - 2];
    }

    return solve();
}

int main() {
  int N, Q, A, B;
  scanf("%d %d %d %d", &N, &Q, &A, &B);

  std::vector<int> X(Q);
  for (int i = 0; i < Q; ++i) {
    scanf("%d", &X[i]);
  }

  printf("%lld\n", minimum_time(N, Q, A, B, X));
  return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n, h; read(n, h);
	multiset<int> m;
	int ma = 0;

	rep(i, 0, n) {
		int a, b; read(a, b);
		chmax(ma, a);
		m.insert(b);
	}

	int ans = 0;

	while (h > 0 && m.size() && *m.rbegin() > ma)
		h -= *m.rbegin(), ans++, m.erase(prev(m.end()));
	if (h > 0) ans += (h + ma - 1) / ma;

	die(ans);
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,v) for (int i = 0; i < v.size(); i++)
#define SORT(v) sort(v.begin(), v.end())
#define MIN_ELEMENT(v) min_element(v.begin(), v.end())
#define MAX_ELEMENT(v) max_element(v.begin(), v.end())
#define COUNT(v,n) count(v.begin(), v.end(), n);
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

vector<pair<int, int>> vp;
int num[111111];

int main()
{
    int n, q;
    string s;
    cin>>n>>q;
    cin>>s;

    REP(i,q) {
        int l, r;
        cin>>l>>r;
        vp.push_back({l-1, r-1});
    }

    REP(i,n) {
        num[i+1] = num[i];
        if (s[i] == 'A' && s[i+1] == 'C') {
            num[i+1]++;
        }
    }

    REP(i,q) {
        cout<<num[vp[i].second] - num[vp[i].first]<<endl;
    }

    return 0;
}


Measured memory_bytes: 2292
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;

#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(a) (a).rbegin(), (a).rend()

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ans = max(a*b, c*d);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll M,D;
    cin >> M >> D;
    ll count = 0;
    for (int i = 1; i <= M; ++i) {
        for (int j = 1; j <= D; ++j) {
            if(j%10>=2&&j/10>=2){
                if(i == (j%10)*(j/10))count++;
            }
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
#define NUM 1000000

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

int n, p;

bool prime[NUM];

int main(void) {
    for (int i = 0; i < NUM; i++) prime[i] = true;
    prime[0] = prime[1] = false;
    for (int i = 2; i * i <= NUM; i++) {
        if (prime[i]) {
            for (int j = 2; i * j <= NUM; j++) {
                prime[i*j] = false;
            }
        }
    }
    // 素数数列
    vector<int> P;
    for (int i = 2; i < NUM; i++) {
        if (prime[i]) P.push_back(i);
    }
//    for (int i = 0; i < 100; i++) {
//        if (prime[i]) cout << i << endl;
//    }
    while (cin >> n >> p) {
        if (n == -1 && p == -1) break;
        // nより大きい素数を挙げていく
        int index = 0;
        for (int i = 0; i < P.size(); i++) {
            if (n < P[i]) {
                index = i;
                break;
            }
        }
        vector<int> Q;
        for (int i = 0; i <= p; i++) {
            for (int j = i; j <= p; j++) {
                Q.push_back(P[index+i] + P[index+j]);
            }
        }
        sort(Q.begin(), Q.end());
        cout << Q[p-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 2568
import qualified Data.ByteString.Char8 as BS
import qualified Data.Map as Map
import Data.List

main = do
  n <- readLn :: IO Int
  xs <- map ((read :: String -> Int) . BS.unpack) . BS.words <$> BS.getLine
  let n2=n `div` 2
      xs2=group $ sort xs
      ys= take 2 $ filter (\e->snd e>=n2) $ zip (map head xs2) $ scanl1 (+) $ map length $ xs2
  print $ if length ys>1 && (snd (head ys))==n2 then (fst (ys!!1)) - (fst (ys!!0))  else 0

Measured memory_bytes: 16764
#include <bits/stdc++.h>
#include <vector>
using namespace std;
typedef pair<int, int> intint;

class dfs
{
private:
    int n_;
    vector<int> l_;
    vector<int> length_list_; ///最大要素数(2^16個)
    int a_, b_ , c_;

    int calc(vector<int> v){
        int res = 0;
        int a = 0, b = 0, c = 0;
        for (int i = 0; i < n_; i++) {
            switch(v[i]){
                case 0:
                    res += (a != 0) ? 10 : 0;
                    a += l_[i];
                    break;
                case 1:
                    res += (b != 0) ? 10 : 0;
                    b += l_[i];
                    break;
                case 2:
                    res += (c != 0) ? 10 : 0;
                    c += l_[i];
                    break;
            }
        }
        if(a == 0 || b == 0 || c == 0){
            res += 1000;
        }
        res += std::abs(a - a_) + std::abs(b - b_) + std::abs(c - c_);
        return res;
    }

public:
    dfs(int n, vector<int> l, int a, int b, int c) : n_(n), l_(l), a_(a), b_(b), c_(c) {
    }

    void create(int depth, vector<int> v){
        if(depth == n_) {
            length_list_.push_back(calc(v));
            return;
        }
        for(int i = 0; i < 4; i++)
        {
            v[depth] = i;
            create(depth + 1, v);
        }
    }

    int search(int total){
        int min = 10000000;
        for(auto x : length_list_){
            if(x < min)
                min = x;
        }
        return min;
    }
};

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

    vector<int> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }
    
    dfs df(n, l, a, b ,c);
    vector<int> v(n, 0);
    df.create(0, v);
    cout << df.search(a + b + c) << endl;
}

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



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


int gcd(int a, int b){
  int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

int main(void){
  int n;
  scanf("%d",&n);
  int a[n+10];
  a[0]=0;
  int b[n+10];
  for(int i=0;i<n+10;i++){
    b[i]=0;
  }
  int max=0;
  for(int i=1;i<n;i++){
    scanf("%d",&a[i]);
    int num=a[i];
    b[num-1]++;
  }
  for(int i=0;i<n;i++){
    printf("%d\n",b[i]);
  }
  return 0;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int min=*min_element(a, a+n);
  int max=*max_element(a, a+n);
  cout << max - min << endl;
}

Measured memory_bytes: 256
// finish date: 2018/01/20
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


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

    int N;
    cin >> N;
    vector<int> a(N);
    vector<bool> isPushed(N, false);
    rep(i, N) {
        cin >> a[i];
        a[i]--;
    }
    int pos = 0;
    int count = 0;
    while (!isPushed[pos]) {
        if (pos == 1) {
            cout << count << endl;
            return 0;
        }
        isPushed[pos] = true;
        pos = a[pos];
        count++;
    }

    cout << -1 << endl;


    return 0;
}


Measured memory_bytes: 640
from subprocess import*
with open('Main.java','w')as f:f.write(r"""
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		int max = 0;
		int gcd = 0;
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(sc.next());
			max = Math.max(max, a);
			gcd = gcd(gcd, a);
		}
		if (k <= max && k % gcd == 0)
			System.out.println("POSSIBLE");
		else
			System.out.println("IMPOSSIBLE");
	}
	static int gcd(int a, int b) {
		if(b == 0) return a;
		return gcd(b, a%b);
	}
}
""")
call(('javac','Main.java'))
call(('java','Main'))

Measured memory_bytes: 105060
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define PB pop_back 
#define pb push_back
#define mp make_pair
#define int long long
#define y1 y_golabi
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll; 
typedef map<int , int> mii;
typedef pair<int , int> pii; 
typedef map<string , int> msi;
typedef pair<int , string> pis; 
typedef pair<int , pair<int , int> > piii;
const int MAXN = 2e5 + 10;
pii p[MAXN];
int n , ans = 1 , cnt = 1 , mx = -1e9;
int32_t main()
{
	cin >> n;
	/*if(n == 1)
		return cout << 0 << endl , 0;*/
	for(int i = 0 ; i < n ; i ++)
		cin >> p[i].f , p[i].s = i;
	if(n == 1)
		return cout << 0 << endl , 0;
    sort(p , p + n);
    for(int i = 1 ; i < n ; i ++)
		cnt = (p[i].s > p[i - 1].s ? cnt + 1 : 1) , mx = max(mx , cnt);
    return cout << n - mx << endl , 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m,cnt=1;
cin>>n>>m;
if(m==1)
    cnt=0;
m-=n;
if(m>0)
{
    n--;
    cnt+=m/n;
    if(m%n>0)
        cnt++;
}

cout<<cnt<<endl;

return 0;
}


Measured memory_bytes: 256
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b = map(int, input().split())
    # 整数 N 個 (改行区切り)
    S = [int(input()) for i in range(n)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    Score = [[0] * 10001 for _ in range(n+1)]

    for i in range(n):
        for j in range(10001):
            if j+S[i]<=10000:
                Score[i+1][j+S[i]] = max(Score[i+1][j+S[i]], Score[i][j] + S[i])
            Score[i+1][j] = max(Score[i+1][j], Score[i][j])

    ansmax = 0
    for i in range(n+1):
        for j in range(10001):
            if Score[i][j] % 10 != 0:
                ansmax = max(ansmax, Score[i][j])

    print(ansmax)


resolve()

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define boost ios::sync_with_stdio(0); cin.tie(0);
#define int long long

const int N = 1e5 + 10;
const int mod = 1e9 + 7;

int32_t main(){
    boost;
    
    //code
    string s;
    cin >> s;

    for(int i = 0 ; i < s.size() ; ++i){
    	if(s[i] == ',')
    		s[i] = ' ';
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 256
/* ****devACE**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		ll n,i,j,k;
		cin>>n;
		ll a[n+1],b[n];
		for(i=0;i<=n;i++)cin>>a[i];
		for(i=0;i<n;i++)cin>>b[i];

		ll ct=0;
		for(i=0;i<n;i++){
			ll kills=min(a[i],b[i]);
			ct+=kills;
			a[i]-=kills;
			b[i]-=kills;

			kills=min(a[i+1],b[i]);
			ct+=kills;
			a[i+1]-=kills;
			b[i]-=kills;

		}	

		cout<<ct<<"\n";
	}
	return 0;
}

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

int main() {
  vector<int> a(9);
  rep(i, 3 * 3) {
    cin >> a[i];
  }

  vector<bool> is_bingo(9);

  int N;
  cin >> N;

  rep(i, N) {
    int b;
    cin >> b;
    rep(i, 3 * 3) {
      if (a[i] == b) {
        is_bingo[i] = true;
      }
    }
  }


  string ans = "No";
  rep(i, 3) {
    // 縦
    if (is_bingo[0 + i] && is_bingo[3 + i] && is_bingo[6 + i]) {
      ans = "Yes";
    }
    // 横
    if (is_bingo[3 * i] && is_bingo[3 * i + 1] && is_bingo[3 * i + 2]) {
      ans = "Yes";
    }
  }
  // 斜め
  if (is_bingo[0] && is_bingo[4] && is_bingo[8]) {
    ans = "Yes";
  }
  if (is_bingo[2] && is_bingo[4] && is_bingo[6]) {
    ans = "Yes";
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define variable
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector<pair<ll, ll>> prime_factorize(ll n)
{
  vector<pair<ll, ll>> p;
  for (ll i = 2; i * i <= n; i++)
  {
    if ((n % i) != 0)
      continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0)
    {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1)
    p.push_back(make_pair(n, 1));
  return p;
}
string alphabet() { return "abcdefghijklmnopqrstuvwxyz"; }

int main()
{
  string Sx, T;
  cin >> Sx >> T;

  string result = "";

  int idx = -1, count = 0;
  string t0 = T.substr(0, 1);

  /*****/
  repeat(i, Sx.length() - T.length() + 1) {
    repeat(j, T.length()) {
      string s1 = Sx.substr(i + j, 1);
      if (s1 == T.substr(j, 1) || s1 == "?") count += 1;
    }

		if (count == T.length()) idx = i;

		count = 0;
  }
  /****/
	bool is_exist = false;
  repeat(i, Sx.length()) {
    if (i == idx) {
      result += T;
      i += T.length() - 1;
			is_exist = true;
    } else {
      string s1 = Sx.substr(i, 1);
      if (s1 == "?") result += "a";
      else result += s1;
    }
  }

  cout << ((is_exist) ? result : "UNRESTORABLE") << endl;
  return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : (x))
#define all(x) x.begin(), x.end() // sort(all(x))
#define sz(x) (int)(x).size()
#define mp(x, y) make_pair((x), (y))

typedef long long ll;

typedef double T;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> tiii;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<T> vt;
typedef vector<vt> vvt;
typedef vector<pii> vpi;
typedef vector<pii> vpl;
typedef vector<vpi> graph;
typedef complex<T> Pt;
typedef pair<Pt, Pt> Line;

const ll MOD = 1e9 + 7; // 998244353;
const T EPS = 1e-10;
const int INF = 1e9 + 1;

/* Mod Library */

struct Mod {
    ll x;
    Mod (ll x = 0) : x(x) {}
    Mod operator+(Mod b) { return Mod((x + b.x)%MOD); }
    Mod operator-(Mod b) { return Mod((x - b.x + MOD)%MOD); }
    Mod operator*(Mod b) { return Mod((x * b.x)%MOD); }
    Mod operator/(Mod b) { return *this * inverse(b); }
    Mod operator%(Mod b) { return Mod(x % b.x); }

    static ll euclid(ll a, ll b, ll &x, ll &y) {
        if (b) {
            ll d = euclid(b, a%b, y, x);
            y -= a/b*x;
            return d;
        }
        x = 1; 
        y = 0;
        return a;
    }
    
    Mod inverse(Mod a) {
        ll x, y, g = euclid(a.x, MOD, x, y);
        assert(g == 1);
        return Mod((x + MOD)%MOD);
    }

    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this^(e/2);
        r = r*r;
        return e&1 ? *this*r : r;
    }
};

/* Input Library */
template <typename A, typename B>
istream& operator>>(istream &in, pair<A, B> &p) {
    in >> p.first >> p.second;
    return in;
}

template <typename A, typename B>
ostream& operator<<(ostream &out, pair<A, B> &p) {
    out << p.first << " " << p.second;
    return out;
}

template <typename I>
istream& operator>>(istream &in, vector<I> &a) {
    trav(i, a) in >> i;
    return in;
}

template <typename I>
ostream& operator<<(ostream &out, vector<I> &a) {
    rep(i, 0, sz(a)) {
        if (i) out << " ";
        out << a[i];
    }
    return out;
}

void fast_io() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    //cout.tie(0);
    cin.exceptions(cin.failbit);
} 

void solve_test() {
  int n; 
  cin >> n;
  map<ll, ll> cnt;
  ll sum = 0;
  for (int i = 0; i < n; ++i) {
    ll a;
    cin >> a;
    sum += a;
    cnt[a]++;
  }

  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum += cnt[b]*(c - b);
    cnt[c] += cnt[b];
    cnt.erase(b);
    cout << sum << endl;
  }
}

void setup() {
}

int main() {
    setup();
    srand(time(0));
    fast_io();
    int t = 1;
    //cin >> t;
    while (t--) {
        solve_test();
    }
}


Measured memory_bytes: 7592