akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define eb emplace_back
#define ep emplace
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
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;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}
const int INF=1e6;
const ll int MOD=998244353;
#define N 50005
bitset<N> a[N],p;
main(){
    int n=in(),m=in(),t=in();
    if(t==1){
        rep(i,n+1)a[i].reset();
        rep(i,n)a[i][i]=1;
        vec x,y;
        rep(i,m)x.pb(in()-1),y.pb(in()-1);
        reverse(all(x)),reverse(all(y));
        rep(i,m){
            a[x[i]]|=a[y[i]];
            a[y[i]]|=a[x[i]];
        }
        rep(i,n)a[0]&=a[i];
        int s=-1;
        rep(i,n){
            if(a[0][i])s=i;
        }
        if(s==-1){
            cout<<-1;return 0;
        }
        p.reset();
        p[s]=1;
        string ans;
        rep(i,m){
            if(p[x[i]]&&!p[y[i]])ans.pb('^');
            else ans.pb('v');
            if(p[x[i]])p[y[i]]=1;
            else if(p[y[i]])p[x[i]]=1;
        }
        reverse(all(ans));
        cout<<ans<<endl;
    }
    else{
        if(n==2) cout<<-1;
        else{
            string ans;
            vec x,y;
            rep(i,m){
                x.pb(in());
                y.pb(in());
            }
            reverse(all(x));
            reverse(all(y));
            vec mem(4);
            rep(i,m){
                if(y[i]>3)ans.pb('^');
                else{
                    if(mem[x[i]])ans.pb('v');
                    else ans.pb('^');
                    mem=vec(4);
                    mem[x[i]]=mem[y[i]]=1;
                }
            }
            reverse(all(ans));
            cout<<ans;
        }
    }
}

Measured memory_bytes: 306804
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define ll long long int
using namespace std;
void solveB(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(a[i]!=a[j] && a[i]!=a[j] && a[j]!=a[k] && a[i]+a[j]>a[k]) ans++;
            }
        }
    }
    cout<<ans;
}
int main()
{
    solveB();
    return 0;
}


Measured memory_bytes: 3596
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstring>
using namespace std;
int main(){
  int h,i,j,k,l;
  int n,m;
  while(cin>>n>>m,n||m){
    string s[1024][3];
    for(i=0;i<n;++i)
      cin>>s[i][2]>>s[i][0]>>s[i][1];
    vector<string> t[3];
    for(i=0;i<m;++i){
      string u[3];
      cin>>u[0]>>u[1]>>u[2];
      h=0;
      for(j=0;j<n;++j){
	for(k=0;k<2;++k){
	  for(l=0;l<8;++l){
	    if(s[j][k][l]!='?'&&s[j][k][l]!=u[k][l])
	      break;
	  }
	  if(l<8)
	    break;
	}
	if(k==2){
	  if(s[j][2][0]=='p')
	    h=1;
	  else
	    h=0;
	}
      }
      if(h){
	for(j=0;j<3;++j)
	  t[j].push_back(u[j]);
      }
    }
    cout<<t[0].size()<<endl;
    for(i=0;i<(int)t[0].size();++i)
      cout<<t[0][i]<<" "<<t[1][i]<<" "<<t[2][i]<<endl;
  }
  return 0;
}

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

int main() {
  int H,N;
  int count=0;
  cin>>H>>N;
  rep(i,N){
    int x;
    cin>>x;
    count+=x;
  }
  if(count>=H){
    cout<<"Yes";
  }
  else {
    cout<<"No";
  }
}


Measured memory_bytes: 384
n=int(input())
a=list(reversed(list(map(int,input().split()))))
if a[0]>2:
	print("-1")
	exit()
a1,a2=2,2
for i in range(1,n):
	a1+=(a[i]-a1%a[i])%a[i]
	pre=a2
	a2+=a[i-1]-1
	a2-=a2%a[i]
	if a1>a2:
		print("-1")
		exit()	
print(a1,a2+a[n-1]-1)

Measured memory_bytes: 63856
n, m, *L = map(int, open(0).read().split())
con = [[] for _ in range(n)]
vis = [None] * n
for l, r, d in zip(*[iter(L)] * 3):
	con[l - 1] += [(r - 1, d)]
	con[r - 1] += [(l - 1, -d)]

def check(s):
	if vis[s] is not None:
		return True
	q = [s]
	vis[s] = 0
	while q:
		cur = q.pop()
		for nxt, d in con[cur]:
			if vis[nxt] is not None:
				if vis[nxt] != vis[cur] + d:
					return False
				continue
			vis[nxt] = vis[cur] + d
			q += [nxt]
	return True

print("Yes" if all(check(s) for s in range(n)) else "No")

Measured memory_bytes: 81852
import java.util.Scanner;

public class Main {

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

		if(n+a+b>=22) {
			System.out.println("bust");
		}else {
			System.out.println("win");
		}


	}

	public static int res(int n) {
		if(n==1) {
			return 1;
		}

		return n+res(n-1);
	}
}




Measured memory_bytes: 23764
from collections import defaultdict

N = int(input())
A = list(map(int,input().split()))
Q = int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
    B[i],C[i] = map(int,input().split())

d = defaultdict(int)

for a in A:
    d[a] += 1
S = sum(A)

for q in range(Q):
    b = B[q]
    c = C[q]
    if d[b]==0:
        print(S)
    else:
        S -= d[b]*b
        S += c*d[b]
        d[c] += d[b]
        d[b] = 0
        print(S)











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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }

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

    int a, b;
    cin >> a >> b;
    if ((1 <= a && a <= 9) && (1 <= b && b <= 9)) {
        cout << a * b << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a>>b>>c>>d;
  if((a+b) < (c+d)){
    cout << "Right" <<endl;
  }else if((a+b) > (c+d)){
    cout << "Left" <<endl;
  }else{
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }

void main() {
    int N, M; readf("%d %d\n", &N, &M);
    auto G = new bool[][](N, N);
    foreach (i; 0 .. M) {
        int a, b; readf("%d %d\n", &a, &b); a--; b--;
        G[a][b] = G[b][a] = true;
    }

    int ans = 0;
    void dfs(int v, int used) {
        used |= 1 << v;
        if (used == (1 << N) - 1) {
            ans++;
            return;
        }
        foreach (u; 0 .. N) {
            if (v == u) continue;
            if (! G[v][u]) continue;
            if (used & (1 << u)) continue;
            dfs(u, used);
        }
    }
    dfs(0, 0);
    writeln(ans);
}


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

int main(void){
    int N;
    string S;
    cin >> N >> S;
    
    vector<char> A;
    for(char c = 'A' ; c <= 'Z' ; c++){
        A.push_back(c);
    }
    
    for(int i = 0 ; i < S.size() ; i++){
        for(int j = 0 ; j < 26 ; j++){
            if(S.at(i) == A.at(j)){
                if(j+N >= 26){
                    cout << A.at(j+N -26);
                }
                else{
                    cout << A.at(j+N);
                }
            }
        }
    }
}

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

using namespace std;
int bot[110000];
int a;
int c;
int d;

int main(void){
	d = -1;
	c = 0;
	cin >> a;
	for(int i=0;i<a;i++){
		cin >> bot[i];
		bot[i] = bot[i] - 1;
	}
	for(int i = 0;i<a+1;i++){
		c = bot[c];
		if(c==1 && d==-1){
			d = i+1;
		}
	}
	cout << d << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
    int a,b,c;
    string s;
    cin >> a >> b >> c;
    cout << a+b+c-max({a,b,c}) << endl;
   

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

const int INF=1e9;

class SegmentTree
{
 private:
    int n;
    vector<int> node,lazy;
 public:
    SegmentTree(int sz){
        n=1;
        while(n<sz) n*=2;
        node.assign(2*n-1,0);
        lazy.assign(2*n-1,0);
    }
    void update(int a,int b,int x,int k,int l,int r){
        if(a<=l and r<=b) node[k]+=x,lazy[k]+=x;
        else{
            if(lazy[k]!=0) push(k),lazy[k]=0;
            if(check(a,b,l,(l+r)/2)) update(a,b,x,2*k+1,l,(l+r)/2);
            if(check(a,b,(l+r)/2,r)) update(a,b,x,2*k+2,(l+r)/2,r);
            node[k]=max(node[2*k+1],node[2*k+2]);
        }
    }
    int get(int a,int b,int k,int l,int r){
        if(a<=l and r<=b) return node[k];
        else{
            if(lazy[k]!=0) push(k),lazy[k]=0;
            int res=-INF;
            if(check(a,b,l,(l+r)/2)) res=max(res,get(a,b,2*k+1,l,(l+r)/2));
            if(check(a,b,(l+r)/2,r)) res=max(res,get(a,b,2*k+2,(l+r)/2,r));
            return res;
        }
    }
    void push(int k){
        node[2*k+1]+=lazy[k]; node[2*k+2]+=lazy[k];
        lazy[2*k+1]+=lazy[k]; lazy[2*k+2]+=lazy[k];
    }
    bool check(int a,int b,int l,int r){
        return max(a,l)<min(b,r);
    }
    void update(int a,int b,int x){ update(a,b,x,0,0,n); }
    int get(int a,int b){ return get(a,b,0,0,n); }
};

typedef pair<int,int> pint;

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

    int N,M; cin>>N>>M;
    vector<pair<pint,int>> v;
    for(int i=0;i<M;i++){
        int l,r,a; cin>>l>>r>>a;
        v.push_back({{r,l},a});
    }
    sort(v.begin(),v.end());
    vector<int> l(M),r(M),a(M);
    for(int i=0;i<M;i++){
        l[i]=v[i].first.second;
        r[i]=v[i].first.first;
        a[i]=v[i].second;
    }

    SegmentTree dp(N+1);
    int idx=0;
    for(int i=1;i<=N;i++){
        int x=dp.get(0,i);
        dp.update(i,i+1,x);
        while(idx<M and r[idx]==i){
            dp.update(l[idx],r[idx]+1,a[idx]);
            idx++;
        }
        // for(int i=0;i<=N;i++) cout<<dp.get(i,i+1)<<' '; cout<<endl;
    }
    cout<<dp.get(0,N+1)<<endl;
    return 0;
}

Measured memory_bytes: 19180
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong(),a=sc.nextLong(),b=sc.nextLong();
		long count = 0;
		if((b-a)%2!=0) {
			if(a-1<=n-b) {
				count += a;
				count += (b-a-1)/2;
				System.out.println(count);
			}else{
				count += n-b+1;
				count += (b-a-1)/2;
				System.out.println(count);
			}
		}else {
			System.out.println((b-a)/2);
		}
	}
}




Measured memory_bytes: 22996
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n = cin.nextInt();
		int m = cin.nextInt();
		int[] arr = new int[m + 1];
		for (int i = 0; i < n; i++) {
			int t = cin.nextInt();
			for (int j = 0; j < t; j++) {
				int idx = cin.nextInt();
				arr[idx]++;
			}
		}
		int sum = 0;
		for (int i = 1; i <= m; i++) 
			if (arr[i] == n)
				sum++;
		System.out.println(sum);
	}
}

Measured memory_bytes: 24916
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main()
{
  int N,ans=0,last=1000000,cnt,a;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>a;
    if(last!=a){
      cnt=1;
      last=a;
    }else{
      cnt+=1;
      if(cnt%2==0)ans+=1;
    }
  }
  cout<< ans <<endl;
}



Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int n;

int main(){
    int n,t;
    cin >> n >> t;
    vector<int> a(n);
    REP(i,n)cin >> a[i];
    ll res = (ll)t*n;
    REP(i,n-1){
        res -= max(0,t-(a[i+1]-a[i]));
    }
    put(res);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define pb push_back
#define pob pop_back
#define mp make_pair
#define FILL(a,v) memset((void*)a,v,sizeof(a))
#define FILL0(a) FILL(a,0)
#define FILL1(a) FILL(a,-1)
#define FILLBIG(a) FILL(a,0x7f)
#define ALL(a) (a).begin(),(a).end()
#define Inf ((int)0x7f7f7f7f)
#define INF ((long long)0x7f7f7f7f7f7f7f7f)
#define Mod 1000000007
#define foreach(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define FOR(i,x) for(int i=0;i<x;i++)
#define RFOR(i,x) for(int i=x-1;i>=0;i--)
#define FFOR(i,a,b) for(int i=a;i<b;i++)
#define FRFOR(i,a,b) for(int i=a-1;i>=b;i--)
#define SZ(a) ((int)(a).size())
#define FI first
#define SE second
#define OVER(a) return puts(a),0
#define fastio ios::sync_with_stdio(0)
#define filei(f) freopen(f,"r",stdin)
#define fileo(f) freopen(f,"w",stdout)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define MASK(a) (1<<(a))
#define MASKX(x,a) ((x)<<(a))
#define BIT(a,b) ((a>>b)&1)
#define cddx(a) priority_queue<a >
#define cxdd(a) priority_queue<a,vector<a >,greater<a > >
#define deval(a) {cerr<<#a<<" = "<<a<<endl;}
#define reg register
using namespace std;
typedef pair<int,int> pii;
typedef unsigned long long UINT;
typedef unsigned int uint;
typedef long long INT;
typedef long double ldouble;
typedef pair<INT,INT> PII;
typedef stringstream sst;
typedef istringstream iss;
typedef vector<int> vint;
typedef vector<INT> VINT;
typedef vector<pii> vpii;
typedef vector<PII> VPII;
typedef priority_queue<int> pqi;
typedef priority_queue<INT> PQI;
typedef priority_queue<pii> pqp;
typedef priority_queue<PII> PQP;
typedef priority_queue<int,vint,greater<int> > xqi;
typedef priority_queue<INT,VINT,greater<INT> > XQI;
typedef priority_queue<pii,vpii,greater<pii> > xqp;
typedef priority_queue<PII,VPII,greater<PII> > XQP;

string s,t;
int main()
{
	cin>>s;
	t=s;
	int cnt=0;
	for(int i=0;i<=SZ(s)/2;i++)
	{
		int j=SZ(s)-i-1;
		if(s[i]!='x'&&s[j]!='x'&&s[i]!=s[j])OVER("-1");
		if(s[i]=='x'&&s[j]!='x')
		{
			s.erase(i,1);
			i--;
			cnt++;
		}
		if(s[i]!='x'&&s[j]=='x')
		{
			s.insert(i,"x");
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}

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

#define int long long

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

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

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

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

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

signed main(){
	int n;
	cin>>n;
	cout<<n*n*n<<endl;
	return 0;
}

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

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			var d = (from ds in Console.ReadLine().Split()
					 select int.Parse(ds)).ToList<int>();

			int total = 0;
			for (int i = 0; i < n - 1; i++)
			{
				for (int j = i + 1; j < n; j++)
				{
					total += d[i] * d[j];
				}
			}
			Console.WriteLine(total);
		}
	}
}


Measured memory_bytes: 13268
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
	tmp = input[0].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(tmp[0], 10);
	var b = parseInt(tmp[1], 10);
	var c = parseInt(tmp[2], 10);
	//出力
	if (a<= c && c <= b) {
		console.log('Yes');
	}else {
		console.log('No');
	}
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21192
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define plll pair<pll,ll>
#define ppll pair<pll, pll>
#define pii pair<int, int> 
#define piii pair<pii, int>
#define sort(p) sort(p.begin(),p.end())
#define rsort(p) sort(p.rbegin(),p.rend())
#define pb push_back
const ll llinf = 2e18 + 7;
const int inf = 2e9 + 7;
const ll mod = 998244353;
const ll N = 1e5 + 7;
const ld pi = 3.14159265358979; 

void solve() {
    ll n,a,b,q;
    cin>>n;
    vector<ll> arr(n);
    map<ll,ll> mp;
    ll sum = 0;
    for(int i=0;i<n;i++) {
        cin>>arr[i];
        mp[arr[i]]++;
        sum+=arr[i];
    }
    cin>>q;
    while(q--) {
        cin>>a>>b;
        if(mp.find(a)==mp.end()) {
            cout<<sum<<"\n";
            continue;
        }
        ll cnt = mp[a];
        mp.erase(a);
        mp[b]+=cnt;
        ll ans = sum - cnt*a + cnt*b;
        sum = ans;
        cout<<ans<<"\n";
    }
}

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    t=1;
    // cin>>t;
    while(t--) {
        solve();
        // cout<<"\n";
    }
    return 0; 

}


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

int main(){
    int n;
    cin >> n;
    int array[n];
    for(int i = 0; i < n; i++){
        cin >> array[i]; 
    }
    bool flag = true;
    for(int i = 0; i < n-1; i++){
        if(array[i] > i || array[i+1] - array[i] > 1 )flag = false;
    }
    if(array[n-1] > n - 1)flag = false;
    if(!flag){
        cout << -1 << endl;
        return 0;
    }
    long long int cnt = array[n-1];
    long long int tmp = array[n-1];
    for(long long int i= n -1; i >= 0; i-- ){
        if(tmp == array[i]){
            tmp--;
        }else{
            tmp = array[i] - 1;
            cnt += array[i];
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
N,X = map(int,input().split())
#バーガーは2*cnt+3、パティは2*cnt+1
#レベルNバーガー&パティの総数リスト　indexは[N-1]
numB = [1]
numP = [1]
for i in range(50):
    numB.append(numB[i]*2+3)
    numP.append(numP[i]*2+1)
#二分探索の作成
L = 0; R = numB[N]+1
K = N   #Kは今調べているバーガー
ans = 0
while K>0:
    Mid = (L+R)//2
    if X == L+1:
        break
    if L+2 <= X <= Mid-1:
        K -= 1
        L += 1; R = Mid
        continue
    if X == Mid:
        ans += numP[K-1]+1
        break
    if Mid+1 <= X <= R-2:
        ans += numP[K-1]+1
        K -= 1
        L = Mid; R -= 1
        continue
    if X == R-1:
        ans += numP[K]
        break
else:
    ans += 1
print(ans)



Measured memory_bytes: 38384
#!/usr/local/bin/python3
# https://atcoder.jp/contests/abc160/tasks/abc160_c

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

dist = []
for i in range(N-1):
    dist.append(A[i+1] - A[i])
dist.append(K - A[-1] + A[0])

print(K - max(dist))


Measured memory_bytes: 32244
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()

typedef long long int ll;

//ll num[50];
//ll num2[50];
//ll num[ten52];
//stack<char> stk;
//set<ll> sll;
//map<string,ll> mp,mp1;
//map<string,ll>::iterator iter;
//map<ll,ll> mp;
//deque<char> deq;
priority_queue<double> pq;


int main(void)
{
    double ans=0.0,d,d1,d2,sumd=0.0;
    //float f,g,h;
    long long int m,n,i,j,k=1;
    long long int a,a1,a2,a3,sum;
    string s,s1,s2;
    char c,c1;
    sum=a=a1=a2=a3=0;
    cin>>n>>m;
    for(i=0;i<n;i++)
    {
        cin>>d;
        pq.push(d);
        sumd+=d;
    }
    for(i=0;i<m;i++)
    {
        if(!(pq.top()>=sumd/(4*m)))
        {
            cout<<"No";
            return 0;
        }
        pq.pop();
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 256
/**
 * B - 81
 * https://atcoder.jp/contests/abc144/tasks/abc144_b
 **/
#include<iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    if(N > 81) {
        cout << "No" << endl; 
        return 0;
    }

    bool flag = false;
    for(int i=1; i<10; i++) {
        if((N%i==0)&&(N/i<10)) {
            flag = true;
            break;
        }
    }

    if(flag){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;

}

Measured memory_bytes: 256
S = str(input())
# 余りのリスト
counts = [0] * 2019
n, d = 0, 1

for s in S[::-1]:
    n += int(s) * d
    d *= 10
    n %= 2019
    d %= 2019
    counts[n] += 1
ans = counts[0]
for count in counts:
    ans += count * (count - 1) // 2
print(ans)


Measured memory_bytes: 9196
from collections import defaultdict
class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

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

h, w = map(int, input().split())
S = []
for i in range(h):
    s = input()
    S.append(s)

uf = UnionFind(h*w)

for i in range(h):
    for j in range(w):
        if i < h - 1 and S[i][j] != S[i+1][j]:
            uf.union(i*w+j, (i+1)*w+j)
        if j < w - 1 and S[i][j] != S[i][j+1]:
            uf.union(i*w+j, i*w+j+1)

ans = 0

d = defaultdict(int)

for i in range(h*w):
    if S[i//w][i%w] == '.':
        d[uf.find(i)] += 1

for i, x in enumerate(uf.parents):
    if x < 0:
        # print(-x, d[i])
        cnt = -x
        ans += d[uf.find(i)] * (cnt-d[i])

print(ans)


            


Measured memory_bytes: 20836
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N (1<<18)

int a[(2 * N)];

void init(void){
	f(i, 2 * N)a[i] = -MOD;
	return;
}


void change(int k, int x){
	k += N;
	if (a[k]<x)a[k] = x;
	else return;
	while (k > 1){
		k = k / 2;
		a[k] = max(a[2 * k], a[2 * k + 1]);
	}
	return;
}
//探索(0<=l<r<=n)範囲は(l<=x<r)初期は(l,r,1,0,N)
int max_search(int l, int r, int k, int sl, int sr){
	if (r <= sl || sr <= l)return -MOD;
	else if (l <= sl&&sr <= r) return a[k];
	else{
		int vl = max_search(l, r, 2 * k, sl, (sl + sr) / 2);
		int vr = max_search(l, r, 2 * k + 1, (sl + sr) / 2, sr);
		return max(vl, vr);
	}
}




int main(void){
	int b[N];
	int s[N];
	vector<pair<int, int> >qq;
	int nx = 0;
	int n;
	int m;
	int x, y, z;
	int xx;
	scanf("%d", &n);
	init();
	b[0] = 0;
	s[0] = b[0];
	f(i, n){
		scanf("%d", &x);
		if (x == 0){
			b[i + 1] = b[i] + 1;
			s[i + 1] = b[i + 1];
		}
		else{
			b[i + 1] = b[i];
			s[i + 1] = b[i + 1];
		}
	}
	scanf("%d", &m);
	f(i, m){
		scanf("%d %d", &x, &y);
		qq.push_back(make_pair(x, y));
	}
	sort(qq.begin(), qq.end());
	for (int i = 1; i <= n; i++){
		if (b[i - 1]<b[i]){
			s[i] = max(s[i - 1] + 1, s[i]);
		}
		else s[i] = max(s[i - 1], s[i]);
		if (nx < qq.size()){
			while (qq[nx].first <= i){
				xx = qq[nx].second;
				x = s[i - 1] + (xx - b[xx]) - (i - 1 - b[i - 1]);
				y = max_search(i, xx + 1, 1, 0, N);
				if (y > (-MOD)){
					y += (xx - b[xx]);
					z = max(x, y);
				}
				else z = x;
				s[xx] = max(s[xx], z);
				change(xx, z - (xx - b[xx]));
				nx++;
				if (nx >= qq.size())break;
			}
		}

	}
	printf("%d\n", n-s[n]);

	return 0;

}


Measured memory_bytes: 6004
<?php
 $a = trim(fgets(STDIN));
$ans=0;
for($i=0;$i<$a;$i++){
list($b,$c) = explode(" ",trim(fgets(STDIN)));
if($c=="JPY"){
$ans +=$b;
}else{
$ans +=$b*380000;
}
}
echo $ans;

Measured memory_bytes: 4856
n, m = map(int, input().split())
arr1 = [list(map(int, input().split())) for _ in range(n)]
arr2 = [int(input()) for _ in range(m)]
for ans in ([sum([a1*a2 for a1,a2 in zip(arr1[j], arr2)]) for j in range(n)]):
    print(ans)


Measured memory_bytes: 6028
<?php
  

//$abc = explode(" ",trim(fgets(STDIN)));
fscanf(STDIN,"%d %d",$a,$b);
$count=0;

for($i=$a;$i<=$b;$i++){
  $str_i = (string)$i;
  if($str_i[0]==$str_i[4] && $str_i[1]==$str_i[3]){
     $count++;
  }
}

echo $count."\n";

Measured memory_bytes: 4732
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#define MOD 1000000007
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
signed main(){
    int a;
    string s;
    cin>>a>>s;
    if(a<3200)cout<<"red"<<endl;
    else cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	s := next()
	m := make(map[rune]int)
	for _, r := range s {
		m[r]++
	}

	for _, c := range m {
		if c != 2 {
			fmt.Println("No")
			return
		}
	}

	if len(m) == 2 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 640
n, a = map(int, input().split())
xxx = list(map(int, input().split()))
limit = a * n
dp = [[0] * (limit + 1) for i in range(n + 1)]
dp[0][0] = 1
for i, x in enumerate(xxx):
    if x > limit:
        continue
    for j in range(i, -1, -1):
        for k in range(limit - x, -1, -1):
            dp[j + 1][k + x] += dp[j][k]

print(sum(dp[i][i * a] for i in range(1, n + 1)))


Measured memory_bytes: 4468
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int m,t,p,r;
struct team{
int time[200];
bool ok[200];
int id;
int ac;
};
//team a,team b
int oror(team a,team b){//aのほうが強ければ1,bなら0,同じなら2
if(a.ac>b.ac)return 1;
else if(a.ac<b.ac)return 0;
int at=0,bt=0;
for(int i=0;i<=p;i++){
if(a.ok[i]==true)at+=a.time[i];
if(b.ok[i]==true)bt+=b.time[i];
}
if(at<bt)return 1;
else if(at>bt)return 0;
else return 2;
}
int main(){

	while(true){
	cin>>m>>t>>p>>r;
	if(m+t+p+r==0)break;
	vector<team>ta(0);
	ta.resize(200);

	for(int i=0;i<=t;i++)for(int j=0;j<200;j++)ta[i].time[j]=0,ta[i].ok[j]=0;
	for(int i=0;i<=t;i++)ta[i].id=i,ta[i].ac=0;
	for(int i=0;i<r;i++){
	int a,b,c,d;
	cin>>a>>b>>c>>d;//a:経過時間:bチーム番号c:問題番号j:0奈良正解それ以外不正解
	if(d==0){
	ta[b].time[c]+=a;
	ta[b].ac++;
	ta[b].ok[c]=true;
	}
	else {
	ta[b].time[c]+=20;
	}
	}
	ta.erase(ta.begin());
	for(int i=0;i<t;i++){
	for(int j=0;j<t;j++){
	if(oror(ta[i],ta[j])==1)swap(ta[i],ta[j]);
	if(oror(ta[i],ta[j])==2&&ta[i].id>ta[j].id)swap(ta[i],ta[j]);
	}
	}
	for(int i=0;i<t-1;i++){
	if(oror(ta[i],ta[i+1])!=2)cout<<ta[i].id<<",";
	else cout<<ta[i].id<<"=";
	}
	cout<<ta[t-1].id<<endl;
	}
	return 0;
}

Measured memory_bytes: 1416
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

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

int main() {
  vector<int> lst(3);
  cin >> lst[0] >> lst[1] >> lst[2];

  sort(lst.begin(), lst.end());
  int nn = lst[2] - lst[0];
  nn += lst[2] - lst[1];

  int ans = nn / 2;
  if (nn % 2 == 1) ans += 2;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#define MAX3(x) std::max((x)[0], std::max((x)[1], (x)[2]))
typedef long long lld;
const int INFN = 1E9+5;
const int MAXN = 1E5+5;
int array[MAXN]{ };
lld    dp[MAXN][2]{ }; // [0, 1] Cards Left
lld Ans=0;
int N;

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; ++i)
	{
		scanf("%d", &array[i]);
		for(int j = 0; j < 2; ++j)
			dp[i][j] = -INFN;
	}
	dp[1][array[1] & 1] = array[1]>>1;
	for(int i = 2; i <= N; ++i)
	{	// No Remaining Cards
		int half = array[i]>>1;
		if(!(array[i] & 1))
		{
			dp[i][0] = std::max(dp[i-1][0], dp[i-1][1]) + half;
			if(array[i] >= 1)
				dp[i][1] = dp[i-1][1] + (array[i]-1)/2 + 1;
		}
		else
		{
			dp[i][0] = dp[i-1][1] + half + 1;
			if(array[i] >= 1)
				dp[i][1] = std::max(dp[i-1][0], dp[i-1][1]) + half;
		}
		for(int j = 0; j < 2; ++j)
			if(dp[i][j] < 0) dp[i][j] = -INFN;
	}
	printf("%lld\n", std::max(dp[N][0], dp[N][1]));
	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = int;
using vll = vector<ll>;
using pll = pair<ll, ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)

ll dp[3001][3000];

void solve(ll N, ll T, std::vector<ll> A, std::vector<ll> B){

    REP(j, T){
        dp[0][j] = 0;
    }
    REP(i, N){
        REP(j, T){
            //* A -> weight B-> value
            if( j< A[i]){
                dp[i+1][j] = dp[i][j];
            }
            else{
                dp[i+1][j] = max(dp[i][j], dp[i][j-A[i]]+ B[i]);
            }

        }
    }
    ll C = T-1;
    set<ll> myset;
    for(ll i= N-1; i>=0; i--){ //* check i-th item
        if(A[i]<=C && dp[i][C- A[i]]+ B[i] >= dp[i][C]){
            myset.insert(i);
            C -= A[i];
        }
    }
    ll maxRemain=0;
    REP(i, N){
        if(!myset.count(i)){
            maxRemain = max(maxRemain, B[i]);
        }
    }
    cout << dp[N][T-1] + maxRemain << endl;

}

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


Measured memory_bytes: 35584
import sys
sys.setrecursionlimit(10 ** 9)
H, W = map(int, input().split())
G = [list(input()) for i in range(H)]
C = [[0] * W for i in range(H)]


def dfs(nh, nw, color):
    direction = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    C[nh][nw] = color
    for dh, dw in direction:
        if not ((0 <= nh + dh < H) and (0 <= nw + dw < W)):
            continue
        if C[nh + dh][nw + dw] != 0:
            continue
        if G[nh][nw] == G[nh + dh][nw + dw]:
            continue
        C[nh + dh][nw + dw] = color
        dfs(nh + dh, nw + dw, -color)


Color = 1
for h in range(H):
    for w in range(W):
        if C[h][w] == 0:
            dfs(h, w, Color)
            Color += 1


Count = {}
for h in range(H):
    for w in range(W):
        Count[C[h][w]] = 0
        Count[-C[h][w]] = 0


for h in range(H):
    for w in range(W):
        Count[C[h][w]] += 1


ans = 0
for key in Count.keys():
    ans += Count[key] * Count[-key]

print(ans // 2)


Measured memory_bytes: 168404
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,a;
  cin >> n >> a;
  vector<int>x(n);
  rep(i,n) cin >> x[i];
  ll dp[n+10][n+10][50*n+100]={};
  dp[0][0][0]=1;
  
  rep(i,n){
    for(int j=0;j<=n;j++){
      for(int k=0;k<=50*n;k++){
        if(dp[i][j][k]==0)continue;
        dp[i+1][j+1][k+x[i]]+=dp[i][j][k];
        dp[i+1][j][k]+=dp[i][j][k];
      }
    }
  }
  ll res = 0;
  for(int i=1;i<=n;i++){
    res+=dp[n][i][i*a];
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 73344
s = input()
counter = 0
if s[0] == "1":
    for i in range(len(s)):
        if i % 2 == 0:
            if int(s[i]) == 0:
                counter += 1
        else:
            if int(s[i]) == 1:
                counter += 1
else:
    for i in range(len(s)):
        if i % 2 == 0:
            if int(s[i]) == 1:
                counter += 1
        else:
            if int(s[i]) == 0:
                counter += 1

print(counter)

Measured memory_bytes: 3188
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
char c[200233];
int main()
{
	int n;
	scanf("%d",&n);
	int sumw=0,sumr=0;
	for (int i=1;i<=n;i++)
	{
		cin>>c[i];
		if (c[i]=='W') sumw++;
		else sumr++;
	}
	int ans=0;
	for (int i=1;i<=sumr;i++)
		if (c[i]=='W') ans++;
		printf("%d\n",ans);
		return 0;
}

Measured memory_bytes: 3380
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const int INF = 1001001001;
const double pi = acos(-1);

int main()
{
    for (int i = 0; i < 5; i++)
    {
        int x;
        cin >> x;
        if (x != i + 1)
        {
            cout << i + 1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <map>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>
using namespace std;

int main(){
  const int n = getInt();
  map<char, int> m;
  REP(i,n){
    string s; cin >> s;
    map<char, int> mm;
    for(char c = 'a'; c <= 'z'; c++) mm[c] = 0;
    for(char c : s) mm[c]++;

    for(auto p : mm){
      if(m.count(p.first)){
        m[p.first] = min(m[p.first], p.second);
      }else{
        m[p.first] = p.second;
      }
    }
  }

  for(auto p : m){
    REP(i,p.second) putchar(p.first);
  }
  puts("");

  return 0;
}


Measured memory_bytes: 256
def getfly(x,a,m,i):
        if x==1 and i!=0:
            return i
        else:
            return getfly((a*x)%m,a,m,i+1)

def getgcd(a,b):
    #print a,b
    (a,b)=max(a,b),min(a,b)
    if a%b==0:
        return b
    else:
        return getgcd(b,a%b)

while(1):
    indata=[int(x) for x in raw_input().split()]
    if indata[0]==0:
        break
    else:
        a=indata[0::2]
        m=indata[1::2]
        A=[]
        for j in range(3):
            i=0
            x=1
            p=a[j]
            q=m[j]
            while (x!=1 or i==0):
                i+=1
                x=p*x%q
            A.append(i)
        gab=getgcd(A[0],A[1])
        lab=A[0]*A[1]/gab
        gac=getgcd(A[2],lab)
        ans=A[2]*lab/gac
        print ans

Measured memory_bytes: 4272
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define lson rt<<1, l, mid
#define rson rt<<1|1, mid + 1, r
#define lowbit(x) (x&-x)
using namespace std;
struct point
{
    int x,y;
}p[10050];
struct edge
{
    int u;
    int v;
    double len;
}e[10000*200];
int n,m;
bool vis[20005];
bool cmp(const edge &e1, const edge &e2)
{
    return e1.len > e2.len;
}
int par[20005];
int ran[20005];
void init(int n)
{
    for(int i = 0; i <= n; i++) {
        par[i] = i;
        ran[i] = 0;
    }
}
int find(int x)
{
    if(par[x] == x)
        return x;
    return par[x] = find(par[x]);
}
void unite(int x, int y)
{
    int fx = find(x);
    int fy = find(y);
    if(fx == fy)
        return;
    if(ran[fx] > ran[fy])
        par[fy] = fx;
    else {
        par[fx] = fy;
        if(ran[fx] == ran[fy])
            ran[fy]++;
    }
}
double kruskal()
{
    sort(e,e+m,cmp);
    init(n);
    double res = 0;
    for(int i = 0; i < m; i++) {
        if(find(e[i].u)!=find(e[i].v)){
            unite(e[i].u,e[i].v);
            res += e[i].len;
        }
    }
    return res;
}
double calc(double x1, double y1, double x2, double y2)
{
    return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}
int main()
{
    cin>>n>>m;
    for(int i = 1; i <= n; i++)
        scanf("%d%d",&p[i].x,&p[i].y);
    double sum = 0;
    for(int i = 0; i < m; i++) {
        int x, y;
        scanf("%d%d",&x,&y);
        e[i].len = calc(p[x].x,p[x].y,p[y].x,p[y].y);
        e[i].u = x;
        e[i].v = y;
        sum += e[i].len;
    }
    double res = kruskal();
    printf("%.3lf",sum-res);
    return 0;
}



Measured memory_bytes: 3816
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(1, n - 1):
    if (p[i] > p[i-1] or p[i] > p[i+1]) and not (p[i] > p[i-1] and p[i] > p[i+1]):
        count += 1

print(count)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
	public static void main(String args[]){
    	Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
      
        int[] A = new int[N];
        int[] a = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = scanner.nextInt();
            a[i] = A[i];
        }
		
        int max_first = 0;
        int max_second = 0;
        int max_first_position = 0;
        
        /*
        * 1つ目の最大値の箇所のみ2つ目の最大値を出力。他は最大値を出力。
        * 2つ目の最大値 = 最大値　の可能性もある。
        */
      
        //1つ目の最大値探索
        for(int i = 0; i < N; i++){
            if(A[i] > max_first){
                max_first = A[i];
                max_first_position = i;
            }
        }
      
        a[max_first_position] = 0; //a配列では、1つ目の最大値の箇所を0にする
        
        //2つ目の最大値探索
        for(int i = 0; i < N; i++){
            if(a[i] > max_second){
                max_second = a[i];
            }
        } 
      
        for(int i = 0; i < N; i++){  
            if(a[i] == 0){
                System.out.println(max_second);
            } else {
                System.out.println(max_first);
            }
        } 
    }
}

Measured memory_bytes: 94516
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll X;
    cin >> X;

    int ans = 0;
    ll tmp = 100;
    while(tmp < X) {
        tmp *= 1.01;
        ans++;
    }

    cout << ans << endl;

    
}


Measured memory_bytes: 3640
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long ans = 0L;
		long bef2 = 2L;
		long bef1 = 1L;
		if (n == 1) {
			System.out.println(bef1);
			return;
		}
		for (int i = 2; i <= n; i++) {
			ans = bef1 + bef2;
			bef2 = bef1;
			bef1 = ans;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
typedef long long llong;
// static const int max_n = 110;
// static const llong max_cost = 2000000000000000;
// // vector<vector<llong>> matrix(max_n, vector<llong>(max_n, 0));
// // vector<vector<llong>> adj_matrix(max_n, vector<llong>(max_n, max_cost));
// vector<vector<pair<llong, int>>> adj_list(max_n);
// vector<llong> distance_table(max_n, max_cost);
// set<pair<llong, int>> points_sort_x;
// set<pair<llong, int>> points_sort_y;

// int N;



int main(){
    // int u, v;
    // bool updated = false;
    llong N, M, cost, total_num;
    scanf("%lld %lld", &N, &M);
    vector<llong> goods_list(N);
    for(int i=0;i<N;i++){
        scanf("%lld", &cost);
        // printf("i=%d cost = %lld\n", i, cost);
        goods_list[i] = cost;
        total_num += cost;
    }
    sort(goods_list.begin(), goods_list.end(), greater<llong>());
    // printf("ok3\n");
    llong last_num = goods_list[M-1];
    llong limit = last_num * 4 * M;
    if(limit >= total_num)printf("Yes\n");
    else printf("No\n");
    // double limit = 1. / (double)(4 * M);



    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
long long int pwo(long long int x,long long int y)
{
    long long int i,a,mod = 1000000000 + 7;
    a = x;
    if(y == 0)
    {
        return 1;
    }
    for(i = 1 ; i < y ; i++)
    {
        x = x*a;
        x = x;
    }
    return x;
}
int main(void)
{
    long long int n,i,j,mod = 1000000000 + 7,sum = 0;
    scanf("%lld",&n);
    if(n >= 30)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    
    return 0;
}

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

class Progaram
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var line = Console.ReadLine().Split(' ');

        for (var i = 0; n > i; i++)
        {
            if (int.Parse(line[i]) % 2 == 0 && (int.Parse(line[i]) % 3 != 0 && int.Parse(line[i]) % 5 != 0))
            {
                Console.WriteLine("DENIED");
                return;
            }
        }

        Console.WriteLine("APPROVED");
    }
}

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

int main() {
  int x, y, group[]={0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
  cin >> x >> y;

  cout << (group[x]==group[y] ? "Yes": "No");
}

Measured memory_bytes: 256
use std::cmp;

fn main() {
    // input
    // N
    let _ = read_line::<usize>();
    // B
    let b = read_vec::<u64>();

    let mut before = std::u64::MAX;
    let mut ans: u64 = *(b.last().unwrap());
    for now in b {
        ans += cmp::min(before, now);
        before = now;
    }
    println!("{}", ans);
}

#[allow(dead_code)]
fn read_line<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<tuple>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll h[100005];
ll dp[100005];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);
	for (int i = 1; i < n; i++) {
		dp[i + 1] = min(dp[i] + abs(h[i+1] - h[i]), dp[i - 1] + abs(h[i+1] - h[i - 1]));
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 5132