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


public class Main {
    static final int UNCALC = -1;
    static int n;
    static int[][] memo;
    static int[][] points;

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        n = sc.nextInt();
        memo = new int[3][n];
        for (int[] a : memo)
            Arrays.fill(a, UNCALC);
        points = new int[3][n];
        for (int i = 0; i < n; i++)
            for (int j = 0; j < 3; j++)
                points[j][i] = sc.nextInt();
        out.println(dp(0, 0));
        out.flush();
        out.close();

    }

    static int dp(int prev, int i) {
        if (i == n) return 0;
        if (memo[prev][i] != UNCALC) return memo[prev][i];
        int max = 0;
        for (int j = 0; j < 3; j++) {
            if (i != 0 && j == prev) continue;
            max = Math.max(max, points[j][i] + dp(j, i + 1));
        }
        return memo[prev][i] = max;
    }


    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        public Scanner(String file) throws Exception {
            br = new BufferedReader(new FileReader(file));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

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

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

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

        public boolean ready() throws IOException {
            return br.ready();
        }

        public void waitForInput() throws InterruptedException {
            Thread.sleep(3000);
        }

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

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

    }
}

Measured memory_bytes: 53532
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(v) v.begin(),v.end()
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define MOD 998244353 

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ordered_set<ll> ors;

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

ll power(ll a, ll n, ll m)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=(ans*a)%m;
        n>>=1;
        a=(a*a)%m;
    }
    return ans;
}

ll invmod(ll a, ll m)
{
    return power(a,m-2,m);
}

ll lp[10000001];

void prime()
{
    repf(i,1,10000001) lp[i]=i;
    repf(i,2,10000001)
    {
        if(lp[i]==i)
        {
            for(ll j=2*i;j<10000001;j+=i)
            {
                if(lp[j]==j) lp[j]=i;
            }
        }
    }
}

ll w(ll a, ll b) {
    ll res=(b/2)*(a/2)+ceil((ld)b/2)*ceil((ld)a/2);
    return res;
}

ll W(ll a, ll b, ll c, ll d) {
    return w(c,d)-w(a-1,d)-w(c,b-1)+w(a-1,b-1);
}

ll B(ll a, ll b, ll c, ll d) {
    return (c-a+1)*(d-b+1)-W(a,b,c,d);
}

ll f[2000001];

void solve(ll tt) {
    ll n;
    cin>>n;
    ll a[n];
    repf(i,0,n) {
        cin>>a[i];
        f[a[i]]++;
    }
    sort(a,a+n);
    ll ans=0;
    repf(i,0,n) {
        bool pos=true;
        for(ll j=1;pos && j*j<=a[i];j++) {
            if(a[i]%j==0 && a[i]!=j) {
                if(f[j]) pos=false;
                if(j*j!=a[i] && j!=1) {
                    if(f[a[i]/j]) pos=false;
                }
            }
        }
        if(pos && f[a[i]]==1) ans++;
    }
    cout<<ans<<endl;
}

int main()
{
    IOS;
    ll t;
    // cin>>t;
    t=1;
    repf(tt,1,t+1) {
        solve(tt);
    }
}     

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

const int INF = 1e9;

class union_find {
	vector<int> par;
	vector<int> rank;
	int find(int a) {
		return par[a] < 0 ? a : par[a] = find(par[a]);
	}
public:
	union_find(int n) : par(n, -1), rank(n, 1) {}
	bool same(int a, int b) {
		return find(a) == find(b);
	}
	void unite(int a, int b) {
		a = find(a);
		b = find(b);
		if (a == b) return;
		if (rank[a] > rank[b]) {
			par[a] += par[b];
			par[b] = a;
		}
		else {
			par[b] += par[a];
			par[a] = b;
			if (rank[a] == rank[b]) rank[b]++;
		}
	}
	int size(int a) {
		return -par[find(a)];
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int R;
	while (cin >> R, R) {
		vector<vector<int>> v(2);
		for (int k = 0; k < 2; k++) {
			int W, H, X, Y;
			cin >> W >> H >> X >> Y; X--, Y--;
			vector<vector<int>> a(H, vector<int>(W));
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					cin >> a[i][j];
				}
			}
			vector<int> cs;
			vector<vector<int>> es;
			for (int i = 0; i < H; i++) {
				for (int j = 0; j < W; j++) {
					if (i + 1 < H) {
						cs.push_back(max(a[i][j], a[i + 1][j]));
						es.push_back(vector<int>({ max(a[i][j], a[i + 1][j]), i * W + j, (i + 1) * W + j }));
					}
					if (j + 1 < W) {
						cs.push_back(max(a[i][j], a[i][j + 1]));
						es.push_back(vector<int>({ max(a[i][j], a[i][j + 1]), i * W + j, i * W + j + 1 }));
					}
				}
			}
			sort(cs.begin(), cs.end());
			cs.erase(unique(cs.begin(), cs.end()), cs.end());
			sort(es.begin(), es.end());

			v[k].assign(H * W + 1, INF);
			v[k][0] = 0;
			v[k][1] = 1;
			union_find uf(H * W);
			for (int i = 0, j = 0; i < (int)cs.size(); i++) {
				while (j < (int)es.size() && es[j][0] == cs[i]) {
					uf.unite(es[j][1], es[j][2]);
					j++;
				}
				int sz = uf.size(Y * W + X);
				v[k][sz] = min(v[k][sz], cs[i]);
			}
			for (int i = H * W - 1; i >= 2; i--) {
				v[k][i] = min(v[k][i], v[k][i + 1]);
			}
		}
		int res = INF;
		for (int i = 0; i < (int)v[0].size(); i++) if (0 <= R - i && R - i < (int)v[1].size()) {
			res = min(res, v[0][i] + v[1][R - i]);
		}
		cout << res << endl;
	}
	return 0;
}



Measured memory_bytes: 37132
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

signed main() {
	int x, y;
	cin >> x >> y;
	int ans = 0;
	if (x == 1)ans += 300000;
	if (y == 1) ans += 300000;
	if (x == 2) ans += 200000;
	if (y == 2) ans += 200000;
	if (x == 3) ans += 100000;
	if (y == 3) ans += 100000;
	if (x == 1 && y == 1) ans += 400000;
	cout << ans << endl;

	return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)

ll N;
ll cnt;

ll prime[100005];
void prime_fact(ll n){
  ll nn=n;
  for(ll i=2; i<=n; i++){
    while(1){
      if(nn%i==0){
      nn/=i;
      prime[i]++;
      }else{
      break;
      }
    }
  }
}

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;

rep(i,N+1) prime_fact(i);

//a^74
rep(i,N+1){
	if(prime[i]>=74){
				cnt++;
	}
}
//a^2*b^24
rep(i,N+1){
	if(prime[i]>=2){
		rep(j,N+1){
			if(prime[j]>=24&&i!=j){
				cnt++;
			}
		}
	}
}
//a^4*b^14
rep(i,N+1){
	if(prime[i]>=4){
		rep(j,N+1){
			if(prime[j]>=14&&(i!=j)){
				cnt++;
			}
		}
	}
}

//a^4*b^4*c^2
ll exp=0;
rep(i,N+1){
	if(prime[i]>=4){
		rep(j,N+1){
			if(prime[j]>=4&&i!=j){
				rep(k,N+1){
					if(prime[k]>=2&&k!=i&&k!=j){
					exp++;
					}
				}
			}
		}
	}
}

cnt+=exp/2;

cout<<cnt<<endl;

}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
    
int main(){
    int n;
    cin >> n;
    vector <long long> a(n);
    rep(i,n) cin >> a[i];

    vector <long long> b(n);

    for(int i=0; i<n; i++){
        b[0] += pow(-1,i%2) * a[i];
    }
    for(int i=1; i<=n-1; i++){
        b[i] = 2 * a[i-1] - b[i-1];
    }
    b[n-1] = 2 * a[n-1] - b[0];

    rep(i,n){
        if(i == n-1){
            cout << b[i] << endl;
        }
        else
        {
            cout << b[i] << " ";
        }
        
    }
}

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

int main(){
  int n,m;
  cin>>n>>m;
  int x[100005];
  rep(i,m) cin>>x[i];
  sort(x,x+m);
  vector<int> v;
  rep(i,m-1){
    v.push_back(x[i+1]-x[i]-1);
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  int sum=0;
  rep(i,min(n-1,(int)v.size())){
    sum+=v[i];
  }
  cout<<max(0,x[m-1]-x[0]+1-sum-n)<<endl;
  return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}
 
 bool re(vector<int>x,vector<int>y){
   bool ok=true;
   for(int i=0;i<x.size();i++){
     if(x[i]!=y[i]){ok=false;}
   }
   return ok;
  }

int main() {
  int N;
  cin>>N;
  vector<int>P(N);
  vector<int>Q(N);
  vector<int>s(N);
  for(int i=0;i<N;i++){
    cin>>P[i];
    s[i]=P[i];
  }
  for(int i=0;i<N;i++){
    cin>>Q[i];
  }
  
  int i=0;
  int a=0,b=0;
  sort(s.begin(),s.end());
  do{
   if(re(s,P)){a=i;}
   if(re(s,Q)){b=i;}
   i++;
  }while(next_permutation(s.begin(),s.end()));
  
  cout<<abs(a-b)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
    scanf("%d",&head);
    RI(tail...);
}
using namespace std;
typedef long long LL;
int n,m;
char in1[M],in2[M];
int main()
{

	while (~scanf("%d %d",&n,&m)) {
		scanf("%s %s",in1+1,in2+1);
		LL lcm = (LL)n*m / __gcd(n,m);
		LL g1 = lcm/n;
		LL g2 = lcm/m;

		map<int,char> mp;
		int p2 = 1;
		LL pos = 1;
		while(pos<=lcm) {
			mp[pos] = in1[p2];
			p2++;
			pos += g1;
		}

		bool ans = true;
		p2=1;
		pos=1;
		while(pos<=lcm) {
			if (mp[pos] && mp[pos]!=in2[p2]) {
				ans = false;
				break;
			}
			p2++;
			pos += g2;
		}

		printf("%lld\n", ans ? lcm : -1);
	}
	return 0;
}



Measured memory_bytes: 8192
#include <stdio.h>

 int main(void){
 int a[3][10][4] = {0};
 int i, j, k;
 int n, p;
 int b, f, r, v; 

scanf("%d", &n);
 for(i=0; i<n; i++){
 scanf("%d%d%d%d", &b, &f, &r, &v);

 a[f-1][r-1][b-1] += v;
 }

 for(k=0; k<4; k++){
 for(i=0; i<3; i++){
 for(j=0; j<10; j++){
 if(a[i][j][k] == 0){
 printf(" 0");
 }else{
 printf(" %d", a[i][j][k]);
 }
 }
 printf("\n");
 }
 if(k != 3){
 printf("####################\n");
 }
 }

 return 0;
 }



Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
  
int main() {
  int N;
  cin >> N;
 
  rep(i,N){
    string s;
    int n;
    cin >> s;
    if (s=="Y") {
      cout << "Four";
      break;
    }else if (i==N-1) {
      cout << "Three";
    }
  }
  
}

Measured memory_bytes: 256
# 2020/04/04
# AtCoder Beginner Contest 161 - B

# Input
n, m = map(int,input().split())
a = list(map(int,input().split()))

# Init
sump = 0
sump_m = 0

# Calc
for i in range(n):
    sump = sump + a[i]

a.sort()
a.reverse()

ans = 'Yes'
for i in range(m):
    if a[i] < sump / (4 * m):
        ans = 'No'

# Output
print(ans)


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#include <assert.h>
#define FOR(i,a,n) for(i=(a);i<(n);i++)
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0)
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define MOD 1000000007
#define SIZE 100005
#define LOCAL
#ifdef LOCAL
    #define DEBUG(...) printf(" "__VA_ARGS__)
#else
    #define DEBUG(...)
#endif /* LOCAL */
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}

int main(void)
{
	ll k,a,b,d;
	scanf("%lld%lld%lld",&k,&a,&b);
	if(k<=a) puts("1");
	else{
		k-=a,d=a-b;
		if(d<=0) puts("-1");
		else printf("%lld\n",(k+d-1)/d*2LL+1);
	}
	return 0;
}
    
    


Measured memory_bytes: 128
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#include <chrono>
#include <random>
#include <time.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
#define N 500000
ll MOD=1e9+7;
int dp[1<<26+2];
main(){
    string s;
    cin>>s;
    string check;
    rep(i,s.size()){
        if(s[i]!='x')check.pb(s[i]);
    }
    bool flag=true;int c=check.size();
    rep(i,c){
        if(check[i]!=check[c-1-i])flag=false;
    }
    if(!flag){
        cout<<-1<<endl;
        return 0;
    }
    if(check.size()%2){
        vec v;
        int now=0;
        int count=0;
        while(now<s.size()){
            while(s[now]=='x'){
                now++;count++;
            }
            v.pb(count);count=0;now++;
        }
        v.pb(0);
        int ans=0;
        rep(i,(c+1)/2){
            ans+=abs(v[i]-v[c-i]);
        }
        cout<<ans;
    }
    else{
        vec v;
        int now=0;
        int count=0;
        while(now<s.size()){
            while(s[now]=='x'){
                now++;count++;
            }
            v.pb(count);count=0;now++;
        }
        int ans=0;
        rep(i,c/2){
            ans+=abs(v[i]-v[c-i]);
        }
        cout<<ans;
    }
    return 0;
}



Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
   ll n,f=0;
   cin>>n;
   ll a[n];
   for(int i=0;i<n;i++)
      {
        cin>>a[i];
        if(a[i]&1)
          f=1;
        
      } 
      if(f)
       cout<<0<<endl;
       else
       {
        
        sort(a,a+n);
        vi v;

        for(int i=0;i<n;i++)
        { ll c=0;
          while(a[i]%2==0&&a[i]>0)
          {
                c++;
                a[i]/=2;
          }
          v.pb(c);
        }
        sort(v.begin(),v.end());
        cout<<v[0]<<endl;
        

        
       }  
}
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long llong;

static llong dist(const vector<int>& x, int m) {
  llong dist = 0;
  for (int i = 0; i < x.size(); ++i) {
    int mm = x[i] - m;
    dist += mm * mm;
  }
  return dist;
}

void CRally(std::istream& in, std::ostream& out) {
  int n;
  in >> n;
  vector<int> x;
  int minx = -1;
  int maxx = 1000;
  for (int i = 0; i < n; ++i) {
    int y;
    in >> y;
    x.push_back(y);
    minx = min(y, minx);
    maxx = max(y, maxx);
  }

  llong mindist = 1000000;
  for (int i = minx; i <= maxx; ++i) {
    llong d = dist(x, i);
    mindist = min(d, mindist);
  }
  out << mindist << endl;
}

int main() {
  CRally(cin, cout);
  return 0;
}

Measured memory_bytes: 256
N,*H=`dd`.split.map &:to_i;
B=[0]*-~N;
U=->i,w{(B[i]=[B[i],w].max;i+=i&-i)while i<=N};
Q=->i{r=0;(r=[r,B[i]].max;i-=i&-i)while i>0;r};
A=H.pop N;
G=H.sort;
N.times{|i|
k=1+G.bsearch_index{|h|H[i]-h};
U[k,Q[k]+A[i]]
};
p Q[N]


Measured memory_bytes: 40564
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int,int);
void dfs( vector< vector<int> >&, int , vector<int>& );
void bfs( vector< vector<int> >&, int , vector<int>& );

void solve()
{
    int a,b,n;
    cin>>a>>b>>n;
    // int ans = 0;
    
    if ( b-1 <= n )
    {
        cout<<(a*((b-1)%b) - (a*(b-1))%b)/b<<endl;
    }
    else
    {
        cout<<(a*(n%b) - (a*n)%b) / b<<endl;
    }
    

    // cout<<ans<<endl;
}

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void dfs ( vector< vector<int> > &v , int x , vector<int> &vis )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            dfs(v,v[x][i],vis);
        }
    }
}

void bfs( vector< vector<int> > &v , int x , vector<int> &vis )
{
    queue<int> q;
    q.push(x);

    while( !q.empty() )
    {
        int p = q.front();
        q.pop();

        rep(i,0,v[p].size())
        {
            if ( vis[v[p][i]] == 0 )
            {
                vis[v[p][i]] = 1;
                q.push(v[p][i]);
            }
        }
    }
}

Measured memory_bytes: 3616
import Data.List (intercalate)

main :: IO ()
main = do
    line <- getLine
    let
        n1 = (read line :: Int)
        (n2, s) = divMod n1 60
        (h,  m) = divMod n2 60
    putStrLn $ intercalate ":" [show h, show m, show s]



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

#define FOR(i, a, b) for(i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define comp(a, b) int comp(const void *a, const void *b)
#define MOD  1000000007

typedef unsigned int uint;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

void TF_print(int boolean, char T[], char F[]){
    if(boolean){
        printf("%s\n", T);
    }else{
        printf("%s\n", F);
    }
}

int main(){
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);
    TF_print(C <= A + B, "Yes", "No");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;


void solve(){

    while(true){
        ll n,x;
        cin >> n >> x;
        if(n==0&&x==0) break;
        ll count=0;
        for(ll i=1; i<=n; i++){
            for(ll j=i+1; j<=n; j++){
                if(x-i-j>=1&&x-i-j<=n&&x-i-j>i&&x-i-j>j) count++;
            }
        }
        cout << count << endl;
    }    

}

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



Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {

	private static Scanner sc;

	public static void main(String[] args){
		sc = new Scanner(System.in);
		while(true){
			int m=sc.nextInt();
			int f=sc.nextInt();
			int r=sc.nextInt();
			if(m==-1&&f==-1&&r==-1)break;
			if(m!=-1&&f!=-1){
				if(m+f>=80){
					System.out.println("A");
				}else if(m+f>=65){
					System.out.println("B");
				}else if(m+f>=50||r>=50){
					System.out.println("C");
				}else if(m+f>=30){
					System.out.println("D");
				}else if(m+f<30){
					System.out.println("F");
				}
			}else System.out.println("F");
		}
	}
}

Measured memory_bytes: 26332
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;


#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll unsigned long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


int main() {
	__int128 now = 100;
  ll x;
	cin >> x;
	ll cnt = 0;
	while (1) {
		cnt++;
		now = now * 101 / 100;
		if (now >= x)break;
	}
	cout << cnt << endl;

}

Measured memory_bytes: 3624
import math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n = readInt()
p = readInts()
q = readInts()

def countmin(arr,x):
	arr.sort()
	ans = 0
	for i in range(len(arr)):
		if arr[i]<x:
			ans+=1
	return ans;

def calc(arr):
	ans=1
	ra = list(range(1,n+1))
	for i in range(n-1):
		ra.remove(arr[i])
		ans+=countmin(ra,arr[i])*fact(len(ra))
		#print(ans,countmin(ra,arr[i]))
	return ans

def calc2():
	return abs(calc(p)-calc(q))

print(calc2())

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

using namespace std;

int main(){
  string s;
  cin >> s;
  
  int a = 0, b = 0;
  for(int i = 0; i < 3; i++){
    if(s[i] == 'A') a++;
    else b++;
  }
  
  if(a && b) puts("Yes");
  else puts("No");
  
  return 0;
}

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

int main()
{
	int n,k;
  cin>>n>>k;
vector<int> tree_height(n);
      for (int i = 0; i <n; i++) {
        cin>> tree_height[i];
    }
      sort(tree_height.begin(), tree_height.end()); 
    reverse(tree_height.begin(), tree_height.end()); 
vector<int> sa(0);
  for(int i=0;i+k-1<n;i++){
    sa.push_back(tree_height[i]-tree_height[i+k-1]);

 }
  sort(sa.begin(),sa.end());
  cout<<sa[0]<<endl;
}


Measured memory_bytes: 4056
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int x[10], y[10];
int r[10] = { 0,1,2,3,4,5,6,7 };

int square(int a) {
	return a * a;
}
int main()
{
	int N; cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
	}
	double ans = 0.0;
	int  cnt = 0;
	do {
		for (int i = 1; i < N; i++) {
			ans += (double)(sqrt(square(x[r[i]] - x[r[i - 1]]) + square(y[r[i]] - y[r[i - 1]])));
		}
	} while (next_permutation(r, r + N));
	for (int i = N; i > 1; i--) {
		ans /= i;
	}
	printf("%.8f\n", ans);
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
int M = 100000;
int main(){
  int N;
  cin >> N;
  ll a[N];

  int cnt = 0;
  int full[M+1];
  for(int i=1;i<=M;i++) full[i] = 0;

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

  for(int i=0;i<N;i++){
    if(a[i]>M) cnt++;
    else{
      full[a[i]]++;
    }
  }

  for(int i=1;i<=M;i++){
    if(full[i]>i){
      cnt += full[i] - i;
    }else if(full[i]<i){
      cnt += full[i];
    }
  }

  cout << cnt << endl;


  return 0;
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
//#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vin(Vi &v){REP(i,0,(v).size()) cin>>v[i];}
void vin(Vi &v,Vi &v2){REP(i,0,(v).size()) cin>>v[i]>>v2[i];}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
void accum(Vi &v){REP(i,1,(v).size()) v[i]+=v[i-1];}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}


void solve(long long n, std::vector<std::string> s, std::vector<long long> t, std::string x){
    vector<pair<string,int>> a(n);
    REP(i,0,n){
        a[i]=mp(s[i],t[i]);
    }

    int ans=0;
    bool check=false;
    REP(i,0,n){
        if(check) ans+= a[i].second;
        if(a[i].first==x) check=true;
    }
    cout<<ans<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> s(N);
    std::vector<long long> t(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> s[i];
        scanf("%lld",&t[i]);
    }
    std::string X;
    std::cin >> X;
    solve(N, std::move(s), std::move(t), X);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

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

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    string s;
    cin>>s;
    vi a(n),b(n);
    rep(i,n){
      cin>>a[i]>>b[i];
      a[i]--;b[i]--;
    }
    for(i=n-1;i>=0;i--){
      int diff=b[i]-a[i];
      swap(s[a[i]],s[b[i]]);
      s[a[i]]=(s[a[i]]-'a'+diff)%26+'a';
      s[b[i]]=(s[b[i]]-'a'+diff)%26+'a';
    }
    cout<<s<<endl;
  }
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
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 lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




int main() {
    string s;
    cin >> s;
    int n=s.size();

//——————————————bit全探索——————————————
  ll ans=0;
  ll now,sum;
  rep(i, (1<<n-1)){
    sum=0;
    now=0;
    rep(j,n){
      now=now*10+(s[j]-'0');
      if(i & (1<<j)){
      sum+=now;
      now=0;
      }
    }
    sum+=now;
    ans+=sum;
  }

  cout << ans << endl;

//——————————————————————————————————————

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N;
    string S;
    void solve()
    {
        S = cin.next;
        N = S.Length;
        var A = new int[26];
        var B = new int[N];
        for (int i = 0; i < N; i++)
        {
            B[i] = alfa.IndexOf(S[i]);
            A[B[i]]++;
        }
        long ans = 1;
        ans += (long)N * (N - 1) / 2;
        for (int i = 0; i < 26; i++)
        {
            if(A[i] > 1)
            {
                ans -= (long)A[i] * (A[i] - 1) / 2;
            }
        }
        WriteLine(ans);

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13404
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<utility>
#include<array>
#include<set>
#include <numeric>
#include <stdio.h>
#include <map>
#include <iomanip>
#include <sstream>
//#include <boost/math/common_factor_rt.hpp>
#include<fstream>
#define EPS (1e-7)
using namespace std;
#define ll long long



class Employee {
public:
	int id;
	int parent;
	vector<int> children;
	int salary;

	Employee() {
		
	}

	Employee(int num, int nparent) {
		id = num;
		parent = nparent;
		salary = -1;
	}



};



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





pair<int, int> count_nonzero_cluster(vector<int>& vs) {

	int number = 0;
	int prev = 0;
	int vmax = -1;
	pair<int, int> re = make_pair(number, vmax);
	for (auto& v:vs)
	{
		if (prev <= 0 && v > 0) {
			re.first += 1;
		}
		if (re.second < v)re.second = v;
		prev = v;
	}


	return re;
}

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

	string ans = "IMPOSSIBLE";
	vector<int> from1(N,0), fromn(N,0);
	
	int a, b;
	for (auto i = 0; i < M; i++)
	{
		cin >> a >> b;
		if (a == 1) {
			from1[b]+=1;
			continue;
		}

		if (a == N) {
			fromn[b]+=1;
		}
		else if (b == N) {
			fromn[a]+=1;
		}
	}
	int check;
	for (auto i = 0; i < N; i++)
	{
		check = fromn[i] + from1[i];
		if (check == 2) {
			ans = "POSSIBLE";
			break;
		}
	}




	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "C:\Users\navodit\Desktop\mycodes\pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  



void solve(){
	int n ;
	cin >> n; 
	map<int,int>m;
	int sum = 0 ;
	rep(i,0,n){
		int a ;
		cin >> a ;
		m[a]++;
		sum+=a;
	}
	int q ;
	cin >>q ;
	rep(i,0,q){
		int b , c; 
		cin >> b>> c ;
		sum-=b*m[b];
		sum+=c*m[b];
		m[c]+=m[b];
		m[b]=0;
		cout << sum << endl;
	}
}


signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 9492
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s1;
	string s2;
	cin>>s1>>s2;
	int ans = 0;
	int i;
	for(i=0;i<3;i++)
	{
		if(s1[i]==s2[i])
			ans++;
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;

int main() {
    
  	int N;
  	cin >> N;
  	int a[1000000];
  	long long ans = 0;
    for(int i= 1;i<=sqrt(N)+1;i++){
      ans = i*i;
      if(ans > N){
        cout << (i-1)*(i-1) << endl;
        return 0;
      }
    }

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define L long long
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define aa first
#define bb second
#define xx aa.aa
#define yy aa.bb
#define zz bb
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
using namespace std;
#define SZ 666666
typedef long long ll;
int fst[SZ],nxt[SZ],vb[SZ],cap[SZ],ff[SZ],M=1,N=0;
#define add ad_dl
void _ad_dl(int a,int b,int c) {++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;cap[M]=c;}
void ad_dl(int a,int b,int c)
{_ad_dl(a,b,c); _ad_dl(b,a,0);}
int S,T,q[SZ],d[SZ];
bool bfs()
{
    memset(d,-1,4*(N+1));
    d[T]=0; q[1]=T; int h=1,t=2;
    while(h!=t)
    {
        int cur=q[h++];
        for(int e=fst[cur];e;e=nxt[e])
        {
            int b=vb[e];
            if(d[b]==-1&&cap[e^1])
            {
                d[b]=d[cur]+1, q[t++]=b;
                if(b==S) return 1; //???? 
            }
        }
    }
    return d[S]!=-1;
}
int dfs(int x,int f)
{
    if(f<=0) return 0;
    if(x==T) return f;
    int ca=0;
    for(int& e=fst[x];e;e=nxt[e]) //????? 
    {
        int b=vb[e];
        if(d[b]+1!=d[x]) continue;
        int w=dfs(b,(cap[e]<f-ca)?cap[e]:(f-ca));
        cap[e]-=w; cap[e^1]+=w; ca+=w;
        if(ca==f) break;
    }
    if(!ca) d[x]=-1; //????? 
    return ca;
}
#define inf 2e9+3
int dinic()
{
    int ans=0;
    memcpy(ff,fst,4*(N+1));
    while(bfs())
    {
        //?????
        ans+=dfs(S,inf);
        memcpy(fst,ff,4*(N+1));
    }
    return ans;
}
int n,m;
char s[110][110];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++)
	  scanf("%s",&s[i][0]+1);
	for(i=1;i<=n;i++)
	  for(j=1;j<=m;j++)
	    if(s[i][j]!='.')
	      {
		   add((i-1)*m+j,n*m+i,1e9);
		   add((i-1)*m+j,n*m+n+j,1e9);
		   add(n*m+i,(i-1)*m+j+n*m+n+m,1e9);
		   add(n*m+n+j,(i-1)*m+j+n*m+n+m,1e9);
		   if(s[i][j]=='o')
		     add((i-1)*m+j+n*m+n+m,(i-1)*m+j,1);
		   else
		     add((i-1)*m+j+n*m+n+m,(i-1)*m+j,1e9);
		   if(s[i][j]=='S')
		     S=(i-1)*m+j;
		   if(s[i][j]=='T')
		     T=(i-1)*m+j;
		  }
	N=n*m+n+m+n*m;
	i=dinic();
	printf("%d\n",i>1e8?-1:i);
	return 0;
}


Measured memory_bytes: 14720
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set>
#include<ctime>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
inline void write(long long a){
	if(a>=10)write(a/10);
	putchar('0'+a%10);
}
inline void writeln(long long a){
	write(a); puts("");
}
inline long long read()//不管是正负数，都可以 
{
	long long x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
		return positive ? x : -x;
}
long long a[1005],k,T,n,ans;
int main(){
	//freopen("std.in","w",stdout);
	k=read();
	n=50; 
	for(int i=1;i<=n;i++)a[i]=k/n+n-1;
	k%=n;
	//for(int i=1;i<=k;i++)a[i]+=(k-i+1);
	writeln(n);
	for(int i=1;i<=n;i++){
		write(a[i]-k+(i<=k?(k-i)+2:0)); putchar(' ');
	}
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int p[n];
    rep(i, 0, n) {
        cin >> p[i];
        p[i]--;
    }
    int ans = 0;
    rep(i, 0, n - 1) {
        if (p[i] == i) {
            swap(p[i], p[i + 1]);
            ans++;
        }
    }
    if (p[n - 1] == n - 1) {
        swap(p[n - 2], p[n - 1]);
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

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

    std::vector<std::pair<long long, int>> v(N);
    for (int i = 0; i < N; i++) {
        long long A;
        std::cin >> A;
        v[i] = std::make_pair(A, i);
    }
    
    std::sort(v.begin(),
              v.end(),
              std::greater<std::pair<long long, int>>()
    );

    std::vector<long long> dp(N + 1);
    for (int i = 0; i < N; i++) {
        for (int j = i; j >= 0; j--) {
            int k;
            k = std::abs(v[i].second - j);
            dp[j + 1] = std::max(dp[j + 1], dp[j] + v[i].first * k);
            k = std::abs(v[i].second - ((N - 1) - (i - j)));
            dp[j] = dp[j] + v[i].first * k;
        }
    }

    long long ans = 0;
    for (int i = 0; i < N; i++)
        ans = std::max(ans, dp[i]);
    std::cout << ans << "\n";
}

Measured memory_bytes: 3680
//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<assert.h>
#define DEBUG(s,a) cerr<<#s" = "<<(s)<<" \n"[(a)==1]

using namespace std;  typedef long long ll;   char __buf[1<<18],*__c=__buf,*__ed=__buf;
inline int qr(){
	int ret=0,f=0,c=getchar();
	while(!isdigit(c))f|=c==45,c=getchar();
	while(isdigit(c)) ret=ret*10+c-48,c=getchar();
	return f?-ret:ret;
}
const int maxn=8000+5;
const int mod=1e9+7;
int dp[maxn][maxn],N,n,jc[maxn],inv[maxn],A[200000+1],B[200000+1];

inline int MOD(const int&x){return x>=mod?x-mod:x;}
inline int MOD(const int&x,const int&y){return 1ll*x*y%mod;}

inline int ksm(const int&ba,const int&p){
	int ret=1;
	for(int t=p,b=ba;t;t>>=1,b=MOD(b,b))
		if(t&1) ret=MOD(ret,b);
	return ret;
}

void pre(const int&n){
	jc[0]=inv[0]=1;
	for(int t=1;t<=n;++t) jc[t]=MOD(jc[t-1],t);
	inv[n]=ksm(jc[n],mod-2);
	for(int t=n-1;t;--t) inv[t]=MOD(inv[t+1],t+1);
	for(int t=1;t<=n;++t) assert(MOD(inv[t],jc[t])==1);
}

int c(const int&n,const int&m){
	if(n<m) return 0;
	return MOD(jc[n],MOD(inv[m],inv[n-m]));
}

int main(){
	n=qr();
	for(int t=1;t<=n;++t) A[t]=qr(),B[t]=qr(),N=max({N,A[t],B[t]});
	++N;
	pre(8000);
	int ans=0;
	for(int t=1;t<=n;++t) ans=MOD(ans-c(A[t]+A[t]+B[t]+B[t],A[t]+A[t])+mod),dp[N-A[t]][N-B[t]]=MOD(dp[N-A[t]][N-B[t]]+1);
	for(int t=-N+1;t<N;++t)
		for(int i=-N+1;i<N;++i)
			dp[t+N][i+N]=MOD(dp[t+N][i+N]+MOD(dp[-1+t+N][i+N]+dp[t+N][-1+i+N]));
	for(int t=1;t<=n;++t) ans=MOD(ans+dp[A[t]+N][B[t]+N]);
	ans=MOD(ans,(mod+1)/2);
	printf("%d\n",ans);
	return 0;
}




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

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

	int val = n % 10;
	string ret;

	if (val == 3) ret = "bon";
	else if ((val == 0) || (val == 1) || (val == 6) || (val == 8)) ret = "pon";
	else ret = "hon";

	cout << ret;

	return 0;
}

Measured memory_bytes: 3580
import java.util.*;

public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			String str = sc.nextLine();
			if(str.equals(".")) break;
			LinkedList<Character> s = new LinkedList<Character>();
			boolean flg = true;
			int len = str.length();
			for(int i = 0; i < len; i++){
				char now = str.charAt(i);
				if(now == '(' || now == '['){
					s.addLast(now);
				}
				else if(now == ')' || now == ']'){
					if(s.isEmpty()) {
						flg = false;
						break;
					}
					char pop = s.removeLast();
					if((pop == '(' && now == ')') || (pop == '[' && now == ']')){
						
					}
					else{
						flg = false;
						break;
					}
				}
			}
			if(! s.isEmpty()){
				flg = false;
			}
			if(flg){
				System.out.println("yes");
			}
			else{
				System.out.println("no");
			}
		}
			
		
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <iostream>
using namespace std;

int n;
int a[100005];
bool f[100005];

int main()
{
    scanf ("%d",&n);
    for (int i=1;i<=n;i++)
        scanf ("%d",&a[i]);
    for (int i=1;i<=n;i++)
        if (a[i]!=i) f[i]=1;
    int ans=0;
    int last=0;
    f[n+1]=1;
    for (int i=1;i<=n+1;i++)
        if (f[i]==1)
            {
            if (last==i-1) {last=i; continue;}
            else
                {
                int num;
                num=i-last-1;
                ans+=(num+1)/2;
                last=i;
                }
            }
    printf ("%d",ans);
}


Measured memory_bytes: 768