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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

class UnionFind {
    vector<int> parent;

    public:
        UnionFind(int size) {
            parent = vector<int>(size, -1);
        }

        int find(int x) {
            if (parent[x] < 0) {
                // parent itself
                return x;
            } else {
                return parent[x] = find(parent[x]);
            }
        }

        bool unite(int x, int y) {
            int rX, rY;
            if ((rX = find(x)) == (rY = find(y))) {
                // already united
                return false;
            }
            if (size(rX) < size(rY)) {
                int tmp = rX;
                rX = rY;
                rY = tmp;
            }
            parent[rX] += parent[rY];
            parent[rY] = rX;
            return true;
        }

        int size(int x) {
            return -parent[find(x)];
        }

        bool isSame(int x, int y) {
            return find(x) == find (y);
        }
        
        int component_count() {
            int c = 0;
            for (const int x : parent) {
                if (x < 0) {
                    c++;
                }
            }
            return c;
        }
};

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

    vector<pair<int, int>> x, y;
    int r, c;
    for (int i = 0; i < n; i++) {
        cin >> r >> c;
        x.emplace_back(r, i);
        y.emplace_back(c, i);
    }

    sort(ALL(x));
    sort(ALL(y));
    // dist, idx1, idx2 
    vector<tuple<int, int, int>> d;
    for (int i = 1; i < n; i++) {
        d.emplace_back(abs(x[i].first - x[i - 1].first), x[i].second, x[i - 1].second);
        d.emplace_back(abs(y[i].first - y[i - 1].first), y[i].second, y[i - 1].second);
    }

    sort(ALL(d));

    UnionFind uf = UnionFind(n);

    int t = 0;
    for (const auto e : d) {
        if (uf.isSame(get<1>(e), get<2>(e))) {
            continue;
        }

        t += get<0>(e);
        uf.unite(get<1>(e), get<2>(e));
    }

    cout << t << endl;
}


Measured memory_bytes: 7144
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>

using namespace std;
typedef long long ll;

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int,int> > vp;
  for (int i = 0; i < N; ++i) {
    int A, B;
    cin >> A >> B;
    vp.push_back(make_pair(A, B));
  }
  sort(vp.begin(), vp.end());

  priority_queue<int> pq;
  ll ans = 0;
  int i = 0;
  for (int d = 1; d <= M; ++d) {
    while (i < N and vp[i].first <= d) {
      pq.push(vp[i].second);
      ++i;
    }
    if (not pq.empty()){
      ans += pq.top();
      pq.pop();
    }
  }

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


Measured memory_bytes: 1908
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  rep(i, n) cin >> x[i];
  int ans = 0;
  rep(i, n){
    ans += min(abs(x[i] - k), x[i]) * 2;
  }
  cout << ans << endl;
}

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

int main() 
{
	// your code goes here
	// freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
	int n, k;
	cin >> n >> k;

	int arr[n];

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

	sort(arr, arr+n);

	int total = 0;

	for(int i = 0; i < k; i++)
	{
		total +=  arr[i];
	}
	
	cout << total << '\n';


		
	return 0;

	} 


Measured memory_bytes: 3512
#include <bits/stdc++.h>
#define lol long long
using namespace std;
int main(){
    int a,b,c;
    string s,t,q;
    cin>>s>>t>>q;
    a='A'-'a';
    s[0]=s[0]+a;
    t[0]=t[0]+a;
    q[0]=q[0]+a;
    cout<<s[0]<<t[0]<<q[0]<<"\n";
    return(0);
}

Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {

    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        System.out.println(t+s);
    }
}


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

using namespace std;

int sz;

void print(pair<char,int> a[])
{
    for(int i=0; i<sz; i++)
        cout<<a[i].first<<" "<<a[i].second<<"\n";
}


int Partition(pair<char,int> a[],int p,int r)
{
    int x= a[r].second;
    int i= p-1;
    for(int j=p ; j<=r-1; j++)
    {
        if(a[j].second<=x)
        {
            i++;
            swap(a[i],a[j]);
        }

    }
    swap(a[i+1],a[r]);
    return (i+1);
}

void QuickSort(pair<char,int>a[],int p,int r)
{
    if(p<r)
    {
        int q=Partition(a,p,r);
        QuickSort(a,p,q-1);
        QuickSort(a,q+1,r);
    }

}

int main()
{
    //freopen("inp.txt","r",stdin);
    //freopen("outp.txt","w",stdout);
    int n,a2,p,r;
    char a1;
    cin>>n;
    sz=n;
    pair<char,int> a[n],b[n];
    for(int i=0; i<n; i++)
    {
        cin>>a1>>a2;
        a[i]=make_pair(a1,a2);
        b[i]=make_pair(a1,a2);
    }
    QuickSort(a,0,n-1);
    ///////////
    int f=0;
    for(int i=0; i<sz; i++)
    {
        if(f==1)
            break;
        for(int j=0; j<sz; j++)
        {
            if(a[i].second==b[j].second)
            {
                if(a[i].first==b[j].first)
                {
                    b[j].second=0;
                    break;
                }
                else
                {
                    f=1;
                    break;
                }
            }

        }
    }
    if(f==0)
        cout<<"Stable"<<"\n";
    else
        cout<<"Not stable"<<"\n";
    ///////////
    print(a);
    return 0;
}



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

typedef long long ll;
const int maxn = 300010, P = 998244353;
int n, fact[maxn], finv[maxn];
ll a, b, s;

int qp(int x, int y) {
    int z = 1;
    for (; y; y >>= 1, x = 1LL * x * x % P) {
        if (y & 1) z = 1LL * z * x % P;
    }
    return z;
}

int C(int x, int y) {
    return 1LL * fact[x] * finv[y] % P * finv[x - y] % P;
}

int main() {
    cin >> n >> a >> b >> s;
    for (int i = fact[0] = finv[0] = 1; i <= n; i++) {
        fact[i] = 1LL * i * fact[i - 1] % P;
        finv[i] = qp(fact[i], P - 2);
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        ll r = n * (a + b) - s - i * a;
        if (r < 0 || r % b) continue;
        ll t = r / b;
        if (t > n) continue;
        ans = (ans + 1LL * C(n, i) * C(n, t)) % P;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
using namespace std;
int arisutoteresu[200][200] = {0};
int imap[200][200] = {0};
int n,u[200],k[200];
int GetIt[200]={0};
int FinIt[200]={0};
bool used[200];
int fincou=1;
int Gcounter;
int Fcounter;
int Find;
void dfs(int where){
  Find++;
  //cout << "where " << where << " " << Find << endl; 
 GetIt[where]=Find;
  //cout << "GetIt[" << where << "] = " << GetIt[where] << endl;

  if(k[where] != 0){ 
    for(int i=0;i<k[where];i++){
      if(!used[imap[where][i]]){
	Gcounter++;

	used[imap[where][i]] = true;
	dfs(imap[where][i]);

      }
    }
  }
  Find++;
    FinIt[where] = Find;
     
}
 
int main(){
  
  int ad;
   
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    cin >> u[i];
    cin >> k[u[i]];
    for(int j=0;j<k[u[i]];j++){
      cin >> ad;
      imap[u[i]][j] = ad;
    }
  }
 
 
  for(int j=0;j<200;j++)used[j] = false;
  Gcounter=Fcounter=1;
 
  Find = 0;
  int Index=0;
  bool fin = true;
  fincou = 1;

  
    for(int i=0;i<n;i++){
      if(!used[u[i]]){//cout << "not used" << u[i] << endl;
	used[u[i]]=true;
	dfs(u[i]);

      }
    }
    
    //dfs(u[0]);   

   
  
  //cout << "counter - " << Find << ", F" << fincou << endl;
  for(int i=0;i<n;i++){
    cout << u[i] << " " << GetIt[u[i]]  << " " << FinIt[u[i]];
    cout << endl;
  }
 
  return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
using ll = long long;
using Interval = pair<ll, ll>;

int edgeIndex(int H, int W, int y, int x) {
  if (y == 0) return W - x;
  if (x == 0) return W + y;
  if (y == H) return W + H + x;
  if (x == W) return W + H + W + (H - y);
  return -1;
}

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  vector<Interval> intervals;
  for (int i = 0; i < N; i++) {
    int y1, x1, y2, x2;
    cin >> y1 >> x1 >> y2 >> x2;
    int s = edgeIndex(H, W, y1, x1);
    int t = edgeIndex(H, W, y2, x2);
    if (s != -1 && t != -1) {
      if (s > t) swap(s, t);
      intervals.emplace_back(s, t);
    }
  }
  sort(intervals.begin(), intervals.end());
  stack<Interval> stk;
  bool res = true;
  for (auto &interval : intervals) {
    while (!stk.empty() && stk.top().second < interval.first) {
      stk.pop();
    }
    if (!stk.empty() && stk.top().second < interval.second) {
      res = false;
      break;
    }
    stk.push(interval);
  }
  cout << (res ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 2420
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

void test()
{
	ll now = 100;

	for(ll i = 1; i <= 1000; i++)
	{
		now += (now / 100);

		cout << i << ": " << now << endl;
	}
}
int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

//    test();

	while(cin >> n)
	{
		ll now = 100;

		for(ans = 0; ans <= 10000 && now < n; ans++)
		{
			now += (now / 100);
		}

		cout << ans << '\n';
	}

}





Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define MAX 100001
int a[MAX],N;

int main(){
  cin >> N;
  int max=0,res;
  for(int i=1;i<=N;i++){
    int count=0;
    int j=i;
    while(j%2==0){
      j/=2;
      count++;
    }
    if(count>=max){
      max=count;
      res=i;
    }
  }
  cout << res << endl;
  return 0;
}


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

int n,res = 0;
string s,ss;

typedef pair<int,int> P;

int main(){
	cin >> n >> s;
	for(int i = 0;i < n;i++){
		bool flag = false;
		vector<int> start;
		vector<P> cand;
		cin >> ss;
		for(int j = 0;j < ss.length();j++){
			if(s[0] == ss[j]) start.push_back(j);
		}
		for(int j = 0;j < start.size();j++){
			for(int k = 1;k < ss.length();k++){
				if(start[j] + k >= ss.length()) break;
				if(ss[start[j] + k] == s[1]) cand.push_back(P(start[j],k));
			}
		}
		for(int j = 0;j < cand.size();j++){
			int pos = cand[j].first,d = cand[j].second;
			bool f = true;
			for(int k = 0;k < s.length();k++){
				if(pos >= ss.length() || ss[pos] != s[k]){
					f = false;
					break;
				}
				pos += d;
			}
			if(f) {
				flag = true;
				break;
			}
		}
		if(flag) res++;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3156
n, k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0] * n
for i in range(1, n):
    min_tmp = float('inf')
    for j in range(1, k+1):
        if j > i:
            break
        min_tmp = min(min_tmp, dp[i-j] + abs(h[i]-h[i-j]))
    dp[i] = min_tmp
print(dp[-1])

Measured memory_bytes: 52448
n=int(input())
a=[]
for i in range(1,n+1):
    for j in range(i,n+1-n%2):
        if j!=i!=n-j+1-n%2:
            a.append((i,j))
if n%2:
    a+=[(i,n)for i in range(1,n)]
print(len(a))
for t in a:
    print(*t)

Measured memory_bytes: 3956
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
//typedef __int64 LL;
typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int,int> P;
//typedef pair<LL,LL> PL;
LL n,k;
LL a[200020],f[200020];
const int MOD=1000000007;

bool hantei(LL x)
{
	LL sum=0;
	for(LL i=0;i<n;i++)
	{
		sum+=max((LL)0,a[i]-x/f[i]);	
	}
	return (sum<=k);
} 
int main(){
	LL ans=0;
	cin>>n>>k;
	for(LL i=0;i<n;i++)cin>>a[i];
	for(LL i=0;i<n;i++)cin>>f[i];
	sort(a,a+n);
	sort(f,f+n,greater<LL>());
	
	LL l=0,r=100000000000000;
	
	while(r-l>=1)
	{
		LL mid=(l+r)/2;
		bool flag=hantei(mid);
		if(flag)r=mid;
		else l=mid+1;
	}
	cout<<l<<"\n";
	return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;

int main(){

ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a;
    string s;
    cin>>a>>s;
    if(a>=3200)
    cout<<s;
    else
    cout<<"red";

}


Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
    return a%10>b%10;
}
int main()
{
    int a[5],s=0,j,r;
    for(int i=0;i<5;i++)
    scanf("%d",&a[i]);
    sort(a,a+5,cmp);
    for(j=0;j<5;j++)
    {
        if(a[j+1]%10==0)
            break;
    }
    r=a[j];
    a[j]=a[4];
    a[4]=r;
    for(int i=0;i<5;i++)
    {
        if(i==4)
            s+=a[i];
        else
        {
        if(a[i]%10!=0)
            s+=a[i]+10-a[i]%10;
        else s+=a[i];
        }
    }
    cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

struct UnionFind {
  vector<int> parent;  // parent[root] is the negative of the size.
  UnionFind(int n)
      : parent(n, -1){};
  bool unite(int u, int v) {
    u = root(u);
    v = root(v);
    if (u == v) return false;
    if (parent[u] > parent[v]) swap(u, v);
    parent[u] += parent[v];
    parent[v] = u;
    return true;
  }
  bool find(int u, int v) {
    return root(u) == root(v);
  }
  int root(int u) {
    return parent[u] < 0 ? u : parent[u] = root(parent[u]);
  }
  int size(int u) {
    return -parent[root(u)];
  }
};

int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};

int main() {
  int H, W;
  while (cin >> H >> W) {
    vector<string> grid(H);
    for (int i = 0; i < H; i++) cin >> grid[i];
    UnionFind uf(H * W);
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        for (int k = 0; k < 4; k++) {
          int ni = i + dy[k];
          int nj = j + dx[k];
          if (ni < 0 || ni >= H || nj < 0 || nj >= W) continue;
          if (grid[i][j] != grid[ni][nj]) {
            uf.unite(i * W + j, ni * W + nj);
          }
        }
      }
    }
    vector<int> w(H * W, 0), b(H * W, 0);
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        int r = uf.root(i * W + j);
        if (grid[i][j] == '.') {
          ++w[r];
        } else {
          ++b[r];
        }
      }
    }
    ll res = 0;
    for (int i = 0; i < H * W; i++) res += (ll)w[i] * b[i];
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 2304
n,*t=map(int,open(0).read().split())
e=[[]for i in range(n+1)]
for a,b in zip(t[1::2],t[2::2]):
  e[a].append(b)
  e[b].append(a)
i=0
for v in e[1]:
  for w in e[v]:
    if w==n:
      i=2
print('IMPOSSIBLE'[i:])

Measured memory_bytes: 46660
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    int[] B = new int[N+1];
    int[] C = new int[N+1];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    for (int i = 1; i <= N; i++) {
      B[i] = sc.nextInt();
    }
    for (int i = 1; i <= N-1; i++) {
      C[i] = sc.nextInt();
    }
    
    int ans = 0;
    int prev = -1;
    for (int i = 0; i < N; i++) {
      ans += B[A[i]];
      if (prev+1 == A[i]) {
        ans += C[prev];
      }
      prev = A[i];
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 23760
a,b= map(int, input().split())

amin = int(a//0.08)
amax = int((a+1)//0.08)
bmin = int(b//0.1)
bmax = int((b+1)//0.1)

if a%0.08 > 0:
	amin += 1
if (a+1)%0.08 > 0:
	amax -= 1
if b%0.1 > 0:
	bmin += 1
if (b+1)%0.1 > 0:
	bmax -= 1

if amin <= bmin:
	if bmin <= amax:
		print(bmin)
	else:
		print('-1')
else:
	if amin <= bmax:
		print(amin)
	else:
		print('-1')


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999;
	
	public static void Main(string[] args)
	{
		var n = Input().ToInt();
		var s = Console.ReadLine().Split('-');
		if(s.Length != 2)
		{
			Console.WriteLine("No");
			return;
		}
		if(s[0].Length == n[0] && s[1].Length == n[1])
		{
			Console.WriteLine("Yes");
			return;
		}
		Console.WriteLine("No");
		
	}

	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)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

//#define _USE_MATH_DEFINES
//#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>
#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef int long long i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 1000000007; // 10000000000000007ll;

const double eps = 1e-8;

const i64 MAXN = 400005;
const i64 MAXM = 20;


i64 n;
pair<i64, i64> a[MAXN];
i64 z[MAXN];

i64 dp[MAXN];

i64 binpow(i64 a, i64 n) {
    i64 res = 1;
    while (n) {
        if (n & 1) {
            res *= a;
            res %= smod;
        }
        a *= a;
        a %= smod;
        n >>= 1;
    }
    return res % smod;
}

i64 st[MAXN * 4];

void sset(i64 i, i64 tl, i64 tr, i64 j, i64 v) {
    if (tl == tr) {
        st[i] = v;
        return;
    }

    i64 t = (tl + tr) / 2;
    if (j <= t) {
        sset(i * 2, tl, t, j, v);
    }
    else {
        sset(i * 2 + 1, t + 1, tr, j, v);
    }
    st[i] = max(st[i * 2], st[i * 2 + 1]);
}

void sset(i64 j, i64 v) {
    sset(1, 0, n - 1, j, v);
}

i64 smax(i64 i, i64 tl, i64 tr, i64 l, i64 r) {
    if (l > r) {
        return 0;
    }

    if (tl == l && tr == r) {
        return st[i];
    }

    i64 t = (tl + tr) / 2;
    i64 v1 = smax(i * 2, tl, t, max(tl, l), min(t, r));
    i64 v2 = smax(i * 2 + 1, t + 1, tr, max(t + 1, l), min(tr, r));

    return max(v1, v2);
}

i64 smax(i64 l, i64 r) {
    return smax(1, 0, n - 1, l, r);
}

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

    cin >> n;
    for (i64 i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }

    sort(a, a + n);

    z[n] = n;
    for (i64 i = n - 1; i >= 0; i--) {
        z[i] = upper_bound(a + i, a + n, make_pair(a[i].first + a[i].second, 0ll)) - a;
        for (;;) {
            i64 k = max(z[i], smax(i + 1, z[i] - 1));
            if (z[i] == k) {
                break;
            }
            z[i] = k;
        }
        sset(i, z[i]);
    }

    dp[n] = 1;
    for (i64 i = n - 1; i >= 0; i--) {
        dp[i] = dp[i + 1] + dp[z[i]];
        dp[i] %= smod;
    }

    cout << dp[0] << endl;

    //i64 R = 0;
    //for (i64 i = 0; i < n; i++) {
    //    i64 S = binpow(2 ^ z[i]);
    //}

    return 0;
}

Measured memory_bytes: 16640
class Combinatorics:
    def __init__(self, N, mod):
        '''
        Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N)
        over the finite field Z/(mod)Z.
        Input:
            N (int): maximum n
            mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated.
        '''
        self.mod = mod
        self.fact = {i: None for i in range(N+1)}         # n!
        self.inverse = {i: None for i in range(1, N+1)}   # inverse of n in the field Z/(MOD)Z
        self.fact_inverse = {i: None for i in range(N+1)} # inverse of n! in the field Z/(MOD)Z
        
        # preprocess
        self.fact[0] = self.fact[1] = 1
        self.fact_inverse[0] = self.fact_inverse[1] = 1
        self.inverse[1] = 1
        for i in range(2, N+1):
            self.fact[i] = i * self.fact[i-1] % self.mod
            q, r = divmod(self.mod, i)
            self.inverse[i] = (- (q % self.mod) * self.inverse[r]) % self.mod
            self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i-1] % self.mod
    
    def perm(self, n, r):
        '''
        Calculate nPr = n! / (n-r)! % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return (self.fact[n] * self.fact_inverse[n-r]) % self.mod
    
    def binom(self, n, r):
        '''
        Calculate nCr = n! /(r! (n-r)!) % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return self.fact[n] * (self.fact_inverse[r] * self.fact_inverse[n-r] % self.mod) % self.mod
        
    def hom(self, n, r):
        '''
        Calculate nHr = {n+r-1}Cr % mod.
        Assign r objects to one of n classes.
        Arrangement of r circles and n-1 partitions:
            o o o | o o | | | o | | | o o | | o
        '''
        if n == 0 and r > 0:
            return 0
        if n >= 0 and r == 0:
            return 1
        return self.binom(n + r - 1, r)

MOD = 10**9 + 7
X, Y = map(int, input().split())
if (X + Y) % 3 != 0: print(0)
else:
    x, y = ((2*X - Y) // 3, (-X + 2*Y) // 3)
    com = Combinatorics(x + y, MOD)
    print(com.binom(x+y, x))


Measured memory_bytes: 203892
#include<bits/stdc++.h>//可以拿笔算一算 
using namespace std;
int n,k,ans,p;
int rili[12][6]= {
    {4,2,0,9,7},
    {1,10,8,6,4},
    {9,7,5,3,1},
    {6,4,2,0,9},
    {3,1,10,8,6},
    {0,9,7,5,3},
    {8,6,4,2,0},
    {5,3,1,10,8},
    {2,0,9,7,5},
    {10,8,6,4,2},
    {7,5,3,1,10}};//找出来的规律 ，7列14行的3*3矩阵相加得出来的一个二维答案数组 
int main() {
    scanf("%d%d",&n,&k);
    ans=((n-2)/11)*5;
    if(n<=2)//因为前两行是单独的 
        for(int i=0; i<p; i++)
            for(int j=0; j<5; j++) {
                if(rili[i][j]==k)ans++;}//相等就++ 
    else//而后几行是是每12行就有规律的 
        for(int i=0;i<(n-2)%11;i++)//可能会很大得取模 
            for(int j=0;j<5;j++)
                if(rili[i][j]==k)ans++;//相等就++ 
    printf("%d\n",ans);//输出答案 
    return 0;//功德圆满 
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <vector>

int main() {
	int x = 0;
	int n = 0;
	std::cin >> x >> n;
	std::vector<decltype(x)> vect(n);
	bool vect_contains_x = false;
	for (auto& elem : vect) {
		std::cin >> elem;
		if (elem == x) {
			vect_contains_x = true;
		}
	}
	int num = 0;
	if (!vect_contains_x) {
		num = x;
	}
	else {
		std::sort(vect.begin(), vect.end());
		while (1) {
			static int i = 1;
			if (std::find(vect.begin(), vect.end(), x - i) == vect.end()) {
				num = x - i;
				break;
			}
			else if (std::find(vect.begin(), vect.end(), x + i) == vect.end()) {
				num = x + i;
				break;
			}
			else {
				i += 1;
			}
		}
	}
	std::cout << num << "\n";
	return 0;
}

Measured memory_bytes: 3100
#include<iostream>
using namespace std;
int main(){
    int n1 = 0 ,n2 = 0;
    int a , b , c ;
    char d;
    while(cin >> a >> d >> b >> d >> c){
        if(a*a + b*b == c*c){
            n1 ++ ;
        }
        else if(a == b){
            n2 ++ ;
        }
    }
    cout << n1 << endl << n2 << endl;
    return 0;
}


Measured memory_bytes: 3076
n = int(input())
s = list(input())
r = s.count("R")
g = s.count("G")
b = s.count("B")
c = 0
for i in range(n):
    j = 1
    while i+j+j+1 <= n:
        if  len(set([s[i],s[i+j],s[i+j+j]]))==3:
            c += 1
        j += 1
print(r*g*b - c)

Measured memory_bytes: 73700
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };

int color_check(int a) {
	if (a < 400) return 0;
	else if (a < 800) return 1;
	else if (a < 1200) return 2;
	else if (a < 1600) return 3;
	else if (a < 2000) return 4;
	else if (a < 2400) return 5;
	else if (a < 2800) return 6;
	else if (a < 3200) return 7;
	else return 8;
}


int main() {

	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a.at(i);
	vector<int> num(9);

	rep(i, n) {
		int color = color_check(a.at(i));
		if (color == 8) {
			num.at(8)++;
		}
		else {
			num.at(color) = 1;
		}
	}
	int ans_min = 0;
	int ans_max = 0;
	rep(i, 8) {
		if (num.at(i) != 0) ans_min++;
	}
	ans_max = ans_min + num.at(8);
	if (ans_min == 0) ans_min = 1;

	cout << ans_min << ' ' << ans_max << endl;


	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#include<stdlib.h>
#define MAX 400

void push(int S[],int *top,int x){

 S[(*top)]=x;
 (*top)++;

return;
}

int pop(int S[],int *top){

 (*top)--;
 return S[(*top)];

}

int main(){
 char str[400];
 int i,j;
 int R,top;
 char temp[50];
 int S[80];
 int x1,x2;

 while(fgets(str,sizeof str,stdin)!=NULL){

   R=strlen(str);
   j=0; i=0; top=0;

   while(i<=R){

     if(i<R && str[i]!=' ')temp[j++]=str[i++];
     else {

       temp[j]='\0';

       if(isdigit(temp[0]))
          push(S,&top,atoi(temp));
       else if( !isdigit(temp[0]) && isdigit(temp[1]) )
          push(S,&top,atoi(temp));/*負の数*/
       else {
          x1=pop(S,&top);
          x2=pop(S,&top);
          switch(temp[0]){
            case '+':push(S,&top,x2+x1);
                     break;
            case '-':push(S,&top,x2-x1);
                     break;
            case '*':push(S,&top,x2*x1);
                     break;
            case '/':push(S,&top,x2/x1);
                     break;
          }

       }
       i++;
       j=0;

     }


   }
   printf("%d\n",S[0]);

 }


return 0;
}


Measured memory_bytes: 2100
/**
 *  author: Haunted_Cpp
**/
 
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
 
template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
 
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
 
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

const int MAX_N = 3e3 + 5;
const int MAX_K = 5;

long long dp[MAX_N][MAX_N][MAX_K];

int r, c, k;

int g[MAX_N][MAX_N];

long long solve(int linha, int coluna, int how_many) {
  if (linha == r - 1 && coluna == c - 1) {
    if (how_many + 1 <= 3) return g[linha][coluna];
    return 0;
  }
  if (linha >= r) return -1e18;
  if (coluna >= c) return -1e18;
  long long &res = dp[linha][coluna][how_many];
  if (~res) return res;
  res = -1e18;
  res = max(res, solve(linha + 1, coluna, 0));
  res = max(res, solve(linha, coluna + 1, how_many));
  if (how_many + 1 <= 3) {
    res = max(res, solve(linha + 1, coluna, 0) + g[linha][coluna]);
    res = max(res, solve(linha, coluna + 1, how_many + 1) + g[linha][coluna]);
  }
  return res;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); 
  cin >> r >> c >> k;
  memset(g, 0, sizeof(g));
  for (int i = 0; i < k; i++) {
    int x, y, w;
    cin >> x >> y >> w; 
    --x; --y;
    g[x][y] = w;
  }
  memset(dp, -1, sizeof(dp));
  cout << solve(0, 0, 0) << '\n';
  return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
	ost<<"{";
	for(int i=0;i<v.size();i++){
		if(i)ost<<",";
		ost<<v[i];
	}
	ost<<"}";
	return ost;
}

signed main(){
	int N,K;
	cin>>N>>K;
	string S;cin>>S;
	vint lis;
	rep(i,N-1){
		if(S[i]=='R'&&S[i+1]=='L')lis.pb(2);
	}
	if(S.front()=='L')lis.pb(1);
	if(S.back()=='R')lis.pb(1);
	sort(all(lis));
	reverse(all(lis));
	int ans=N-accumulate(all(lis),0ll);
	lis.back()--;
	chmin(K,lis.size());
	ans+=accumulate(lis.begin(),lis.begin()+K,0ll);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <time.h>
#define int long long
using namespace std;
signed main(){
	int k;
	cin >> k;
	if (k % 2 == 0) {
		cout << (k / 2)*(k / 2) << endl;
		return 0;
	}
	else {
		cout << (k / 2)*(k / 2 + 1) << endl;
	}
	system("PAUSE");
	return 0;
}


Measured memory_bytes: 504
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define int long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
int n,d,a,siz=1;
P p[800010];
vector<int> dat,laz;
void init(int x){
    while(siz<x)siz*=2;
    dat.resize(2*siz-1,0);
    laz.resize(2*siz-1,0);
    for(int i=0;i<n;i++)dat[i+siz-1]=p[i].se;
    for(int i=siz-2;i>=0;i--)dat[i]=dat[i*2+1]+dat[i*2+2];
}
void eval(int k,int l,int r){
    dat[k]+=laz[k];
    if(r-l>1){
        laz[k*2+1]+=laz[k]/2;
        laz[k*2+2]+=laz[k]/2;
    }
    laz[k]=0;
}
void update(int a,int b,int x,int k=0,int l=0,int r=-1){
    if(r==-1)r=siz;
    eval(k,l,r);
    if(r<=a||b<=l)return;
    if(a<=l&&r<=b){
        laz[k]=(r-l)*x;
        eval(k,l,r);
        return;
    }
    update(a,b,x,k*2+1,l,(l+r)/2);
    update(a,b,x,k*2+2,(l+r)/2,r);
}
int query(int a,int k=0,int l=0,int r=-1){
    if(r==-1)r=siz;
    eval(k,l,r);
    if(r-l==1)return dat[k];
    if(a<(l+r)/2)return query(a,k*2+1,l,(l+r)/2);
    return query(a,k*2+2,(l+r)/2,r);
}
signed main(){
    cin>>n>>d>>a;
    rep(i,n){
        cin>>p[i].fi>>p[i].se;
        p[i].se=(p[i].se-1)/a+1;
    }
    sort(p,p+n);
    int h[200010];
    rep(i,n)h[i]=p[i].fi;
    init(n);
    int ans=0;
    rep(i,n){
        int q=query(i);
        if(q>0){
            ans+=q;
            update(i,upper_bound(h,h+n,h[i]+d+d)-h,-q);
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	double x[n],y[n];
	for(int i=0;i<n;i++) cin >> x[i];
	for(int i=0;i<n;i++) cin >> y[i];
	for(int i=1;i<=3;i++){
		double s = 0;
		for(int j=0;j<n;j++) s += pow(abs(x[j]-y[j]),i);
		s = pow(s,1.0/i);
		cout << setprecision(10) << s << endl;
	}
	double t = 0;
	for(int i=0;i<n;i++) if(t<abs(x[i]-y[i])) t = abs(x[i]-y[i]);
	cout << setprecision(10) << t << endl;
}

Measured memory_bytes: 1340
import java.util.ArrayList;
import java.util.Scanner;
 
class Main {
 
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
 
		Scanner scanner = new Scanner(System.in);
 
		int A[] = new int[9];
		for(int ij = 0; ij<9;ij++){
 
			A[ij]= scanner.nextInt();
		}
 
		int N =scanner.nextInt();
 
		int B;
 
		ArrayList<Integer> result =new ArrayList<Integer>();
 
		for(int b=0; b<N;b++){
			B=scanner.nextInt();
 
			for(int n=0;n<9;n++){
				if(A[n]==B){
					result.add(n);
				}
			}
		}
 
			if((result.contains(0)&&result.contains(1)&&result.contains(2))
					||(result.contains(3)&&result.contains(4)&&result.contains(5))
					||(result.contains(6)&&result.contains(7)&&result.contains(8))
					||(result.contains(0)&&result.contains(3)&&result.contains(6))
					||(result.contains(1)&&result.contains(4)&&result.contains(7))
					||(result.contains(2)&&result.contains(5)&&result.contains(8))
					||(result.contains(2)&&result.contains(4)&&result.contains(6))
					||(result.contains(0)&&result.contains(4)&&result.contains(8))){
				System.out.println("Yes");
 
			}else{
				System.out.println("No");
			}
 
	}
 
}

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

int main(){
  bool A=false;
  bool B=false;
  bool C=true;
  int a,b;
  cin >> a >> b;
  vector<int>N(7);
  N.at(0)=1;
  N.at(1)=3;
  N.at(2)=5;
  N.at(3)=7;
  N.at(4)=8;
  N.at(5)=10;
  N.at(6)=12;
  vector<int>M(4);
  M.at(0)=4;
  M.at(1)=6;
  M.at(2)=9;
  M.at(3)=11;
  for(int i=0;i<7;i++){
    if(N.at(i)==a){
      A=true;
      C=false;
    }
    if(N.at(i)==b){
      B=true;
      C=false;
    }
  }
  if(C==true){
    for(int i=0;i<4;i++){
      if(M.at(i)==a){
        A=true;
        C=false;
      }
      if(M.at(i)==b){
        B=true;
        C=false;
      }
    }
  }
  if(A&&B){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


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


int main() {
  char a;
  cin >> a;
  if((a>='a') && (a<='z')){
    cout << "a" << endl;
  }
  else cout << "A" << endl;
  return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
const int N=100010;

int main(){ 
    long long n,d;
    cin>>n>>d;
    int ans=0;
    for(int i=0;i<n;i++){
        long long a,b;
        cin>>a>>b;
        long long c=a*a+b*b;
        if(c<=d*d) ans++;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3628
s,t,i,W[100],m;main(N){scanf("%d",&N);for(;i<N;)scanf("%d",W+i),s+=W[i++];m=s;for(;--i+1;)m=(N=(t+=W[i])>(s-=W[i])?t-s:s-t)>m?m:N;printf("%d\n",m);}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		if(A-B*2<=0){
      System.out.println(0);
        }else{
      System.out.println(A-B*2);          
}
}
}


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

struct RS {
	using type = ll;
	static type id() { return 0; }
	static type op(const type& l, const type& r) {
		return l + r;
	}
};

class seg_node {
public:
	using M = RS;
	using T = typename M::type;
	using U = ll;

	T get() const {
		return val + lazy * size;
	}
	void update(U v) {
		lazy += v;
	}
	bool is_updated() const {
		return lazy;
	}
	void push(seg_node& l, seg_node& r) {
		if (lazy == 0) return;
		l.update(lazy);
		r.update(lazy);
		val = get();
		lazy = 0;
	}
	void init(const seg_node& l, const seg_node& r) {
		size = l.size + r.size;
	}
	void init(const T& v) {
		val = v;
	}
	seg_node() : val(M::id()), size(1), lazy(0) {}

public:
	T val;

private:
	int size;
	U lazy;

};

class segment_tree {
	using M = typename seg_node::M;
	using T = typename seg_node::T;
	using U = typename seg_node::U;
	const int h, n;
	vector<seg_node> data;
	void push(int node) {
		data[node].push(data[node << 1], data[(node << 1) | 1]);
	}
	void update(int node) {
		data[node].val = M::op(data[node << 1].get(), data[(node << 1) | 1].get());
	}
public:
	segment_tree(int n_)
		: h(ceil(log2(n_))), n(1 << h), data(n * 2) {
		init();
	}
	segment_tree(int n_, T v1)
		: h(ceil(log2(n_))), n(1 << h), data(n * 2) {
		for (int i = 0; i < n_; i++) {
			data[i + n].init(v1);
		}
		init();
	}
	segment_tree(const vector<T>& data_)
		: h(ceil(log2(data_.size()))), n(1 << h), data(n * 2) {
		for (int i = 0; i < (int)data_.size(); i++) {
			data[i + n].init(data_[i]);
		}
		init();
	}
	void init() {
		for (int i = n - 1; i >= 1; i--) {
			data[i].init(data[i << 1], data[(i << 1) | 1]);
		}
	}
	void update(int l, int r, U val) {
		l += n, r += n;
		for (int i = h; i > 0; i--) push(l >> i), push(r >> i);
		int tl = l, tr = r;
		r++;
		while (l < r) {
			if (l & 1) data[l++].update(val);
			if (r & 1) data[--r].update(val);
			l >>= 1; r >>= 1;
		}
		while (tl >>= 1, tr >>= 1, tl) {
			if (!data[tl].is_updated()) update(tl);
			if (!data[tr].is_updated()) update(tr);
		}
	}
	T find(int l, int r) {
		l += n, r += n;
		for (int i = h; i > 0; i--) push(l >> i), push(r >> i);
		r++;
		T res1 = M::id(), res2 = M::id();
		while (l < r) {
			if (l & 1) res1 = M::op(res1, data[l++].get());
			if (r & 1) res2 = M::op(data[--r].get(), res2);
			l >>= 1; r >>= 1;
		}
		return M::op(res1, res2);
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	segment_tree st(n);
	while (q--) {
		int type, s, t;
		cin >> type >> s >> t; s--; t--;
		if (type) {
			printf("%lld\n", st.find(s, t));
		}
		else {
			int x;
			cin >> x;
			st.update(s, t, x);
		}
	}
	return 0;
}



Measured memory_bytes: 9092
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b;
  cin>>a>>b;
  
  if(a>b){
    for(int i = 0;i<a;i++){
      cout<<b;
    }
  }
  else{
    for(int i = 0;i<b;i++){
      cout<<a;
    }
  }
}


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

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

    map<int, ll> m;
    rep(i, N) {
        int A;
        cin >> A;
        ++m[A];
    }
    ll sum = 0;
    for (const auto& x : m) {
        sum += x.first * x.second;
    }

    int Q;
    cin >> Q;

    rep(i, Q) {
        int B, C;
        cin >> B >> C;

        const ll diff = m[B] * (C - B);
        sum += diff;
        cout << sum << endl;

        m[C] += m[B];
        m[B] = 0;
    }
}


Measured memory_bytes: 9368
#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <numeric>
#include<algorithm>

int main() {
  int n;
  std::cin >> n;
  std::vector<double> x;
  for (int i = 0; i < n; i++)
  {
    double a;
    std::cin >> a;
    x.push_back(a);
  }
  for (int i = 0; i < n; i++)
  {
    double a;
    std::cin >> a;
    x[i] = std::fabs(x[i] - a);
  }
  std::cout << std::fixed;
  std::cout << std::accumulate(x.begin(), x.end(), 0.0) << "\n";
  double sum = 0.0;
  for (int i = 0; i < n; i++)
  {
    sum += x[i] * x[i];
  }
  std::cout << std::sqrt(sum) << "\n";
  sum = 0.0;
  for (int i = 0; i < n; i++)
  {
    sum += x[i] * x[i] * x[i];
  }
  std::cout << std::cbrt(sum) << "\n";
  std::cout << *std::max_element(x.begin(), x.end()) << "\n";
}


Measured memory_bytes: 3468
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
#define ull unsigned long long int
using namespace std;

ll n,m,ar[N],sum,t;

string a,b,c;


int main()
{
	fast;
	// cin>>n;
	cin>>a>>b>>n>>m>>c;
	if(a==c)
		n--;
	else
		m--;
	cout<<n<<sp<<m<<endl;
}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  s.at(5) = ' ';
  s.at(13) = ' ';
  cout << s << endl;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
typedef long long l;
int main()
{
    l n ; 
    cin>>n;
    l arr[n];
    for(l i = 0 ; i<n;i++)
    cin>>arr[i];
    l dp[n];
    dp[0]=0;
    dp[1]=abs(arr[1]-arr[0]);
    for(l i = 1 ; i<n ; i++)
    {
        l a = dp[i-1] + abs(arr[i]-arr[i-1]);
        l b = dp[i-2] + abs(arr[i]-arr[i-2]);
        dp[i]=min(a,b);
    }
    cout<<dp[n-1];
    
    return 0;
}

Measured memory_bytes: 1792
a,b=map(int,input().split())

def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1

aa=divisor(a)
bb=divisor(b)
c=set(aa)&set(bb)
d=[i for i in c if is_prime(i)]
print(len(d)+1)

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

int main()
{
  int n,x;
  cin>>n>>x;
  vector<int> a(n);
  for(auto &i:a)
     cin>>i;
  long long int ans=0;
  for(int i=0;i<n-1;i++)
    if(a[i]+a[i+1]>x)
      {
        long long sub = a[i+1]+a[i]-x;
        ans += sub;
        a[i+1]-=sub;
      }
  if(a[n-1]>x)
    ans += a[n-1]-x;    
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

int main( void ){
	int* arr = eratosthenes(600000);
	int N;
	cin >> N;
	rep(i, N, 600000+1){
		if(arr[i] == 1){
			cout << i << endl;
			return 0;
		}
	}
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);

		int N=sc.nextInt();

		int[] W=new int[N+1];
		W[0]=0;

		for(int i=0;i<N;i++)  W[i+1]=sc.nextInt()+W[i];

		int ans=1000000;

		for(int i=1;i<N;i++) {
			int S1=W[i];
			int S2=W[N]-W[i];
			ans=Math.min(Math.abs(S1-S2), ans);
		}

		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 23764
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;

    if(a < 10 && b < 10)
        cout << (a * b) << endl;
    else
        cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 256
S = input()
T = input()
ans = "UNRESTORABLE"
if len(S) >= len(T):
    for i in range(len(S) - len(T) + 1):
        s = S[i:len(T) + i]
        for j in range(len(s)):
            if s[j] != "?" and s[j] != T[j]:
                break
            if j == len(s) - 1:
                c = S[:i] + T + S[len(T) + i:]
                ans = c.replace("?", "a")

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    vector<int> a(3); cin >> a[0] >> a[1] >> a[2];
    int n; cin >> n;
    whole(sort, a, greater<int>());
    REP(i, n) a[0] *= 2;
    cout << whole(accumulate, a, 0) << endl;


}

Measured memory_bytes: 256