akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.math.*;
import java.util.*;





public class Main {

    static MyScanner in = new MyScanner();
    static   PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    int N;
    static int max = 200001;
    static int [] dr = {1,-1,0,0};
    static int [] dc={0,0,-1,1};
    static class Edge{
        int u,w;
        Edge(int u, int w){
            this.u =u;this.w = w;
        }
    }
    public static void main(String args[]) throws IOException {
        int N = in.nextInt();
        long [] arr = new long[N+1];
        for(int i=1;i<=N;i++){
            arr[i] = in.nextInt();
        }
        long [][] dp = new long[N+1][N+1];
        for(int L=N;L>0;L--){
            for(int R = L;R<=N;R++){
                if(L==R){
                    dp[L][R] = arr[L];
                }else{
                    long leftChoice = arr[L]-dp[L+1][R];
                    long rightChoice = arr[R]-dp[L][R-1];
                    dp[L][R] = Math.max(leftChoice,rightChoice);
                }
            }
        }
        out.println(dp[1][N]);
        out.flush();
        }
       static boolean isEven(long a){
            return (a&1)==0;
        }
       static  void swap (int a, int b){

        int temmp = b;
        b=a;
        a = temmp;
        }
        static boolean same(int [] arr,int [] temp){
            Arrays.sort(arr);
           Arrays.sort(temp);
            for(int i=0;i<arr.length;i++){
                if(temp[i]!=arr[i])
                return false;
            }
            return true;
        }

 
  


    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
   
        public MyScanner() {
           br = new BufferedReader(new InputStreamReader(System.in));
        }
   
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
   
        int nextInt() {
            return Integer.parseInt(next());
        }
   
        long nextLong() {
            return Long.parseLong(next());
        }
   
        double nextDouble() {
            return Double.parseDouble(next());
        }
   
        String nextLine(){
            String str = "";
        try {
           str = br.readLine();
        } catch (IOException e) {
           e.printStackTrace();
        }
        return str;
        }
  
     }
    }

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

const long long mod=1e9+7;

int main(){
	long long  n, k; cin >> n >> k;
    vector<long long> a(n);
    for(long long i=0; i<n; i++) cin >> a[i];

    long long cnt=0;
    for(long long i=0; i<n-1; i++){
        for(long long j=i+1; j<n; j++){
            if(a[i]>a[j]) cnt++;
            cnt %= mod;
        }
    }
    cnt=cnt*k%mod;

    sort(a.begin(), a.end());
    vector<long long> dp(n);
    for(long long i=1; i<n; i++){
        if(a[i]==a[i-1]) dp[i]=dp[i-1];
        else dp[i]=(k-1)*k/2%mod*i%mod;
        cnt=(cnt+dp[i])%mod;
    }

	cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;

typedef long long int ll;

int a, b, c, d, e, f;
int ok[4096], ok2[4096];
int main(void){
	cin >> a >> b >> c >> d >> e >> f;
	ok[0] = 1;
	for(int i=0;i<=f;i++){
		if (ok[i]){
			if (i+100*a<=f) ok[i+100*a] = 1;
			if (i+100*b<=f) ok[i+100*b] = 1;
		}
	}
	ok2[0] = 1;
	for(int i=0;i<=f;i++){
		if (ok2[i]){
			if (i+c<=f) ok2[i+c] = 1;
			if (i+d<=f) ok2[i+d] = 1;
		}
	}
	vector<int> oks, oks2;
	for(int i=0;i<=f;i++) if (ok[i]) oks.pb(i);
	for(int i=0;i<=f;i++) if (ok2[i]) oks2.pb(i);

	int ans = -1, ans2 = -1;
	double maxi = -1;
	for(int i=0;i<oks.size();i++){
		for(int j=0;j<oks2.size();j++){
			if (0<oks[i]+oks2[j] && oks[i]+oks2[j] <= f){
				if (oks[i]*e>=oks2[j]*100){
					if (maxi < (0.0+oks2[j])/oks[i]){
						maxi = (0.0+oks2[j])/oks[i];
						ans = oks[i], ans2 = oks2[j];
					}
				}
			}
		}
	}
	cout << ans+ans2 << " " << ans2 << endl;


	return 0;
}


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

int main(){
    int N,K;
    string str;
    cin >> N;
    cin >> str;
    cin >> K;
    char c=str[K-1];
    for(int i=0;i<str.length();i++){
        if(str[i]!=c) str[i]='*';
    }
    cout << str << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


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

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

const long long INF = 1000000000000000;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h,w, n, m;
char maze[60][60];
int dis[60][60];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main() {
	ll a[5];cin >> n;ll mi = INF;ll b[5];
	rep(i, 5) {
		cin >> a[i];
		chmin(mi, a[i]);
	}
	ll res;
	res = (n / mi)+1 + 4;
	if (n%mi == 0) {
		res = (n / mi)+ 4;
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define pri(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
//#define int long long


using namespace std;


int dy[4] = { 0,0,1,-1 };
int dx[4] = { 1,-1,0,0 };
int dxx[8] = { 0,0,1,1,1,-1,-1,-1 };
int dyy[8] = { 1,-1,0,1,-1,0,1,-1 };




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(ll a, ll n) {//aのn乗を計算します。
	ll x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}


const int MOD = 1000000007;

bool arr[1050000];
int sosuu[100010];
void Eratosthenes() {
	ll N = 1050000;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (int i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (int j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (int i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu[c] = i;
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}
vector<int>v;
void digit2(ll N){
	ll n=N;
	if(n==0)v.pb(0);
	while(n!=0){
		if(n%(-2)!=0){
			v.pb(1);
			n--;
			n/=-2;
		}
		else{
			v.pb(0);
			n/=-2;
		}
	}
}

int main() {
	int N;
	cin>>N;
	digit2(N);
	int l=v.size();
	REPR(i,l-1){
		cout<<v[i];
	}
}


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

#define ll long long
#define Ok puts("OK");

using namespace std;

const int N = (int)2e5 + 7;

vector <int> gr[N];
int tin[N], tout[N], pos[N];
int tiktak;
int n;

void dfs(int v, int pr = 0) {
  tin[v] = ++tiktak;
  pos[tiktak] = v;
  for (int to : gr[v]) {
    if (to == pr) continue;
    dfs(to, v);
  }
  tout[v] = tiktak;
}

int pref[N], ans[N];
int q;

main() {
  scanf("%d %d", &n, &q);
  for (int i = 0, a, b; i < n - 1; i++) {
    scanf("%d %d", &a, &b);
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  dfs(1);
  for (int i = 0; i < q; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    pref[tin[a]] += b;
    pref[tout[a] + 1] -= b;
  }
  for (int i = 1; i <= n; i++) {
    pref[i] += pref[i - 1];
    ans[pos[i]] = pref[i];
  }
  for (int i = 1; i <= n; i++) {
    printf("%d ", ans[i]);
  }
}


Measured memory_bytes: 26624
object Main {
  def main(args: Array[String]): Unit = {
    solve2
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, c, k = sc.nextInt
    var list = Array.fill(n)(sc.nextInt).sorted

    var count = 1
    var g = list(0) + k
    var num = 1
    for(t <- list.tail) {
      if(t > g || num == c) {
        count += 1
        num = 1
        g = t + k
      }else{
        num += 1
      }
    }

    println(count)
  }

  def solve2(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, c, k = sc.nextInt
    var list = Array.fill(n)(sc.nextInt).sorted

    var count = 1
    var prev = 0
    for(i <- 0 until n) {
      if(i - prev == c || list(i) - list(prev) > k) {
        count += 1
        prev = i
      }
    }

    println(count)
  }
}


Measured memory_bytes: 50420
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if(a + b >= 10)cout << "error" << endl;
    else cout << a + b << endl;
}

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

int get_digit(int x) {
    int d = 1;
    while (x / 10 != 0) {
        d += 1;
        x /= 10;
    }
    return d;
}

int main() {
    int a, b, count = 0;
    cin >> a >> b;
    
    int l = get_digit(b);
    int s = a*(pow(10, l)) + b;
    
    for (int i = 0; i < 400; i++) {
        if (i*i == s) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}





Measured memory_bytes: 256
while True:
  n = int(input())
  if n == 0:
    break

  def_dic = {}
  for _ in range(n):
    s, p = input().split()
    def_dic[s] = int(p)
  
  m = int(input())
  com_dic = {}
  for _ in range(m):
    lst = input().split()
    com_dic[lst[0]] = lst[2:]
  
  price_dic = {}
  
  def get_price(t):
    if t in price_dic:
      return price_dic[t]
    if t not in com_dic:
      price_dic[t] = def_dic[t]
      return def_dic[t]
    
    x = 0
    for q in com_dic[t]:
      x += get_price(q)
    ret = min(x, def_dic[t])
    price_dic[t] = ret
    return ret
  
  print(get_price(input()))


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<char> vc;
#define mp make_pair
#define pb push_back
#define read(array,n) for(ll i=0;i<n;i++) cin>>array[i];
#define f(i,n) for(i=0;i<n;i++)
#define F(i,n) for(i=1;i<=n;i++)
#define inf 1000000007;
// function to transform string to lowercase --> transform(s.begin(),s.end(),s.begin(),::tolower)
//(a + b ) % m = (a % m + b % m ) %m
//(a - b ) % m = ( ((//(//(a - b ) % m = ( (a % m - b % m ) + m ) %m
// a % m - b % m ) + m ) %m
//(a * b ) % m = (a % m * b % m ) %m
//(a / b ) % m = (a % m * inv(b) ) %m where inv(b) = pow(b,m,m-2)

ll power(ll i,ll j){
	ll prod=1;
	while(j>0){
		if(j&1){
			prod=prod*i;
		}
		j=j>>1;
		i=i*i;
	}
	return prod;
}
void solve(){
	ll i,j,n,k,m;
	cin>>n;
	ll ar[n];
	read(ar,n);
	ll ans=0;
	ll ini=1000;
	for(i=0;i<n-1;i++){
		if(ar[i+1]>=ar[i]){
			ll pp=(ini/ar[i])*ar[i];
			ll qq=(ini/ar[i])*ar[i+1];
			ini+=(qq-pp);
		}
	}
	cout<<ini<<endl;
}
int main(){
	// freopen("input.txt","r",stdin);
	solve();
	// ll t;
	// cin>>t;
	// while(t--){
	// 	solve();
	// }
}

Measured memory_bytes: 3608
using System;
using System.Linq;
using System.Text;

namespace ALDS1_1_A {
    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            int[] A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            StringBuilder sb = new StringBuilder();
            sb.AppendLine(ArrToString(A));
            for(int i = 1; i < n; i++) {
                int v = A[i];
                int j = i - 1;
                while (j >= 0 && A[j] > v) {
                    A[j + 1] = A[j];
                    j--;
                }
                A[j + 1] = v;
                sb.AppendLine(ArrToString(A));
            }
            Console.Write(sb);
        }

        static string ArrToString(int[] arr) {
            StringBuilder ret = new StringBuilder();
            foreach (var n in arr) {
                ret.Append(" " + n);
            }
            return ret.ToString().TrimStart();
        }
    }
}

Measured memory_bytes: 9956
n = int(input())
a = list(map(int, input().split()))

money = 1000
# 谷で買い、山で売るを繰り返すのが最適

def search_V(st):
    for j in range(st, n):
        if a[j] > a[j-1]:
            return j-1
    return -1

def search_A(st):
    for j in range(st, n):
        if a[j] < a[j-1]:
            return j-1
    return -1

i = 0
stock = 0
while i < n:
    # 谷を探す
    V = search_V(i+1)
    if V == -1:
        break
    else:
        # ありったけ買う
        stock, money = divmod(money, a[V])
        
    # 山を探す
    A = search_A(V+1)
    if A == -1:
        # ありったけ売る        
        money += stock * a[A]
        break
    else:
        money += stock * a[A]
    
    i = A

print(money)

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

int main() {
vector<int> a(3);
rep(i,3) cin >> a.at(i);

int t = 1000; 
rep(i,3)rep(j,3)rep(k,3)if(i!=j && j!=k && k!=i){
  int ans = abs(a.at(j)-a.at(i)) + abs(a.at(k)-a.at(j));
  if(t>ans) t = ans;
}
cout << t << endl;
}
  


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

class Main
{
    public static boolean isRTri(int a, int b, int c)
    {
        return a * a + b * b == c * c;
    }
    public static void main(String[] args)
    {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        for (int k = 1; k <= n; k++)
        {
            int a[] = new int [3];
            for (int i = 0; i < 3; i++)
            {
                a[i] = input.nextInt();
            }
            Arrays.sort(a);
            boolean r = isRTri(a[0], a[1], a[2]);
            System.out.printf("%s\n", r ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 38684
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
  int i,j,k,l;
  char s[5][9][7][8]={
    {{
	{"#######"},
	{"#.....#"},
	{"#...|.#"},
	{"#.....#"},
	{"#...|.#"},
	{"#..-..#"},
	{"#######"}},{
	{"#######"},
	{"#..-..#"},
	{"#...|.#"},
	{"#..-..#"},
	{"#.|...#"},
	{"#..-..#"},
	{"#######"}},{
	{"#######"},
	{"#..-..#"},
	{"#...|.#"},
	{"#..-..#"},
	{"#...|.#"},
	{"#..-..#"},
	{"#######"}},{
	{"#######"},
	{"#.....#"},
	{"#.|.|.#"},
	{"#..-..#"},
	{"#...|.#"},
	{"#.....#"},
	{"#######"}},{
	{"#######"},
	{"#..-..#"},
	{"#.|...#"},
	{"#..-..#"},
	{"#...|.#"},
	{"#..-..#"},
	{"#######"}},{
	{"#######"},
	{"#..-..#"},
	{"#.|...#"},
	{"#..-..#"},
	{"#.|.|.#"},
	{"#..-..#"},
	{"#######"}},{
	{"#######"},
	{"#..-..#"},
	{"#...|.#"},
	{"#.....#"},
	{"#...|.#"},
	{"#.....#"},
	{"#######"}},{
	{"#######"},
	{"#..-..#"},
	{"#.|.|.#"},
	{"#..-..#"},
	{"#.|.|.#"},
	{"#..-..#"},
	{"#######"}},{
	{"#######"},
	{"#..-..#"},
	{"#.|.|.#"},
	{"#..-..#"},
	{"#...|.#"},
	{"#..-..#"},
	{"#######"}}}
  };
  for(i=0;i<9;++i)
    for(j=0;j<7;++j)
      for(k=0;k<7;++k)
	s[1][i][j][k]=s[0][i][j][6-k];
  for(i=0;i<9;++i){
    for(j=0;j<7;++j){
      for(k=0;k<7;++k){
	if(0){
	}else if(s[1][i][k][6-j]=='|'){
	  s[2][i][j][k]='-';
	}else if(s[1][i][k][6-j]=='-'){
	  s[2][i][j][k]='|';
	}else{
	  s[2][i][j][k]=s[1][i][k][6-j];
	}
	if(0){
	}else if(s[1][i][6-k][j]=='|'){
	  s[3][i][j][k]='-';
	}else if(s[1][i][6-k][j]=='-'){
	  s[3][i][j][k]='|';
	}else{
	  s[3][i][j][k]=s[1][i][6-k][j];
	}
	s[4][i][j][k]=s[1][i][6-j][k];
      }
    }
  }
  int a[3][8]={{0,1,0,0,0,1,0,0},{2,1,3,1,2,1,3,1},{0,4,0,0,0,4,0,0}};
  for(;;){
    char t[3][8][7][8]={};
    for(i=0;i<3;++i){
      for(j=0;j<7;++j){
	for(k=0;k<4;++k){
	  for(l=0;l<7;++l){
	    t[i][k][j][l]=getchar();
	    if(t[i][k][j][l]=='0')
	      return 0;
	  }
	}
	getchar();
	for(;k<8;++k)
	  for(l=0;l<7;++l)
	    t[i][k][j][l]=getchar();
	getchar();
      }
    }
    vector<int> sm[2];
    for(i=0;i<3;++i){
      for(j=0;j<8;++j){
	if(a[i][j]){
	  for(k=0;k<9;++k){
	    for(l=0;l<7;++l){
	      if(strcmp(s[a[i][j]][k][l],t[i][j][l]))
		break;
	    }
	    if(l==7)
	      break;
	  }
	  sm[j/4].push_back(k);
	}
      }
    }
    int ct=0;
    for(i=0;i<6;++i){
      for(j=0;j<6;++j){
	if(0){
	}else if(sm[0][i]<sm[1][j]){
	  --ct;
	}else if(sm[0][i]>sm[1][j]){
	  ++ct;
	}
      }
    }
    if(ct<0)
      puts("LOW");
    else
      puts("HIGH");
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define sws                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define qi queue<int>
#define si stack<int>
#define s string
#define ll long long;

int main()
{
    sws;
    int age;
    cin >> age;
    if (age == 3 or age == 5 or age == 7)
        cout << "YES" << endl;
    else
    {
        cout << "NO" << endl;
    }
}

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

int main() {
  int N;
  cin >> N;
  
  bool isThree = true;

  for (int i = 0; i < N; i++) {
    char color;
    
    cin >> color;
    
    if (color == 'Y') {
      isThree = false;
      break;
    }
  }
  
  if (isThree) {
    cout << "Three" << endl;
  } else {
    cout << "Four" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;

int main(){
    int N, cnt = 0, ans = 0, tmp = 0;
    string n;
    cin >> n;
    rep(i, 3){
        if(n[i] == '1') n[i] = '9';
        else if(n[i] == '9') n[i] = '1';
    }
    cout << n << endl;
    return 0;
    
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var a = Input().ToInt();
		
		var map = new Dictionary<long, long>();
		for(int i = 0; i < n; i++)
		{
			if(!map.ContainsKey(a[i]))
				map.Add(a[i], 0);
			map[a[i]]++;
			
		}
		long wa =0;
		foreach(var k in map.Keys)
		{
			wa += k * map[k];
		}
			
		var q = Console.ReadLine().ToInt();
		
		
		for(int i = 0; i < q; i++)
		{
			var pq = Input();
			var p = new long[]{pq[0].ToLong(), pq[1].ToLong()};
			if(map.ContainsKey(p[0]))
			{
				long size = map[p[0]];
				if(map.ContainsKey(p[1]))
				{
					map[p[1]] += size;
					map.Remove(p[0]);
					
					wa += size * p[1];
					wa -= p[0] * size;
				}
				else
				{
					map.Remove(p[0]);
					map.Add(p[1], size);
					wa += size * p[1];
					wa -= p[0] * size;
				}
			}
			Console.WriteLine(wa);
			

		}
		

	}

	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

Measured memory_bytes: 47716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
const ll mod=1e9+7;
ll mpow(ll x,ll n){
    if(n==0)return 1;
    if(n%2==0) return mpow(x*x%mod,n/2);
    else return x*mpow(x,n-1)%mod;
}
int main(void){
    ll n;
    cin>>n;
    ll tmp1=0,tmp2=0;
    rep(0,i,n){
        ll a;
        cin>>a;
        tmp1=(tmp1+a)%mod;
        tmp2=(tmp2+a*a%mod)%mod;
    }
    tmp1=tmp1*tmp1%mod;
    cout<<(tmp1-tmp2+mod)%mod*mpow(2,mod-2)%mod;
}


Measured memory_bytes: 3596
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h = 0;
        int w = 0;
        while(true){
            h = sc.nextInt();
            w = sc.nextInt();
            if(h == 0 && w == 0){break;}
            for(int i = 1; i <= h;i++){
                for(int j = 1; j <= w;j++){
                    if(i==1||i==h||j==1||j==w){
                        System.out.print("#");
                    } else {
                        System.out.print(".");
                    }
                }
                System.out.println("");
            }
            System.out.println();
        }
    }
}


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

int main(){
    int h,n,sum = 0;
    cin >> h >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    //sort(a.begin(),a.end());
    rep(i,n)sum += a[i];
    if(h <= sum)cout <<"Yes"<<endl;
    else cout <<"No"<<endl;



    return 0;

}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3512
#include<bits/stdc++.h>
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define INF 2000000000
#define PI 3.1415926535897932384626
const ll MOD=1e9+7;
char in[1005];
int main(){
        int n,m;
        while(~getII(n,m)){
                int ans=n/m+(n%m!=0);
                printf("%d\n",ans);
        }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<int, null_type , less<int> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
int main()
{
    fastIO;
    ll a,b;
    cin>>a>>b;
    ll ans;
    ans=(a*b)/(__gcd(a,b));
    cout<<ans<<'\n';
    return 0;
}

Measured memory_bytes: 256
N = int(input())
Q = [0]*N
for i in range(N):
        Q[int(input())-1] = i

subset_num = num = 0
for i in range(N-1):
    num += 1
    if Q[i] > Q[i+1]:
        subset_num = max(subset_num, num)
        num = 0
else:
    num += 1   # 最後だけ数えられないので注意
    subset_num = max(subset_num, num)
print(N - subset_num)

Measured memory_bytes: 12980
#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long 

int main() {
  int n;
  
  cin >> n;
  
  n = n %1000;
  
  int res = 1000-n;
  res %= 1000; 
  cout << res << endl;
}

Measured memory_bytes: 3620
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var row = input.split('\n');
for(var i=0;i<row.length;i++){
    var number = row[i].split(' ').map(Number);
    var n = number[0];
    var x = number[1];
    if(n === 0 && x === 0){
        break;
    }
    var result = 0;
    for(var j=1;j<=n;j++){
        for(var k=j+1;k<=n;k++){
            if(j+k >= x){
                break;
            }
            var l = x-(j+k);
            if(l>k && l<=n){
                result++;
            }
        }
    }
console.log(result);
}


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

int main(void){
    long long int n,k;
    cin>>n>>k;
    int ans=0;
    while(n>0){
        n=n/k;
        ans++;
        
    }
    cout<<ans<<endl;
    

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static final long MOD = 1000000007;

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			int n = sc.nextInt();
			long[] a = new long[n];
			long[] sum = new long[n];

			a[0] = sc.nextLong();
			sum[0] = a[0];
			for (int i = 1; i < n; i++) {
				a[i] = sc.nextLong();
				sum[i] = (sum[i - 1] + a[i]);
			}

			long result = 0;
			for (int i = 0; i < n - 1; i++) {
				long nokori = (sum[n - 1] - sum[i])%MOD;
				
				result = (result + (a[i] * nokori) % MOD) % MOD;
			}

			System.out.println(result);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}

Measured memory_bytes: 64004
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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


int main(){
    int n, m; cin >> n;
    VI a(n);
    REP(i, n) cin >> a[i];
    cin >> m;
    VI b(m);
    REP(i, m) cin >> b[i];
    VI res;
    set_difference(ALL(a), ALL(b), inserter(res, res.end()));
    REP(i, res.size()){
        cout << res[i] << "\n";
    }
    return 0;
}



Measured memory_bytes: 5488
#include<iostream>
#include<string>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
string h[]={"Rock","Fire","Scissors","Snake","Human","Tree",
	"Wolf","Sponge","Paper","Air","Water","Dragon","Devil","Lightning","Gun"};
map<string,int> m;int n,t,c;
int main(){
	rep(i,15)m[h[i]]=i;
	while(cin>>n,n){
		int lose[15]={0},exist[15]={0};
		string buf;
		rep(i,n){
			cin>>buf;t=m[buf];
			exist[t]=1;
			rep(j,7)lose[(t+j+1)%15]=1;
		}
		t=-1;c=0;
		rep(i,15){
			c+=exist[i];
			if(!lose[i]&&exist[i])t=t==-1?i:-2;
		}
		cout<<(c<2||t<0?"Draw":h[t])<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
<?php
error_reporting(0);
$stdin = file_get_contents('php://stdin');
$line = explode("\n",$stdin);
$fi = 0;
$cnt = 0;
$list = array();
$key = new stdclass();
foreach($line as $l) {
  if (strlen($l)==0) continue;
  if ($fi == 0) {
    $a = explode(" ",$l);
    $key->A = $a;
    $fi++;
    continue;
  }
  if ($fi > 0) {
    $a = explode(" ",$l);
    $key->X[] = $a;
  }
}
//すぎていい日付け
$X = $key->A[0];
//賞味期限前
$A = $key->A[1];
//食べた日付け
$B = $key->A[2];

$res = $B - $A;
if ($res > $X) {
  printf("dangerous\n");
  exit;
}
if ($res <= 0) {
  printf("delicious\n");
}
else {
  printf("safe\n");
}


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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

int n;
int a, b;

int f(int a, int b){
	int ret = 0;
	for(int i = 0; i < n; i++){
		if((a ^ b) & (1 << i)){
			ret++;
		}
	}
	return ret;
}

int N; // ugly fix

void gen(int n, int a, int b, int mask){
//	printf("gen %d %d %d %d\n", n, a, b, mask);
	// mask is the bit fixed at this stage
	// target: go from a to b in 2^n - 1 steps
	if(n == 1){
		// only one bit can be changed, so...
		printf(" %d", b);
		return;
	}
	// choose one bit to toggle
	int bit1, bit2;
	
	// choose any TWO; a and b have to be different at bit1
	for(int i = 0; i < N; i++){
		if(mask & (1 << i)){
			continue;
		}
		if((a ^ b) & (1 << i)){
			bit1 = i;
			break;
		}
	}
	for(int i = 0; i < N; i++){
		if(mask & (1 << i)){
			continue;
		}
		if(i != bit1){
			bit2 = i;
			break;
		}
	}
	
//	printf("%d %d\n", bit1, bit2);
	// first half: go from a to a ^ (1 << bit2)
	gen(n - 1, a, a ^ (1 << bit2), mask | (1 << bit1));
	// change bit1 of start, go to end
	printf(" %d", a ^ (1 << bit1) ^ (1 << bit2));
	gen(n - 1, a ^ (1 << bit1) ^ (1 << bit2), b, mask | (1 << bit1));
}

int main(){
	scanf("%d", &n);
	scanf("%d %d", &a, &b);
	int diff = f(a, b);
	if(diff % 2 == 0){
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	printf("%d", a);
	
	N = n;
	gen(n, a, b, 0);
	puts("");
	return 0;
}

Measured memory_bytes: 1024
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int64_t N, K;
std::pair<int64_t, int> A[100000];
std::pair<int64_t, int>* maxt[100000];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N >> K;
	for (size_t i = 0; i < N; i++)
	{
		in >> A[i].second >> A[i].first;
	}
	std::sort(A, A + N, std::greater<>{});

	for (auto& i : A)
	{
		if (maxt[i.second] == nullptr) {
			maxt[i.second] = &i;
		}
	}

	int64_t max = 0;
	int64_t res = 0;
	int64_t count = 0;
	std::stack<int64_t> mul;
	size_t i = 0;
	for (; i < K; i++)
	{
		if (&A[i] != maxt[A[i].second]) {
			mul.push(A[i].first);
		}
		else {
			++count;
		}
		res += A[i].first;
	}
	max = res + count * count;

	while (!mul.empty() && i < N)
	{
		if (&A[i] != maxt[A[i].second]) {
			++i;
			continue;
		}

		res -= mul.top(); mul.pop();
		res += A[i].first;
		++count;

		max = std::max(max, res + count * count);
		++i;
	}
	out << max << endl;

	return 0;
}
#endif


Measured memory_bytes: 2816
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

ll digsum(ll n, ll b) {
    ll ret = 0;
    while (n) {
        ret += n % b;
        n /= b;
    }
    return ret;
}

int main() {
    ll n, s;
    cin >> n >> s;
    if (n == s) {
        cout << n + 1 << "\n";
        return 0;
    } else if (s > (n + 1) / 2) {
        cout << -1 << "\n";
        return 0;
    }
    ll ret = INF;
    for (ll i = 2; i <= sqrt(n); ++i) {
        ll d = digsum(n, i);
        if (d == s)
            chmin(ret, i);
    }

    for (ll i = 1; i <= sqrt(n); ++i) {
        if ((n - (s - i)) % i == 0) {
            ll b = (n - (s - i)) / i;
            if (digsum(n, b) == s)
                chmin(ret, b);
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
const int maxn = 100;
double dis(double a,double b)
{
    return sqrt(a*a+b*b);
}
int main(){
    int n,d;
    cin>>n>>d;
    double x,y;
    int cnt = 0;
    for(int i = 0;i < n;i++)
    {
        cin>>x>>y;
        if(dis(x,y) <= d)cnt++;
    }
    cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    string s; cin>>s;
    string key="keyence";
    ll n=s.size();
    ll a=0, b=0;
    rep(i,n){
        if(s[i]==key[i]) a++;
        else break;
    }
    rep(i,n){
        if(s[n-1-i]==key[6-i]) b++;
        else break;
    }
    if(a+b>=7) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, ans=10000;
    cin >> N;
    for(int i=0; i<N; i++){
        int A;
        cin >> A;
        int d = 0;
        while(A % 2 == 0){
            A /= 2;
            d++;
        }
        ans = min(ans, d);
    }
    cout << ans << endl;
    return 0; 
}

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

int main() {
  for (int i = 0; i < 5; i++) {
    int x;
    cin >> x;
    if (x == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3636
h=int(input())
key=list(map(int,input().split()))
p=[None]*h
l=[None]*h
r=[None]*h
for i in range(h):
    if i>=1:
        p[i]=key[(i+1)//2-1]
    if (i+1)*2<=h:
        l[i]=key[i*2+1]
    if (i+1)*2+1<=h:
        r[i]=key[i*2+2]
for i in range(h):
    print("node {}:".format(i+1),end="")
    print(" key = {}".format(key[i]),end=",")
    if p[i]:
        print(" parent key = {}".format(p[i]),end=",")
    if l[i]:
        print(" left key = {}".format(l[i]),end=",")
    if r[i]:
        print(" right key = {}".format(r[i]),end=",")
    print(" ")


Measured memory_bytes: 5716
#include<bits/stdc++.h>
#define int long long

using namespace std;

// int dp[105][105][37];

signed main(){
    int q=1;
    // cin>>q;
    while(q--){
        int H,W,K;
        cin>>H>>W>>K;
        int a[H][W];
        vector<string> arr(H);
        for(int i=0;i<H;i++){
            cin>>arr[i];
        }
        memset(a,0,sizeof(a));
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(arr[i][j]=='#') a[i][j]=1;
            }
        }
        int ans=0;
        for(int mask_r=0;mask_r<(1<<H);mask_r++){
            for(int mask_c=0;mask_c<(1<<W);mask_c++){
                vector<int> r,c;
                int temp=mask_r,black=0;
                for(int i=0;i<H;i++){
                    if((temp&1) == 1) r.push_back(i);
                    temp = temp>>1;
                }
                temp = mask_c;
                for(int i=0;i<W;i++){
                    if((temp&1) == 1) c.push_back(i);
                    temp = temp>>1;
                }

                for(int i=0;i<H;i++){
                    for(int j=0;j<W;j++){
                        if(a[i][j]==1){
                            if(!binary_search(r.begin(),r.end(),i) && !binary_search(c.begin(),c.end(),j)){
                                black++;
                            }
                        }
                    }
                }
                if(black == K){
                    ans++;
                }
            }
        }
        cout<<ans;

    }
        
}

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

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

void solve(long long A, long long B) {
  if( B % A == 0 ){
  cout << A+ B << endl;
  }else{
    cout << B - A << endl;
  }
}

int main() {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);
  solve(A, B);
  return 0;
}


Measured memory_bytes: 764
import math
A,B = map(int,input().split())
cnt = 0
while True:
    cnt += 1
    if math.floor(cnt * 0.08) == A and math.floor(cnt * 0.1) == B:
        print(cnt)
        exit()
    elif cnt == 10**5:
        print(-1)
        exit()

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

int main(){
  int N, L;
  cin >> N >> L;

  vector<string> vec(N);
  for (int i=0; i<N; i++){
    cin >> vec.at(i);
  }

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

  for (int i=0; i<N; i++){
    cout << vec.at(i);
  }
  cout << endl;
}


Measured memory_bytes: 256
cl = [*"a".."z"]
table_a = (1..26).select {|i| 26.gcd(i) == 1}
b = nil

$<.readlines.drop(1).each do |str|
  a = table_a.find do |i|
    b = (0..26).find do |j|
      nominees = str.split.select {|w| w.length == 4}
      ["that", "this"].map do |x|
        nominees.include?(x.chars.map {|c| cl[(i * cl.index(c) + j) % 26]}.join)
      end.any?
    end
  end
  table = (0..25).map {|i| (a * i + b) % 26}
  puts str.chomp.chars.map {|c| (c == " ") ? c : cl[table.index(cl.index(c))]}.join
end


Measured memory_bytes: 7052
#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;
  vi a(n); 
  cin >> a;
  int tot = 0;
  for (int el : a) {
    tot ^= el;
  }

  for (int el : a) {
    cout << (tot ^ el) << " ";
  }
  cout << endl;
}

void setup() {
}

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


Measured memory_bytes: 3984
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
typedef long long ll;

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

    int n;
    cin>>n;
    int ans=0;
    for(int i=1;i<=n;i+=2){
        int cnt=0;
        for(int j=1;j<=i;j++){
            if(i%j==0)cnt++;
        }
        if(cnt==8)ans++;
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 256
import sys
if sys.version_info.major >= 3 and sys.version_info.minor >= 5:
    from math import gcd
else:
    from fractions import gcd


N, M = map(int, input().split())
A = sorted(set(int(x) for x in input().split()))
if any(a % 2 > 0 for a in A):
    print(0)
    quit()
div_2 = []
for a in A:
    cnt = 0
    while a % 2 == 0:
        a //= 2
        cnt += 1
    div_2.append(cnt)
if len(set(div_2)) > 1:
    print(0)
    quit()

g = A[0]
for a in A:
    g = gcd(g, a)
lcm = 1
too_big = False

for a in A:
    if not too_big:
        lcm = lcm * a // gcd(lcm, a)
        if lcm > M * 2:
            too_big = True

if too_big:
    print(0)
elif lcm > M:
    print(1)
else:
    K = M // lcm
    ans = K + 1
    if lcm * K + lcm // 2 > M:
        ans -= 1
    print(ans)


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

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int N=sc.nextInt();
		int M=sc.nextInt();
		int[] dist=new int[N];
		int[] cond=new int[M];
		for(int i=0; i<N; i++) {
			dist[i]=sc.nextInt();
		}
		for(int i=0; i<M; i++) {
			cond[i]=sc.nextInt();
		}
		int[][] dp=new int[M+1][N+1];
		int INF=1000000007;
		for(int i=0; i<=M; i++) {
			for(int j=0; j<=N; j++) {
				dp[i][j]=INF;
			}
		}
		dp[0][0]=0;
		for(int i=0; i<M; i++) {
			for(int j=0; j<N; j++) {
				if(dp[i][j]<INF) {		//何らかの方法が確定している時
					dp[i+1][j]=Math.min(dp[i][j], dp[i+1][j]);	//STAY~
					dp[i+1][j+1]=Math.min(dp[i+1][j+1], Math.min(dp[i][j]+dist[j]*cond[i],dp[i][j+1]));
				}
			}
		}
		/*for(int i=0; i<=M; i++) {
			for(int j=0; j<=N; j++) {
				p(dp[i][j]+" ");
			}
			pl();
		}*/
		int min=INF;
		for(int i=0; i<=M; i++) {
			min=Math.min(min, dp[i][N]);
		}
		pl(min);
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}


Measured memory_bytes: 28792
#include <iostream>
#include <stack>
using namespace std;
int main(void){
	int n;
	int flag=0;
	string s;
	stack<int> st;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s;
		if(st.empty() && s == "Un"){
			flag = 1;
			break;
		}
		if(s == "A"){
			st.push(1);
		}
		else if(s == "Un"){
			st.pop();
		}		
	}
	if(flag != 1 && st.empty()){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3168
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N, P; cin >> N >> P;
    vector<int> elem(N);

    int S = 0;
    rep(i,0,N) {
        int w, b; cin >> w >> b;
        S += b;
        elem[i] = (100 - P) * w + P * b;
    }

    sort(elem.begin(), elem.end(), greater<int>());
    int sum = 0;
    rep(i,0,N) {
        if(sum + elem[i] >= P * S) {
            cout << i+1 << endl;
            return 0;
        }
        sum += elem[i];
    }
    return 0;
}

Measured memory_bytes: 1024