akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void){

	int R=0;
	double enshuritu=0;
  	double kekka=0;
  	
  	enshuritu=3.14;
  
	scanf("%d",&R);
  	kekka=R*2*enshuritu;
  	
  	printf("%f",kekka);
  
  	return 0;
  
}

Measured memory_bytes: 2184
#include <bits/stdc++.h>
    using namespace std;
	typedef long long int ll; 
     
    int main() {
      ll X,Y,Z,K; 
      cin>> X >> Y >> Z >> K; 
      vector<ll> A(X);
      vector<ll> B(Y);
      vector<ll> C(Z);
     
      for(int i=0; i<X; i++){
        cin >> A.at(i);
      }
      for(int i=0; i<Y; i++){
        cin >> B.at(i);
      }
      for(int i=0; i<Z; i++){
        cin >> C.at(i);
      }
      
      vector<ll> D(X*Y);
      
      for(int i=0; i<X; i++){
        for(int j=0; j<Y; j++){
          D.at( i*Y + j ) = A.at(i) + B.at(j); 
        }
      }
      sort(D.begin(), D.end());
      reverse(D.begin(), D.end()); 
      
      ll K_min = min(K, X*Y); 
      
      vector<ll> E(K*Z);
      for(int i=0; i<K_min ; i++){
        for(int j=0; j<Z ; j++){
          E.at( i*Z + j ) = D.at(i) + C.at(j); 
        }
      }
      
      sort(E.begin(), E.end());
      reverse(E.begin(), E.end()); 

      // 和を出力
      for(int i=0; i<K; i++){
      cout << E.at(i) << endl;
      }
    }

Measured memory_bytes: 31616
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long int ll;

struct Edge{
    int to; ll cost;
    Edge(){}
    Edge(int to,ll cost):to(to),cost(cost){}
};

int n;
vector<Edge> G[101000];

int ans[101000];
int used[101000];

void dfs(int s,ll cost){
	if(used[s]) return ;
	used[s]=1;
	if(cost%2==0)ans[s]=0;
	else ans[s]=1;
	for(auto p:G[s]){
		dfs(p.to,cost+p.cost);
	}
}

int main(){
	cin >> n;
	for(int i=0;i<n-1;i++){
		ll u,v,w; cin >> u >> v >> w;
		u--; v--;
		G[u].push_back(Edge(v,w));
		G[v].push_back(Edge(u,w));
	}
	dfs(0,0);
	for(int i=0;i<n;i++){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 9472
//import java.io.*;
import java.util.*;
//import java.math.*;
public class Main {
 
    public static void main(String[] args) throws java.io.IOException{
        Scanner scan = new Scanner(System.in);
     while(true){
    	 int n= scan.nextInt();
    	 if(n==0)break;
      	 int m2=0;
    	 int m5 =0;
    	 for(int i=n;i>0;i--){
    	int k=i;
    		 while(k%2==0|| k%5==0){
    	 if(k%10==0){m2++;m5++; k/=10;}
    	 else if(k%2==0){m2++;k/=2;}
    	 else if(k%5==0){m5++;k/=5;}
    	 }
    	 }
     System.out.println(Math.min(m2, m5));
     }
    }
}

Measured memory_bytes: 11000
#include <iostream>
using namespace std;
void func(int x,int y);
int h,w;
char c;
char a[111][111];
int dx[4]={0,-1,0,1};
int dy[4]={-1,0,1,0};
int nx,ny;
int main(){
  int count=0;
  while(1){
    cin >> h >> w;
    if(h==0 && w==0)break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin >> a[i][j];
      }
    }
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(a[i][j]!='.'){
	c=a[i][j];
	func(i,j);
	count++;
	}
      }
    }
    cout << count << endl;
    count=0;
  }
}
void func(int x,int y){
  if(x<0 || x>=h || y<0 || y>=w || c!=a[x][y])return;
  a[x][y]='.';
  for(int i=0;i<4;i++){
    nx=dx[i]+x;
    ny=dy[i]+y;
    func(nx,ny);
  }
}

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

// region template
#define rep(i, a, b) for (int i = (a); i < (b); ++i)
#define trav(a, x) for (auto &a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

ll gcd(ll a, ll b) { return __gcd(a, b); }

ll euclid(ll a, ll b, ll &x, ll &y) {
    if (b) { ll d = euclid(b, a % b, y, x);
        return y -= a/b * x, d; }
    return x = 1, y = 0, a;
}

typedef unsigned long long ull;
typedef long double ld;
ull mod_mul(ull a, ull b, ull M) {
    ll ret = a * b - M * ull(ld(a) * ld(b) / ld(M));
    return ret + M * (ret < 0) - M * (ret >= (ll)M);
}
ull mod_pow(ull b, ull e, ull mod) {
    ull ans = 1;
    for (; e; b = mod_mul(b, b, mod), e /= 2)
        if (e & 1) ans = mod_mul(ans, b, mod);
    return ans;
}

const ll mod = 1000000007;
struct Mod {
    ll x;
    Mod(ll xx) : x(xx) {}
    Mod operator+(Mod b) { return Mod((x + b.x) % mod); }
    Mod operator-(Mod b) { return Mod((x - b.x) % mod); }
    Mod operator*(Mod b) { return Mod((x * b.x) % mod); }
    Mod operator/(Mod b) { return *this * invert(b); }
    Mod invert(Mod a) {
        ll x, y, g = euclid(a.x, mod, x, y);
        assert(g == 1); return Mod((x + mod) % mod);
    }
    Mod operator^(ll e) {
        if (!e) return Mod(1);
        Mod r = *this ^ (e / 2); r = r * r;
        return e & 1 ? *this * r : r;
    }
};
// endregion

const int mx = 300000;
int prime[mx], ps[mx];

int main() {
    cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit);

    string ln;
    while (true) {
        getline(cin, ln);
        if (ln == ".") break;

        bool bd = false;
        stack<char> s;
        for (char c : ln) {
            switch(c) {
                case '(':
                case '[':
                    s.push(c);
                    break;
                case ')':
                    if (s.size() && s.top() == '(') s.pop();
                    else bd = true;
                    break;
                case ']':
                    if (s.size() && s.top() == '[') s.pop();
                    else bd = true;
                    break;
            }
        }
        if (s.size()) bd = true;
        cout << (!bd ? "yes" : "no") << endl;
    }
}


Measured memory_bytes: 3192
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MAX 300005
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
   	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
int main()
{
	fast();
	int a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<' '<<b<<' '<<c;
}

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

int main(){
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(u==s)a--;
    else b--;
    cout<<a<<" "<<b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, num = 0;
  cin >> N;
 
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    num += (r - l + 1);
}
     
  cout << num << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int n;
    char s[100];
    
    cin >> n;
    cin >> s;
    
    if(n%2==1){
        
        cout << "No" << endl;
        return 0;
        
    }
    
    for(int i=0; i<n/2; i++){
        
        if(s[i]!=s[i+n/2]){
            
            cout << "No" << endl;
            return 0;
            
        }
        
    }
    
    cout << "Yes" << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import collections as cl
import math
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N = II()
    print(math.ceil(N / 2))


main()


Measured memory_bytes: 65252
#ifdef loc
    #include "loc_debug.h"
#else
    #include <bits/stdc++.h>
    #define pr(...)
    #define pra(a,n)
    #define praa(a,n,m)
    #define prl()
#endif
using namespace std;

typedef long long ll;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define sz(a) int(a.size())
const int N = 100005;


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    int n;
    cin>>n>>s;
    map<char,int> a;
    for(auto it: s) {
        a[it]++;
    }
    int res = 1;
    int mod = 1e9+7;
    for(auto it: a) {
        res = (res*(ll)(1+it.second))%mod;
    }
    cout<<res-1<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <utility>
#include <map>
#include <cmath>

using namespace std;

int main(){
    long int w,h,x,y,b;
    cin >> w >> h >> x >> y;
    if(x==float(w)/2.0 and y==float(h)/2.0){
        b=1;
    } else b=0;
    cout << float(w*h)/2.0 << ' ' << b << endl;

    return 0;
}

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

namespace ABC
{
    class ProgramA
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var ab = long.Parse(inputs[0]);
            var bc = long.Parse(inputs[1]);
            var ca = long.Parse(inputs[2]);
            var result = (bc * ab) / 2;
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 27484
#include<bits/stdc++.h>
using namespace std;
#define N 10000000
#define maxn (N + 10)
#define maxm (maxn * 2)
#define pb push_back
#define lc (id * 2)
#define rc (id * 2 + 1)
typedef long long ll;
const ll INF = (1e8);
const ll mod = (1e9 + 7);
ll f[maxn];
void init(){
    for(ll i = 1;i * i <= N;i++){
        for(ll j = i;i * j <= N;j++){
            f[i * j] += 2;
            if(i == j)f[i * j]--;
        }
    }
}
int main(){
    init();
    ll n;scanf("%lld",&n);
    ll ans = 0;
    for(ll i = 1;i <= n;i++){
        ans += f[i] * i;
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 81932
#include <bits/stdc++.h>
using namespace std;
unordered_map <int,vector<int>> mp;
bool vis[200001];
vector <int> v;
int cnt = 0;
void dfs(int x)
{
    vis[x] = 1;
    cnt++;
    for(auto i = mp[x].begin();i!=mp[x].end();i++)
    {
        if(!vis[*i])
        {
            dfs(*i);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t,n;
    t = 1;
    for(int i=0;i<t;i++)
    {
        int n,k;
        cin>>n>>k;
        for(int i=0;i<k;i++)
        {
            int a,b;
            cin>>a>>b;
            mp[a].push_back(b);
            mp[b].push_back(a);
        }
        for(int i=1;i<=n;i++)
        {
            cnt = 0;
            if(!vis[i])
            {
                dfs(i);
            }
            v.push_back(cnt);
        }
        sort(v.begin(),v.end());
        int count = 0;
        for(int i = 0;i<v.size();i++)
        {
            if(i==0)
            {
                count = v[i];
            }
            else
            {
                count += v[i]-v[i-1];
            }    
        }
        cout<<count;
    }
    return 0;
}

Measured memory_bytes: 35324
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

ll calc(ll s1,ll s2,ll s3){
  ll smax = max(max(s1,s2),s3);
  ll smin = min(min(s1,s2),s3);
  return smax-smin;
}
ll solve(ll h,ll w){
  ll ret = 10000000000;
  for(int i=0;i<=1;++i){
    for(int j=0;j<=1;++j){
      ll y = h/3+i;
      ll x = w/2+j;
      ll S0 = w*y;
      ll S1 = (h-y)*x;
      ll S2 = w*h-S0-S1;
      ret = min(ret,calc(S0,S1,S2));
    }
  }

  for(int i=0;i<=1;++i){
    for(int j=0;j<=1;++j){
      ll y = h/3+i;
      ll z = h-h/3+j;
      ll S0 = w*y;
      ll S1 = w*(z-y);
      ll S2 = w*(h-z);
      ret = min(ret,calc(S0,S1,S2));
    }
  }
  
  return ret;
}
int main(){
  ll h,w;
  cin >> h >> w;
  cout << min(solve(h,w),solve(w,h)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a)  (a).begin(),(a).end()
int main(){
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  for(int i = 0; i < N; i++){
   cin >> A.at(i);
   A.at(i)--;
  }
  for(int i = 0; i < N; i++){
   cin >> B.at(i);
  }
  for(int i = 0; i < N - 1; i++){
   cin >> C.at(i);
  }

  int result;
  for(int i = 0; i < N; i++){
   result += B.at(A.at(i));
   if(i >= 1 && A.at(i) == A.at(i-1)+1) result += C.at(A.at(i-1));
  }
  cout << result << endl;
}

Measured memory_bytes: 256
(lambda collections: (lambda n: (lambda a: (lambda c: print(n-max(c.values(),default=0)))(collections.Counter((y[0]-x[0],y[1]-x[1]) for x in a for y in a if x<y)))([tuple(map(int,input().split())) for _ in range(n)]))(int(input())))(__import__('collections'))

Measured memory_bytes: 3564
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: String,
    }

    let mut tmp_c = 'a';
    let mut count = 0;
    let mut max_c = 0;
    for i in s.chars() {
        if i == 'R' {
            count += 1;
            if max_c < count {
                max_c = count;
            }
        } else {
            count = 0;
        }
    }
    println!("{}", max_c);
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  
  int low = A.at(0);
  int cnt = 1;
  FOR(i,1,N){
    if(A.at(i)<low){
      low = A.at(i);
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
using namespace std;
typedef long long LL;

int main(void) {
	LL n, a, x = 0, y = 0, z = 0, i, j, k, ans, a2;

	cin >> n >> a;

	for (i = 0; i <= n; i++) {
		for (j = 0; j <= n; j++) {
			a2 = a;
			if (i + j <= n) {
				a2 -= (i * 10000) + (j * 5000);
				if (i + j + (a2 / 1000) == n) {
					cout << i << " " << j << " " << a2 / 1000 << endl;
					return 0;
				}
			}
		}
	}

	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
cnt = {}
cnt2 = {}

for i in range(N):
  if A[i] in cnt2:
    cnt[A[i]] += cnt2[A[i]]
    cnt2[A[i]] += 1
  else:
    cnt[A[i]] = 0
    cnt2[A[i]] = 1
ans = sum(cnt.values())
#print(ans, cnt, cnt2)
for i in range(N):
  print(ans - cnt2[A[i]]+1)

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

int main()
{
string s ;
cin >> s ;
int n = s.size() ;
string s1 =s;
reverse(s1.begin(),s1.end());
if (s!=s1){
    cout <<"No";
    return 0 ;
}
string x="" ;
for (int i =0 ; i <(n-1)/2 ; i++)
    x+=s[i];
s1=x;
reverse(s1.begin(),s1.end());
if (x!=s1){
    cout <<"No";
    return 0 ;
}
x="";
for (int i =((n+3)/2)-1 ; i <n ; i++)
    x+=s[i];
s1=x;
reverse(s1.begin(),s1.end());
if (x!=s1){
    cout <<"No";
    return 0 ;
}
cout << "Yes";
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>
#include <random>

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

using namespace std;
typedef long long int ll;
const ll INF = 10000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int n, d;

double CalcDist(vector<int> a, vector<int>b) {
    int sum = 0;
    rep(i, d) {
        sum += (a[i] - b[i]) * (a[i] - b[i]);
    }
    return sqrt((double)sum);
}

bool IsInteger(double x) {
    return floor(x) == x;
}

int main()
{
    cin >> n >> d;
    vector<vector<int>> x(n);
    rep(i, n) rep(j, d) {
        int tmp;
        cin >> tmp;
        x[i].push_back(tmp);
    }

    int ans = 0;
    rep(i, n) {
        for (int j = i + 1; j < n; j++) {
            double dist = CalcDist(x[i], x[j]);
            if (IsInteger(dist)) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    double r;
    cin >> r;
    printf("%f %f\n", M_PI*r*r, 2*M_PI*r);
    //cout << M_PI * r * r << ' ' << 2 * M_PI * r << endl;
}

Measured memory_bytes: 1232
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <stdlib.h>
#include <math.h>

long int n;
long int c[100000] = {0};

int main(void)
{
	long int i, j, k, l, m, n;
	long int a;
	long int count = 0;
	long int num[10][10][10] = {{{0}}};
	long int flg1, flg2;
	char str[30001];
	char work;
	
	scanf("%ld%s", &a, str);
	//scanf("%c", &work);
	/*
	for(i = 0; i < a; i++) {
		scanf("%c", &str[i]);
		scanf("%c", &work);
		
	}
	str[a] = '\0';
	*/
	//printf("%s\n", str);
	
	for(i = 0; i < 10; i++) {
		flg1 = 0;
		for(j = 0; j < a; j++) {
			if(flg1 >= 1) {
				break;
			}
			//printf("%c\n", str[j]);
			if( (str[j] - '0') == i) {
				flg1 = 1;
				//printf("O1K%c\n", str[j]);
				for(k = 0; k < 10; k++) {
					flg2 = 0;
					for(l = j + 1; l < a; l++) {
						if(flg2 >= 1) {
							break;
						}
						if( (str[l] - '0') == k) {
							flg2 = 1;
							for(m = 0; m < 10; m++) {
								for(n = l + 1; n < a; n++) {
									//printf("%c %c %c\n", str[j], str[l], str[n]);
									if( (str[n] - '0') == m) {
										count++;
										//printf("%c %c %c\n", str[j], str[l], str[n]);
										num[str[j] - '0'][str[l] - '0'][str[n] - '0']++;
										break;
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	printf("%ld\n", count);
	
	return 0;
}

Measured memory_bytes: 256
# https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_1_A
import sys
from functools import reduce


def to_str(x, y):
    return str(x) + ' ' + str(y)


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

print(reduce(to_str, A))
for i in range(1, len(A)):
    v = A[i]
    j = i - 1
    while j >= 0 and A[j] > v:
        A[j + 1] = A[j]
        j -= 1
    A[j + 1] = v
    print(reduce(to_str, A))

# A[i}がどこに入ればよいかという観点



Measured memory_bytes: 6276
n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((abs(tmp[0] + tmp[1]), tmp[0], tmp[1]))

dishes = sorted(dishes, key=lambda x: x[0], reverse=True)

point = [0, 0]
player = 0
while len(dishes) > 0:
    dish = dishes.pop(0)
    point[player] += dish[player + 1]
    player = int(not player)
print(point[0] - point[1])


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

using namespace std;
struct CinInit
{
    CinInit()
    {
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout << fixed << setprecision(20);
    };
} CinInit;

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

int main()
{
    int n, cnt = 0;
    cin >> n;
    vector<int> a(n), l(n), r(n);
    l[0] = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        if (i < n - 1)
            l[i + 1] = gcd(l[i], a[i]);
    }
    r[n - 1] = 0;
    for (int i = n - 1; i >= 1; i--)
    {
        r[i - 1] = gcd(a[i], r[i]);
    }

    int ans = 1;
    for (int i = 0; i < n; i++)
    {
        ans = max(gcd(l[i], r[i]), ans);
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 1408
//abc066_a ringring


#include <bits/stdc++.h>
using namespace std;

int main()
{
int P[ 5 ];

	cin >> P[ 0 ];
	cin >> P[ 1 ];
	cin >> P[ 2 ];
	sort( P, P + 3 );
	cout << P[ 0 ] + P[ 1 ] << endl;

	return 0;
}






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

int main()
{
	char c;
	cin >> c;
	if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')
		cout << "vowel" << endl;
	else
		cout << "consonant" << endl;	
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        int t[] = new int[n];
        for (int i = 0; i < n; i++) {
            t[i] = sc.nextInt();
        }
        Arrays.sort(t);

        int bus = 0, wait = 0;
        int time = 0;
        for (int i = 0; i < n; i++) {
            if (wait == 0) {
                time = t[i];
                wait = 1;
            } else if (wait >= c || t[i] > time + k) {
                bus++;
                time = t[i];
                wait = 1;
            } else {
                wait++;
            }
        }
        if (wait > 0) {
            bus++;
        }

        System.out.println(bus);
    }
}


Measured memory_bytes: 51640
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int inf = INT_MAX / 2;
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; }
 
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
 
    long long X, K, D;
    cin >> X >> K >> D;

    long long k = X / D;
    if (K < abs(k)) cout << abs(abs(X) - K * D) << endl;
    else {
        X = X - k * D;
        if ((K - abs(k)) % 2 == 0) cout << abs(X) << endl;
        else cout << min(abs(X-D), abs(X+D)) << endl;
    }
}

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

int main() {
	int h, w; cin >> h >> w;
	vector<string> s(h + 2);

	string pad;
	for (int i = 0; i < w + 2; i++) {
		pad += "-";
	}
	s[0] = pad;
	for (int i = 1; i < h + 1; i++) {
		string tmp; cin >> tmp;
		tmp.insert(0, "-");
		tmp.append("-");
		s[i] = tmp;
	}
	s[h + 1] = pad;

	for (int i = 1; i < h + 1; i++) {
		for (int j = 1; j < w + 1; j++) {
			int count = 0;
			if (s[i][j] == '.') {
				if (s[i - 1][j - 1] == '#') count++;
				if (s[i][j - 1] == '#') count++;
				if (s[i + 1][j - 1] == '#') count++;
				if (s[i - 1][j] == '#') count++;
				if (s[i + 1][j] == '#') count++;
				if (s[i - 1][j + 1] == '#') count++;
				if (s[i][j + 1] == '#') count++;
				if (s[i + 1][j + 1] == '#') count++;
				s[i][j] = to_string(count)[0];
			}
			cout << s[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


class Program
{


    static void Main(string[] args)
    {
        Solve();
    }

    static void Solve()
    {
        Scan sc = new Scan();
        write wr = new write();

        string k1 = sc.str;
        string k2 = sc.str;
        string k3 = sc.str;
        wr.wri<string>(k1[0].ToString() + k2[1].ToString() + k3[2].ToString());
    }

}
    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => strarr.Select(char.Parse).ToArray();


}



class write
{
    public void wri<Type>(Type x)
    {
        Console.WriteLine(x);
    }
}


Measured memory_bytes: 11092
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
    
    private int[][][] counts = new int[4][3][10];
    
    private void solv() {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        while (n-- > 0) {
            int b = input.nextInt();
            int f = input.nextInt();
            int r = input.nextInt();
            int v = input.nextInt();
            counts[b-1][f-1][r-1] += v;
        }
        for (int i = 0; i < 4; i++) {
            if (i != 0) {
                System.out.println("####################");
            }
            for (int j = 0; j < 3; j++) {
                StringBuilder sb = new StringBuilder();
                for (int k = 0; k < 10; k++) {
                    sb.append(' ').append(counts[i][j][k]);
                }
                System.out.println(sb.toString());
            }
        }
    }
}

Measured memory_bytes: 21048
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second
int main(){
	string s;
	cin>>s;
	int o=0;
	r(i,s.size()){
		if(!o&&s[i]=='C')o++;
		if(o&&s[i]=='F')o++;
	}
	if(o>=2)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n, ninngen[4][3][10] = {}, d, f, r, v;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> d;
		cin >> f;
		cin >> r;
		cin >> v;
		ninngen[d - 1][f - 1][r - 1] += v;
	}
	for (int i2 = 0; i2 < 3; i2++){
		for (int i3 = 0; i3 < 3; i3++){
			for (int i4 = 0; i4 < 10; i4++){
				cout << " " << ninngen[i2][i3][i4];
			}
			cout << endl;
		}
		cout << "####################" << endl;
	}
	for (int i3 = 0; i3 < 2; i3++){
		for (int i4 = 0; i4 < 10; i4++){
			cout << " " << ninngen[3][i3][i4];
		}
		cout << endl;
	}
	for (int i4 = 0; i4 < 10; i4++){
		cout << " " << ninngen[3][2][i4];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3088
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Tasks
{
    public class B
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var NL = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (N, L) = (NL[0], NL[1]);
            var S = new string[N].Select(x => x = Console.ReadLine()).OrderBy(x => x).ToArray();
            Console.WriteLine(string.Join("", S));
        }
    }
}


Measured memory_bytes: 28580
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	k := getNextInt(scanner)
	aa := make([]int, n)
	ss := make([]int, n+1)
	im := IntMap{}
	im.increment(0)

	ans := 0
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner) % k
		ss[i+1] = (ss[i] + aa[i]) % k
		key := (k + i + 1 - ss[i+1]) % k
		if i+1 >= k {
			hk := (k + i + 1 - ss[i+1-k]) % k
			im[hk] = im.get(hk) - 1
		}
		ans += im.get(key)
		im.increment(key)
	}

	fmt.Fprintln(writer, ans)
	writer.Flush()
}

// IntMap ...
type IntMap map[int]int

func (m IntMap) get(key int) int {
	if _, ok := m[key]; ok {
		return m[key]
	}
	return 0
}

func (m IntMap) increment(key int) {
	m[key] = m.get(key) + 1
}


Measured memory_bytes: 16128
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n;
        cin >> n;
        double a = (n * 1.0) / 3;
        cout << fixed << setprecision(8);
        cout << (a * a * a) << '\n';
    }
}

Measured memory_bytes: 31488
#include <iostream>
using namespace std;
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
#include <cstdlib>

int Board[100][100] = {};
int dx[8] = {1, 2, 1, 2, -1, -2, -1, -2}, dy[8] = {2, 1, -2, -1, -2, -1, 2, 1};

int main() {
	int n, k, x, y; cin >> n >> k >> x >> y;
	if(n>k) cout << k*x+(n-k)*y;
	else cout << n*x;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int k, n;
	cin>>k>>n;
	int A[n+1];
	for (int i = 1; i <= n; ++i)
	{
		cin>>A[i];
	}
	int ans[n+1];
	ans[0] = INT_MIN;
	ans[1] = A[n] - A[1];
	for (int i = 2; i <= n; ++i)
	{
		ans[i] = k - A[i] + A[i-1];
	}
	sort(ans, ans+n+1);
	cout<<ans[1]<<endl;
}

Measured memory_bytes: 5152
#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<ll,ll>
#define INT_MAX 2147483647
#define MOD 998244353
#define PI 3.14159265358979323846
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;

#define MAX 1000000000000

int main(void) {
	string s; cin >> s;
	if (s[s.size() - 1] == 's') {
		cout << s << "es" << endl;
	}
	else {
		cout << s << "s" << endl;
	}
	return 0;
	
}

Measured memory_bytes: 3592
using System;
using System.Linq;

public class Program
{
	static void Main(string[] args)
	{
		var InputValue = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToList<int>();

		if (0 > InputValue[2] - InputValue[4])
			Console.WriteLine("No");

		else if (0 > InputValue[3] - InputValue[4])
			Console.WriteLine("No");

		else if (InputValue[0] < InputValue[2] + InputValue[4])
			Console.WriteLine("No");

		else if (InputValue[1] < InputValue[3] + InputValue[4])
			Console.WriteLine("No");

		else
			Console.WriteLine("Yes");
	}
}






Measured memory_bytes: 9472
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner a = new Scanner(System.in);
		int n = a.nextInt();
		while (n != 0) {
			// int[] point = new int[20];
			int num, resule = 0;
			int sum = 0, max = 0, min = 1000;
			for (int i = 0; i < n; i++) {
				num = a.nextInt();
				sum += num;
				if (num > max)
					max = num;
				if (num < min)
					min = num;

			}

			resule = (sum - min - max) / (n - 2);
			System.out.println(resule);
			n = a.nextInt();
		}
	}
}

Measured memory_bytes: 29448
import fractions
a,b,c,d=map(int,input().split())

e=b//c
f=-(-a//c)

ans=e-f+1

g=b//d
h=-(-a//d)

ans=ans+g-h+1

i=(c*d)//fractions.gcd(c,d)

j=b//i
k=-(-a//i)

ans=ans-(j-k+1)

print(b-a+1-ans)

Measured memory_bytes: 5048
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 #include <queue>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


void solve(long long N, long long M, std::vector<long long> A){
    priority_queue<int> que;
    REP(i, N){
        que.push(A[i]);
    }
    REP(i, M){
        int a = que.top();
        que.pop();
        a/=2;
        que.push(a);
    }
    LL ans=0;
    REP(i, N){
        ans+=que.top();
        que.pop();
    }
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
int main(void){
    [[maybe_unused]] long long int n,m,i,j,c=0,h[1000010],a[1000010],b[1000010],x[1000010],ans=0;
    cin >> n >> m;
    for(i=0;i<n;i++)
    {
        cin >> h[i];
        x[i]=0;
    }
    for(i=0;i<m;i++)
    {
        cin >> a[i] >> b[i];
        if(h[a[i]-1]>h[b[i]-1])
        {
            x[b[i]-1]++;
        }
        else if(h[a[i]-1]<h[b[i]-1])
        {
            x[a[i]-1]++;
        }        
        else
        {
            x[a[i]-1]++;
            x[b[i]-1]++;
        }
    }
    for(i=0;i<n;i++)
    {
        if(x[i]==0)
        {
            ans++;
        }
    }
    cout << ans << endl;
 
    return 0;

}


Measured memory_bytes: 6748
#include <iostream>

int main() {
  int h, w;
  while (std::cin >> h >> w) {
    if (h == 0 && w == 0) {
      return 0;
    }
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if (
            (i%2==0&&j%2!=0)||
            (j%2==0&&i%2!=0)
            ){
          std::cout << '.';
        }else{
        std::cout << '#';
        }
      }
      std::cout << std::endl;
    }
    std::cout << std::endl;
  }
}



Measured memory_bytes: 3108
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		
		if(s.charAt(0) == s.charAt(1)|| s.charAt(1) == s.charAt(2)|| s.charAt(2) == s.charAt(3)) {
			System.out.println("Bad");
		}else {
			System.out.println("Good");
		}

		
	}
}


Measured memory_bytes: 21716
#include <iostream>
using namespace std;
int main(void){
    string str = "CODEFESTIVAL2016";
    int ans = 0;
    string comp;
    cin >> comp;
    
    for (int i = 0; i < str.length(); i++) {
        if(comp[i] != str[i]){
            ans++;
        }
    }
    
    cout << ans << endl;
        
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int h,w,x,y;
    cin>>h>>w>>x>>y;
    if((h*w)%2==1&&(x+y)%2==1){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }
}



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

#define all(v) v.begin(), v.end()
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int main() {
    int n; cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];
    sort(all(v));
    int ma = v[n - 1];
    int mi = v[0];

    int ans = INT_INF;
    for(int i = mi; i <= ma; i++){
        int sum = 0;
        for(int j = 0; j < n; j++){
            sum += pow(v[j] - i, 2);
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define Max(x,y) ((x>y)?x:y)
#define min(x,y) ((x<y)?x:y)
int dp[9][55];
int main(){
	int i,j,n,a,b,c,f;
	int p[]={380,550,850,1520,1870,2244};
	int w[]={2,3,5,10,12,15};
	for(i=0;i<7;i++)for(j=1;j<=50;j++)dp[i][j]=10000000;
	for(i=0;i<6;i++){
		for(j=1;j<=50;j++){
			if(j-w[i]>=0)dp[i+1][j]=min(dp[i][j],min(dp[i][j-w[i]]+p[i],dp[i+1][j-w[i]]+p[i]));
			else dp[i+1][j]=dp[i][j];
			//printf("%4d ",(dp[i+1][j]!=10000000)?dp[i+1][j]:0);
		}
		//printf("\n");
	}
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		printf("%d\n",dp[6][n/100]);
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int top[3]={0,0,0};

void judge(int);

int main(){
  int n, i;

  for(i=0;i<10;i++){
    scanf("%d",&n);
    judge(n);
  }

  for(i=0;i<3;i++){
    printf("%d\n",top[i]);
  }
  
  return 0;
}

void judge(int n){
  if(n>top[0]){
    top[2]=top[1];
    top[1]=top[0];
    top[0]=n;
  }
  else if(n>top[1]){
    top[2]=top[1];
    top[1]=n;
  }
  else if(n>top[2]) top[2]=n;
}



Measured memory_bytes: 2148
#include <stdio.h>

int main() {
  int n;
  scanf("%d", &n);
  long long int arr[n], max = 1e18, res = 1, check = 0, zero = 0;
  
  int c;
  for (c = 0; c < n; c++) {
    scanf("%lld", &arr[c]);
    check = (arr[c] > max) ? 1 : check;
    res *= arr[c];
    (arr[c]) ? max /= arr[c] : zero = 1;
  }

  (zero) ? printf("0\n") : ((check) ? printf("-1\n") : printf("%lld\n", res));
  return 0;
}


Measured memory_bytes: 2448
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int gcd(int n, int m) {
	if (n < m) {
		swap(n,m);
	}
	if (n%m == 0) {
		return m;
	}
	return gcd(m,n%m);
}

int main(void) {
	int N,X;
	cin >> N >> X;
	vector<int> town(N+1);
	town[N] = X;
	for (int i = 0; i < N; ++i) {
		cin >> town[i];
	}
	sort(town.begin(),town.end());
	int res = town[1] - town[0];
	for (int i = 1; !res != 1 && i < N; ++i) {
		res = gcd(res,town[i+1]-town[i]);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
words = lambda t : list(map(t, input().split()))
n = int(input())
a = words(int)

mv = max(a)

xs = [0] * (mv+1)
for y in a:
    xs[y] += 1

#print(xs)

if xs[0] > 1:
    print(0)
elif a[0] != 0:
    print(0)
else:
    ans = 1
    for i in range(len(xs)-1):
        ans *= xs[i] ** xs[i+1]
        ans %= 998244353

    print(ans)


Measured memory_bytes: 52824
import java.io.*;
import java.util.*;
import java.lang.Math.*;

public class Main{ 
    
    public static void main(String[] args)throws IOException{
	InputStreamReader isr = new InputStreamReader(System.in);
	BufferedReader br=new BufferedReader(isr);
	boolean[] pri = new boolean[1000001];
	
        for(int i=0;i<=1000000;i++){
	    pri[i]=true;
	}
	pri[0]=false;
	pri[1]=false;
	for(int i=3;i<=1000000;i++){
	    if(i%2==0)
		pri[i]=false;
	}
	for(int i=3;i<=1000000;i++){
	    if(pri[i]){
		for(int j=2*i;j<=1000000;j+=i)
		    pri[j]=false;
	    }
	}
	String line;
	while((line=br.readLine()) !=null){
	    int cnt=0;
	    int n=Integer.parseInt(line);
	    for(int i=0;i<=n;i++)
		if(pri[i])
		    cnt++;
	
	System.out.println(cnt);
	}
    }
}

Measured memory_bytes: 22532
#include <iostream>
#include <cstdio>
#include <fstream>

#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <unordered_map>
#include <string>

#include <functional>
#include <utility>
#include <cmath>
#include <algorithm>
#include <iterator>
#include <iomanip>

#include <cassert>
#include <random>
#include <chrono>

#include <ccomplex>

using namespace std;

#define ll long long
#define prll pair<ll,ll>
#define m_p make_pair
#define INF (ll)1e18

const ll q = 239017;
const ll mod = 1e9 + 7;
const ll mod2 = 1e9 + 13;
const ll N = 1e6 + 100;
const ll M = 100;
const ll L = 26;

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

ll line[N], a[N], b[N];

void $main()
{
	ll n; cin >> n;

	vector<ll> v(n);
	for (ll i = 0; i < n; ++i)
	{
		cin >> v[i];
		++line[v[i]];
	}

	ll ans = 0;
	for (ll el : v)
	{
		bool bad = 0;

		for (ll i = 1; i*i <= el; ++i)
		{
			if (el%i)continue;

			if (line[i] - (i == el) > 0)bad = 1;
			if (line[el/i] - ((el/i) == el) > 0)bad = 1;
		}

		ans += !bad;
	}

	cout << ans;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#else
	//freopen("champions", "r", stdin);
	//freopen("club", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	$main();

	return 0;
}

Measured memory_bytes: 12724
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) {rep(a,x.size()) cout << x[a] << " "; cout << endl;}
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 2e5;

int main() {
    int n, a, b; cin >> n >> a >> b;
    if (b < a) cout << 0 << endl; 
    else if (n == 1) {
        if (a != b) cout << 0 << endl;
        else cout << 1 << endl;
    } 
    else if (n == 2) {
        if (a == b) cout << 0 << endl;
        else cout << 1 << endl;
    }
    else {
        cout << (ll)(b-a)*(n-2)+1 << endl;;
    }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  for(int i=0; i<M; i++) {
    cin >> a.at(i) >> b.at(i);
    a.at(i)--; b.at(i)--;
  }
  
  vector<vector<bool>> ok(N, vector<bool>(N));
  for(int i=0; i<M; i++) {
    ok.at(a.at(i)).at(b.at(i)) = true;
    ok.at(b.at(i)).at(a.at(i)) = true;
  }
  
  vector<int> perm(N-1);
  for(int i=0; i<N-1; i++) perm.at(i) = i+1;
  
  int ans = 0;
  do {
    bool x = true;
    int v = 0;
    for(int i=0; i<N-1; i++) {
      if(!ok.at(v).at(perm.at(i))) x = false;
      v = perm.at(i);
    }
    if(x) ans++;
  } while (next_permutation(perm.begin(), perm.end()));
  
  cout << ans << endl;
  
}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

min_dif = float('inf')
idx = 0
for i in range(N):
    temp = T - 0.006 * H[i]
    dif = abs(temp - A)
    if dif < min_dif:
        min_dif = dif
        idx = i + 1
        
print(idx)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define all(obj) obj.begin(), obj.end()
#define dbg(x) cerr << #x << ":" << x << " "
#define dbgl(x) cerr << #x << ":" << x << "\n"
#define dbgv(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define dbgvv(vv) cerr << #vv << ":\n"; for (auto vec : vv) { for (auto e : vec) cerr << e << " "; cerr << endl; }
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main () {
	int N, M; cin >> N >> M; // スイッチN個，電球M個
	vi k(M); vvi s(M);
	rep(i, M) { // i:電球の番号(0-ind)
		cin >> k.at(i); // 電球iとつながったスイッチの個数
		rep(j, k.at(i)) { // 電球iに繋がったスイッチのうちj個目(0-ind)のもの
			int temp; cin >> temp;
			s.at(i).push_back(temp - 1); // 0-indとした
		}
	}
	vi p(M); rep(i, M) cin >> p.at(i);
	int ans = 0;
	rep(k, 1 << N) { // N個のスイッチのON/OFFの組合せの全て
		int x = k;
		vector<bool> f(M); // 電球のON/OFF
		rep(t, N) { // t桁目の0/1／t個目のスイッチのON/OFF
			if (x & 1) { // スイッチがONのとき
				rep(i, M) {
					if (find(all(s.at(i)), t) != s.at(i).end()) f.at(i) = !f.at(i);
				}
			}
			x >>= 1;
		}
		bool g = true;
		rep(i, M) {
			if (f.at(i) != p.at(i)) {
				g = false;
				break;
			}
		}		
		if (g) ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
//package com.company.practice;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.lang.*;

import static java.lang.Character.isUpperCase;

public class Main {
    public static Scanner key = new Scanner(System.in);
    public static void solveJuice()
    {
        int n = key.nextInt();
        int k = key.nextInt();
        int[] f = new int[n];
        for(int i = 0;i <= n-1;i++)
            f[i] = key.nextInt();
        Arrays.sort(f,0,n);
        int sum = 0;
        for(int j =0;j <= k-1;j++)
        {
            sum += f[j];
        }
        System.out.println(sum);
    }

    /*public static void redScarf()
    {

    }
*/
    public static void replacing()
    {
        int N = key.nextInt();
        int[] A = new int[N];
        HashMap<Integer,Integer> map = new HashMap<Integer,Integer>();
        long sum = 0;
        for(int i = 0;i <= N - 1;i++) {
            A[i] = key.nextInt();
            map.put(A[i],map.getOrDefault(A[i],0) + 1);
            sum += A[i];
        }
        int q = key.nextInt();
        while(q > 0)
        {
            q--;
            int a = key.nextInt();
            int b = key.nextInt();
            if(map.containsKey(a))
            {
                sum += (b-a)*map.get(a);
                int c = map.get(a);
                map.remove(a);
                map.put(b,map.getOrDefault(b,0)+c);
                System.out.println(sum);
            }
            else
                System.out.println(sum);
        }
    }

    public static void main(String[] args)
    {
       /* solveJuice();*/
        replacing();
    }
}


Measured memory_bytes: 66212
#!/usr/bin/env python3
import sys


def solve(S: str):
    if S == "ARC":
        print("ABC")
    else:
        print("ARC")
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9108
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, k;
  cin >> n >> k;
  int ans = n - k;
  if(k == 1) ans = 0;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3540