akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)
 
ll calcNumOfCombination(ll n, ll r) {
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}
 
 
int main() {
    ll n;
    cin >> n;
    ll ans = 0;
 
    for (ll i = 1; i <= n; i++) {
        if (i % 3 == 0 || i % 5 == 0) {
 
        } else {
            ans += i;
        }
 
    }
 
    cout << ans << endl;
 
    return 0;
}

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

using namespace std;
using ll=long long;
using vi=vector<int>;
using vl=vector<ll>;
using vs=vector<string>;

#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define rep(i, a, n) for (int i = (n); i < (a); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)

template<typename T,typename U>
void Inparray(T &f,U n){
  for(int i=0;i<n;i++) cin>>f[i];
}

template<typename T,typename U>
void Printarray(T f,U n){
  for(int i=0;i<n;i++) i!=n ? cout<<f[i]<<" " : cout<<f[i];
}

void flagfunc(bool flag,string A,string B){
  flag ? cout<<A<<endl : cout<<B<<endl;
}

void flag2func(bool flag){
  flag ? cout<<"Yes"<<endl : cout<<"No"<<endl;
}

void flag3func(bool flag){
  flag ? cout<<"YES"<<endl : cout<<"NO"<<endl;
}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  string c;cin>>c;
  flagfunc(c=="a" || c=="e" || c=="i" || c=="o" || c=="u","vowel","consonant");
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
    int n;
    char buf[20];
    while( 1 == scanf("%s", buf) ) {
        const char s[] = "CODEFESTIVAL2016";
        int count = 0;
        for (int i = 0; s[i]; ++i) {
            if (buf[i] != s[i]) {
                ++count;
            }
        }
        printf("%d\n", count);
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MX = 3e5+5;


template<typename T> struct seg_tree {
	T seg[4*MX], tmp[4*MX];
	inline T pull(const T & a, const T & b) { return a+b; }
	inline void push(int l, int r, int n) {
		seg[n] += (r-l+1)*tmp[n];
		if (l != r) tmp[n<<1] += tmp[n], tmp[n<<1|1] += tmp[n];
		tmp[n] = 0;
	}
	void update(int a, int b, T v, int l = 0, int r = MX-1, int n = 1) {
		push(l, r, n);
		if (l > r || l > b || r < a) return;
		if (l >= a && r <= b) { tmp[n] += v, push(l, r, n); return; }
		int m = l+r>>1;
		update(a, b, v, l, m, n<<1), update(a, b, v, m+1, r, n<<1|1);
		seg[n] = pull(seg[n<<1], seg[n<<1|1]);
	}
	T query(int a, int b, int l = 0, int r = MX-1, int n = 1) {
		if (a > b || l > b || r < a) return 0;
		push(l, r, n);
		if (l >= a && r <= b) return seg[n];
		int m = l+r>>1;
		return pull(query(a, b, l, m, n<<1), query(a, b, m+1, r, n<<1|1));
	}
};


ii A[MX];
seg_tree<int> st;

int main() {
	if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
	ios_base::sync_with_stdio(0), cin.tie(0);

	int N, M; cin >> N >> M;
	for (int i = 0; i < N; ++i) cin >> A[i].f >> A[i].s;
	sort(A, A+N, [](auto a, auto b) { return a.s-a.f < b.s-b.f; });

	for (int i = 1, j = 0; i <= M; ++i) {
		while (j < N && A[j].s-A[j].f < i) st.update(A[j].f, A[j].s, 1), ++j;
		int ans = N-j;
		for (int k = 0; k <= M; k += i) ans += st.query(k, k);
		cout << ans << '\n';
	}
}


Measured memory_bytes: 8760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, ll> Pil;

int K;

int main() {
    cin >> K;

    for (int i = 0; i < K; i++) {
        cout << "ACL";
    }
    cout << endl;
    
    return 0; 
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define lp(i,n) for(int i=0;i<n;i++)
#define DEKAI 1000000007
#define INF (1<<28)
#define int long long
/* ┗(^o^)┛ｗｗｗｗｗ┏(^o^)┓ﾄﾞｺﾄﾞｺﾄﾞｺﾄﾞｺｗｗｗｗｗ */

signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a<b) swap(a,b);
	if(a<c) swap(a,c);
	cout<<a*10+b+c<<endl;
	return 0;
}


Measured memory_bytes: 256
import itertools

n = int(input())
a = tuple(map(int,input().split()))
b = tuple(map(int,input().split()))

ls = [i for i in range(1, n + 1)]
pls = list(itertools.permutations(ls, n))

x1 = pls.index(a)
x2 = pls.index(b)
print(abs(x1 - x2))


Measured memory_bytes: 13900
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
#define N 150000
#define LL long long
#define rep(i,j,k) for(i=j;i<=k;++i)
struct node{ LL a,b; };
int n,m,i,j,k,a,b;
int fa[N],v[N],ch[N][2],f[N];
LL ma[N];
vector<node> s[N];
LL l,r,mid;
void read(int &p){
	p=0; char x=getchar();
	while(x<'0' || x>'9') x=getchar();
	while(x>='0'&&x<='9'){p=p*10+x-'0'; x=getchar();}
}
bool bmp_b(node a,node b){ return a.b<b.b; }
bool bmp_a(node a,node b){ return a.a<b.a; }
void merge(int x,int lc,int rc,LL mid){
	int sl=s[lc].size(),sr=s[rc].size();
	if((!sl)||(!sr)) return ;
	sort(s[lc].begin(),s[lc].end(),bmp_b);
	sort(s[rc].begin(),s[rc].end(),bmp_a);
	j=sr-1; k=f[0]=0; ma[0]=-1; b=s[rc][0].b;
	rep(i,1,j){
		ma[i]=-1;
		if(b>s[rc][i].b){ 
			b=s[rc][i].b; k=i;
		}
		f[i]=k;
	}
	rep(i,0,sl-1){
		b=s[lc][i].b;
		while((j>=0)&&(b+s[rc][j].a>mid)) j--;
		if(j>=0){
			if(ma[f[j]]==-1) ma[f[j]]=s[lc][i].a;
			else ma[f[j]]=min(s[lc][i].a,ma[f[j]]);
		}
	}
	rep(i,0,sr-1)
	if(ma[i]>=0)
		s[x].push_back((node){ma[i]+v[lc],s[rc][i].b+v[rc]});
}
void dfs(int x){
	if(!x) return ;
	s[x].clear();
	dfs(ch[x][0]); 
	dfs(ch[x][1]);
	if(!ch[x][0]){
		s[x].push_back((node){0,0});
		return ;
	}else{
		merge(x,ch[x][0],ch[x][1],mid-v[ch[x][0]]-v[ch[x][1]]);
		merge(x,ch[x][1],ch[x][0],mid-v[ch[x][0]]-v[ch[x][1]]);
	}
}
int check(LL mid){
	dfs(1);
	return s[1].size();
}
int main(){
//	freopen("in.txt","r",stdin);
	read(n);
	rep(i,2,n){
		read(fa[i]); read(v[i]);
		if(ch[fa[i]][0]) ch[fa[i]][1]=i;
		else ch[fa[i]][0]=i;
	}
	l=0; r=131072*1LL*131072;
	while(l<r){
		if(r-l>1) mid=(l+r)>>1;
		else mid=l;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%lld\n",l);
	return 0;
}

Measured memory_bytes: 30376
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] V = new int[N];
        
        for(int i = 0; i < N; i++){
            V[i] = sc.nextInt();
        }
        
        int gemScoreMax = 0;
        for(int l = 0; l <= K; l++){
            for(int r = 0; r <= K - l; r++){
                
                if( l + r > N ) break;
                
                List<Integer> takenOutGems = new ArrayList<>();
                int gemScore = 0;
                
                for(int i = 0; i < l; i++){
                    gemScore += V[i];
                    takenOutGems.add(V[i]);
                }
                
                for(int i = 0; i < r; i++){
                    gemScore += V[N-1-i];
                    takenOutGems.add(V[N-1-i]);
                }
                
                Collections.sort(takenOutGems);
                
                int canDeleteNum = K - l - r;
                for(int i = 0; i < canDeleteNum; i++){
                    if ( i >= takenOutGems.size() ) break;
                    if ( takenOutGems.get(i) > 0 ) break;
                    gemScore -= takenOutGems.get(i);
                }
                
                gemScoreMax = Math.max(gemScoreMax, gemScore);
                
            }
        }
        
        System.out.println(gemScoreMax);
    }
}


Measured memory_bytes: 25300
import sys

def find_word_v4():
    W = input()
    s = sys.stdin.readline()
    count = 0

    while s != "END_OF_TEXT\n" and s != "END_OF_TEXT":
        words = s.lower().split()
        count += words.count(W)
        s = sys.stdin.readline()

    print(count)


if __name__ == "__main__":
    find_word_v4()



Measured memory_bytes: 5568
package main

import (
	"fmt"
)

func main() {
	var t, pdmax string
	fmt.Scanf("%s", &t)

	for _, r := range t {
		if r == '?' {
			pdmax += "D"
		} else {
			pdmax += string(r)
		}
	}

	fmt.Printf("%s\n", pdmax)
}


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

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

int main() {
    int h1, m1, h2, m2, k, H1, H2, ans;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    H1 = h1 * 60 + m1;
    H2 = h2 * 60 + m2;
    ans = H2 - H1 - k;

    cout << ans << endl;
    return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n;string s;
    cin >> n >> s;
    ll res = 0,x = 0;
    rep(i,n){
        if(s[i] == 'I')x++;
        else x--;
        res = max(res,x);
    }
    out(res);
}


Measured memory_bytes: 256
a, b = map(int, input().split())
L = [["#"]*100 for _ in range(50)] + [["."]*100 for _ in range(50)]
qa, ra = divmod(a-1, 50)
for i in range(qa):
  L[i*2] = ["#" if j%2 else "." for j in range(100)]
L[qa*2] = ["#" if j%2 else "." for j in range(ra*2)] + ["#"]*(100-ra*2)
qb, rb = divmod(b-1, 50)
for i in range(qb):
  L[51+i*2] = ["." if j%2 else "#" for j in range(100)]
L[51+qb*2] = ["." if j%2 else "#" for j in range(rb*2)] + ["."]*(100-rb*2)
print(100, 100)
for l in L:
  print(*l, sep="")

Measured memory_bytes: 4596
#include<stdio.h>
#include <math.h>

int main(){
    int N , i , F_max , S_max , F_max_arg , S_max_arg;
    int tmp;
    F_max_arg   =   0;
    S_max_arg   =   0;
    F_max_arg   =   0;
    S_max_arg   =   0;
    scanf("%d",&N);
    for (i = 0 ; i < N ; i++){
        scanf("%d",&tmp);
        if(F_max <= tmp){
            S_max       =   F_max;
            S_max_arg   =   F_max_arg;
            F_max       =   tmp;
            F_max_arg   =   i;
        }else if(S_max <= tmp){
            S_max       =   tmp;
            S_max_arg   =   i;
        }
    }
    for(i = 0 ; i < N ; i++){
        if(i == F_max_arg){
            printf("%d\n",S_max);
        }else{
            printf("%d\n",F_max);
        }
    }
    
    return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   int x,a,b;
   cin >> x >> a >> b;

   if(abs(a-x) > abs(b-x)) cout <<"B" << endl;
   else cout << "A" << endl;

   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdio.h>

using namespace std;

double dabs(double a){
	if (a>0) return a;
	else return -a;
}

int main(){
	int n;
	int x[1000],y[1000];
	double D1=0,D2=0,D3=0,Dm=0;
	cin >> n;
	
	for (int i = 0; i < n; i++)	cin >> x[i];
	for (int i = 0; i < n; i++)	cin >> y[i];
	
	
	for (int i = 0; i < n; i++){	
		D1 += dabs(x[i]-y[i]);
		D2 += pow(dabs(x[i]-y[i]),2);
		D3 += pow(dabs(x[i]-y[i]),3);
		Dm = Dm < dabs(x[i]-y[i]) ? dabs(x[i]-y[i]):Dm;
	}
	
	printf("%.8f\n",D1);	
	printf("%.8f\n",sqrt(D2));
	printf("%.8f\n",pow(D3,1.0/3.0));
	printf("%.8f\n",Dm);
	return 0;
}

Measured memory_bytes: 1240
import sys
S = int(input())
a_list = []
a_list.append(S)

def function(n):
    if (n%2)==0:
        return int((n/2))
    else:
        return int((3*n+1))

for i in range(10000):
    if i>1:
        tmp=function(a_list[i-2])
        a_list.append(tmp)
        for j in range(i-1):
            if a_list[i-1]==a_list[j]:
                print(i)
                sys.exit()

Measured memory_bytes: 3064
x,y,a,b,c = list(map(int,input().split()))
parr = list(map(int,input().split()));parr.sort(reverse=True);parr = parr[:x]
qarr = list(map(int,input().split()));qarr.sort(reverse=True);qarr = qarr[:y]
rarr = list(map(int,input().split()))
arr = parr+qarr+rarr
arr.sort(reverse=True)
print(sum(arr[:x+y]))

Measured memory_bytes: 22528
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define fbo find_by_order
#define ook order_of_key
#define INF (ll)1e18
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    string s;cin>>s;
    if(s.size()<=n)cout<<s<<"\n";
    else cout<<s.substr(0,n)<<"...\n";
}


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

int M,N,K;
int planet[1005][1005][3] = {};

int ijoi(char c){
	switch(c){
		case 'J':
			return 0;
		case 'O':
			return 1;
		case 'I':
			return 2;
	}
	cout << "err" << endl;
	return -1;
}

void add(int i,const char *line){
	int joi[3] = {};
	for(int k=0;k<N;++k){
		joi[ijoi(line[k])]++;
		copy(joi,joi+3,planet[i][k+1]);
	}
}

int main(){
	cin >> M >> N >> K;
	for(int i=0;i<M;++i){
		char buf[10005];
		scanf("%s",buf);
		add(i,buf);
	}

	for(int i=0;i<K;++i){
		int m1,n1,m2,n2;
		int joi[3] = {};
		cin >> m1 >> n1 >> m2 >> n2;
		for(int k=m1-1;k<m2;++k){
			for(int j=0;j<3;++j){
				joi[j] += planet[k][n2][j] - planet[k][n1-1][j];
			}
		}
		printf("%d %d %d\n",joi[0],joi[1],joi[2]);
	}
	return 0;
}

Measured memory_bytes: 12828
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define int long long
int n;
char s[500][500];
int f1(int p) {
	if (p >= n)return p - n;
	else return p;
}
bool f(int k) {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (s[i][f1(j+k)] != s[j][f1(i+k)])return 0;
		}
	}
	return 1;
}
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)cin >> s[i][j];
	}
	int ans = 0;
	for (int i = 0; i < n; i++)if (f(i))ans += n;
	cout << ans << endl;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

def main():
    H,W = map(int,input().split())

    # 番兵法 (#を外周に設置する)
    visited = [[True]*(W+2)]
    visited += [[True] + [x == '#' for x in input().rstrip()] + [True] for _ in range(H)]
    visited.append([True]*(W+2))

    # #の位置をqに格納
    q = []
    for i in range(1,H+1):
        for j in range(1,W+1):
            if visited[i][j]:
                q.append((i,j))

    # dx,dyを使用せずにBFS 
    # 定数倍改善
    ans = -1
    while q:
        qq = []
        # 新たに#となった地点をqqに格納
        for x,y in q:
            if not visited[x-1][y]:
                visited[x-1][y] = True
                qq.append((x-1,y))
            if not visited[x+1][y]:
                visited[x+1][y] = True
                qq.append((x+1,y))
            if not visited[x][y-1]:
                visited[x][y-1] = True
                qq.append((x,y-1))
            if not visited[x][y+1]:
                visited[x][y+1] = True
                qq.append((x,y+1))
        q = qq
        ans += 1
    
    print(ans)

if __name__ == '__main__':
    main()

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

int main() {
  string s,t;
  cin >> s >> t;

  string temp = t;
  for(int i=0; i<s.length(); i++) {
    for(int j=0; j<s.length(); j++) {
      temp[j] = t[(j+i)%s.length()];
    }
    if(s == temp) {
      cout << "Yes" << endl;
      break;
    }
    if(i == s.length()-1) {
      cout << "No" << endl;
    }
  } 
  return 0;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int n, m;
vector<P> S,A,B,C;

void shuffle(int x,int y){
  
  A.clear();
  B.clear();
  C.clear();

  int idx=0;
  
  for(int i=0;i<S.size();i++){
    
    int d=S[i].second-S[i].first+1;
    int f=0;
    
    if(d<=x){
      if(d==x) f=1;
      A.push_back(S[i]);
      
      x-=d;
      
    }
    else{
      
      A.push_back(P(S[i].first,S[i].first+x-1));
      
      S[i]=P(S[i].first+x,S[i].second);
      
      x=0;
           
    }
    
    idx=i+f;
    
    if(!x) break;
  }
  
  for(int i=idx;i<S.size();i++){
  
    int d=S[i].second-S[i].first+1;
    int f=0;
    if(d<=y){
      if(d==y) f=1;
      B.push_back(S[i]);
      
      y-=d;
      
    }
    else{
      
      B.push_back(P(S[i].first,S[i].first+y-1));
      
      S[i]=P(S[i].first+y,S[i].second);
      
      y=0;
            
    }
    
    idx=i+f;
    
    if(!y) break;
  }
  
  for(int i=idx;i<S.size();i++) C.push_back(S[i]);
    
  S.clear();

  for(int i=0;i<C.size();i++) S.push_back(C[i]);
  
  for(int i=0;i<B.size();i++) S.push_back(B[i]);
  
  for(int i=0;i<A.size();i++) S.push_back(A[i]);
  
}

int cal(int p,int q,int r){
  
  int res=0;

  q=q-p+1;
  p--;
  for(int i=0;i<S.size();i++){
  
    int d=S[i].second-S[i].first+1;
	
    if(d<=p){
      
      p-=d;
      
      S.erase(S.begin());
      
      i--;
    }
    else{
      
      S[i]=P(S[i].first+p,S[i].second);
      
      p=0;
            
    }
    
    if(!p) break;
  }

  for(int i=0;i<S.size();i++){

    int d=S[i].second-S[i].first+1;

    if(d<=q){
      
      if(S[i].first<=r) res+=min(r,S[i].second)-S[i].first+1;
      
      q-=d;
    }else{
      
      S[i]=P(S[i].first,S[i].first+q-1);
      
      if(S[i].first<=r) res+=min(r,S[i].second)-S[i].first+1;
    
      q=0;
    }
    
    if(!q) break;
  }
  
  return res;
}

int main(){

  while(1){
    
    cin>>n;
    if(!n) break;
    
    cin>>m;
    
    int p, q, r;

    cin>>p>>q>>r;
        
    S.clear();
    
    S.push_back(P(1,n));
    
    for(int i=0;i<m;i++){

      int x, y;
      cin>>x>>y;
      
      shuffle(x,y-x);
    }
    
    cout<<cal(p,q,r)<<endl;
    
  }
  
  return 0;
}

Measured memory_bytes: 3256
#include<iostream>

using namespace std;

int main(){
    int N, i, j;
    cin >> N;
    int a[N + 1];
    for (i = 0; i < N; ++i){
        cin >> a[i];
    }
    i = 0;
    while(true){
        ++j;
        i = a[i];
        if(i == 2){
            cout << j << endl;
            break;
        }
        if(N < j){
            cout << "-1" << endl;
            break;
        }
        i = i - 1;
    }
    return 0;
}

Measured memory_bytes: 640
N, K = map(int, input().split())
lists = []
res = []

for i in range(1, N + 1):
    lists.append(int(i))

for _ in range(K):
    d = int(input())
    A = input().split()
    for p in range(len(A)):
        res.append(int(A[p]))

res_l = set(lists)
res_s = set(res)
result = res_l - res_s

li = list(result)
cnt = len(li)
print(cnt)


Measured memory_bytes: 9204
#include <iostream>
#include <vector>
using namespace std;
using int64 = long long;
#define int int64

signed main(){
  int n;cin>>n;
  vector<int> t(n),a(n);
  for(int i=0;i<n;++i){
    cin>>t[i]>>a[i];
  }

  int p=1,q=1;
  for(int i=0;i<n;++i){
    int tmp = max((p+t[i]-1)/t[i], (q+a[i]-1)/a[i]);
    p = tmp * t[i];
    q = tmp * a[i];
  }

  cout<<p+q<<endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <utility>

using namespace std;

template <class T>
using lp_queue=priority_queue<T, deque<T>, greater<T>>;

using Weight=long long;
static const Weight INF=1LL<<57;

struct Edge {
    size_t src, dst;
    Weight weight;
    Edge() {}
    Edge(size_t src, size_t dst, Weight weight=1):
        src(src), dst(dst), weight(weight)
    {}
};

bool operator<(const Edge &e, const Edge &f) {
    if (e.weight != f.weight) {
        return e.weight > f.weight;
    } else {
        return e.src!=f.src? e.src<f.src : e.dst<f.dst;
    }
}

using Edges=vector<Edge>;
using Vertex=vector<Edge>;
using Graph=vector<Vertex>;

void join(Graph &g, size_t s, size_t d, Weight w=1) {
    // non-directed
    g[s].push_back(Edge(s, d, w));
    g[d].push_back(Edge(d, s, w));
}

void connect(Graph &g, size_t s, size_t d, Weight w=1) {
    // directed
    g[s].push_back(Edge(s, d, w));
}

pair<Weight, size_t> visit(const Graph &g, size_t s, size_t v) {
    pair<Weight, size_t> r(0, v);
    for (const Edge &e: g[v]) if (e.dst != s) {
        pair<Weight, size_t> t=visit(g, v, e.dst);
        t.first += e.weight;
        if (r.first < t.first)
            r = t;
    }
    return r;
}

Weight get_diameter(const Graph &g) {
    pair<Weight, size_t> r=visit(g, -1, 0), t=visit(g, -1, r.second);
    return t.first;  // <r.second, t.second>
}

int main() {
    size_t V, E;
    scanf("%zu", &V);
    E = V-1;

    Graph g(V);
    for (size_t i=0; i<E; ++i) {
        size_t s, t;
        Weight w;
        scanf("%zu %zu %lld", &s, &t, &w);

        join(g, s, t, w);
    }

    printf("%lld\n", get_diameter(g));
    return 0;
}

Measured memory_bytes: 18800
n,k = map(int,input().split())
sunuke_ls = [1] * n
for i in range(k):
    d = int(input())
    a_ls = list(map(int,input().split()))
    for j in range(d):
        sunuke_ls[a_ls[j]-1] = 0
print(sum(sunuke_ls))

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define        sqr(a)       ((a)*(a))
int ar[600][600];
int main()
{
     int i,j,k,n,x,m;

    cin >> n>>  m ;

    for(i=1;i<=n;i++)for(j=1;j<=m;j++)cin >> ar[i][j];
    vector<pair<pii,pii>>ans;
    for(i=1;i<=n-1;i++)
    {
        for(j=1;j<=m;j++)
        {
            if(ar[i][j]%2)
            {
                ar[i][j]--;
                ar[i+1][j]++;
                ans.pb({{i,j},{i+1,j}});
            }
        }
    }

    for(i=1;i<=m-1;i++)
    {
        if(ar[n][i]%2)
        {
            ar[n][i]--;
            ar[n][i+1]++;

            ans.pb({{n,i},{n,i+1}});
        }
    }
     
//     for(i=1;i<=n;i++)
//    {
//        for(j = 1;j<=m;j++)cout << ar[i][j]<<" ";
//
//        cout << endl;
//    }

    cout << ans.size() << endl;

    for(auto x : ans)cout << x.F.F << " " << x.F.S << " " << x.S.F << " " << x.S.S << endl;

  

//    ll cnt = 0;
//    for(i=0; i<n; i++)
//    {
//        cin >> ar[i];
//    }
//
//    for(i=1; i<n; i++)
//    {
//        m = ar[i]+ar[i-1];
//        if(m>x)
//        {
//            ll baki = m-x,f1,f2;
//             cnt += baki;
//
//            f1 = min(ar[i],baki);
//
//            ar[i] -= f1;
//            baki -= f1;
//
//            f1 = min(ar[i-1],baki);
//
//            ar[i-1] -= f1;
//
//
//
//        }
//    }
//
//    cout << cnt << endl;
}


Measured memory_bytes: 6548
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long INF = INT_MAX;
const long long LINF = LLONG_MAX;
const long long N = 5e5+1;
 
typedef long long ll;
typedef long double ld;  

void test_case()
{  
    char c;
    cin >> c;
    if( c >= 'a' && c <= 'z')
        cout << 'a' <<'\n';
    else
        cout << 'A' << '\n';
}
 
int32_t main()
{
    IOS(); 
  
    int tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

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

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

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n;
            n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = in.nextInt();
            }
            boolean flag = false;
            int i = 1, j = 0;
            while (j++ < n) {
                if (arr[i - 1] == 2) {
                    flag = true;
                    break;
                } else {
                    i = arr[i - 1];
                }
            }
            out.println(flag == true ? j : -1);
        }

    }
}



Measured memory_bytes: 50960
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
template <typename T, typename U>
T max(T x, U y)
{
    return x>y ? x : y;
}
template <typename T, typename U>
T min(T x, U y)
{
    return x<y ? x : y;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,w;cin >> n >> w;
    ll a[n],b[n];
    for (int i = 0; i < n; ++i)
    {
    	cin >> a[i];cin >> b[i];
    }
    ll dp[n+1][w+1];
    for (int i = 0; i <= n; ++i)
    {
    	for (int j = 0; j <= w; ++j)
    	{
    		dp[i][j]=0;
    	}
    }
    /*for (int i = 0; i <=n; ++i)
    {
    	for (int j = 0; j <=w; ++j)
    	{
    		trace(dp[i][j]);
    	}
    }*/
    for (int i = 0; i <= n; ++i)
    {
    	for (int j = 0; j <= w; ++j)
    	{
    		if(i==0 or j==0)dp[i][j]=0;
    		else
    		{
    			if(a[i-1]<=j)dp[i][j]=max3(dp[i][j],dp[i-1][j-a[i-1]]+b[i-1],dp[i-1][j]);
    			else 
    				dp[i][j]=max(dp[i][j],dp[i-1][j]);
    		}

    	}
    }
    
    cout << dp[n][w];
    }

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define N 1000
using namespace std;
int n;
char s[N];
int main() {
	cin >> n;
	cin >> s;
	int cnt = 0;
	int lft = 0;
	for (int i = 0; i < n; i ++) {
		if (s[i] == '(') cnt ++;
		else cnt --;
		if (cnt < 0) {
			lft ++;
			cnt = 0;
		}
	}
	for (int i = 1; i <= lft; i ++) {
		printf("(");
	}
	printf("%s", s);
	for (int i = 1; i <= cnt; i ++) {
		printf(")");
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

int main(){
	int n;
	cin >> n;
	if (ceil(n/1.08) < (n+1)/1.08 )
	{
		cout << (int)ceil(n/1.08) << endl;	
	}
	else cout << ":(" << endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	int n;
	int array[];
	int q;
	int m[];
	Scanner scan;
	public static void main(String args[]) {
		new Main().run();
	}
	Main() {
		scan = new Scanner(System.in);
		n = scan.nextInt();
		array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = scan.nextInt();
		}

	}

	void run() {
		boolean ans[] = new boolean[2 << n];
		for (int i = 0; i < 2 << n; i++) {
			boolean bits[] = toBoolean(i);
			int num = 0;
			for (int j = 0; j < n; j++) {
				if (bits[j]) {
					num += array[j];
				}
			}
			ans[num] = true;
		}
		q = scan.nextInt();
		for (int i = 0; i < q; i++) {
			int m = scan.nextInt();
			if (m < ans.length && ans[m]) {
				System.out.println("yes");
			} else {
				System.out.println("no");
			}
		}
	}

	boolean[] toBoolean(int num) {
		boolean[] bits = new boolean[n];
		for (int i = 0; i < n; i ++) {
			bits[i] = (num  & 1) == 1;
			num = num >>> 1;
		}
		return bits;
	}
}



Measured memory_bytes: 62972
sx,sy,tx,ty = map(int,input().split())
dx, dy = tx-sx, ty-sy
ans = ''
for i in range(2):
    for x in range(dx):
        if i==0:
            ans += 'R'
        else:
            ans += 'L'
    for y in range(dy):
        if i==0:
            ans += 'U'
        else:
            ans += 'D'
for i in range(2):
    if i==0:
        ans += 'L'
    else:
        ans += 'R'
    for y in range(dy+1):
        if i==0:
            ans += 'U'
        else:
            ans += 'D'
    for x in range(dx+1):
        if i==0:
            ans += 'R'
        else:
            ans += 'L'
    if i==0:
        ans += 'D'
    else:
        ans += 'U'
print(ans)


Measured memory_bytes: 43996
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    bool ok = false;
    rep (i, s.size() - 1) {
        cerr << s.substr(i, 2) << "\n";
        if (s.substr(i, 2) == "AC") ok = true;
    }
    cout << (ok ? "Yes\n" : "No\n");
    return 0;
}

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

int main(){
    char s[10],r;
    int i;
    
    while(cin>>s){
        r='d';
        for(int i=0; i<3; i++){
            if(s[0+3*i]==s[1+3*i]&&s[1+3*i]==s[2+3*i]&&s[0+3*i]!='s'){
                r=s[3*i];
                break;
            }
            else if(s[0+i]==s[3+i]&&s[3+i]==s[6+i]&&s[0+i]!='s'){
                r=s[i];
                break;
            }
        }
        if(s[0]==s[4]&&s[4]==s[8]&&s[0]!='s') r=s[0];
        else if(s[2]==s[4]&&s[4]==s[6]&&s[2]!='s') r=s[2];
        cout << r << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1132
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<stack> 

using namespace std;

const int maxn=1e5+5;

int fa[maxn],a[maxn],b[maxn];
pair<int,int>sx[maxn],sy[maxn];

int find(int x)
{     
      return x==fa[x]?x:fa[x]=find(fa[x]);
} 
int un(int x,int y)
{     
      x=find(x);
      y=find(y);
	  if(x==y)
	    return 0;
	  fa[x]=y;
	  return 1;
}
int minn(int x,int y)
{     
      return min(abs(a[x]-a[y]),abs(b[x]-b[y]));
}
int main()
{     
      int n,m,j,i,k;
      cin>>n;
      for(i=0;i<n;++i){
      	cin>>a[i]>>b[i];
      	fa[i]=i;
      	sx[i]=make_pair(a[i],i);
      	sy[i]=make_pair(b[i],i);
		  }
	  
      sort(sx,sx+n);
      sort(sy,sy+n);
      
      set<pair<int,pair<int,int> > >st;
      
      for(i=0;i<n-1;++i){
      	st.insert(make_pair(minn(sx[i].second,sx[i+1].second),
		  make_pair(sx[i].second,sx[i+1].second)));
      	st.insert(make_pair(minn(sy[i].second,sy[i+1].second),
		  make_pair(sy[i].second,sy[i+1].second)));
		  }
	  
      int res=0;
      while((int)st.size()){
	    for(set<pair<int,pair<int,int> > >::iterator it=st.begin();it!=st.end();it++){
		   	st.erase(it);
		   	int u=(*it).second.first;
		   	int v=(*it).second.second;
		   	res+=un(u,v)*minn(u,v);
			   }
			}
	  
	  cout<<res<<endl;
	  
	  return 0;
}


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

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

    vector<int> a(N);

    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    int Alice = 0, Bob = 0;

    for (int i = 0; i < N; i++) {
        if ((i % 2) == 0)
            Alice += a.at(i);
        else
            Bob += a.at(i);
    }

    cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  if(n == 1){
    cout << "Hello World";
  }else{
    int a, b;
    cin >> a >> b;
    cout << a + b;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    int N, ans = 0;
    cin >> N;
    for (int i = 0, a; i < N; i++) {
        cin >> a;
        while (a % 2 == 0) {
            ans++;
            a /= 2;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <set>
#include <cstdio>

using namespace std;
const int Max_N(200050);

struct node
{
	node(int _l = 0, int _r = 0, int _c = 0) : l(_l), r(_r), c(_c) {}
	int l, r, c;
	inline bool operator<(const node &b) const
	{
		return l < b.l;
	}
};

int N, A[Max_N];

bool check(int D)
{
	set<node> S;
	S.insert(node(1, A[1], 0));
	for (int i = 2;i <= N;++i)
		if (A[i] > A[i - 1])
			S.insert(node(A[i - 1] + 1, A[i], 0));
		else
		{
			for (node t;(t = *S.rbegin()).r > A[i];)
			{
				S.erase(t);
				if (t.l <= A[i])
				{
					t.r = A[i], S.insert(t);
					break;
				}
			}
			int _l = 0X3F3F3F3F;
			for (set<node>::reverse_iterator it = S.rbegin();it != S.rend();it = S.rbegin())
			{
				node t = *it;
				S.erase(t);
				if (t.c + 1 < D)
				{
					if (t.l <= t.r - 1)
						S.insert(node(t.l, t.r - 1, t.c));
					S.insert(node(t.r, t.r, t.c + 1));
					goto loop;
				}
				else
					_l = t.l;
			}
			return false;
			loop :
			if (_l <= A[i])
				S.insert(node(_l, A[i], 0));
		}
	return true;
}

int main()
{
	scanf("%d", &N);
	for (int i = 1;i <= N;++i)
		scanf("%d", A + i);
	int l = 1, r = N + 1, mid;
	while (l < r)
	{
		mid = l + ((r - l) >> 1);
		if (check(mid))
			r = mid;
		else
			l = mid + 1;
	}
	printf("%d", l);
	return 0;
}

Measured memory_bytes: 13568
#include<bits/stdc++.h>
using namespace std;
long long arr[305][305];
bool banned[305][305];
int main(){
	int n;
	cin>>n;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			cin>>arr[i][j];
		}
	}
	for(int k=1; k<=n; k++){
		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				if(i==j || j==k || k==i) continue;
				if(arr[i][k]+arr[k][j]<arr[i][j]){
					cout<<-1;
					return 0;
				}
				if(arr[i][k]+arr[k][j]==arr[i][j]) banned[i][j] = true;
			}
		}
	}
	long long ans = 0;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			if(!banned[i][j]) ans+=arr[i][j];
		}
	}
	cout<<ans/2;
}

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

#define ll long long

using namespace std;

int main()
{
	ll s, t; cin>>s>>t;
	ll p, q, M; cin>>p>>q>>M;
	ll y; cin>>y;

	const ll MAX = 1e8;

	ll ans = y;
	ll a = 0;
	for(int i=1;i<MAX;i++){
		a = (a*p+q)%M;
		ans = ans xor a;
	}
	cout << ans << "\n";
	return 0;
}


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

#define int long long
#define rep(i, l, r) for (int i = (int)(l); i < (int)(r); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)x.size())
template <class T> bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> using V = vector<T>;
using P = pair<int, int>;

/*
 *  */

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

  V<string> s(n);
  map<string, int> cnt;
  rep(i, 0, n){
    cin >> s[i];
    cnt[s[i]]++;
  }

  int ma = -1;
  set<string> st;
  for(auto i : cnt){
    if(i.second > ma){
      ma = i.second;
      st.clear();
      st.insert(i.first);
    }else if(i.second == ma){
      st.insert(i.first);
    }
  }

  for(auto i : st){
    cout << i << endl;
  }

  return 0;
}


Measured memory_bytes: 36096
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define PI 3.141592653589793238
int main()
{
    // #ifndef ONLINE_JUDGE
    // freopen("F:/cpp/input.txt", "r", stdin);
    // freopen("F:/cpp/output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    ll a[n],i, sum = 0, q, x, y;
    unordered_map <ll, ll> mp;
    for (i=0;i<n;i++)
    {
        cin >> a[i];
        mp[a[i]]++;
        sum += a[i];
    }
    cin >> q;
    while (q--)
    {
        cin >> x >> y;
        sum = sum - mp[x]*x + mp[x]*y;
        mp[y] += mp[x];
        mp[x] = 0;
        cout << sum << "\n";
    }
    return 0;
}

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

#define MAX 200
#define SMAX 1000000
int stack[MAX];
int top=0;

void define_code(void);//0~9,+,-,*,/に対応する文字コードを特定する。
void initialize(void);//topを0にしてスタックを初期化する
int isEmpty(void);//スタックが空なら１を返す
int isFull(void);//スタックが満杯なら１を返す
void push(int push_num);//値をpushする
int pop(void);
void cal(char str);//計算を行う
void stack_input(void);//スタックに値を入れる
//
int main(void)
{
    initialize();
    stack_input();
    printf("%d\n",stack[1]);
    return 0;
}
//
void initialize(void)
{
    top=0;
}
int isEmpty(void)
{
    if(top==0){return 1;}
    else{return 0;}
}
int isFull(void)
{
    if(top>=MAX-1){return 1;}
    else{return 0;} 
}
void push(int push_num)
{
    if (isFull())
    {
        //printf("over-flow\n");
        exit(1);
    }
    else
    {
        top++;
        stack[top] = push_num;
        //printf("push:%d\n",push_num);
    }
}
int pop(void)
{
    if(isEmpty())
    {
        //printf("under-flow\n");
        exit(1);
    }
    else
    {
        top--;
        //printf("pop:%d\n",stack[top+1]);
        return stack[top+1];
    }
}
void cal(char str)
{
    int x,y;
    x=pop();
    y=pop();
    if(str=='+'){y=y+x;}
    else if(str=='-'){y=y-x;}
    else if(str='*'){y=y*x;}
    push(y);
    
}
void stack_input(void)
{
    char str[SMAX];
    int x;
    fgets(str,SMAX,stdin);
    int i=0;
    while(str[i]>=' ')
    {
        while(isspace(str[i])){i++;}
        if(isdigit(str[i]))
        {
            x=0;
            while(isdigit(str[i]))
            {
                x=10*x+(str[i]-'0');
                i++;
            }
            push(x);
        }
        else
        {
            cal(str[i]);
            i++;
        }
    }
}



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

#[fastout]
fn main() {
    input! {
        n: usize,
        d: f64,
    };
    let mut count = 0;
    for _ in 0..n {
        input! {
            x: isize,
            y: isize,
        };
        let z = ((x * x) + (y * y)) as f64;
        if z.sqrt() <= d {
            count += 1;
        }
    };
    println!("{}", count);

}


Measured memory_bytes: 4976
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
#define F first
#define S second
#define MP make_pair
#define PB push_back
const int N=100;
const int MAXN=(1<<20)+10;
bool cmp(const pll &a,const pll &b){
    return a.S==b.S?a.F>b.F:a.S<b.S;
}
int main(){
    int n,all,mid,half,res,l,r;
    ll m,ans;
    pll a[N],val[MAXN],temp;
    vector<pll> v;
    scanf("%d%lld",&n,&m);
    half=n/2;
    all=1<<half;
    for(int i=0;i<n;i++)scanf("%lld%lld",&a[i].F,&a[i].S);
    for(int i=0;i<all;i++){
        val[i]=MP(0,0);
        for(int j=0;j<half;j++)if(i&(1<<j)){
            val[i].F+=a[j].F;
            val[i].S+=a[j].S;
        }
    }
    sort(val,val+all,cmp);
    v.PB(val[0]);
    for(int i=1;i<all;i++)if(val[i].S>m)break;
    else if(val[i].F>v.back().F)v.PB(val[i]);
    res=(n-half);
    all=1<<res;
    ans=v.back().F;
    for(int i=0;i<all;i++){
        temp=MP(0,0);
        for(int j=0;j<res;j++)if(i&(1<<j)){
            temp.F+=a[half+j].F;
            temp.S+=a[half+j].S;
        }
        if(temp.S>m)continue;
        l=0;
        r=static_cast<int>(v.size());
        while(r-l>1){
            mid=(r+l)>>1;
            if(v[mid].S+temp.S<=m)l=mid;
            else r=mid;
        }
        ans=max(ans,v[l].F+temp.F);
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 19144
n=int(input())
a=[int(input()) for i in range(n)]
a.sort()
l=[]
c=0
for j in range(n):
  if j==0:
    l.append(a[0]%2)
    if a[0]%2==1:
      c+=1
  else:
    l.append((a[j]-a[j-1])%2)
    if (a[j]-a[j-1])%2==1:
      c+=1
l.reverse()
if c==0:
  print("second")
elif c==1:
  print("first")
elif c==2:
    print("first")
elif c==3:
  if l[0]==1 and l[1]==1 and l[2]==1:
    print("second")
  else:
    print("first")
else:
  print("first")

Measured memory_bytes: 8016
#include <bits/stdc++.h>
#include<string>
using namespace std;
#define ll long long
#define ld long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int maxn=1*1e5+5;
ll lcm(ll a,ll b)
{
    return (a*b)/__gcd(a,b);
}
int main()
{
    FAST
    char x;
    cin>>x;
    x++;
    cout<<(char)x<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int pNum = sc.nextInt();
        int trainm = sc.nextInt();
        int carm = sc.nextInt();
        int trSum = pNum * trainm;
        if(trSum < carm){
            //電車の代金を出力
            out.println(trSum);
        } else {
            //同じ場合も入っている
            out.println(carm);
        }
        
    }
}

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

#pragma warning(disable:4996)
using namespace std;


int main() {
	int N;cin>>N;
	map<int,int>mp;
	for (int i = 0; i < N; ++i) {
		int a,b;cin>>a>>b;
		mp[a]++;
		mp[b]--;
	}
	int answer=0;
	int sum=0;
	for (auto m : mp) {
		sum+=m.second;
		answer=max(answer,sum);
	}
	cout<<answer<<endl;

	return 0;
}



Measured memory_bytes: 12480
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))
D = defaultdict(int)
for a in A:
  D[a] += 1
Q = int(input())
B = []
C = []
for _ in range(Q):
  l = list(map(int, input().split()))
  B.append(l[0])
  C.append(l[1])

ans = sum(A)
for i in range(Q):
  k = D[B[i]]
  D[B[i]] = 0
  D[C[i]] += k
  ans = ans - (B[i]*k) + (C[i]*k)
  print(ans)

Measured memory_bytes: 103804
import sys,os,io
input = sys.stdin.readline
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

N = int(input())
edge = [[] for _ in range(N)]
for i in range(N-1):
  a,b = list(map(int, input().split()))
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
mod = 10**9+7

def fact(N):
  ans = [1]*(N+1)
  for i in range(1,N+1):
    ans[i] = ans[i-1]*i%mod
  return ans

def combs_mod(n,k):
  #nC0からnCkまで
  inv = [1]*(k+1)
  for i in range(1,k+1):
    inv[i] = pow(i,mod-2,mod)
  ans = [1]*(k+1)
  for i in range(1,k+1):
    ans[i] = ans[i-1]*(n+1-i)*inv[i]%mod
  return ans

def dfs(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  fac = fact(N)
  while stack:
    v = stack[-1]
    marker = 0
    for u in edge[v]:
      if u==parent[v]:
        continue
      if parent[u]==N: #子へ降ろす
        marker = 1
        parent[u] = v
        stack.append(u)
      else: #子から吸い上げる
        part_num[v] += part_num[u]
        ans[v] *= pow(fac[part_num[u]],mod-2,mod)*ans[u]%mod
        ans[v] %= mod
    if marker==0:
      stack.pop()
      ans[v] *= fac[part_num[v]-1]
      ans[v] %= mod
  return

def dfs2(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  p_value = [0]*N
  combs = combs_mod(N-1,N-1)
  while stack:
    v = stack.pop()
    for i,u in enumerate(edge[v]):
      if u==parent[v]:
        continue
      parent[u]=v
      p_value[u] = ans[v]*pow(ans[u]*combs[part_num[u]],mod-2,mod)%mod
      ans[u] *= combs[part_num[u]-1]*p_value[u]
      ans[u] %= mod
      stack.append(u)
  return

ans = [1]*N
part_num = [1]*N
dfs(0)
dfs2(0)
print(*ans, sep='\n')

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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

int n,d;
signed main() {
    cin >> n >> d;
    int ans = 0;
    while(ans*(2*d+1)<n) {
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Text;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input1 = Console.ReadLine().Split();
            int h = int.Parse(input1[0]);
            int a = int.Parse(input1[1]);

            int count = 0;

            while (h > 0)
            {
                h = h - a;
                count++;
            }
            
            Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 11092
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a=sort(parseMap(split(readline())),rev=true)
    alice,bob=0,0
    for i in 1:n
        if i%2==1
            alice+=a[i]
        else
            bob+=a[i]
        end
    end
    println(alice-bob)
end
main()

Measured memory_bytes: 114428