akhauriyash/Code-Regression huggingface dataset:
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 100000007
# define INF 100000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline char nc(){
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int Scan(){
    char ch=nc();int sum=0, f=1;
    if (ch=='-') f=-1, ch=nc();
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum*f;
}
const int N=8005;

char s[N];
VI v[2];
int dp[2][N*10];

int sol(int x){return x+N*2;}
int main ()
{
    int x, y;
    scanf("%s%d%d",s,&x,&y);
    int cnt=0, num=0;
    for (int i=0; s[i]; ++i) {
        if (s[i]=='T') v[cnt].pb(num), cnt^=1, num=0;
        else ++num;
    }
    v[cnt].pb(num);
    //for (int i=0; i<v[0].size(); ++i) cout<<v[0][i]<<endl;
    int flag=0;
    dp[flag][sol(0)]=dp[flag][sol(v[0][0])]=1;
    for (int i=1; i<v[0].size(); ++i) {
        flag^=1; mem(dp[flag],0);
        for (int j=N; j>=-N; --j) {
            dp[flag][sol(j)]|=dp[flag^1][sol(j-v[0][i])];
            dp[flag][sol(j)]|=dp[flag^1][sol(j+v[0][i])];
        }
    }
    if (dp[flag][sol(x)]!=1) puts("No");
    else {
        mem(dp,0); flag=0;
        dp[flag][sol(0)]=1;
        for (int i=0; i<v[1].size(); ++i) {
            flag^=1; mem(dp[flag],0);
            for (int j=N; j>=-N; --j) {
                dp[flag][sol(j)]|=dp[flag^1][sol(j-v[1][i])];
                dp[flag][sol(j)]|=dp[flag^1][sol(j+v[1][i])];
            }
        }
        puts(dp[flag][sol(y)]?"Yes":"No");
    }
    return 0;
}



Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long

using namespace std;

signed main() {
    int N;
    cin >> N;

    double r[500];
    double pos[500];
    for (int i = 0; i < N; i++) {
	cin >> r[i];
    }

    int arg = 0;
    pos[0] = r[0];
    for (int i = 1; i < N; i++) {
	double maxPos = -1;
	for (int j = 0; j < i; j++) {
	    double tmpPos = sqrt((r[j]+r[i])*(r[j]+r[i]) - (r[j]-r[i])*(r[j]-r[i]));
	    maxPos = max(pos[j] + tmpPos, maxPos);
	}
	maxPos = max(maxPos, r[i]);
	pos[i] = maxPos;
    }

    double maxPos = 0;
    for (int i = 0; i < N; i++) {
	maxPos = max(maxPos, pos[i]+r[i]);
    }
    printf("%.10f\n", maxPos);
    
    return 0;
}

Measured memory_bytes: 1252
import java.util.Scanner;

public class Main {
        private final static int WHITE=0;
        private final static int BLACK=1;
        private static int[][] mat;
        private static int n;

        public static void main(String[] args) {
                final Scanner sc = new Scanner(System.in);
                int i,j;
                n=sc.nextInt();
                mat = new int[n][n];
                for(i=0;i<n;i++){
                        for (j=0;j<n;j++){
                                mat[i][j]=sc.nextInt();
                                if(mat[i][j]==-1) mat[i][j]=Integer.MAX_VALUE;
                        }
                }
                System.out.println(Prim());
        }

        public static int Prim(){
                int sum=0;
                int u,min,i,j;
                int[] d=new int[100];
                int[] p=new int[100];
                int[] color=new int[100];
                for(i=0;i<n;i++){
                        d[i]=Integer.MAX_VALUE;
                        p[i]=-1;
                        color[i]=WHITE;
                }
                d[0]=0;
                while(true){
                        min=Integer.MAX_VALUE;
                        u=-1;
                        for(i=0;i<n;i++){
                                if(min>d[i] && color[i]!=BLACK){
                                        u=i;
                                        min=d[i];
                                }
                        }
                        if(u==-1) break;
                        color[u]=BLACK;
                        for(j=0;j<n;j++){
                                if(color[j]!=BLACK && mat[u][j]!=Integer.MAX_VALUE){
                                        if(d[j]>mat[u][j]){
                                                d[j]=mat[u][j];
                                                p[j]=u;
                                        }
                                }
                        }
                }
                for(i=0;i<n;i++) if(p[i]!=-1) sum+=mat[i][p[i]];
                return sum;
        }
}

Measured memory_bytes: 40672
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
int main(){
    ll a, b, c; cin >> a >> b >> c;
    ll x, y; cin >> x >> y;
    ll nedan;
    ll ans_min = INFINITY;

    for(ll i = 0; i <= max(x, y); i++){
        nedan = 2 * c * i + a * (max(0LL, x - i)) + b * (max(0LL, y - i));
        ans_min = min(nedan, ans_min);
        //cout << i << " " << ans_min << endl;
    }
    cout << ans_min << endl;
}

Measured memory_bytes: 256
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())
total = 0

for a in range(1, k+1):
    for b in range(a, k+1):
        for c in range(b, k+1):
            n = gcd(a, b, c)
            uni = len(set([a, b, c]))
            if uni == 1:
                total += n
            elif uni == 2:
                total += n * 3
            else:
                total += n * 6
print(total)

Measured memory_bytes: 9640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
const long long INF=1LL<<60;
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; }
using namespace std;
int main(){
int n,x,t;
  cin>>n>>x>>t;
  if(n%x==0) cout<<n/x *t<<endl;
  else cout<<n/x *t +t<<endl;
 }

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int const mod = 1e9 + 7;
int f[305][305][305];

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  int n, m; read(n), read(m);
  for (RI i = 1, l, r, x; i <= m; ++i) {
    read(l), read(r), read(x);
    for (RI j = 0; j <= r; ++j)
      for (RI k = 0; k <= r; ++k) {
        int res = 1 + (j >= l) + (k >= l);
        if (res != x) f[r][j][k] = -1;
      }
  }
  f[0][0][0] = 1;
  for (RI i = 0; i < n; ++i)
    for (RI j = 0; j <= i; ++j)
      for (RI k = 0; k <= i; ++k)
        if (f[i][j][k] > 0) {
          if (f[i + 1][j][k] != -1) (f[i + 1][j][k] += f[i][j][k]) %= mod;
          if (f[i + 1][i][k] != -1) (f[i + 1][i][k] += f[i][j][k]) %= mod;
          if (f[i + 1][j][i] != -1) (f[i + 1][j][i] += f[i][j][k]) %= mod;
        }
  int ans = 0;
  for (RI i = 0; i <= n; ++i)
    for (RI j = 0; j <= n; ++j)
      if (f[n][i][j] != -1)
        ans = (ans + f[n][i][j]) % mod;
  printf("%d\n", ans);

  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 108800
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

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; }

int main() {
  string s;
  cin >> s;
  if(s[2]==s[3]&&s[4]==s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

vector<ll> v;
ll dsum(ll n){
    ll sum=0;
    while(n){
        sum+=n%10;
        n/=10;
    }
    return sum;
}
int main(){
    int k;
    cin>>k;
    int cnt=0;
    FOR(i,1,10) v.pb(i);
    ll p=100000000000;
    double mn=1000100010001000100;
    while(p>0){
    for(ll i=9999;i>=1000;--i){
        ll t=i*p+p-1;
        double ans=(double)t/dsum(t);
        if(ans<mn){
            mn=ans;
            v.pb(i*p+p-1);
        }
    }
    p/=10;
    }
    for(ll i=1000;i>=1;--i){
        ll t=i;
        double ans=(double)t/dsum(t);
        if(ans<mn){
            mn=ans;
            v.pb(t);
        }
    }
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
    for(auto it:v){
        cout<<it<<endl;
        ++cnt;
        if(cnt==k) break;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <stdio.h>
#include<algorithm>
#include<cstring>
#include <string>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<map>
#include<vector>
#include<bits/stdc++.h>
#include <set>
#define ll   long long
#define IO ios::sync_with_stdio(false);cin.tie();cout.tie(0)
#define inf 0x3f3f3f
#define pi 3.1415926535898
using namespace std;
ll m,n;
const int N=3e5+10;
struct A
{
    int l,r;
}a[N];
int cmp(A a,A b)
{
    return a.l<b.l;
}

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        a[i].l=x-y;
        a[i].r=x+y;
    }
    sort(a,a+n,cmp);
    int now=-1e9;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        if(a[i].l>=now)
        {
            now=a[i].r;
            ans++;
        }
        else
        {
            now=min(a[i].r,now);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4388
//last updated on 28.12.2019
#include <bits/stdc++.h>
#pragma GCC optimization ("O3")
using namespace std;

#define ll              long long
#define ld              long double
#define pii             pair <int, int>
#define piii            pair <int, pii>
#define pll             pair <ll, ll>
#define plll            pair <ll, pll>
#define pss             pair <string, string>

#define fa(i, n, N)     for (ll i = n; i <= N; i++)
#define fac(i, n, b, N) for (ll i = n; i <= N && b; i++)
#define fd(i, n, N)     for (ll i = n; i >= N; i--)

#define mp              make_pair
#define pb              push_back
#define pob             pop_back
#define pf              push_front
#define pof             pop_front
#define fi              first
#define se              second

#define ms(arr,t)       memset (arr, t, sizeof(arr));
#define all(x)          x.begin(), x.end()
#define len             length()
#define endl            '\n'

#define db(x)           cerr << ">>>>>> " << #x << " -> " << x << endl

const ll inf = 1e9;
const ll inf2 = 1e18;
const ll MAX = 1e5+5;
const ll MOD = 1e9+7;
const double pi = acos(-1.0);
const double EPS = 1e-9;

void init(int precision){
  	ios_base::sync_with_stdio(false);
  	cin.tie(0);
  	cout.tie(0);
  	cout.setf(ios::fixed);
  	cout.setf(ios::showpoint);
  	cout.precision(precision);
}

inline void iofile (){
	freopen ("input.txt", "r", stdin);
	//freopen ("output.txt", "w", stdout);
}

ll n, m, q, ac, pen;
string ver;
ll arr[MAX];

int main() {
    init(10);
    //iofile();

    cin >> n >> m;
    while (m--){
      cin >> q >> ver;
      if (arr[q] != -1){
        if (ver == "AC"){
          ac++;
          pen += arr[q];
          arr[q] = -1;
        }
        else {
          arr[q]++;
        }
      }
    }
    cout << ac << " " << pen << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>

using namespace std;

int roundup_w(int x, int n) {
    return ((x+n-1) / n) * n;
}

int main() {
    int n;
    cin >> n;
    int c[509], s[509], f[509];  
    for(int i=1; i<n; i++) {
        cin >> c[i] >> s[i] >> f[i];
    }
    for(int i=1; i<n; i++) {
        int t = 0;
        for(int j=i; j<n; j++) {
            int tt = max(s[j], roundup_w(t, f[j]));
            t = tt + c[j];
//            cerr << i << ": " << j << "->" << j+1 << ": [" << tt << ", " << t << "]" << endl;
        }
        cout << t << endl;
    }
    cout << 0 << endl;

}

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

int main() {
    int a, b, count=0;
    double n, k, ans=0,cnt=1;
    cin >> n >> k;
    b=n;
    cout << fixed << setprecision(16);
    while(k>=0.5) {
        if(b>=k) {
            a=(int)(b+1-k);
            ans += a*cnt;
            b=ceil(k)-1;
        }
        k /= 2;
        cnt /= 2;

    }
    ans /= n;
    cout << ans;
}

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

#define int long long
#define rep(i,a,n) for(int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define ALL(x) (x).begin(),(x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort((c).begin(), (c).end(), greater<int>());
#define fi first
#define se second
#define INF (1e9)

typedef pair<int,int> P;
typedef vector<int> vi;

int n,d;

signed main() {
    cin>>n>>d;
    int x[n+1][d+1];
    rep(i,0,n) {
        rep(j,0,d) {
            cin>>x[i][j];
        }
    }
    
    int ans=0;
    rep(i,0,n) {
        rep(j,i+1,n) {
            int dis=0;
            rep(k,0,d) dis+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
            int ndis=sqrt(dis);
            if(ndis*ndis==dis) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}







Measured memory_bytes: 256
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;

int main()
{
    fast_io
    ll i,t,n,j,a,b;
    string s;
    cin>>a>>b;
    if(a+b==15)
    cout<<"+"<<endl;
    else if(a*b==15)
    cout<<"*"<<endl;
    else cout<<"x"<<endl;

    return 0;
}





Measured memory_bytes: 3560
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

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

int main(){
  int t;
  string s;
  while(cin>>t>>s && t){
    bool reject = false;
    int ans = -1;
    vector<int> ans_v;
    for(int S = 0; S < (1<<(s.size() - 1)); S++){
      int sum = 0;
      int tmp = 0;
      vector<int> tmp_v;
      REP(i, s.size()){
        tmp = tmp * 10 + (s[i] - '0');
        if(i == s.size() - 1 || (S & (1<<i))){
          tmp_v.push_back(tmp);
          sum += tmp;
          tmp = 0;
        }
      }
      if(sum > t){
      }else if(ans < sum){
        reject = false;
        ans = sum;
        ans_v = tmp_v;
      }else if(ans == sum){
        reject = true;
      }
    }
    if(reject){
      cout<<"rejected"<<endl;
    }else if(ans == -1){
      cout<<"error"<<endl;
    }else{
      cout<<ans<<" ";
      REP(i, ans_v.size()){
        cout<<ans_v[i];
        if(i == ans_v.size() - 1) cout<<endl;
        else cout<<" ";
      }
    }
  }
  return 0;
}

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

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		for(int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		int min = 0;
		int ans = 0;
		for(int i = 1; i < n; i++) {
			if(h[i] < h[i-1]) {
				ans += h[i-1] - min;
				min = h[i];
			}
		}
		ans += h[n-1]-min;
		System.out.println(ans);
	}

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

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

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

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

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

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

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

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

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


Measured memory_bytes: 32512
package main

import (
	"fmt"
	"math"
)

func main() {
	var N int
	fmt.Scan(&N)
	var x, y [8]float64
	for i := 0; i < N; i++ {
		fmt.Scan(&x[i], &y[i])
	}
	
	ans := 0.0
	for i := 0; i < N; i++ {
		for j := 0; j < N; j++ {
			ans += math.Hypot(x[i] - x[j], y[i] - y[j])
		}
	}
	fmt.Println(ans / float64(N))
}

Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
using namespace std;
int main(int argc, const char * argv[]) {
    float a, b;

    scanf("%f %f", &a, &b);
    
    if(a < b){
        printf("a < b\n");
    }
    else if(a>b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
    
    return 0;
}



Measured memory_bytes: 3208
// Believe in yourself...
#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define F first
#define S second
#define sz(c) (c).size()
#define REP(i,n)  for(ll i=0;i<n;i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)

#define bit(num,i) ((num>>i)&1)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

const ll inf=4e18;
const ll maxn=1e5+10;

#pragma GCC Optimize("Ofast")

ll a[maxn];

int main(){
	ll n;cin>>n;
	ll ln=0;
	FOR(i,1,n){
		cin>>a[i];
		ln+=abs(a[i]-a[i-1]);
	}
	ln+=abs(a[n]);
	FOR(i,1,n){
		ll A=a[(i+n)%(n+1)],C=a[(i+1)%(n+1)],B=a[i];
		cout<<(ln-abs(A-B)-abs(B-C)+abs(A-C))<<endl;
	}
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;

int gcd(int A, int B) {
    int rem;
    if(A<B) {
        int tmp = A;
        A = B;
        B = tmp;
    }
    rem = A % B;
    if (rem == 0) {
        return B;
    }

    return gcd(B, rem);
}

int main() { 
    int N, X; cin >> N >> X;
    vector<int> P(N);
    vector<int> dist(N);
    int x;
    cin >> x;
    dist[0] = abs(X-x);
    int divisor = dist[0];
    REP(i, N-1) {
        cin >> x;
        dist[i] = abs(X-x);
        divisor = gcd(divisor, dist[i]);
    }
    // print(dist);

    print(divisor);
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
char b;
cin >> b;
if (b == 'A') cout << 'T' << endl;
else if (b == 'T') cout << 'A' << endl;
else if (b == 'C') cout << 'G' << endl;
else if (b == 'G') cout << 'C' << endl;




return 0;
}


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

using namespace std;

int gcd(int,int);

int main(){
    int n,x;
    cin >> n >> x;
    int ans=0;
    for(int i=0;i<n;i++){
        int tmp;
        cin >> tmp;
        if(i==0){
            ans=abs(x-tmp);
        }else{
            ans=gcd(ans,abs(x-tmp));
        }
        if(ans==1) break;
    }
    cout << ans;
    return 0;
}

int gcd(int a,int b){
    if(a<b){
        int tmp=a;
        a=b;
        b=tmp;
    }
    int r=a%b;
    if(r==0){
        return b;
    }else{
        gcd(b,r);
    }
}

Measured memory_bytes: 256
use std::io;

#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

fn f(n: usize) -> usize {
    let s = str2vec(&n.to_string());
    let mut left = 0;
    let mut right = s.len() - 1;
    let mut flag = true;
    while left < right {
        if s[left] != s[right] {
            flag = false;
            break;
        }
        left += 1;
        right -= 1;
    }
    if flag {
        1
    } else {
        0
    }
}

#[allow(dead_code)]
fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}


fn main() {
    let a: usize;
    let b: usize;
    input!(a, b);
    let mut s = 0;

    for z in a..b + 1 {
        s += f(z);
    }
    p(s);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

void solve() {
    string S;
    cin >> S;
    int ans1 = 0;
    int ans2 = 0;
    int ans3 = 0;
    if(S[0] == 'R') {
        ans1++;
        if(S[1] == 'R' && S[2] == 'R') ans1 += 2;
        else if(S[1] == 'R') ans1++;
    } else if(S[1] == 'R') {
        ans2++;
        if(S[2] == 'R') ans2++;
    } else if(S[2] == 'R') ans3++;
    cout << max(ans1,max(ans2,ans3)) << endl;
}

int main() {
    int T;
    T = 1;
    while(T--) {
        solve();
    }
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define SIZE_OF_ARRAY(a) (sizeof(a)/sizeof(a[0]))

unsigned GetDigit(unsigned num){
    return std::to_string(num).length();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string N;
    cin >> N;
    string M;
    cin >> M;
    string a = N + M;
    int b[a.size()];
    for(int i = 0;i < a.size();i++){
        b[i] = a.at(i) - 48;
    }
    int c = 0;
    for(int i = 0;i < a.size();i++){
        c += b[i] * pow(10,a.size() - 1  -i);
      //  cout << c << endl;
    }
  //  cout << c << endl;
    string ans ="No";
    for(int i = 0; i < 100000;i++){
        if(c == i*i){
            ans = "Yes";
            break;
        }
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n;
  cin>>n;

  vector<ll> ans(n);

  repo(i,200){
    repo(j,200){
      repo(k,200){
        if(i*i+j*j+k*k+i*j+j*k+k*i<=n) ans[i*i+j*j+k*k+i*j+j*k+k*i-1]++;
      }
    }
  }

  rep(i,n){
    cout << ans[i] << endl;
  }

}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int i,t,j;
    cin>>s;
    t=s.size();
    for(i=0;i<t-2;i++)
    {
       if((s[i]==s[i+1])or(s[i]==s[i+2]))
       {
           cout<<i+1<<" "<<i+3<<endl;
           return 0;
       }
    }
      if((s[t-1]==s[t-2])&&(t>=2))
       {
           cout<<t-1<<" "<<t<<endl;
           return 0;
       }
    cout<<-1<<" "<<-1<<endl;
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    sort(all(v));
    double ans = v[0];
    for(int i = 1; i < n; ++i){
        ans = (ans+v[i])/2;
    }
    printf("%.10f", ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define rep(i,n) for(int i=0;i<(n);i++)
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); \
                                                  it != container.end(); ++it)
#define mp(a,b) make_pair((a),(b))

typedef long long ll;
typedef complex<double> point;

// up right down left
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};

const double EPS = 1e-9;
const int days[]     = {31,28,31,30,31,30,31,31,30,31,30,31};
const int daysleap[] = {31,29,31,30,31,30,31,31,30,31,30,31};

double logn(ll n,ll x){
    return log(x) / log(n);
}
int main(){
    ll n;
    cin >> n;
    double l = logn(3,n);
    if(abs(l-int(l)) < EPS){
        cout << round(l) << endl;
    }else{
        cout << ceil(l) << endl;
    }
    return 0;
}

Measured memory_bytes: 1276
using System;
using System.Linq;
using System.Collections.Generic;

namespace program
{
    class Program
    {
        static void Main()
        {
          int X = Input.ScanInt();
          int A = Input.ScanInt();
          int B = Input.ScanInt();
          
          X -=A;
          X -= (X/B)*B;
          Console.WriteLine(X);
        }
    }

    static class Input
    {
        static public int ScanInt() { return int.Parse(Console.ReadLine()); }
        static public uint ScanUint() { return uint.Parse(Console.ReadLine()); }
        static public double ScanDouble() { return double.Parse(Console.ReadLine()); }
        static public long ScanLong() { return long.Parse(Console.ReadLine()); }
        static public ulong ScanUlong() { return ulong.Parse(Console.ReadLine()); }
        static public int[] ScanIntArray() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        static public uint[] ScanUintArray() { return Console.ReadLine().Split(' ').Select(x => uint.Parse(x)).ToArray(); }
        static public double[] ScanDoubleArray() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        static public long[] ScanLongArray() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        static public ulong[] ScanUlongArray() { return Console.ReadLine().Split(' ').Select(x => ulong.Parse(x)).ToArray(); }

        static public string ScanStr() { return Console.ReadLine(); }
        static public string[] ScanStrArray() { return ScanStr().Split(' '); }
    }

    static class MyMath
    {
        public static int GCD(int a, int b)
        {
            Func<int, int, int> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static ulong GCD(ulong a, ulong b)
        {
            Func<ulong, ulong, ulong> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
        public static int LCM(int a, int b)
        {
            return a * b / GCD(a, b);
        }
        public static ulong LCM(ulong a, ulong b)
        {
            return a * b / GCD(a, b);
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>

int main(){
  int card[4][13], i, j, maisuu, num;
  char mark;
  
  for(i=0;i<4;i++){
    for(j=0;j<13;j++){
      card[i][j]=0;
    }
  }
  
  scanf("%d",&maisuu);
  
  for(i=0;i<maisuu;i++){
    scanf("%c",&mark);
    scanf("%c %d",&mark,&num);
    
    if(mark=='S') card[0][num-1]=1;
    if(mark=='H') card[1][num-1]=1;
    if(mark=='C') card[2][num-1]=1;
    if(mark=='D') card[3][num-1]=1;
  }
  
  for(i=0;i<4;i++){
    for(j=0;j<13;j++){
      if(card[i][j]==0){
	if(i==0) printf("S %d\n",j+1);
	if(i==1) printf("H %d\n",j+1);
	if(i==2) printf("C %d\n",j+1);
	if(i==3) printf("D %d\n",j+1);
      }
    }
  }
  
  return 0;
}



Measured memory_bytes: 2076
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;

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

	ll N;
	cin >> N;
	ll k = 1;
	while((k + 1) * (k + 0) / 2 < N) k++;
	//cout << k << endl;

	vector<int> ans;
	for(int i = k; i >= 1; i--) {
		if(i <= N) {
			N -= i;
			ans.push_back(i);
		}
	}

	for(int i = 0; i < ans.size(); i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 384
n,d = gets.split.map(&:to_i)
a = n.times.map{gets.split.map(&:to_i)}
ans = 0
(0..(n-2)).each do |i|
    ((i+1)...n).each do |j|
        sum = 0
        d.times do |k|
            sum += (a[i][k]-a[j][k])**2
        end
        s = Math.sqrt(sum).floor
        if (s*s == sum || (s+1)*(s+1) == sum)
            ans += 1
        end
    end
end
puts ans

Measured memory_bytes: 3836
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
char s[100100];
char str[100100];
int p[100100],pp[100100];
int main(){
	scanf("%s",str+1);
	int n=strlen(str+1);
	int num=0;
	for(int i=1;i<=n;i++)
	{
		if(str[i]!='x')
		{
			s[++num]=str[i];
			p[num]=i;
		}
	}
	for(int i=1;i<=num;i++){
		if(s[i]!=s[num-i+1]){
			printf("-1\n");
			return 0;
		}
	}
	int nn=0;
	p[++num]=n+1;
	for(int i=1;i<=num;i++)
		pp[++nn]=p[i]-p[i-1];
	long long ans=0;
	for(int i=1;i<=nn/2;i++)
		ans=ans+abs(pp[i]-pp[num-i+1]);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1152
#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 a, b, c;
    cin >> a >> b >> c;
    if (a<b+c) cout << b+c-a <<endl;
    else cout << 0 <<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define MAX 100000
#define rep(i, n) for(int i=0;i<(int)(n);i++)

typedef long long llong;

int n, k;
llong T[MAX];

int check(llong P){
    int i=0;
    rep(j, k){
        llong s=0;
        while(s+T[i]<=P){
            s+=T[i];
            i++;
            if(i==n) return n;
        }
    }
    return i;
}

int solve(){
    llong left=0;
    llong right=100000*10000;
    llong mid;
    while(right-left>1){
        mid=(left+right)/2;
        int v=check(mid);
        if(v>=n) right=mid;
        else left=mid;
    }
    return right;
}

main(){
    cin>>n>>k;
    rep(i,n) cin>>T[i];
    llong ans=solve();
    cout<<ans<<endl;
}


Measured memory_bytes: 3876
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#include <fstream>
#include <cassert>
#include <cmath>
#include <sstream>
#include <time.h>
#include <complex>
#include <iomanip>
//#include <unordered_set>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l4;
const double eps = 0.005;
const int maxn = 2010;
const ll mod = 1e9+7;
const int INF = 1e9;
const double pi = acos(-1);
typedef double Matrix[maxn][maxn];
int n;
char s[maxn];
int main() {
    scanf("%s",s);
    int len = strlen(s);
    int ans = len;
    for (int i = 0; i < 26; i++) {
        int tmp = 0;
        int maxi = 0;
        for (int j = 0; j < len; j++) {
            if (s[j] != i+'a') {
                tmp++;
            } else {
                maxi = max(maxi,tmp);
                tmp = 0;
            }
        }
        maxi = max(maxi,tmp);
        ans = min(ans,maxi);
    }
    printf("%d",ans);
    return 0;
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb          push_back
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define endl        "\n"
#define fast        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int         long long int
#define mod         1000000007
#define test        int t;cin>>t;while(t--)
#define REP(i,a,b)  for(int i=a,i<=b;i++)
#define MAXN        200001

int32_t main()
{
    string str;
    cin>>str;

    bool ok=true;
    map<char,int>mp;
    for(int i=0;i<4;i++){
        mp[str[i]]++;
    }

    if(mp.size()==2){
        for(auto x:mp){
            if(x.S!=2){
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout<<"Yes"<<endl;
    }

    else
        cout<<"No"<<endl;

    return 0;
}

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

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

    bool flagL = false;
    bool flagR = false;

    if(N[0] == N[1] && N[1] == N[2]) flagL = true;
    if(N[1] == N[2] && N[2] == N[3]) flagR = true;

    if(flagL || flagR) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin>>a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
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; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;

int main(){
    LL(n);
    VEC(ll,a,n+1);
    VEC(ll,b,n);
    ll ans = 0;

    for(int i = 0; i < n; i++){
        ll c = min(a[i],b[i]);
        b[i]-=c;
        a[i]-=c;
        ans+=c;
        c=min(a[i+1],b[i]);
        b[i]-=c;
        a[i+1]-=c;
        ans+=c;
    }
    cout << ans << endl;

}

Measured memory_bytes: 1792
#include <stdio.h>

int n,k,a[128],ans;
char ss[100010];
int main(){
	scanf("%d%d%d%d%d %s",&n,&k,&a['s'],&a['p'],&a['r'],ss);
	for(int i=0;i<n;i++){
		if(i>=k&&ss[i-k]==ss[i])ss[i]=0;
		ans+=a[ss[i]];
	}
	printf("%d\n",ans);
}

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

using namespace std;

typedef long long ll;
ll mod = 1000000007;
#define f first
#define s second
#define ss string
#define mp make_pair
#define pb push_back
#define p pair<int, int>
#define pp pair<int, p>
#define v vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vs vector<string>
#define vp vector<p>
#define vpp vector<pair<int, p>>
#define vv vector<v>
#define vvl vector<vl>
#define vvp vector<vp>
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repa(i, a, n) for(int i = a; i <= (n); ++i)
#define repd(i, n) for(int i = n; i >= 0; --i)
#define all(x) (x).begin(), (x).end()

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    ll ans = 0;
    vl a(n);
    unordered_map<int, int> map;
    rep(i, n){
        cin >> a[i];
        map[a[i]]++;
        ans += a[i];
    }
    int q, x, y;
    cin >> q;
    while(q--){
        cin >> x >> y;
        int t = map[x];
        map[x] = 0;
        map[y] += t;
        ans = ans + t*(y-x);
        cout << ans << endl;
    }
    return 0;
}   

Measured memory_bytes: 7908
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1e18;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;



int main() {
  string s,t;
  cin>>s>>t;
  s += s;
  cout<<(s.find(t)!=string::npos?"Yes":"No")<<endl;
  return 0;
}






















Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
long long n,x;
int main()
{
    scanf("%lld",&n);
    if(n%2==0)
        printf("%lld\n",n);
    else
    {
        x=n*2;
        printf("%lld\n",x);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


int main() {
    
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n)    cin >> s[i];

    sort(all(s));
    int ans = 1;
    rep(i,n-1) {
        if(s[i+1] != s[i])  ans++;
    }

    cout<<ans<<endl;

 return 0;
}


Measured memory_bytes: 9544
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  int a,b; cin >> a >> b;
  if(a>=1&&a<=9&&b>=1&&b<=9) cout << a*b;
  else cout << -1;
  


  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <map>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define EPS 1e-9

int main(){
	int k;
	while(scanf("%d",&k),k){
		int s = 0;
		for(int i=0; i<k*(k-1)/2; i++){
			int t; scanf("%d",&t);
			s += t;
		}
		printf("%d\n",s/(k-1));
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN_LL(v) ll v;cin>>v;
#define OUT(v) cout<<v<<"\n"

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

  ll n = X;
  int ans = 0;
  while (n <= Y) {
    n *= 2;
    ++ans;
  }
  OUT(ans);


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef long long LL;
typedef istringstream ISS;
typedef ostringstream OSS;

char toChar( int n ) {
    return n + '0';
}

string toSeven( LL n ) {
    string s;
    while ( n >= 8 ) {
        s += toChar( n % 8 );
        n /= 8;
    }
    s += toChar( n );
    reverse( s.begin(), s.end() );
    return s;
}

LL toNewNumber( string s ) {
    char T[8] = { '0', '1', '2', '3', '5', '7', '8', '9' };
    string t = s;
    int n = s.size();
    for ( int i = 0; i < n; ++ i ) {
        s[i] = T[ s[i] - '0' ];
    }
    ISS iss1( s );
    LL res;
    iss1 >> res;
    return res;
}

LL solve( LL n ) {
    return toNewNumber( toSeven( n ) );
}

int main() {
    LL n;
    while ( cin >> n && n ) {
        cout << solve( n ) << endl;
    }
    return 0;
}

Measured memory_bytes: 0