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

int main(){
  int N,M,a,b;
  cin >> N >> M;
  map<int, int> high;
  vector<int> vec;
  for(int i=1; i<=N; i++){
   cin >> high[i]; 
  }
  for(int i=0; i<M; i++){
    cin >> a >> b;

    if(high[a]>high[b]) vec.push_back(b);
    else if(high[a]<high[b]) vec.push_back(a);
    else{
      vec.push_back(a);
      vec.push_back(b);
    }
  }
  
  for(int i=0; i<vec.size(); i++){
    if(high.count(vec[i])){
      high.erase(vec[i]);
    }
  }
  
  cout << high.size() << endl;
}

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

int n, k, a[107];
bool dp[100007];

int main() {
	cin>>n>>k;
	for (int i=0; i<n; i++) cin>>a[i];
	for (int i=1; i<=k; i++) {
		for (int j=0; a[j]<=i && j<n; j++) {
			if (dp[i-a[j]]==0) dp[i]=1;
		}
	}
	if (dp[k]==1) cout<<"First"<<endl;
	else cout<<"Second"<<endl;
	return 0;
}

Measured memory_bytes: 384
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

n = I()
a = LI()

a.sort()
m = a[n-1]
flg = [False]*(m+1)

count = 0
for x in range(n):
    v = a[x]
    if(not flg[v]):
        i = v
        while(i <= m):
            flg[i] = True
            i += v
        if(x == n-1 or v != a[x+1]):
            count += 1

print(count)

Measured memory_bytes: 116844
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

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

char alpha[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

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

int main(){
    ll k; cin >> k;
    if(k % 2 == 0){
        cout << -1 << endl;
        return 0;
    }
    ll a = 7;
    if(k == 7 || k == 1){
        cout << 1 << endl;
        return 0;
    }
    REP(i, 0, k + 10){
        a = a * 10 + 7;
        if(a % k == 0){
            cout << i + 2 << endl;
            return 0;
        }
        a %= k;
    }
    cout << -1 << endl;
}

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

class Program
{
    static int A, B, T;

    public static void Main(string[] args)
    {
        A = Input.NextInt();
        B = Input.NextInt();
        T = Input.NextInt();

        var a = (T / A);
        var b = a * B;

        Console.WriteLine(b);
    }
}

public static class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

Measured memory_bytes: 11220
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	string S; cin >> S;
	REP(i, S.size()) {
		if (S[i] == '?')cout << 'D';
		else cout << S[i];
	}
	cout << endl;

	return 0;
}



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

int main(){
  string s; cin >> s;
  int cnt = 0, ans = 0;
  for(int i = 0; i < (int)s.size(); i++){
    if(s.at(i) == 'A' || s.at(i) == 'C'|| s.at(i) == 'G'|| s.at(i) == 'T'){
      cnt++;
    }
    else{
      cnt = 0;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll mpower(ll a,ll b,ll c){
    int z;
    if(b==0){
        z=1;
        z%=c;
        return z;
    }
    if(b==1){
        z=a;
        z%=c;
        return z;
    }
    else{
        return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
    }
}

int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  ll ans=0;
  ans+=(n/(a+b))*a;
  cout<<ans+min(n-(n/(a+b))*(a+b),a)<<endl;
}

Measured memory_bytes: 256
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n,m = map(int, input().split())
    KSMs = [list(map(int, input().split())) for i in range(m)]
    Ps = list(map(int, input().split()))
    cnt = 0
    # print(KSMs)
    is_ok = True
    #各スイッチのon/offパターンをすべて探索する
    for i in range(pow(2,n)):
        if not is_ok:
            is_ok = True
        for j in range(m):
            km = KSMs[j][0]
            # j個めの電球は，km個のスイッチに繋がれている

            cnt2 = 0
            for k in range(km):
                # 各スイッチのonになっている個数を数える
                # bitのKSMs[j][k+1]-1桁目が1の場合on0の場合false
                # print(KSMs[j][k+1]-1)
                if ((i>> (KSMs[j][k+1]-1)) & 1):
                    cnt2 += 1
            if cnt2 % 2 != Ps[j]:
                # j個目の電球は点灯していない
                is_ok = False
                break
        if is_ok:
            cnt += 1
            #print(bin(i))
               
    print(cnt)

    # 予約を断る
    # 次は土日か19の午後
    # 
    return

if __name__ == '__main__':
    main()

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

int main() {
    int n;
    cin >> n;
    n %= 10;

    string s;

    if (n == 2) s = "hon";
    if (n == 4) s = "hon";
    if (n == 5) s = "hon";
    if (n == 7) s = "hon";
    if (n == 9) s = "hon";

    if (n == 0) s = "pon";
    if (n == 1) s = "pon";
    if (n == 6) s = "pon";
    if (n == 8) s = "pon";

    if (n == 3) s = "bon";

    cout << s << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
#define _GLIBCXX_DEBUG
const int inf=1e9+7;

int main(){
    int n;cin>>n;
    vin h(n);
    set<int> H;
    rep(i,n){
        cin>>h[i];
        H.insert(h[i]);
    }
    int l,r,rad;
    int sum=0;
    for(int i=100;i>=0;i--){
        if(H.count(i)){
            rep(j,n){
                if(h[j]==i){
                    l=(j>0?h[j-1]:0);
                    if(j<n-1){
                        for(int k=j+1;k<n;k++){
                            if(h[k]<h[j]){
                                r=h[k];
                                rad=k;
                                break;
                            }
                            else if(k==n-1){
                                r=0;
                                rad=n;
                            }
                        }
                    }
                    else{
                        r=0;
                        rad=n;
                    }
                    rep2(k,j,rad){
                        sum+=h[j]-max(l,r);
                        h[k]=max(l,r);
                    }
                }
            }
        }
    }
    cout<<sum<<endl;
}

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

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

	vector<int> v( n );

	for( int i = 0; i < n; i++ )
	{
		cin >> v[i];
	}
	int ans = 0;
	for( int i = 0; i < n-2; i++ )
	{
		if( v[i] < v[i + 1] && v[i + 1] < v[i + 2]
			|| v[i] > v[i + 1] && v[i + 1] > v[i + 2] )
			ans++;
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#define F 100000
using namespace std;
int c[F],d[F],n,ctop,dtop;
void news(int cnt,int r){
	int y=F;
	bool k=false;
	while(true){
		if(k){
			d[dtop]=(cnt/y)%10;
			dtop++;
		}
		else if(y<=cnt){
			d[dtop]=(cnt/y)%10;
			dtop++;
			k=true;
		}
		if(y==1)break;
		y/=10;
	}
	d[dtop]=c[r],dtop++;
	return;
}
int main(){
	string s;
	while(true){
		cin>>n;
		if(!n)break;
		cin>>s;
		ctop=s.size();
		for(int i=0;i<ctop;i++)c[i]=s[i]-'0';
		for(int u=0;u<n;u++){
			dtop=0;
			int cnt=1;
			for(int i=1;i<ctop;i++){
				if(c[i]!=c[i-1]){news(cnt,i-1);cnt=0;}
				cnt++;
			}
			news(cnt,ctop-1);
			ctop=dtop;
			for(int i=0;i<dtop;i++)c[i]=d[i];
		}
		for(int i=0;i<ctop;i++)cout<<c[i];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3304
n = int(input())
x = list(input())
x=[1 if s=='1' else 0 for s in x]
sumx=sum(x)

neg=0
pos=0

for i in range(n):
    if sumx-1!=0:
        neg+=pow(2,(n-i-1),sumx-1)*x[i]
        neg%=sumx-1
    pos+=pow(2,(n-i-1),sumx+1)*x[i]
    pos%=sumx+1

pops=[]

for i in range(n):
    if x[i]==1:
        if sumx==1:
            pops.append(-1)
        else:
            pops.append((neg-pow(2,(n-i-1),sumx-1)+sumx-1)%(sumx-1))
    elif x[i]==0:
        pops.append((pos+pow(2,(n-i-1),sumx+1))%(sumx+1))

ans=[0]*(2*10**5+1)

for i in range(1,2*10**5+1):
    cnt=0
    tmp=i+0
    while tmp>0:
        cnt+=1
        b=bin(tmp)[2:]
        b=sum([1 if s=='1' else 0 for s in b])
        tmp%=b
    ans[i]=cnt

for p in pops:
    if p!=-1:
        print(ans[p]+1)
    else:
        print(0)

Measured memory_bytes: 105208
#include "bits/stdc++.h"

using namespace std;

template <int p>
struct Modint
{
	int value;

	Modint() : value(0) {}
	Modint(long x) : value(x >= 0 ? x % p : (p + x % p) % p) {}

	inline Modint &operator+=(const Modint &b)
	{
		if ((this->value += b.value) >= p)
			this->value -= p;
		return (*this);
	}
	inline Modint &operator-=(const Modint &b)
	{
		if ((this->value += p - b.value) >= p)
			this->value -= p;
		return (*this);
	}
	inline Modint &operator*=(const Modint &b)
	{
		this->value = (int)((1LL * this->value * b.value) % p);
		return (*this);
	}
	inline Modint &operator/=(const Modint &b)
	{
		(*this) *= b.inverse();
		return (*this);
	}

	Modint operator+(const Modint &b) const { return Modint(*this) += b; }
	Modint operator-(const Modint &b) const { return Modint(*this) -= b; }
	Modint operator*(const Modint &b) const { return Modint(*this) *= b; }
	Modint operator/(const Modint &b) const { return Modint(*this) /= b; }

	inline Modint &operator++(int) { return (*this) += 1; }
	inline Modint &operator--(int) { return (*this) -= 1; }

	inline bool operator==(const Modint &b) const { return this->value == b.value; }
	inline bool operator!=(const Modint &b) const { return this->value != b.value; }
	inline bool operator<(const Modint &b) const { return this->value < b.value; }
	inline bool operator<=(const Modint &b) const { return this->value <= b.value; }
	inline bool operator>(const Modint &b) const { return this->value > b.value; }
	inline bool operator>=(const Modint &b) const { return this->value >= b.value; }

	//requires that "this->value and p are co-prime"
	// a_i * v + a_(i+1) * p = r_i
	// r_i = r_(i+1) * q_(i+1) * r_(i+2)
	// q == 1 (i > 1)
	// reference: https://atcoder.jp/contests/agc026/submissions/2845729 (line:93)
	inline Modint inverse() const
	{
		assert(this->value != 0);
		int r0 = p, r1 = this->value, a0 = 0, a1 = 1;
		while (r1)
		{
			int q = r0 / r1;
			r0 -= q * r1;
			swap(r0, r1);
			a0 -= q * a1;
			swap(a0, a1);
		}
		return Modint(a0);
	}

	friend istream &operator>>(istream &is, Modint<p> &a)
	{
		long t;
		is >> t;
		a = Modint<p>(t);
		return is;
	}
	friend ostream &operator<<(ostream &os, const Modint<p> &a)
	{
		return os << a.value;
	}
};

const int MOD = 1e6+3;

using Int = Modint<MOD>;

Int pow(Int e, int64_t x)
{
	if (x == 0)
		return 1;
	Int res = (x & 1 ? e : 1), tmp = pow(e, x >> 1);
	res *= tmp * tmp;
	return res;
}

void solve(void)
{
	int q;
	cin >> q;
	vector<Int> acc(MOD);
	acc[1] = 1;
	for (int i = 1; i < MOD-1; i++)
	{
		acc[i + 1] = acc[i] * Int(i + 1);
	}
	while(q--)
	{
		Int x, d;
		int n;
		cin >> x >> d >> n;
		if (d == 0)
		{
			cout << pow(x, n) << endl;
			continue;
		}
		x /= d;
		if (x.value+n-1 >= MOD)
		{
			cout << 0 << endl;
			continue;
		}
		Int ans = acc[x.value+n-1] / acc[x.value-1] * pow(d, n);
		cout << ans << '\n';
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
// const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int l, r;
    cin >> l >> r;

    if (r-l+1 >= 2019) {
        cout << 0 << endl;
    }
    else {
        int mod = 2019;
        int min_num = 1e7;
        REP(i, l, r+1) {
            REP(j, i+1, r+1) {
                int tmpint = (i % mod) * (j % mod);
                min_num = min(min_num, tmpint % mod);
            }
        }
        cout << min_num << endl;
    }
    
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>

using namespace std;

int main()
{
	double x1, y1, x2, y2, point;
	cin >> x1 >> y1 >> x2 >> y2;

	point = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);
	cout << fixed << setprecision(6) << sqrt(point) << "\n";

}

Measured memory_bytes: 1284
#include <bits/stdc++.h>
#define mp make_pair
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 1LL << 30;
const ll LINF = 1LL << 60;
const double eps = 1e-9;
const ll MOD = 1000000007LL;
int main() {
    char c;cin>>c;
    if(c=='A'){
        cout<<'T'<<endl;
    }else if(c=='T'){
        cout<<'A'<<endl;
    }else if(c=='C'){
        cout<<'G'<<endl;
    }else{
        cout<<'C'<<endl;
    }
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in);) {
            long a = scanner.nextLong();
            long b = scanner.nextLong();
            long c = scanner.nextLong();
            long d = scanner.nextLong();
            long[] ary = {a * c, a * d, b * c, b * d};
            long max = ary[0];

            for (int i = 1; i < ary.length; i++) {
                if (ary[i] > max) {
                    max = ary[i];
                }
            }
            
            System.out.println(max);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 35784
def read():
    S, T = input().strip().split()
    A, B = list(map(int, input().strip().split()))
    U = input().strip()
    return S, T, A, B, U

def solve(S, T, A, B, U):
    if U == S:
        A -= 1
    if U == T:
        B -= 1
    return A, B


if __name__ == '__main__':
    inputs = read()
    print("{} {}".format(*solve(*inputs)))


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<queue>
#include<sstream>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define INF 1000000000007
#define MOD 1000000007
#define ARRAY_MAX 3005


//重み付きUnion-Find
struct Potential_UnionFind{

    vector<int> par;//親
    vector<int> rank;//高さ
    vector<int> diff_weight;//根からの重み

    void init(int n) {
        par.resize(n);
        rank.resize(n);
        diff_weight.resize(n);
        REP(i,n){
            par[i] = i;
            rank[i] = 0;
            diff_weight[i] = 0;
        }
    }

    int root(int x) {//親を探す
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    int weight(int x) {
        //親からの重みを返す
        root(x);
        return diff_weight[x];
    }

    bool issame(int x,int y) {
        //同じ親を持つ要素かどうか
        return root(x) == root(y);
    }

    void merge(int x, int y,int w) {
        //weight(y) - weight(x) = wとなるようにつなげる
        int rx = root(x);
        int ry = root(y);
        
        if(rank[rx] < rank[ry]){
            diff_weight[rx] = -w - weight(x) + weight(y);
            par[rx] = ry;
        }else{
            diff_weight[ry] = w + weight(x) - weight(y);
            par[ry] = rx;
            if(rank[rx] == rank[ry]){
                rank[rx]++;
            }
        }
    }

    int diff(int x, int y) {
        //weight(y) - weight(x)を返す
        return weight(y) - weight(x);
    }
};


int main(){

    
    int n;
    while(cin >> n,n){
        Potential_UnionFind tree;
        tree.init(205);
        bool ans = true;
		map<string,int> mp;
		int id_number = 0;

        for(int i = 0;i < n;i++){

			string one,unit1,equal,two,unit2;
			cin >> one >> unit1 >> equal >> two >> unit2;

			//左辺の単位
			if(mp.find(unit1) == mp.end()){
				mp[unit1] = id_number;
				id_number++;
			}

			int id1 = mp[unit1];//単位の番号

			//右辺の単位
			if(mp.find(unit2) == mp.end()){
				mp[unit2] = id_number;
				id_number++;
			}

			int id2 = mp[unit2];//単位の番号

			string ratio = two.substr(3);
			//cout << ratio << endl;

			int ratio_num = stoi(ratio);

			if(tree.issame(id1,id2)){
				if(tree.diff(id1,id2) != ratio_num){
					ans = false;
				}
			}else{
				tree.merge(id1,id2,ratio_num);
			}
        }
		if(ans){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
    }

    return 0;
}


Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
void solve()
{
	ll n;
	cin>>n;
	ll a[n];
	ll sum = 0;
	map<ll,ll> m;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		sum += a[i];
		m[a[i]]++;
	}
	ll q;
	cin>>q;
	for (int i = 0; i < q; ++i)
	{
		ll b,c;
		cin>>b>>c;
		sum += (c-b)*m[b];
		m[c] += m[b];
		m[b] = 0;
		cout<<sum<<endl;
	}
 
}	
 
int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 10272
import java.util.Scanner;

public class Main {

	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		int ab = a + b;
		int ac = a + c;
		int bc = b + c;
		int ans = Math.min(ab, Math.min(ac, bc));
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int i,haj,l,a[30];

int main(){
	while(scanf("%d",&l)*l){
		for(i=0;i<l;i++)scanf("%d",&a[i]);
		haj=32;i=0;
		while(haj>0){

		haj-=(haj-1)%5;
		printf("%d\n",haj);
		
		haj-=a[i];
		if(haj<0)haj=0;
		i=(i+1)%l;
		printf("%d\n",haj);
		}
	}
	return 0;
}

Measured memory_bytes: 600
import sys
sys.setrecursionlimit(10**6)
mod = 10**9+7
p2 = [1]*(3*10**5)
for n in range(3*10**5-1):
    p2[n+1] = p2[n]*2%mod

N = int(input())
AB = [list(map(int,input().split())) for _ in range(N-1)]
g = [[] for _ in range(N+1)]
for i in range(N-1):
    a,b = AB[i]
    g[a].append(b)
    g[b].append(a)

l1 = [0]*(N+1)
l2 = [[] for _ in range(N+1)]

def rec(p,c):
    res = 0
    for a in g[c]:
        if a == p:
            continue
        n = rec(c,a)
        l2[c].append(n+1)
        res += n+1
    l1[c] = res
    return res

n = rec(0,1)
for i in range(1,N+1):
    l2[i].append(N-1-l1[i])

ans = 0
for i in range(1,N+1):
    ans += p2[N-1]-1
    ans %= mod
    for j in l2[i]:
        ans -= p2[j]-1
        ans %= mod
ans *= pow(p2[N],mod-2,mod)
ans %= mod
print(ans)


Measured memory_bytes: 221116
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int[] a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
        int k = Integer.parseInt(sc.next());
        System.out.println(a[k-1]);
    }
}

Measured memory_bytes: 21588
s =input()
s = s[::-1]
t = ['dream','dreamer','erase','eraser']

for i in range(len(t)):
    t[i]=t[i][::-1]

while s != '':
    for j in range(len(t)):
        if s[0:len(t[j])] == t[j]:
            s = s[len(t[j]):]
            break
    else:
        print('NO')
        break
else:
    print('YES')

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

  int main(){
  int a,b,c,d;
  cin >>a>>b>>c>>d;
  
  if (a+b == c+d)
  cout <<"Balanced"<<endl;
  
  else if (a+b >= c+d)
    cout <<"Left"<<endl;
  
  else if (a+b <= c+d)
    cout <<"Right"<<endl;
  }


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

for i in range(1, len(a)):
    print(' '.join(map(str, a)))
    key = a[i]
    j = i - 1;
    while j >= 0 and a[j] > key:
        a[j + 1] = a[j]
        j -= 1
    a[j + 1] = key
print(' '.join(map(str, a)))

Measured memory_bytes: 6720
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
ans = A[0]
n -= 2
ind = 1
for i in range(n//2):
    ans += A[ind] * 2
    ind += 1
if n % 2 == 1:
    ans += A[ind]
print(ans)


Measured memory_bytes: 105192
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n;
	string s, t;
	cin >> n >> s >> t;
	rep(i, n) cout << s[i] << t[i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
string t;
cin>>t;
if((t[0]=='B'&&t[1]=='A')||(t[0]=='A'&&t[1]=='B')||(t[1]=='B'&&t[2]=='A')||(t[1]=='A'&&t[2]=='B'))
cout<<"Yes";
else
cout<<"No";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
int calc(int x){
  int y=0;
  while(x%100==0){  
    x/=100;
    y++;
  }
  return y;  
}
int main(void){
  int d,n;
  scanf("%d%d",&d,&n);
  int cnt,x=0,ans=0,j=0;
  while(j<n){
    x++;
    if(calc(x)==d) {j++;}
  }
  printf("%d",x);
  return 0;
}

Measured memory_bytes: 128
use strict;
use warnings;
use utf8;

chomp(my $ln1 = <STDIN>);
my ($n, $k) = split(/ /, $ln1);
chomp(my $ln2 = <STDIN>);
my @arr = split(/ /, $ln2);

@arr = sort {$b <=> $a} @arr;
my @sliced = splice(@arr, 0, $k);
my $ans = 0;
for my $x (@sliced){
    $ans += $x;
}
print $ans;


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

int partition(int A[], int p, int r)
{
    int x = A[r];
    int i = p - 1;

    for (int j = p; j != r; ++j)
    {
        if (A[j] <= x)
        {
            ++i;
            swap(A[i], A[j]);
        }
    }

    swap(A[i+1], A[r]);

    return i+1;
}

int main()
{
    int n;
    int A[100000];

    scanf("%d", &n);

    for (int i = 0; i != n; ++i)
    {
        scanf("%d", &A[i]);
    }

    int s = partition(A, 0, n-1);

    for (int i = 0; i != n; ++i)
    {
        if (i)
        {
            printf(" ");
        }

        if (i == s)
        {
            printf("[%d]", A[i]);
        }
        else
        {
            printf("%d", A[i]);
        }
    }

    printf("\n");
    
    return 0;
}


Measured memory_bytes: 3516
#include<iostream>
#include<stack>
#include<vector>
#define ll long long
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 200004

using namespace std;

string s;
ll minlength[N];
ll n;
string ans;
ll epomeno[N][26];

ll first_occurence(ll cur,ll id)
{
    return epomeno[cur][id];
}

ll calc(ll cur)
{
    if(cur > n)
        return 0;
    if(cur == n)
        return 1;

    if(minlength[cur])
        return minlength[cur];

    minlength[cur] = n-cur+1;

    rep(i,0,26)
    {
        ll goes = first_occurence(cur,i);

        minlength[cur] = min(minlength[cur],calc(goes+1)+1);
    }

    return minlength[cur];
}

void solve(ll cur,ll pos)
{
    if(cur >= n)
        return;

    rep(i,0,26)
    {
        ll goes = first_occurence(cur,i);

        if(minlength[goes+1]+1==minlength[cur])
        {
            ans[pos]=i+'a';
            solve(goes+1,pos+1);
            break;
        }
    }

    return;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> s;
    n = s.size();

    rep(i,0,26)
    {
        epomeno[n][i]=n;
        for(int j = n-1;j>=0;j--)
        {
            if(s[j]-'a'==i)
                epomeno[j][i]=j;
            else
                epomeno[j][i]=epomeno[j+1][i];
        }
    }

    calc(0);

    rep(i,0,minlength[0])
        ans += "a";

    solve(0,0);

    cout << ans;

    return 0;
}


Measured memory_bytes: 43028
#include <stdio.h>
#include <stdbool.h>

void leapyear(int a, int b);
int a, b;
bool flag,flag2 = true;
int main(void)
{
    while (1) {
        flag =true;
        scanf("%d %d", &a, &b);
        if (a == 0 && b == 0) {
            break;
        }
        if (flag2 == true) {
            flag2 =false;
        } else {
            printf("\n");
        }
        leapyear(a, b);
    }
    return 0;
}

void leapyear(int a, int b)
{
    for (int i = a; b >= i; ++i) {
        if (i % 4 == 0) {
            if (i % 100 == 0) {
                if (i % 400 == 0) {
                    printf("%d\n", i);
                    flag = false;
                }
            } else {
                printf("%d\n", i);
                flag = false;
            } 
        }
    }
    if (flag == true) {
        printf("NA\n");
    }
}

Measured memory_bytes: 1044
#include <stdio.h>
int main()
{
int a,b;
scanf("%d %d",&a,&b);
if(a > b)
{
printf("a > b\n");
}
else if(a < b)
{
printf("a < b\n");
}
else
{
printf("a == b\n");
}
return 0;
}

Measured memory_bytes: 580
N = int(input())
h = list(map(int, input().split()))

# ローカルピークの場所をカウントして、その和が回答だと思う。

count = 0

while True:
    if max(h) == 0: break
    i = 0
    while i < N:
        if h[i]==0:
            i += 1
        else:
            count += 1
            while i < N and h[i] > 0:
                h[i] -= 1
                i += 1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n = 0, m = 1;

	cin >> n;

	vector<int> d(n, 0);

	for (int i = 0; i < n; i++)
		cin >> d[i];

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

	if (n > 1) {
		for (int i = 0; i < n - 1; i++) {
			if (d[i + 1] != d[i])
				m++;
		}
	}

	cout << m << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    string s;
    cin >> s;

    ll ans = 0LL;
    for (int i = 0; i < s.size(); i++) {
        for (int j = i; j < s.size(); j++) {
            ll t = 0LL;

            for (int k = i; k <= j; k++) {
                t *= 10;
                t += (ll)(s[k] - '0');
            }

            int left = max(0, i-1);
            int right = max(0, (int)s.size() - j - 2);
            ans += t * (1LL << left) * (1LL << right);
        }
    }


    cout << ans << "\n";
    return 0;
}

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

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

	if(a < b && b < c){
		cout << "Yes" << endl;	
	}
	else{
		cout << "No" << endl;
	}

	return 0;
}




Measured memory_bytes: 3120
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N;
	String S, T;
	String result;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		String[] tokens = in.readLine().split(" ");
		S = tokens[0];
		T = tokens[1];
	}

	void calc() {
		StringBuilder strBuilder = new StringBuilder();
		for (int i = 0; i < N; ++i) {
			strBuilder.append(S.charAt(i));
			strBuilder.append(T.charAt(i));
		}
		result = strBuilder.toString();
	}

	void showResult() {
		System.out.println(result);
	}
}


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

int main(){
    int n;
    int d[100000];
    cin >>n;
    for(int i=0;i<n;i++){
        cin >>d[i];
    }
    sort(d,d+n);
    cout << d[n/2] - d[n/2 -1] <<endl;
    return 0;
}

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

int main(){

    cout<<setprecision(5)<<fixed;

    int n; cin>>n;
    
    vector<int> val(n);
    
    for(int i=0; i<n; i++)cin>>val.at(i);

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

    double ans = (double) ( val.at(0) + val.at(1) ) / 2;

    for(int i=2; i<n; i++){

        ans = (double) (ans + val.at(i)) / 2;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#input
h, w, k = map(int, input().split())
c = [[0] * w for _ in range(h)]
for i in range(h):
    c[i] = input()

#output
import itertools
A_1 = list(itertools.product([0, 1], repeat = h))
A_2 = list(itertools.product([0, 1], repeat = w))

answer = 0
for a_1 in A_1:
    for a_2 in A_2:
        temp = 0
        for i in range(h):
            for j in range(w):
                if a_1[i] and a_2[j]:
                    if c[i][j] == "#":
                        temp += 1
        if temp == k:
            answer += 1
print(answer)

Measured memory_bytes: 9220
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(a%b,b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}

int main(){
    init();
	string s,t;
	cin>>s>>t;
	cout<<t<<s<<endl;
}

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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> pii;

const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	ios::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	string s, t; cin >> s >> t;
	for (int i = 0; i < n; i++) {
		cout << s[i] << t[i];
	}
	cout << '\n';

	return 0;
}

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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pll;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

ll gcd(ll x,ll y){
  return y? gcd(y,x%y):x;
}

template <typename T>
struct SegmentTree{
    using F = function<T(T,T)>;
    int n;
    F f;
    T ti;
    vector<T> dat;
    SegmentTree(){};
    SegmentTree(F f,T ti):f(f),ti(ti){}
    void init(int n_){
        n=1;
        while(n<n_) n<<=1;
        dat.assign(n<<1,ti);
    }
    void build(const vector<T> &v){
        int n_=v.size();
        init(n_);
        for(int i=0;i<n_;i++) dat[n+i]=v[i];
        for(int i=n-1;i;i--)
            dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
    }
    void set_val(int k,T x){
        dat[k+=n]=x;
        while(k>>=1)
            dat[k]=f(dat[(k<<1)|0],dat[(k<<1)|1]);
    }
    //[a,b)
    T query(int a,int b){
        T vl=ti,vr=ti;
        for(int l=a+n,r=b+n;l<r;l>>=1,r>>=1) {
            if(l&1) vl=f(vl,dat[l++]);
            if(r&1) vr=f(dat[--r],vr);
        }
        return f(vl,vr);
    }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N;cin>>N;
  vll A(N);
  for(ll i=0;i<N;i++){
    cin>>A[i];
  }
  SegmentTree<ll> seg([](ll a,ll b){return gcd(a,b);},0);
  seg.build(A);
  ll ans = 0;
  for(ll i=0;i<N;i++){
    seg.set_val(i,0);
    ans = max(ans,seg.query(0,N));
    seg.set_val(i,A[i]);
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

int main(){
  
  int n,x;
  cin >> n >> x;
  int res = n;
  vector<int> v(n);
  for(int i = 0;i < n;i++)cin >> v[i];
  sort(v.begin(),v.end());
  for(int i = 0;i < n;i++)x -= v[i];
  while(x >= v[0]){
    x -= v[0];
    res++;
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

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

	priority_queue <pair<ll,int>> a;
	int n, m;
	cin >> n >> m;
	rep(i, n) {
		ll k;
		cin >> k;
		a.push(make_pair(k, 1));
	}
	rep(i, m) {
		ll b, c;
		cin >> b >> c;
		a.push(make_pair(c, b));
	}
	ll ans = 0;
	int cnt = 0;
	while (cnt < n) {
		pair<ll, int> p;
		p = a.top(); a.pop();
		if (p.second + cnt > n) {
			ans += p.first * (n - cnt);
		}
		else ans += p.first * p.second;
		cnt += p.second;
	}
	cout << ans << endl;
}

Measured memory_bytes: 6384
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n;
	int a[101]={0};
	int i,j,minj;
	int cut=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
		minj=i;
		for(j=i;j<n;j++){
			if(a[j]<a[minj]){
				minj=j;
			}
		}
		if(minj!=i){
			swap(a[i],a[minj]);
			cut++;
		}
	}
	for(i=0;i<n;i++){
		if(i!=0)cout<<" ";
		cout<<a[i];
	}
	cout<<endl<<cut<<endl;
	return 0;
}
	

Measured memory_bytes: 3092
#include<stdio.h>
int main(){
 int n;
 scanf("%d",&n);
 int a[100];
 for(int i=0;i<n;i++){
   scanf("%d",&a[i]);
 }
  
  int checked=0;
  for(int i=0;i<n;i++){
  if(a[i]%2==0){
  if(a[i]%3!=0&&a[i]%5!=0){
    checked=1;
   }
  }
 }
  
  if(checked==0){
   printf("APPROVED");
  }
  else{
     printf("DENIED");
  }
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<sstream>
using namespace std;
int inf = 1000000000;

int n, m;
vector<long long int> x;
vector<long long int> y;
vector<long long int> z;

long long int func(long long int a, long long int b, long long int c){
  long long int ret = 0;
  vector<long long int> s(n, 0);
  for(int i=0; i<n; i++){
    s[i] += a*x[i] + b*y[i] + c*z[i];
  }
  sort(s.begin(), s.end());
  for(int i=0; i<m; i++){
    ret += s[n-1-i];
  }
  cerr << ret << endl;
  return ret;
}

int main(){

  cin >> n >> m;
  x.resize(n);
  y.resize(n);
  z.resize(n);
  for(int i=0; i<n; i++) cin >> x[i] >> y[i] >> z[i];

  long long int ans = func(1, 1, 1);
  ans = max(ans, func(1, 1, -1));
  ans = max(ans, func(1, -1, 1));
  ans = max(ans, func(1, -1, -1));
  ans = max(ans, func(-1, 1, 1));
  ans = max(ans, func(-1, 1, -1));
  ans = max(ans, func(-1, -1, 1));
  ans = max(ans, func(-1, -1, -1));
  cout << ans << endl;

  return 0;
}



//


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

const char itos[2] = {'S', 'W'};
int id[256];

bool dif(char A, char T) {
    return (A == 'S' && T == 'x') || (A == 'W' && T == 'o');
}

string solve(int N, const string &S, int a, int b) {
    int M = S.size();
    string res(M, 'A');
    res[0] = itos[a], res[1] = itos[b];
    for(int i = 1; i < M - 1; ++i) {
        res[i + 1] = itos[id[res[i - 1]] ^ dif(res[i], S[i])];
        if(i + 1 >= N && res[i + 1 - N] != res[i + 1]) return "";
    }
    return res.substr(N);
}

int main() {
    int N; string S;
    cin >> N >> S;
    S += S;
    id['S'] = 0; id['W'] = 1;
    for(int i = 0; i < 2; ++i) {
        for(int j = 0; j < 2; ++j) {
            auto res = solve(N, S, i, j);
            if(res != "") {
                cout << res << '\n';
                return 0;
            }
        }
    }
    cout << -1 << '\n';
    return 0;
}


Measured memory_bytes: 856
#pragma GCC target("avx2")
#pragma GCC optimize("O3")

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

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

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

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;


bool check (ll x) {
	if (x <= 2) return 1;
	if (x % 2 == 0) return 0;
	for (ll i = 3; i * i <= x; i += 2) if (x % i == 0) return 0;
	return 1;
}

int main () {
   SpeedForce;
   ll a, b;
   cin >> a >> b;
   ll cur = __gcd(a, b);

   int cnt = 0;
   for (ll i = 1; i * i <= cur; i ++) {
   	if (cur % i == 0) {
   		cnt += check(i);
   		if (cur / i != i) cnt += check(cur / i);
   	}
   }
   cout << cnt;

   return Accepted;
}

// B...a

Measured memory_bytes: 18688
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;

const int V = 100001;
vector<int> g[V*2];
int used[V*2];
int cnt[2];

void dfs(int v){
	if(used[v]) return;
	used[v] = true;

	cnt[v/V]++;
	for(int nv: g[v]){
		if(used[nv]) continue;
		dfs(nv);
	}
}

int main(void){
	int N;
	cin >> N;
	for(int i = 0; i < N; i++){
		int x, y;
		cin >> x >> y;
		y += V;
		g[x].push_back(y);
		g[y].push_back(x);
	}

	ll res = 0;
	for(int i = 0; i < V*2; i++){
		if(used[i]) continue;

		cnt[0] = 0;
		cnt[1] = 0;
		dfs(i);
		res += (ll)cnt[0]*cnt[1];
	}

	res -= N;

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 10752
from collections import defaultdict
from bisect import bisect

N = int(input())

A = tuple(map(int,input().split()))

T = defaultdict(list)
for i,a in enumerate(A):
    T[a-i].append(i)

cnt = 0
for i,a in enumerate(A):
    x = -a-i
    if x in T:
        l = T[x]
        cnt += len(l) - bisect(l, i)

print(cnt)

Measured memory_bytes: 62968
#include<stdio.h>

main(){
	int H1[4][11], H2[4][11], H3[4][11], H4[4][11], n, b, f, r, v, i, j;
	
	for(i=0;i<4;i++){
		for(j=0;j<11;j++){
			H1[i][j]=0;
		}
	}
	for(i=0;i<4;i++){
		for(j=0;j<11;j++){
			H2[i][j]=0;
		}
	}
	for(i=0;i<4;i++){
		for(j=0;j<11;j++){
			H3[i][j]=0;
		}
	}
	for(i=0;i<4;i++){
		for(j=0;j<11;j++){
			H4[i][j]=0;
		}
	}
	scanf("%d%*c",&n);
	
	for(i=0;i<n;i++){
		
		scanf("%d %d %d %d",&b,&f,&r,&v);
		
		if(b==1){
			H1[f][r]+=v;
		}
		else if(b==2){
			H2[f][r]+=v;
		}
		else if(b==3){
			H3[f][r]+=v;
		}
		else if(b==4){
			H4[f][r]+=v;
		}
	}
	
	for(i=1;i<4;i++){
		for(j=1;j<11;j++){
			printf(" %d",H1[i][j]);
		}
		printf("\n");
	}
	
	printf("####################\n");
	
	for(i=1;i<4;i++){
		for(j=1;j<11;j++){
			printf(" %d",H2[i][j]);
		}
		printf("\n");
	}
	
	printf("####################\n");
	
	for(i=1;i<4;i++){
		for(j=1;j<11;j++){
			printf(" %d",H3[i][j]);
		}
		printf("\n");
	}
	
	printf("####################\n");
	
	for(i=1;i<4;i++){
		for(j=1;j<11;j++){
			printf(" %d",H4[i][j]);
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
#define adrep(i,s,n) for (int i=(s);i<(n);i++)
using namespace std;
typedef long long ll;
static const double pi = 3.141592653589793;

int main(){

  double A,B,H,M;
  cin>>A>>B>>H>>M;
  
  double lx=B*sin(M/60*2*pi);
  double ly=B*cos(M/60*2*pi);
  
  double sx=A*sin(H/12*2*pi+M/60/12*2*pi);
  double sy=A*cos(H/12*2*pi+M/60/12*2*pi);
  
  double ans=sqrt( (lx-sx)*(lx-sx) + (ly-sy)*(ly-sy) );
  cout<<setprecision(15)<<ans<<endl;
  
}

Measured memory_bytes: 4164
#include<stdio.h>

int F[45];

void makefibonacci(void)
{
  int i;
  for(i=0;i<45;i++)
    {
      if(i==0) F[i]=1;
      else if(i==0) F[i]=1;
      else F[i]=F[i-2]+F[i-1];
    }
}

int main()
{
  int d,i,j=0;
  makefibonacci();
  scanf("%d",&d);
  printf("%d\n",F[d]);
  return 0;
}
  

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define M 1000010

int main(){
	IOS;
	ll a,b;cin>>a>>b;
	ll ans=a-2*b;
	cout<<max(ans,0ll);
	
	
	
	
	return 0;
}



Measured memory_bytes: 256
import std.stdio, std.algorithm;

int n, m;
int[] xs, memo;

void main(){
	for(;scanf("%d%d\n", &m, &n) && n;){
		xs.length = n;
		foreach(ref x; xs){
			x = 0;
			auto s = readln;
			foreach(i; 0..m) x |= (s[i]=='1')<<i;
		}
		memo.length = 3^^m;
		memo[] = -1;
		writeln(solve(0));
	}
}

int solve(int state){
	if(memo[state] >= 0) return memo[state];
	int ans = int.max;
	scope(exit) memo[state] = ans;
	int checked = 0, info = 0;
	foreach(i; 0..m)if(state/(3^^i)%3){
		checked |= 1<<i;
		info |= (state/(3^^i)%3 == 1)<<i;
	}
	int cands = cast(int)count!(x=>(x&checked)==info)(xs);
	if(cands <= 1) return ans = 0;
	foreach(i; 0..m)if(state/(3^^i)%3 == 0)
		ans = min(ans, 1 + max(solve(state+(3^^i)*1), solve(state+(3^^i)*2)));
	return ans;
}

Measured memory_bytes: 3096
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	string s, t;
	cin >> s >> t;
	
	int sn = (int)s.size();
	int tn = (int)t.size();
	vector< vector<int> >  dp(sn + 10, vector<int>(tn + 10, 0));
	
	for(int i = 0; i < sn; ++i) {
		for(int j = 0; j < tn; ++j) {
			if( s[i] == t[j] ) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
			} else {
				dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
			}
		}
	}
	
	int a = sn, b = tn;
	string ans = "";
	
	while( a && b ) {
		if( s[a - 1] == t[b - 1] ) {
			ans.push_back(s[a - 1]);
			a--; b--;
		} else {
			if( dp[a][b] == dp[a - 1][b] ) a--;
			else b--;
		}
	}

	reverse(ans.begin(), ans.end());
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 38840
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int K, N;
	cin >> K >> N;
	int MAX = 0;
	int A;
	cin >> A;
	int first = A;
	int before = A;
	for (int i = 1; i < N; i++) {
		cin >> A;
		MAX = max(MAX, A - before);
		before = A;
	}
	MAX = max(MAX, K - before + first);
	cout << K - MAX << endl;

}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<stack>
#include<queue>
#include<stdlib.h>
#include<string.h>
#include<vector>
#define LL long long
#define  long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const double INF=1e9+7;
int Find[10000];
int find(int x) {return Find[x]==x?x:Find[x]=find(Find[x]);}
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if(a*c<=b) printf("%d\n",c);
    else{
        printf("%d\n",b/a);
    }
    return 0;
}


Measured memory_bytes: 256