akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var nm = ReadIntArray();
            var n = nm[0];
            var m = nm[1];
            var r = new int[n, n];
            var edge = new Tuple<int, int>[m * 2];
            for (int i = 0; i < m; i++)
            {
                var abc = ReadIntArray();
                var a = abc[0] - 1;
                var b = abc[1] - 1;
                var c = abc[2];
                r[a, b] = c;
                r[b, a] = c;
                edge[i * 2] = Tuple.Create(a, b);
                edge[i * 2 + 1] = Tuple.Create(b, a);
            }
            var count = 0;
            for (int i = 0; i < n; i++)
            {
                var cost = Enumerable.Repeat(1001, n).ToArray();
                cost[i] = 0;
                for (int j = 0; j < n; j++)
                {
                    for (int k = 0; k < edge.Length; k++)
                    {
                        if (cost[edge[k].Item1] > cost[edge[k].Item2] + r[edge[k].Item1, edge[k].Item2])
                        {
                            cost[edge[k].Item1] = cost[edge[k].Item2] + r[edge[k].Item1, edge[k].Item2];
                        }
                    }
                }
                for (int j = 0; j < n; j++)
                {
                    if (i != j && cost[j] < r[i, j])
                        count++;
                }
            }
            Console.WriteLine(count / 2);
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}


Measured memory_bytes: 13372
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define p(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1<<25

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

int dy[8]={1,1,1,0,0,-1,-1,-1};
int dx[8]={-1,0,1,-1,1,-1,0,1};
struct S{
	int a,b,c;
};
bool asc(const S& left,const S& right){
	return left.c > right.c;
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	char X,Y;
	cin>>X>>Y;
	if(X>Y)cout<<">"<<endl;
	else if(X==Y)cout<<"="<<endl;
	else cout<<"<"<<endl;
	return 0;
}



Measured memory_bytes: 256
def main():
    N = int(input())
    A = map(int, input().split())

    ans = 0
    for i, x in enumerate(A, start=1):
        if (i & 1) and (x & 1):
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 9104
N = int(input())
red = [list(map(int, input().split())) for _ in range(N)]
blue = [list(map(int, input().split())) for _ in range(N)]
ans = 0
red = sorted(red, key = lambda x: -1 * x[1])
blue = sorted(blue)
for b in blue:
	for r in red:
		if r[0] < b[0] and r[1] < b[1]:
			ans += 1
			red.remove(r)
			break
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

typedef long long int ll;
#define REP(i, I, N) for (ll i = I; i < N; ++i)
#define rep(i, N) REP(i, 0, N)

int main() {
    int A, P;
    cin >> A >> P;
    int ans = 0;
    P += A * 3;
    ans = P / 2;

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


Measured memory_bytes: 256
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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 DEBUG_VLL(vec) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vll d(n); REP(i, n) cin >> d[i];
    ll ans = 0;
    for (int i=0; i<n; i++) {
        for (int j=i+1; j<n; j++) {
            ans += d[i]*d[j];
        }
    }
    cout << ans << '\n';
    return 0;
}


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

int main(){
    int N,tmp;
    int min_x = 101; int max_x = -1;
    cin >> N;
    vector<int> X(N);
    for(int i = 0;i < N;i++){
        cin >> tmp;
        X[i] = tmp;
        max_x = max(max_x,tmp);
        min_x = min(min_x,tmp);
    } 
    int min_cost = INT_MAX;
    for(int j = min_x;j <= max_x;j++){
        int cost_tmp = 0;
        for(int i = 0;i < N;i++){
            cost_tmp += pow(X[i]-j,2);
        }
        min_cost = min(min_cost,cost_tmp);
    }
    cout << min_cost << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  ll N, M;
  ll sum = 0;
  cin >> N >> M;
  vector<ll> a(N);

  rep(i, N){
    cin >> a[i];
    sum += a[i];
  } 
  // ここまで入力


  int cnt = 0;
  int b;
  if (sum%(4*M) == 0) b = sum/(4*M);
  else b = sum/(4*M) + 1;

  // cout << b << " " << sum << endl;
  sort(a.begin(), a.end());
  rep(i, N){
    if(a[i] >= b) cnt++;
  }
  
  if (cnt >= M) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n+1];
        for (int i=0; i<n; ++i) {
            a[i] = sc.nextInt();
        }
        int Max = a[0];
        int ans = 1;
        for (int i=1; i<n; ++i) {
            if (a[i]>=Max) {
                ++ans;
            }
            Max = Math.max(Max, a[i]);
        }
        System.out.println(ans);
    }
}


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

int main()
{
	string S; cin >> S;
	vector<int> v;
	for (unsigned int i = 0; i < S.length(); ++i)
		v.push_back(i);

    int cnt = 0;
    bool operate = true;
    // int len;
    while(true)
    {
    	operate = false;
    	// len = S.length();
    	// for (int i = 0; i < len-1; ++i)
    	// {
    	// 	operate = false;
    	// 	if (S[v[i]] != S[v[i+1]])
    	// 	{	
    	// 		auto itr = v.begin();
    	// 		v.erase(itr + i);
    	// 		v.erase(itr + i);
    	// 		cnt += 2;
    	// 		operate = true;
    	// 	}
    	// }
    	if (S.size() == 0)
    		break;

    	for (auto itr = S.begin(); itr != S.end()-1; ++itr)
    	{

    		if (*itr != *(itr+1))
    		{
    			S.erase(itr, itr+2);
    			cnt += 2;
    			operate = true;
    			break;
    		}
    	}
    		if (!operate)
    			break;
    }

	cout << cnt << endl;
}

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

int main(){
	
	unsigned long long a,b,x;
	scanf("%llu %llu %llu",&a,&b,&x);
	unsigned long long i;
	unsigned long long m,n;
	
	if(b-a<x){
		if(a%x==0||b%x==0){
			printf("1\n");
		}else{
			printf("0\n");
		}
	}else{
		if(a%x==0){
			m=a/x;
		}else{
			m=(a+x-a%x)/x;
		}
		
		if(b%x==0){
			n=b/x;
		}else{
			n=(b-b%x)/x;
		}
		
		printf("%llu\n",n-m+1);
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  std::map<std::string, int> m = {
    {"SUN", 7},
    {"MON", 6},
    {"TUE", 5},
    {"WED", 4},
    {"THU", 3},
    {"FRI", 2},
    {"SAT", 1},
  };
  std::string S; std::cin >> S;
  std::cout << m[S] << std::endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{	
	int a[10] = {};
	int i = 0;
	while (cin >> a[i]) {
		i++;
		if (i == 10)break;
	}
	int max;
	for (int j = 0; j < 3; j++) {
		max = j;
		for (int k = j + 1; k < 10; k++) {
			if (a[max] < a[k]) {
				max = k;
			}
		}
		cout << a[max] << endl;
		a[max] = 0;
	}
	return 0;
}


Measured memory_bytes: 3076
import sys
for line in sys.stdin:
    po = [int(i) for i in line.split(",")]
    l = [0]
    for i in range(10):
        l.append(l[-1] + po[i])
    v1,v2 = po[10:]
    t = l[-1] / (v1+v2)
    for i in range(10):
        if l[i] < v1*t < l[i+1]:
            print(i+1)
            break
        elif l[i] == v1*t:
            print(i)
            break


Measured memory_bytes: 5608
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;

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

  int size = s.size();

  for (int i = 0; i < size/2; i++) {
    if (s[i] != s[size-(i+1)]) {
      cout << "No" << endl;
      return 0;
    }
  }

  int condition_2 = ((size-1)/2);
  for (int i = 0; i < condition_2/2; i++) {
    if (s[i] != s[condition_2-(i+1)]) {
      cout << "No" << endl;
      return 0;
    }
  }

  for (int i = ((size+3)/2)-1; i < size; i++) {
    if (s[i] != s[size-(i+1)]) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>){
    val N = readLine()!!.toInt()
    var a: Array<Int> = readLine()!!.split(' ').map { it -> it.toInt() }.toTypedArray()

    val e = a.filter { it -> it!! % 2 == 0 }
    var size = e.size
    var ea: Array<Int?> = arrayOfNulls(size)
    for (j in 0 until size){
        ea[j] = e.get(j)
    }

    size = ea.size

    ea.sort()
    var p2c = 0
    for (k in size downTo  1) {
        while (ea[k - 1]!! % 2 == 0) {
            p2c++
            ea[k - 1] = ea[k - 1]!! / 2
        }
    }

    println(p2c)
}

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

int main() {
	bool f = true;
	bool f1 = false;
	bool f9 = false;
	bool f7 = false;
	bool f4 = false;
	for (int i = 0; i < 4; i++) {
		int x;
		cin >> x;
		if (x == 1 && f1 == false)f1 = true;
		else if (x == 9 && f9 == false)f9 = true;
		else if (x == 7 && f7 == false)f7 = true;
		else if (x == 4 && f4 == false)f4 = true;
		else f = false;
	}
	if (f)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

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


def solve(N: int, s: "List[str]"):
    x = 0
    a = 0
    b = 0
    for i in s:
        if(i[0] == 'B' and i[-1] == 'A'):
            x += 1
        elif(i[-1] == 'A'):
            a += 1
        elif(i[0] == 'B'):
            b += 1
    
    
    ####   AC1   #####    
    # if(x == 0):
    #     ans1 = min(a,b)
    # else:
    #     ans1 = max(0,x-1)+min(a,b)
    #     if(a > 0 or b > 0):
    #         ans1 += 1
    
    #####    AC2   ####
    ans1 = max(0,x-1) + min(a,b)
    if((a > 0 or b >0) and x > 0):
        ans1 += 1
    
    ####   WA    #############
    # ans1 = max(0,x-1) + min(a,b)
    # if(x != 0):
    #     ans1 += 1 
    

    ans1 = max(0,x-1) 
    if(a == b):
        ans1 += min(a,b)
        if((a > 0 or b > 0) and x != 0):
            ans1 += 1
    else:
        if(x == 0):
            ans1 += min(a,b)
        elif(a > 0 or b > 0):
            ans1 += min(a,b)+1 

    ans2 = 0
    for i in s:
        ans2 += i.count('AB')

    print(ans1+ans2)
    
    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
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, s)

if __name__ == '__main__':
    main()


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

int main() {
	int n;cin>>n;
	int ans=0;
	int a,b,c;
	a=n/100;
	b=(n%100)/10;
	c=n%10;
	if(a==1){
		a=9;
	}else if(a==9){
		a=1;
	}
	if(b==1){
		b=9;
	}else if(b==9){
		b=1;
	}
	if(c==1){
		c=9;
	}else if(c==9){
		c=1;
	}
	cout<<100*a+10*b+c<<endl;
	return 0;
}

Measured memory_bytes: 256
a = gets.split.map(&:to_i)
tmp1 = 0
tmp1 += a[0] / 2 * 2
tmp1 += a[3] / 2 * 2
tmp1 += a[4] / 2 * 2
tmp2 = 0
if a[0] > 0 && a[3] > 0 && a[4] > 0
    tmp2 += 3
    a[0] -= 1
    a[3] -= 1
    a[4] -= 1
end
tmp2 += a[0] / 2 * 2
tmp2 += a[3] / 2 * 2
tmp2 += a[4] / 2 * 2
ans = [tmp1, tmp2].max + a[1]
p ans

Measured memory_bytes: 1788
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1100000000;
constexpr long long LLINF = 1100000000000000000LL;
constexpr long long MOD = 1000000007;

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

bool check(vector<int>& v, int a, int b)
{
  swap(v[a], v[b]);

  for (int i = 0; i < v.size(); i++) {
    if (v[i] != i) {
      swap(v[a], v[b]);
      return false;
    }
  }
  swap(v[a], v[b]);
  return true;
}

int main()
{
  int N;
  cin >> N;
  vector<int> p(N);
  REP(i, N) {
    cin >> p[i];
    p[i]--;
  }
  for (int i = 0; i < N; i++) {
    for (int j = i; j < N; j++) {
      if (check(p, i, j)) {
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;

  return 0;
}


Measured memory_bytes: 256
N,Y=map(int,input().split())
for x in range(N+1):
    for y in range(N+1):
        z=N-x-y
        if z>=0 and 10000*x+5000*y+1000*z==Y:
            print(x,y,z)
            exit()

print(-1,-1,-1,sep=" ")


Measured memory_bytes: 9096
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int main() {
	int X;
	int max=0;
	cin >> X;
	if (X == 1) {

		cout << 1;
		return 0;
	}
	int tmp=1;
	for (int i=2; i < 1000; i++) {
		tmp = 1;
		if (X / i < i) {
			break;
		}
		for (int j = 0; j < 1000;j++) {
			if (max < tmp) {
				max = tmp;
			}
			tmp *= i;
			if (tmp>X) {

				break;
			}
		}
	
	}
	cout << max;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

#define mod 1000000000000000000

int main(){
	int n;
	cin >> n;
	long long int arr[n], son = 0;
	bool flag = true, zero = false;
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		if(arr[i] == 0){
			zero = true;
		}
	}	
	son = arr[0];

	if(zero){
		cout << 0;
		return 0;
	}

	else{
		for(int i = 1; i < n; i++){
			if(arr[i] > mod / son){
				flag = false;
				break;
			}
			else{
				son = son * arr[i];
			}
		}

		if(flag){
			cout << son;
		}
		else{
			cout << -1;
		}
	}
} 

Measured memory_bytes: 4404
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

typedef long long ll;

void add_mod(ll& val, ll add_val) {
	val = (val + add_val) % 100000007;
}

int main (int argc, char* argv[]) {
	int n;
	cin >> n;
	double nn = n;
	cout << ((n & 1) ? (n / 2 + 1) / nn : 0.5) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
  long long W,H;
  cin>>W>>H;
  long long x,y;
  cin>>x>>y;
  double a;
  if((W*H)%2==0){
    a=0;
    if(W%2==0&&H%2==0&&W/2==x&&H/2==y){
      cout<<W*H/2+a<<' '<<1<<endl;
    }
    else cout<<W*H/2+a<<' '<<0<<endl;
  }
  else{
    a=0.5;
    cout<<W*H/2+a<<' '<<0<<endl;
  }
}

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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }


/*
--------------------------------------------

	type

--------------------------------------------
*/
using LL = long long;
using ULL = unsigned long long;
//using pair<T1, T2> = p12;

/*
--------------------------------------------

	container

--------------------------------------------
*/
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())

/*
--------------------------------------------

	repetition

--------------------------------------------
*/
#define REP(n) for(int i=0; i<n; i++)
#define REPj(n) for(int j=0; j<n; j++)
#define REPinit(a,n) for(int i=a; i<n; i++)
#define REPinitj(a,n) for(int j=a; j<n; j++)

//algorithm
//#define SORT(c) sort((c).begin(),(c).end())

/*
--------------------------------------------

	constant

--------------------------------------------
*/
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

/*

	Optimizer

*/
//#pragma GCC optimize("Ofast")


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

	string S, T;
	cin >> S >> T;
	cout << T << S << endl;	

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<endl
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  srand((unsigned)time(NULL));
  int T;
  R T;
  ll n=26;
  ll c[n];
  rep(i,n) R c[i];
  ll a[T][n];
  rep(i,T)rep(j,n) R a[i][j];
  ll d[n];
  mem(d);
  ll ans=0;
  rep(k,T) {
    ll M=-MAX,x=0;
    ll s=0;
    rep(i,n) s+=d[i]-c[i];
    rep(i,n) {
      ll z=s-(d[i]-c[i])+a[k][i];
      if(M<z) {
        M=z;
        x=i;
      }
    }
    pr(x+1);
    rep(i,n) d[i]-=c[i];
    d[x]=0;
  }
}

int main(){Main();return 0;}


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

int main(void){
 int n=0;
 char gomi[10];
 
  scanf("%d",&n);
  scanf("%c",&gomi);
  
  
  char str[n];
    gets(str);
    
   int  ans=n;

    for(int i=0;i<n;i++){
        if(strncmp(&str[i],&str[i+1],1)==0){
        //    printf("ans=%d\n",ans);
         ans=ans-1;
         
        }
         

    }
    printf("%d",ans);

}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>

using namespace std;

bool ok(char x[], int p, char y[]) {
  for (int i = 0; x[p + i] && y[i]; i++) {
    if (x[p + i] != y[i] && x[p + i] != '?' && y[i] != '?') {
      return false;
    }
  }
  return true;
}

void genxy(char x[], char y[], vector<int>& xy, int wtf) {
  int i = 0;
  while (true) {
    if (!x[i]) {
      while (i <= wtf) {
        xy.push_back(i++);
      }
      break;
    }
    if (ok(x, i, y)) {
      xy.push_back(i);
    }
    ++i;
  }
}

int calc(char a[], char b[], char c[]) {
  vector<int> ab, bc, ac;
  int la = strlen(a);
  int lb = strlen(b);
  int lc = strlen(c);
  int wtf = max(la, lb);
  wtf = max(wtf, lc);
  genxy(a, b, ab, wtf);
  genxy(b, c, bc, wtf);
  genxy(a, c, ac, wtf);
  int res = 6000;
  for (auto i: ab) {
    for (auto j: bc) {
      if (i + j > la || binary_search(ac.begin(), ac.end(), i + j)) {
        int cur = i + j + lc;
        cur = max(cur, i + lb);
        cur = max(cur, la);
        res = min(res, cur);
      }
    }
  }
  return res;
}

char a[2005], b[2005], c[2005];

int main() {
  scanf("%s", a);
  scanf("%s", b);
  scanf("%s", c);
  int ans = 6000;
  ans = min(ans, calc(a, b, c));
  ans = min(ans, calc(a, c, b));
  ans = min(ans, calc(b, a, c));
  ans = min(ans, calc(b, c, a));
  ans = min(ans, calc(c, a, b));
  ans = min(ans, calc(c, b, a));
  printf("%d\n", ans);
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0

using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/


int main() {
	
	int n;
	scanf("%d", &n);
	printf("%d\n", n * max((n & 1) * 2, 1));
	
	Please AC;
}


Measured memory_bytes: 256
N = gets.to_i
class Node
    attr_accessor :index, :children, :parent, :sibling

    def initialize()
        @children = []
        @parent = nil
        @sibling = nil
    end

    def depth
        parent == nil ? 0 : parent.depth + 1
    end

    def degree
        children.length
    end

    def height
        if children.empty?
            0
        else
            children.map {|e| e.height }.max + 1
        end
    end

    def preorder_array
        left_array = children[0] == nil ? [] : children[0].preorder_array
        right_array = children[1] == nil ? [] : children[1].preorder_array
        [[self], [left_array], [right_array]].flatten
    end

    def inorder_array
        left_array = children[0] == nil ? [] : children[0].inorder_array
        right_array = children[1] == nil ? [] : children[1].inorder_array
        [[left_array], [self], [right_array]].flatten
    end

    def postorder_array
        left_array = children[0] == nil ? [] : children[0].postorder_array
        right_array = children[1] == nil ? [] : children[1].postorder_array
        [[left_array], [right_array], [self]].flatten
    end
end
preorders = gets.chomp.split(" ").map(&:to_i)
inorders = gets.chomp.split(" ").map(&:to_i)

def setNode(preorders, inorders, parent=nil)
    node = Node.new
    node.index = preorders[0]
    node.parent = parent
    left_num = inorders.index(node.index)
    right_num = preorders.length - left_num - 1
    left_node = (left_num == 0) ? nil : setNode(preorders[1..left_num], inorders[0..(left_num-1)], node)
    right_node = (right_num == 0) ? nil : setNode(preorders[(-right_num)..(-1)], inorders[(-right_num)..(-1)], node)
    node.children = [left_node, right_node]
    node
end

root_node = setNode(preorders, inorders)

puts root_node.postorder_array.map {|e|e.index}.join(" ")


Measured memory_bytes: 6880
n = int(raw_input())
S = float(0)
x = []
y = []
for _ in range(n):
  xi,yi = map(float, raw_input().split())
  x.append(xi)
  y.append(yi)
for i in range(n):
  S += x[i] * y[(i+1) % n] - x[(i+1) % n] * y[i]
S = S / 2
print "%.1f" % S

Measured memory_bytes: 6476
(defun b (i)
  (loop for ch across (write-to-string i)
        sum (- (char-code ch) #.(char-code #\0))))

(let ((n (read))
      (a (read))
      (b (read)))
  (format t "~A~%"
          (loop for i from 1 to n
                if (<= a (b i) b)
                sum i)))

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    int n;
    cin >> n;
    vector<ll> v(n);
    for(auto& x:v){
        cin >> x;
    }
    ll ret = 1e9;
    for(int i=-100;i<=100;i++){
        ll cnt = 0;
        for(int j=0;j<n;j++){
            cnt+=(v[j]-i)*(v[j]-i);
        }
        ret = min(ret,cnt);
    }
    cout << ret << endl;
}

Measured memory_bytes: 256
o, e = input(), input()
s = ''
o_idx = 0
e_idx = 0
i = 0
while o_idx < len(o) or e_idx < len(e):
    if i % 2 == 0:
        s += o[o_idx]
        o_idx += 1
    else:
        s += e[e_idx]
        e_idx += 1
    i += 1
print(s)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define ins insert
#define inf INT_MAX
#define vp vector< pair<int,int> >

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll m,k,n;
    cin >> m >> k;
	n = (1 << m) - 1;

	if(k > n) cout << -1 << endl;
	else if(n == 1) {
		if(k == 1) cout << -1 << endl;
		else cout << "0 0 1 1" << endl;
	}
	else {
		repl(i, 0, n) if(i != k) cout << i << " ";
		cout << k << " ";
		for(int i=n;i>=0;i--)
        {if(i != k) cout << i << " ";
        }
		cout << k << " ";
		cout << endl;
	}
    return 0;
}



Measured memory_bytes: 1792
import sys
input = lambda: sys.stdin.readline().rstrip() 

def resolve():
    X, Y, A, B, C = map(int, input().split())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))
    r = list(map(int, input().split()))
    pp = sorted(p, reverse=True)[0:X]
    qq = sorted(q, reverse=True)[0:Y]
    ppqqr = list(sorted(pp+qq+r, reverse=True))

    print(sum(ppqqr[0:X+Y]))

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 23600
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <numeric>
using namespace std;
using ll = long long;

typedef pair <int, int> pii;

int main()
{

	ll a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	string s, t;
	ll n;
	cin >> c;
	cin >> n;
	ans = 1;
	if (c==1)
	{
		cout << n << endl;
		return 0;
	}
	// 割る数の初期値
	a = 2;
	// √n ≧ a ( n ≧ a * a ) の間ループ処理
	while (n >= a * a) {
		// a で割り切れたら、a は素因数
		// そして、割られる数を a で割る
		// a で割り切れなかったら、 a を 1 増加させる
		if (n % a == 0) {
			//printf("%d * ", a);
			n /= a;
			b++;
			if (b==c)
			{
				ans *= a;
				b = 0;
			}
		}
		else {
			a++;
			b = 0;
		}
	}
	// 最後に残った n は素因数
	//printf("%d\n", n);
	if (n % a == 0) {
		//printf("%d * ", a);
		n /= a;
		b++;
		if (b == c)
		{
			ans *= a;
			b = 0;
		}
	}
	else {
		a++;
		b = 0;
	}

	cout << ans << endl;
	//cout <<  << endl;

	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//char型の文字数字は、-'0'で数値に変換できる
//accumulate(x, x + a, 0);//int型までの配列の合計
//memcpy(x, visited, sizeof(ll)*n);
//void kansuu(ll num, ll visited[10]) {}
//kansuu(1, zz);
//cout << setprecision(15) << v << endl;
//cout << char(z - 'a');
//log10(i) + 1 //10進数の桁数を取得

//int temp;
//for (int i = 0; i < n - 1; i++) {
//	for (int j = n - 1; j > i; j--) {
//		if (w[j - 1] < w[j]) {  /* 前の要素の方が大きかったら */
//			temp = w[j];        /* 交換する */
//			w[j] = w[j - 1];
//			w[j - 1] = temp;
//		}
//	}
//}

//最小公倍数
//ll x = a * b;
//ll tmp;
///* 自然数 a > b を確認・入替 */
//if (a<b) {
//	tmp = a;
//	a = b;
//	b = tmp;
//}
///* ユークリッドの互除法 */
//ll r = a % b;
//while (r != 0) {
//	a = b;
//	b = r;
//	r = a % b;
//}
//a = x / b;//答え

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
int lcm(int a, int b){
  return a / gcd(a,b) * b;
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int main(){
  ll h; cin >> h;
  ll ans = 1;
  while(h != 0){
    ans *= 2;
    h /= 2;
  }
  cout << ans-1 << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);++i)
#define fi first
#define se second
#define INF 1000000009
#define lINF 1000000000000000009
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

// GCD, LCM
// https://youtu.be/8lm8o8L9Bmw?t=2285
// https://youtu.be/XI8exXVxZ-Q?t=3595
// https://youtu.be/F2p_e6iKxnk?t=843
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
mint lcm(ll a, ll b) { return a/gcd(a,b)*b;}

map<int,int>mp[10009];
bool f[1000009];
int cnt_p[1000009];
vector<int>p;

void prime(int idx,int n){
  for(int i=2;i*i<=n;i++){
    while(n%i==0){
      ++mp[idx][i];
      cnt_p[i]=max(cnt_p[i],mp[idx][i]);
      if(!f[i]){
        p.push_back(i);
        f[i]=1;
      }
      n/=i;
    }
  }
  if(n!=1){
    mp[idx][n]=1;
    cnt_p[n]=max(cnt_p[n],mp[idx][n]);
    if(!f[n]){
      p.push_back(n);
      f[n]=1;
    }
  }
}

int main(){
  int n;
  ll a[10009];
  cin>>n;
  rep(i,n){
    cin>>a[i];
    prime(i,a[i]);
  }
  mint lcm=1;
  rep(i,p.size()){
    int mx=0;
    rep(j,cnt_p[p[i]]){
      lcm*=p[i];
    }
  }
  mint ans=0;
  rep(i,n){
    ans+=lcm/a[i];
  }
  cout<<ans.x<<endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define size(s) s.size()
using namespace std;
int main()
{
	int m,n;
	cin>>m>>n;
	if(n==m)
		cout<<"Yes\n";
	else cout<<"No\n"; 
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;

class Shop implements Comparable<Shop>{
    String s; int p; int n;
    public Shop(String s, int p, int n){
        this.s = s;
        this.p = p;
        this.n = n;
    }
    @Override
    public int compareTo(Shop m){
        int i = (this.s).compareTo(m.s);
        if(i==0){
            int j = m.p - this.p;
            return j;
        }
        return i;
    }
}

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        ArrayList<Shop> m = new ArrayList<Shop>();
        for(int i=0; i<n; i++){
            String s = sc.next();
            int p = Integer.parseInt(sc.next());
            m.add(new Shop(s,p,i));
        }
        Collections.sort(m);
        for(int i=0;i<n;i++){
            System.out.println(m.get(i).n+1);
        }
        sc.close();
    }
}

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

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

    int n, x;
    cin >> n >> x;
    vector<int> A(n);
    REP(i, n) cin >> A[i];

    sort(A.begin(), A.end());
    int cnt = 0;
    REP(i, n){
        if(x - A[i] >= 0){
            x -= A[i];
            cnt++;
        }else{
            break;
        }
    }

    //xが0より多いということは誰かに押し付ける必要がある
    //押し付け先は必ず満足しないことになる
    //全員が満足している場合は誰か犠牲に
    //そうでない場合は満足してないマンに押し付ければ満足する人数は変わらない
    if(x > 0 and cnt == n){
        cnt--;
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
/* YOU LOST THE GAME */
#include <bits/stdc++.h>     // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main(){
  ll a;
  string s;
  cin >> a;
  cin >> s;
  if (a < 3200)
    cout << "red" << endl;
  else
    cout << s << endl;

  return 0;
} //cin.tie(0) bei schnellem Wechseln



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	int ans=abs(abs(a)-abs(b));
	if (a==0||b==0){
		if (a>b) ans++;
		printf("%d\n",ans);
		return 0;
	}
	if ((a>=0)==(b>=0)){
		if (a>b) ans+=2;
		printf("%d\n",ans);
	}
	else printf("%d\n",ans+1);
	return 0;
}

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

int main()
{
long long A,B,K;scanf("%lld %lld %lld",&A,&B,&K);
if(A>=K)A-=K;
else if(A+B>=K){B-=K-A;A=0;}
else {A=0;B=0;}
printf("%lld %lld",A,B);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;


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 / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n, p / 2);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret;
	}
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


int main() {
	ll N;
	std::cin >> N;
	
	map<ll, ll> dic;
	ll ans = 0;
	rep(i, 0, N) {
		ll A;
		std::cin >> A;
		dic[A]++;
		ans += A;
	}

	ll Q;
	std::cin >> Q;
	rep(i, 0, Q) {
		ll B, C;
		std::cin >> B >> C;
		ans += (C - B) * dic[B];
		dic[C] += dic[B];
		dic[B] = 0;
		std::cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 9444
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=2e5+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }


void solve() {
  string s,p;
  cin>>s>>p;
  int l1=sz(s);
  int l2=sz(p);
  string yo=p.substr(0,l2-1);
  if(yo==s) {
	    cout<<"Yes\n";
	  }
  else 
    cout<<"No\n";     
 }

    
int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
	  solve();

return 0;	   
}


Measured memory_bytes: 3652
using System;

namespace Atcoder2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] hensu = Console.ReadLine().Split(' ');
            int goukei = int.Parse(hensu[0]);
            int ashi = int.Parse(hensu[1]);

            bool flag = false;

            if(goukei >= ashi)
            {
                WriteAns(flag);
                return;
            }

            for(int i = 0; i < goukei + 1; i++)
            {
                int ans = (goukei - i) * 2 + (i * 4);
                if (ans == ashi)
                {
                    flag = true;
                }
            }

            WriteAns(flag);

        }

        static void WriteAns(bool flag)
        {
            if(flag)
            {
                Console.WriteLine("Yes");
            } else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 27472
import java.util.*;
import java.io.*;
 
class Main{
public static void main(String[] args) throws IOException{
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  	String[] str = br.readLine().split(" ");
  	int n = Integer.parseInt(str[0]);
  	int k = Integer.parseInt(str[1]);
  	int[] h = new int[n];
  	String[] s = br.readLine().split(" ");
  	for(int i=0;i<n;i++)
      h[i] = Integer.parseInt(s[i]);
  	int[] dp = new int[n];
    Arrays.fill(dp,Integer.MAX_VALUE);
    dp[0] = 0;
  	dp[1] = Math.abs(h[1]-h[0]);
  	for(int i=2;i<n;i++){
      for(int j=i-1;j>=0 && i-j<=k;j--)
      dp[i] = Math.min(dp[i],dp[j] + Math.abs(h[i]-h[j]));
    }
      System.out.println(dp[n-1]);
    }
}


Measured memory_bytes: 45832
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        for(int i=0;i<5;i++){
            if(sc.nextInt() == 0){
                System.out.println(i+1);
            }
        }
    }
}


Measured memory_bytes: 35548
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
/*
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> s(3,""); int efctnum = 3;
  RPT(i,0,3) cin >> s[i];
  sort(s.begin(), s.end() );
  if(s[0]==s[1] && s[0]==s[2]) {efctnum=1; cout << s[0].size() << endl ; return 0;}
  if(s[0]==s[1] ) {efctnum=2; s[1]=s[2];}
  if(s[0]==s[2] || s[1]==s[2]) efctnum=2;
}
*/

int main(){
cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  queue<pair<string,int>> Q[15]; 
  Q[1].push( {"a",1});
  for(int i=2; i <= n; ++i){
    while( !Q[i-1].empty() ){
      pair<string,int> s = Q[i-1].front();
      for(int j=0; j<s.second+1; ++j){
        Q[i].push( pair<string,int>((s.first+(char)('a'+j)),max(j+1,s.second)) );
      }
      Q[i-1].pop();
    }
  }
  while(!Q[n].empty() ){
    pair<string,int> s;
    s = Q[n].front();
    cout << s.first << endl;
    Q[n].pop();
  }
}



Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, Alice = 0, Bob = 0;
  cin >> N;
  vector<int> card(N);
  
  for (int i = 0; i < N; i++) {
    cin >> card.at(i);
  }
  
  for (int i = 0; i < N - 1; i++) {
    for (int j = 0; j < N - 1; j++) {
      if (card.at(j) < card.at(j + 1)) {
        swap(card.at(j), card.at(j + 1));
      }
    }
  }

  for (int i = 0; i < N; i += 2) {
    Alice += card.at(i);
  }
  
  for (int i = 1; i < N; i += 2) {
    Bob += card.at(i);
  }
  
  cout << Alice - Bob << endl;
}

Measured memory_bytes: 256
# 入力
n, m = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

# i番目の直線とi-1番目の直線の間の領域が使用される回数をもとに解を求める
ans = (
    sum(i * (n - i) * (x[i] - x[i - 1]) for i in range(1, n)) *
    sum(i * (m - i) * (y[i] - y[i - 1]) for i in range(1, m))
) % (10**9 + 7)

# 出力
print(ans)


Measured memory_bytes: 18624
loop do
    n = gets.to_i
    break if n == 0
    input = gets.split.map(&:to_i)

    ans = (0..15).to_a.repeated_permutation(3).to_a.min_by do |s, a, c|
        count = Hash.new(0)
        noise = s
        input.each do |x|
            noise = (noise * a + c) % 256
            output = (x + noise) % 256
            count[output] += 1
        end
        count.values.map {|k| r = k.to_f / input.size; -r * Math.log(r)}.inject(:+)
    end
    puts ans * ' '
end

Measured memory_bytes: 60248