akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    N = int(input())
    D_1, D_2 = [], []
    for i in range(N):
        D_i1, D_i2 = list(map(int, input().split()))
        D_1.append(D_i1)
        D_2.append(D_i2)

    return N, D_1, D_2


def main(N: int, D_1: list, D_2: list) -> None:
    """
    メイン処理.

    Args:\n
        N (int): サイコロを振った回数(3 <= N <= 100)
        D_1 (list): i回目の出目(1 <= D_i1 <= 6)
        D_2 (list): i回目の出目(1 <= D_i2 <= 6)
    """
    # 求解処理
    ans = "No"
    doublet_cnt = 0
    for i in range(N):
        if D_1[i] == D_2[i]:
            doublet_cnt += 1
        else:
            doublet_cnt = 0

        if doublet_cnt >= 3:
            ans = "Yes"
            break

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    N, D_1, D_2 = get_input()

    # メイン処理
    main(N, D_1, D_2)


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

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

ll x,y;
cin>>x>>y;
int sum=0;
for(int i=0;i<=x;i++){
     int j=x-i;
    ll ans=2*i+4*j;

    if(ans==y){
        sum++;
        break;
    }

}
if(sum==0){
    cout<<"No"<<endl;
}
else{
    cout<<"Yes"<<endl;
}


}

Measured memory_bytes: 3648
N, Y = map(int, input().split())
flg = False
if N * 1000 <= Y <= N * 10000:
    for i in range(N + 1)[::-1]:
        if Y < i * 10000:
            continue
        if flg or i * 10000 + (N - i) * 5000 < Y:
            break
        for j in range(N + 1 - i)[::-1]:
            m = i * 10000 + j * 5000 + (N - i - j) * 1000
            if Y < m:
                continue
            if m == Y:
                print(i, j, N - i - j)
                flg = True
            if m <= Y:
                break
if not flg:
    print(-1, -1, -1)


Measured memory_bytes: 39408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //int:2*10**9
typedef long double ld;
typedef pair<ll,ll> P;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define vec2(name,i,j,k) vector<vector<ll>> name(i,vector<ll>(j,k))
#define vec3(name,i,j,k,l) vector<vector<vector<ll>>> name(i,vector<vector<ll>>(j,vector<ll>(k,l)))
#define pb push_back
#define MOD 1000000007 //998244353
#define PI 3.141592653
#define INF 100000000000000 //14
//cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
int main(){
    ll d; cin >> d;
    REP(i,d){
        ll x = i%26;x++;
        cout << x << endl;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int d,n;
    cin>>d>>n;
	int s=1;
	for(int i=0;i<d;i++)s*=100;
	if(n<=99){
		cout<<s*n<<endl;
	}else{
		cout<<s*101<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
import * as fs from 'fs';

const readString = (() => {
  const input = fs.readFileSync(0).toString();
  const words = input.split(/[ \n]/);
  let i = 0;
  return () => words[i++] || '';
})();
const readInt = () => parseInt(readString(), 10);

(function main() {
  const N = readInt();
  let o;
  switch (N % 10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      o = 'hon';
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      o = 'pon'
      break;
    case 3:
      o = 'bon';
      break;
  }
  console.log(o);
})();


Measured memory_bytes: 29572
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

typedef pair<int ,bool> P;//cost ,true:shop false:takuhai
typedef pair<int , int> PI;

int maxd;
int maxn;
int maxm;
vector<P> field;
map<int,int> m;

int main(void)
{
	while(1){
		field.clear();
		m.clear();
		cin >> maxd;
		if(maxd == 0)
			return 0;
		cin >> maxn >> maxm;
		field.push_back(P(0,true));
		field.push_back(P(maxd,true));
		for(int i=0;i<maxn-1;++i){
			int a;
			cin >> a;
			field.push_back(P(a,true));
		}
		for(int i=0;i<maxm;++i){
			int a;
			cin >> a;
			field.push_back(P(a,false));
		}
		sort(field.begin(),field.end());
		int a;
		for(int i=0;i<field.size();++i){
			if(field[i].second)
				a=i;
			else
				m[i] = field[i].first-field[a].first;
		}
		for(int i=field.size()-1;i>=0;--i){
			if(field[i].second)
				a=i;
			else
			{
				if(m[i] > field[a].first - field[i].first)
					m[i] = field[a].first - field[i].first;
			}
		}
		int sum=0;
		for(auto it = m.begin();it!=m.end();++it){
			sum+=(*it).second;
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 2364
#include <bits/stdc++.h>
using namespace std;
#define int long long
//vector<int> v,dp;


signed main()
{
    int n,i,k,j,W;
   cin >> n >> W;
   vector<vector<int>> v(n,vector<int> (2)),dp(n+1,vector<int> (W+1,0));
    for(i =0;i < n;i++){
        for(j = 0;j < 2;j++)
            cin >> v[i][j];
    }
    for(i = 1;i <= n;i++){
        for(j = 1;j <= W;j++){
            if(j-v[i-1][0] >= 0)
               
                dp[i][j] = max(dp[i-1][j]
                                ,dp[i-1][j-v[i-1][0]]+v[i-1][1]);
            else
                dp[i][j] = dp[i-1][j];
        }
    }
   
    cout << dp[n][W];
    return 0;
}


Measured memory_bytes: 80256
#include<iostream>
#include<cstdio>
#include<cstring>
//#include<>
using namespace std;






int main()
{

    long long int N;
    long long int a[100100];

    cin >> N;
    memset(a, 0, sizeof(a));

    for (int i = 1; i < N+1; i++) {
        cin >> a[i];
    }

    long long int ans = 0;
    for (int i = 0; i < N; i++) {
        long long int p = 0,q=0;
       
        if (i==a[a[i]])ans++;
    }
    ans /= 2;
//    long long int ans = 0;

        cout << ans << endl;

    return 0;

}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, pair<ll, ll> > P3;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = INT_MAX;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
string dir[] = {"R", "D", "L", "U"};
#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 (ll i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, a[MAX_N], b[MAX_N]{};
    cin >> n;
    REP(i,n)cin >> a[i+1];
    int k = 1, cnt = 0;
    while(1){
        if(b[k]>0){
            cout << -1 << endl;
            break;
        }
        if(k==2){
            cout << cnt << endl;
            break;
        }
        b[k]++;
        cnt++;
        k = a[k];
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> R, C;
	int r, c;
	R.push_back(0);
	for (int i = 0; i < n; ++i) {
		cin >> r >> c;
		R.push_back(r);
	}
	R.push_back(c);

	int cost[100+1][100+1];
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			cost[i][j] = INT_MAX;
	for (int i = 1; i <= n; ++i)
		cost[i][i] = 0;

	for (int j = 1; j <= n - 1; ++j) {
		for (int i = 1; i <= n - j; ++i) {
			for (int k = i + 1; k <= i + j; ++k) {
				cost[i][i+j] = min(cost[i][i+j], cost[i][k-1] + cost[k][i+j] + R[i]*R[k]*R[i+j+1]);
			}
		}
	}

	cout << cost[1][n] << endl;

	return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
#include <atcoder/dsu>
using namespace std;;
using namespace atcoder;
#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 INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S gsecond
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,q;cin >> n>> q;
  dsu d(n);
  ll t,u,v;
  rep(i,q){
      cin >> t >> u >> v;
      if(t==0){
          d.merge(u,v);
      }else{
          cout << d.same(u,v) << endl;
      }
  }
}

Measured memory_bytes: 3916
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <time.h>
#include <limits.h>

int main(void){
    int n,i;
    double ans=100;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        ans*=1.05;
        ans=ceil(ans);
    }
    printf("%d\n",(int)ans*1000);
    return 0;
}



Measured memory_bytes: 2024
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Linq;
using static System.Math;

class Program
{
    static int N;
    static int M;
    static List<Pair> D;

    static void Main()
    {
        int[] inp = Console.ReadLine().Split().Select(int.Parse).ToArray();
        N = inp[0];
        M = inp[1];
        D = new List<Pair>();
        for (int i = 0; i < N; i++)
        {
            inp = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Pair d = new Pair();
            d.a = inp[0];
            d.b = inp[1];
            D.Add(d);
        }

        D.Sort((x, y) => x.a - y.a);
        long ans = 0;
        for (int i = 0; i < N; i++)
        {
            ans += (long)D[i].a * Min(M, D[i].b);
            M -= Min(M, D[i].b);
            if (M == 0) break;
        }
        Console.WriteLine(ans);
    }
}

struct Pair
{
    public int a { get; set; }
    public int b { get; set; }
}

Measured memory_bytes: 19388
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
using namespace std;
int main()
{
  int k;
  cin>>k;
  int ans;

  if(k%2==0) ans=k*k/4;
  else ans=(k*k-1)/4;

  cout<<ans<<endl;
}


Measured memory_bytes: 256
N,M = map(int,input().split())

Alist = list(map(int,input().split()))

Alist = sorted(Alist,reverse=True)
#print (sum(Alist))
Ans = "No"
for i in range(M):
  #print (Alist[i])
  #print((sum(Alist)/4*M))
  if Alist[i]>=(sum(Alist)/(4*M)):
    Ans ="Yes"
  else:
    Ans = "No"
    
print (Ans)

Measured memory_bytes: 9036
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;



int main()
{
    fastInp;

    ll n;
    cin >> n;
    vector<ll> vec(n);
    for (auto &c : vec) cin >> c;

    ll pr = 0;

    vec.push_back(vec.size() + 10);

    ll ans = 0;
    for (int i = 0; i < vec.size(); i++) {
        vec[i]--;
        if (pr == 1 && vec[i] == i) {
            ans++;
            pr = 0;
        } else if (pr == 1 && vec[i] != i) {
            ans++;
            pr = 0;
        } else if (pr == 0 && vec[i] == i) {
            pr = 1;
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 4760
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int ans = 1;
    int max_h; cin >> max_h;
    for(int i=1;i<N;i++){
        int h; cin >> h;
        if(max_h <= h) ans++;
        max_h = max(max_h, h);
    }
    cout << ans;
    cout << endl;
    return 0;
}




Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>
#include <queue>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;


int main() {
	vector<vector<pair<int, int>>> adjlist(100000, vector < pair<int, int>>());
	ll N, M, i, b, c, j, jcount = 0, icount = 0, ans = 0, num = 0,k;
	bool flag = true;
	string S;
	cin >> N;
	vector < pair<int, pair<string, ll>>> SP(100000);
	pair<int, pair<string, ll>> temp;
	REP(i, N) {
		cin >> S >> M;
		SP[i] = make_pair(i, make_pair(S, M));
	}/*
	REP(j, N) {
		cout << SP[j].second.second << endl;
	}
	cout << endl;*/
	for (i = 0; i < N - 1;i++) {
		k = i;
		S = SP[i].second.first;
		for (j = i + 1; j < N; j++) {
			if (S > SP[j].second.first) {
				k = j;
				S = SP[j].second.first;
			}
			else if (S == SP[j].second.first) {
				if (SP[k].second.second < SP[j].second.second) {
					k = j;
					S = SP[j].second.first;
				}
			}
		}
		temp = SP[i];
		SP[i] = SP[k];
		SP[k] = temp;/*
		REP(j, N) {
			cout << SP[j].second.second << endl;
		}
		cout << endl;*/
	}
	REP(i, N) {
		cout << SP[i].first+1 << endl;;
	}

	return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<queue>
#include<bitset>

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

int main() {
	long long n;
	string ans;

	cin >> n;

	while (n != 0) {
		if (n % 2 != 0) {
			ans = "1" + ans;
			n--;
		}
		else {
			ans = "0" + ans;
		}
		n /= -2;
	}

	if (ans == "")ans = "0";

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
# ALDS1_4_A.
# リニアサーチ。

def intinput():
    a = input().split()
    for i in range(len(a)):
        a[i] = int(a[i])
    return a

def main():
    n = int(input())
    S = intinput()
    q = int(input())
    T = intinput()
    count = 0
    for k in T:
        if k in S: count += 1
    print(count)

    
if __name__ == "__main__":
    main()


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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
string t;
cin>>t;
int n = t.length();
for(int i=0;i<n;i++)if(t[i]=='?') t[i] = 'D';
cout<<t<<"\n";
}


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

using namespace std;

int main(){
  int N;
  cin >> N;
  int A[N+1];
  int B[N];
  unsigned long cnt(0);
  for(int i=0;i<N+1;i++){
    cin >> A[i];
  }
  for(int i=0;i<N;i++){
    cin >> B[i];
  }
  cnt = min(A[0],B[0]);
  B[0] -= cnt;
  for(int i=1;i<N;i++){
    cnt += min(B[i-1],A[i]);
    A[i] -= min(B[i-1],A[i]);
    cnt += min(A[i],B[i]);
    B[i] -=  min(A[i],B[i]);
  }
  cnt +=min(B[N-1],A[N]);
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt();
		if(Math.abs(a-b) < 2) {
			System.out.println(a+b);
		}else {
			if(a>b)System.out.println(a+a-1);
			else System.out.println(b+b-1);
		}
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n;
    cin >> n;
    ll d;
    map<ll, int> mp;
    REP(i,n){
        cin >> d;
        mp[d]++;
    }
    int m;
    cin >> m;
    ll t[m];
    REP(i,m){
        cin >> t[i];
    }
    REP(i,m){
        if(mp[t[i]] == 0){
            cout << "NO" << endl;
            return 0;
        }
        mp[t[i]]--;
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 14336
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val x = readLine()!!.split(' ').map { it.toInt() }
    val sortedX = x.sorted()
    val left = sortedX[n / 2 - 1]
    val right = sortedX[n / 2]
    repeat(n) {
        println(when {
            x[it] <= left -> right
            else -> left
        })
    }
}

Measured memory_bytes: 98860
import math
from collections import Counter
A= int(input())
if A == 1:
    print(0)
    exit()
resArray = []
tmpA = A
i = 1
while i <= math.sqrt(A):
    #print (i)
    i += 1
    if tmpA == 1:
        break

    if i >2 and i %2 == 0:
        continue


    while tmpA % i == 0:
        tmpA = tmpA / i
        resArray.append(i)

res = 0
if tmpA == A:
    print(1)
    exit()
elif tmpA > 1:
    res += 1


cArray = Counter(resArray)

for i in cArray.values():
    if i > 0:
        
        tmp = 1
        while tmp*(tmp+1)//2 <= i:
            tmp += 1
        res += tmp -1
print(res)


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

int main()
{
	while (1)
	{
		int a;
		cin >> a;
		if (a == 0)break;
		vector<int>tate(a+1);
		for (int b = 0; b < a; b++) 
		{
			vector<int>yoko(a);
			int s = 0;
			for (int c = 0; c < a; c++)
			{
				int d;
				cin >> d;
				yoko[c] = d;
				s +=d;
				tate[c] += d;
			}
			for (int k : yoko) {
				cout << setw(5) << k;
			}
			tate[a] += s;
			cout << setw(5) << s <<endl;
		}
		for (int k : tate) {
			cout << setw(5) << k;
		}
		cout << endl;
	}
}

Measured memory_bytes: 3140
#include <cstdint>

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  using mint = modint<1000000007>;
  mint N, k;
  cin >> N.value() >> k.value();
  mint ans;
  ans = 0;
  for(int i = k.value(); i <= (N + 1).value(); i++){
      ans += (mint) i * (N - i + 1);
      ans += 1;
  }
  cout<<ans.value()<<endl;


  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ll = long long;
using ii = pair<ll, ll>;

int32_t main(){
	ios::sync_with_stdio(0);
	int mt[3][3];
	for(int i=0; i<3; ++i)
		for(int j=0; j<3; ++j) cin >> mt[i][j];
	int n;
	map<int, bool> has;
	cin >> n;
	for(int i=0; i<n; ++i){
		int x;
		cin >> x;
		has[x] = true;
	}
	bool ans = false;
	bool d1 = true, d2=true;
	for(int i=0; i<3; ++i){
		bool l=true, c=true;
		if(not has[mt[i][i]]) d1 = false;
		if(not has[mt[i][2-i]]) d2 = false;
		for(int j=0; j<3; ++j){
			if(not has[mt[i][j]]) l = false;
			if(not has[mt[j][i]]) c = false;
		}
		if(c or l) ans = true;
	}
	if(d1 or d2) ans = true;


	if(ans)
		cout << "Yes\n";
	else
		cout << "No\n";
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  int ans = S.length();
  for(int j = 0; j < 2; j++){
    int cnt = 0;
    for(int i = 0; i < S.length(); i++){
      if (i%2 == 0 && S[i] != char('0' + j))cnt++;
      if (i%2 != 0 && S[i] == char('0' + j))cnt++;
    }
    ans = min(cnt, ans);
  }

  cout << ans << endl;

  return 0;
}



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

void call(int n){
  for(int i = 1; i <= n; i++){
    int x = i;
    if(x % 3 == 0){
      cout << " " << i;
    }else{
      do{
        if(x % 10 == 3){
          cout << " " << i;
          break;
        }
        x /= 10;
      }while(x);
    }
  }
  cout << endl;
}

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


Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
int main(){
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
    if(s < t)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

using namespace std;
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
inline void reader(int& x) { int k, m = 0; x = 0; while(1){ mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; x = x * 10 + k - '0'; }if (m) x = -x; }
inline void writer(int x, char c) { int s = 0, m = 0; char f[10]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }
template<class T> void writerLn(T x) { writer(x, '\n'); }
#define rep(i,n)for(int i=0;i<n;i++)
vector<int>E[100000];
int u[200000], v[200000], r[200000], ans[200000], d[100000]{ 1 }, cnt = 1;
char b[200000], ok[100000]{ 1 };
deque<int>que;

void bfs(int u, int t) {
	que.emplace_back(u);
	while (!que.empty()) {
		int p = que.front(); que.pop_front();
		for (int v : E[p]) {
			if (t) {
				if (d[v] > d[p] && !ok[v]) {
					ok[v] = 1; cnt++; que.emplace_back(v);
				}
			}
			else if (!d[v]) {
				d[v] = d[p] + 1; que.emplace_back(v);
			}
		}
	}
}
int main() {
	int n, m, q; reader(n); reader(m); reader(q);
	rep(i, m) {
		reader(u[i]); reader(v[i]);
		u[i]--; v[i]--;
		E[u[i]].emplace_back(v[i]); E[v[i]].emplace_back(u[i]);
	}
	bfs(0, 0);
	rep(i, m) {
		if (d[u[i]] > d[v[i]])swap(u[i], v[i]);
	}
	rep(i, n)E[i].clear();
	rep(i, q) {
		reader(r[i]); r[i]--;
		b[r[i]] = 1;
	}
	rep(i, m) {
		if (!b[i]) {
			if (d[v[i]] > d[u[i]]) {
				E[u[i]].emplace_back(v[i]);
			}
		}
	}
	bfs(0, 1);
	for (int i = q - 1; i >= 0; i--) {
		ans[i] = n - cnt;
		if (d[v[r[i]]] > d[u[r[i]]] && !ok[v[r[i]]]) {
			E[u[r[i]]].emplace_back(v[r[i]]);
			if (ok[u[r[i]]]) {
				cnt++; ok[v[r[i]]] = 1;
				bfs(v[r[i]], 1);
			}
		}
	}
	rep(i, q)writerLn(ans[i]);
}

Measured memory_bytes: 13552
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
 
void err() {
	puts(-1);
	exit(0);
}
 
int main() {
	string s, t;
	cin >> s >> t;
	vector<int>scnt[26];
	for (int i = 0; i < s.size(); i++) {
		scnt[s[i] - 'a'].pb(i);
	}
 
	ll shuuki = 0;
	int cur = -1;
	ll ans = 0;
	for (int i = 0; i < t.size(); i++) {
		if (scnt[t[i] - 'a'].size() == 0)err();
		if (scnt[t[i] - 'a'].back() <= cur) {
			cur = -1;
			shuuki++;
		}
		cur = *upper_bound(all(scnt[t[i] - 'a']),cur);
	}
	puts((int)s.size()*shuuki + cur + 1);
 
	return 0;
}

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

int main() {
	int n;
	vector<int> v, c, w;
	cin >> n;
	int temp;
	for (int i = 0; i < n; i++) {
		cin >> temp;
		v.push_back(temp);
	}
	for (int i = 0; i < n; i++) {
		cin >> temp;
		c.push_back(temp);
	}
	int sum = 0;
	for (int i = 0; i < n; i++) {
		w.push_back(v[i] - c[i]);
		if (w[i] > 0)
			sum += w[i];
	}
	cout << sum << endl;
	return 0;
}

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

int main() {
	int n, k, max = 0;
	cin >> n >> k;
	int v[n];
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}

	for (int m = 0, sum; m <= k && m <= n; m++) {
		for (int a = 0; a <= m; a++) {
			sum = 0;
			priority_queue<int> q;
			for (int i = 0; i < m; i++) {
				if (v[(n - m + i + a) % n] >= 0)
					sum += v[(n - m + i + a) % n];
				else {
					q.push(v[(n - m + i + a) % n]);
					if (q.size() > k - m) {
						sum += q.top();
						q.pop();
					}
				}
			}

			if (sum > max)
				max = sum;
		}

	}

	cout << max << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int k;
  cin >> k;
  int ans = 0;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    ans += min(x, k-x)*2;
  }
  cout << ans << endl;
  return 0;
}





Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  int n; cin >> n;
  if(n == 7 || n == 5 || n == 3) cout << "YES" << endl;
  else cout << "NO" << endl;


  return 0;
}



///


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    main.solve();
    main.show();
  }

  int n;
  char s[];
  Deque<Integer> deq = new ArrayDeque<Integer>();
  int ans;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      s = sc.next().toCharArray();
      n = s.length;
    } finally {
      sc.close();
    }
  }
  
  void solve() {
    for (int i = 0; i < n; i++) {
      // System.out.println(s[i]);
      if (s[i] == '0') append(0);
      if (s[i] == '1') append(1);
      if (s[i] == 'B') delete();
    }
  }

  void append(int a) {
    deq.addLast(a);
  }

  void delete() {
    if (deq.size() > 0) deq.removeLast();
  }

  void show() {
    while (deq.size() > 0) {
      ans = deq.pollFirst();
      System.out.print(ans);
    }
    System.out.println("");
  }
}


Measured memory_bytes: 35472
N = int(input())
S = list(input())

ans = 0

for i in range(1000):
    t = str(i)
    t = t.zfill(3)
    now = t[0]
    count = 0
    for j in S:
        if count == 0 and now == j:
            now = t[1]
            count += 1
            continue
        if count == 1 and now == j:
            now = t[2]
            count += 1
            continue
        if count == 2 and now == j:
            ans += 1
            break

print(ans)

Measured memory_bytes: 75208
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author hakamada
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ABC117_2 solver = new ABC117_2();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC117_2 {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int[] L = new int[N];

            for (int i = 0; i < N; i++) {
                L[i] = in.nextInt();
            }
            Arrays.sort(L);
            int MAX = L[L.length - 1];
            int Othersum = 0;
            for (int i = L.length - 2; i >= 0; i--) {
                Othersum += L[i];
            }
            if (MAX < Othersum) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }
}



Measured memory_bytes: 21844
#include<stdio.h>

int main(void){
  int i;
  int num_candidate,num_stone,num_stone2; 
  while(1){
    scanf("%d %d",&num_candidate,&num_stone); //????£??????°??????????????°
    int candidate[50]={0};
    num_stone2=num_stone;
    int j=0;
    while(candidate[j]!=num_stone){  //??????????£?????????¨????????????????????????????????????
      if(num_stone2>0){ //????????????????????????
	candidate[j]++;
	num_stone2--;
	j++;
      }
      else if(num_stone2==0){ //?????????
	if(candidate[j]==num_stone){ //???????????¨????????????????????????????????????
	  break;
	}
	num_stone2=candidate[j];
	candidate[j]=0;
	j++;
      }

      if(j==num_candidate) //?????¨?????????
	j=0;
    }
    
    if(num_candidate==0 && num_stone==0)
      break;

    if(num_candidate<3 || 50<num_candidate)
      break;

    if(num_stone<2 || 50<num_stone)
      break;

    printf("%d\n",j);
  }

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1000000007;

using min_que = priority_queue<ll, vector<ll>, greater<ll>>;

int main(){
    int N, K, Q;
    cin >> N >> K >> Q;

    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }

    ll ans = 1LL << 60;
    for(int i=0;i<N;i++){
        ll min_value = A[i];

        vector<min_que> ques;
        set<ll> vs;
        ques.push_back(min_que());
        for(int j=0;j<N;j++){
            if(min_value <= A[j]){
                ques.back().push(A[j]);
                vs.insert(A[j]);
            }else{
                if(ques.back().size() > 0){
                    ques.push_back(min_que());
                }
            }
        }
        if(ques.back().size() == 0){
            ques.pop_back();
        }

        vector<ll> vs_vec(vs.begin(), vs.end());
        reverse(vs_vec.begin(), vs_vec.end());

        int l = 0, r = vs_vec.size();
        while(r - l > 1){
            int mid = (r + l) / 2;
            int th = vs_vec[mid];

            int cnt = 0;
            for(auto q : ques){
                while(q.size() >= K && q.top() <= th){
                    q.pop();
                    cnt++;
                }
            }
            if(cnt >= Q){
                l = mid;
            }else{
                r = mid;
            }
        }

        int cnt = 0;
        for(auto q : ques){
            while(q.size() >= K && q.top() <= vs_vec[l]){
                q.pop();
                cnt++;
            }
        }

        if(cnt >= Q){
            ans = min(ans, vs_vec[l] - min_value);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 464
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int i, a, b, c;
		int[] triangle = new int[3];
		for (i = 0; i < n; i++) {
			a = sc.nextInt();
			b = sc.nextInt();
			c = sc.nextInt();
			triangle[0] = a;
			triangle[1] = b;
			triangle[2] = c;
			Arrays.sort(triangle);
			if(triangle[2]*triangle[2] == triangle[1]*triangle[1] + triangle[0]*triangle[0]){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
}

Measured memory_bytes: 21608
import java.io.*;
import java.util.Arrays;

public class Main {

	//@2000 óÎñû
	public static void main(String[] args) throws IOException {
		
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		for(;;) {
			
			int[][] map = new int[21][21];
			
			// óÎ
			int gn = Integer.parseInt(reader.readLine());
			if (gn == 0)
				break;
			for(int i = 0; i < gn; i++) {
				String s = reader.readLine();
				String[] sp = s.split(" ");
				int x = Integer.parseInt(sp[0]);
				int y = Integer.parseInt(sp[1]);
				map[x][y] = 1;
				
			}
	
			// Ú®
			int n = Integer.parseInt(reader.readLine());

			int x = 10;
			int y = 10;
			if (map[x][y] != 0) {
				// óÎæ¾
				gn--;
				map[x][y] = 0;
			}
			
			for(int loop = 0; loop < n; loop++) {
				
				String s = reader.readLine();
				String[] sp = s.split(" ");
				
				int step = Integer.parseInt(sp[1]);
				for(int k = 0; k < step; k++) {
					if (sp[0].equals("N"))
						y++;
					else if (sp[0].equals("S"))
						y--;
					else if (sp[0].equals("E"))
						x++;
					else if (sp[0].equals("W"))
						x--;
					else assert false;
					
					if (map[x][y] != 0) {
						// óÎæ¾
						gn--;
						map[x][y] = 0;
					}

				}
			}
			if (gn == 0) {
				System.out.printf("Yes\n");
			}
			else {
				System.out.printf("No\n");
			}
		}
	}
}

Measured memory_bytes: 12000
import sys
from math import sqrt
from collections import Counter, defaultdict, deque

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)


def I():
    return int(input())


def MI():
    return map(int, input().split())


def LI():
    return list(MI())


def LIN(n: int):
    return [I() for _ in range(n)]


inf = float("inf")
mod = 10 ** 9 + 7


def main():
    a, b, c, k = MI()

    if a >= k:
        print(k)
    elif a + b >= k:
        print(a)
    else:
        print(a - (k - a - b))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9356
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return ('0' <= c && c <= '9')?(c - '0'):-1;}


// TODO: write
int main() {
  int n;cin>>n;
  map<string,int> m;
  rep(i,n){
    string s;cin>>s;
    m[s]++;
  }
  int tmp = 0;
  for(auto a:m){
    tmp = max(tmp,a.se);
  }
  vector<string> s;
  for(auto a:m){
    if(a.se == tmp)s.pb(a.fi);
  }
  sort(all(s));
  rep(i,s.size())print(s[i]);
  return 0;
}



Measured memory_bytes: 26868
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef tree<int,null_type,less<int >,rb_tree_tag,tree_order_statistics_node_update>indexed_set;
template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p);
template <class T>
ostream &operator <<(ostream &os, vector<T>&v);
template <class T>
ostream &operator <<(ostream &os, set<T>&v);
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v);
#ifndef ONLINE_JUDGE
#define debug(a) cout<<#a<<" --> "<<(a)<<"\n";
#define debug2(a) cout<<#a<<" --> "<<(a)<<" ";
#define HERE cout<<"here - "<<__LINE__<<"\n";
#else
#define debug(a)
#define debug2(a)
#define HERE
#endif
const ll mod = 1e9+7;
const int N = 1e5+5;


void TEST_CASES(int cas)
{
    ll n;
    cin>>n;
    vector<ll>v(n);
    ll sum =0;
    vector<ll> cnt(N,0);
    for(ll &i : v)
    {
        cin>>i;
        sum+= i;
        cnt[i]++;
    }
    debug(sum);
    debug(v);
    ll q;
    cin>>q;
    while(q--)
    {
        ll a,b;
        cin>>a>>b;
        sum-= a*cnt[a];
        sum+= b*cnt[a];
        cnt[b]+= cnt[a];
        cnt[a] =0;
        cout<<sum<<"\n";
    }


}


/*

*/

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t=1,cas=0;
    //scanf("%d",&t);
    while(t--)
    {
        TEST_CASES(++cas);
    }

    return 0;
}



//os.order_of_key(v): returns how many elements strictly less than v
//os.find_by_order()

template<class T1, class T2>
ostream &operator <<(ostream &os, pair<T1,T2>&p)
{
    os<<"{"<<p.first<<", "<<p.second<<"} ";
    return os;
}
template <class T>
ostream &operator <<(ostream &os, vector<T>&v)
{
    os<<"[ ";
    for(int i=0; i<v.size(); i++)
    {
        os<<v[i]<<" " ;
    }
    os<<" ]";
    return os;
}

template <class T>
ostream &operator <<(ostream &os, set<T>&v)
{
    os<<"[ ";
    for(T i:v)
    {
        os<<i<<" ";
    }
    os<<" ]";
    return os;
}
template <class T1, class T2>
ostream &operator <<(ostream &os, map<T1,T2>&v)
{
    for(auto i:v)
    {
        os<<"Key : "<<i.first<<" , Value : "<<i.second<<endl;
    }
    return os;
}


Measured memory_bytes: 4820
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  int H[N];
  int ma[N];
  for(int i=0;i<N;i++){
    cin>>H[i];
    ma[i]=0;
  }
  int A[M],B[M];
  for(int i=0;i<M;i++){
    cin>>A[i]>>B[i];
    ma[A[i]-1]=max(ma[A[i]-1],H[B[i]-1]);
    ma[B[i]-1]=max(ma[B[i]-1],H[A[i]-1]);
  }
  int ans=0;
  for(int i=0;i<N;i++){
    if(ma[i]<H[i]){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 5092
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      q: usize,
      c: [Usize1; n],
      mut lr: [(Usize1, Usize1); q]
   }
   let mut query = vec![];
   for (i, (l, r)) in lr.iter().enumerate() {
      query.push((*l, *r, i));
   }

   let mut ans = vec![0; q];

   query.sort_by_key(|(_, r, _)| *r);
   let mut append = vec![n; n];
   let mut bit = vec![0; n + 1];
   for i in 0..=query[0].1 {
      append[c[i]] = i;
   }
   for i in 0..n {
      if append[i] != n {
         bit.add(append[i], 1);
      }
   }
   ans[query[0].2] = bit.range(query[0].0, query[0].1 + 1);

   let mut rn = query[0].1;
   for &(l, r, i) in query.iter().skip(1) {
      for j in rn + 1..=r {
         if append[c[j]] != n {
            bit.add(append[c[j]], !0);
         }
         append[c[j]] = j;
         bit.add(append[c[j]], 1);
      }
      rn = r;
      ans[i] = bit.range(l, r + 1);
   }
   for a in ans {
      println!("{}", a);
   }
}

use std::ops::{AddAssign, Sub};
trait BIT<T: Copy + Clone + Sub + AddAssign> {
   fn add(&mut self, idx: usize, w: T);
   fn sum(&self, idx: usize) -> T;
   fn range(&self, l: usize, r: usize) -> T;
}
impl<T: Copy + Clone + Sub<Output = T> + AddAssign> BIT<T> for [T] {
   /// let mut bit = vec![0; n+1];
   /// for (i, w) in 0..q {
   ///    bit.add(i, w);
   /// }
   fn add(&mut self, idx: usize, w: T) {
      let mut j = (idx + 1) as i64;
      while j < self.len() as i64 {
         self[j as usize] += w;
         j += j & -j;
      }
   }
   /// [0, r]
   fn sum(&self, idx: usize) -> T {
      let mut i = (idx + 1) as i64;
      let mut sum = self[0];
      while i != 0 {
         sum += self[i as usize];
         i -= i & -i;
      }
      sum
   }
   /// [l, r)
   fn range(&self, l: usize, r: usize) -> T {
      match (l, r) {
         (0, _) => self.sum(r - 1),
         _ => self.sum(r - 1) - self.sum(l - 1),
      }
   }
}


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

int main() {
    ll N;
    cin >> N;
    ll ans = 1000000000000;
    ll num;
    bool judge;
    for(ll i = 1; i*i <= N; i++){
        if(N % i == 0){
            num = N / i + i - 2;
            ans = min(ans, num);
        }
    }
    cout << ans << endl;   
}

Measured memory_bytes: 3592
def N():
    return int(input())
def L():
    return list(map(int,input().split()))
def NL(n):
    return [list(map(int,input().split())) for i in range(n)]
mod = pow(10,9)+7
#import numpy as np
import sys
import math
import collections
par = []
def init(n):
    for i in range(n):
        par.append(i)

def root(x):
    if par[x] == x:
        return x
    else:
        par[x] = root(par[x])
        return par[x]

def same(x,y):
    if root(x) == root(y):
        return True
    else:
        return False

def unite(x,y):
    x = root(x)
    y = root(y)
    if x==y:
        return
    par[y] = x
n,m = L()
ab = NL(m)
init(n)
#print(ab)
#print(par)
for a,b in ab:
    unite(a-1,b-1)
    #print(par)

for i in range(len(par)):
    root(i)
#print(par)
count = collections.Counter(par)
print(len(count)-1)

Measured memory_bytes: 92536
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int d,s,t;
    cin>>d>>s>>t;
    if(d<=t*s) cout<<"Yes";
    else cout<<"No";
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n; cin >> n;
	vector<int> ind(n, 0);
	vector<int> X, Y;
	for (int i=0; i<n; i++) {
		int x, y; cin >> x >> y;
		X.push_back(x);
		Y.push_back(y);
		ind[i] = i;
	}

	int cnt = 0;
	double total = 0;
	do {
		cnt++;
		int px = X[ind[0]];
		int py = Y[ind[0]];
		for (int i=1; i<n; i++) {
			int nx = X[ind[i]];
			int ny = Y[ind[i]];
			int dist2 = pow(nx-px, 2) + pow(ny-py, 2);
			total += sqrt(dist2);
			px = nx;
			py = ny;
		}
	} while (next_permutation(ind.begin(), ind.end()));
	
	cout << setprecision(20) << total / cnt << endl;

	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		String S = sc.next();
		String T = "";
		if(S.length()<=K) {
			T = S;
		}else {
			for(int i=0; i<K; i++) {
					T += S.charAt(i);
			}
			T += "...";
		}
		sc.close();
		System.out.println(T);
	}

}

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

string s;

int main()
{
	cin>>s;
    
    sort(s.begin(),s.end());

    if((s[0]==s[1] and s[2]==s[3]) and (s[1]!=s[2]))
        cout<<"Yes";
    else
        cout<<"No";
}


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

int gcd(int a, int b, int c){
  int r;
  vector<int> num(3);
  num.at(0) = a;
  num.at(1) = b;
  num.at(2) = c;
  sort(num.begin(), num.end());
 
  int large = num.at(2);
  int middle = num.at(1);
  int small = num.at(0);
  
  r = large % middle;
  while( r != 0 ){
    large = middle;
    middle = r;
    r = large % middle;
  }
  
 r = middle % small;
 while( r != 0 ){
    middle = small;
    small = r;
    r = middle % small;
  }
  
  return small;
}

int main() {
 int k, sum = 0;
  cin >> k;
  
  for(int a = 1; a <= k; a++){
    for(int b = 1; b <= k; b++){
      for(int c = 1; c <= k; c++)
        sum += gcd(a, b, c);
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 3616