akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 444
#define mod 1000000007

int n, c, i, j, k;
int a[maxN], b[maxN];
ll sum[maxN][maxN];
ll dp[maxN][maxN];

ll get_sum(ll a, ll b) {
    return ((a + b) * (b - a + 1)) / 2;
}

ll poww(ll a, ll b) {
    ll ans = 1;

    while (b > 0) {
        if (b & 1) ans = (ans * a) % mod;
        b >>= 1;
        a = (a * a) % mod;
    }

    return ans;
}

int main()
{
   // freopen("test.in","r",stdin);

    scanf("%d%d", &n, &c);
    for (i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (i = 1; i <= n; i++) scanf("%d", &b[i]);

    for (i = 1; i <= 400; i++) {
        sum[i][0] = 0;
        for (j = 1; j <= 400; j++)
            sum[i][j] = (sum[i][j - 1] + poww(j, i)) % mod;
    }

    dp[0][1] = 1;
    for (i = 0; i <= c; i++) {
        for (j = 1; j <= n; j++) {
            dp[i][j] %= mod;

            dp[i][j + 1] += (dp[i][j] * (b[j] - a[j] + 1)) % mod;

            for (k = 1; i + k <= c; k++)
                dp[i + k][j + 1] += (dp[i][j] * (mod + sum[k][b[j]] - sum[k][a[j] - 1])) % mod;
        }
    }

    dp[c][n + 1] %= mod;
    printf("%lld", dp[c][n + 1]);


    return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  string s;
  cin>>s;
  if(s=="ABC") cout<<"ARC"<<endl;
  else cout<<"ABC"<<endl;
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<map>
#include<algorithm>
#include<sstream>
using namespace std;

string repl(string,string,int);

int main(){
   int flag=0;
   int z;
   string str,str2="";
   stringstream ss;
   string app = "apple",pea = "peach";
   
   getline(cin,str);
   ss<<str;
   
   for(;;){
      ss>>str;
      if(str==str2) break;
      str2=str;
      
      if(str.find(app)!=string::npos){
         z = (int)str.find(app);
         str = repl(str,pea,z);
      }
      else if(str.find(pea)!=string::npos){
         z = (int)str.find(pea);
         str = repl(str,app,z);
      }
      
      if(flag==0) flag++;
      else cout<<" ";
      cout<<str;
      str2=str;
   }
   puts("");
   return 0;
}

string repl(string str,string aft,int z){
   int i,l=0;
   
   for(i=z;i<z+5;i++){
      str[i]=aft[l];
      l++;
   }
   return str;
}

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

int a[1000001];
void precomp()
{
	a[0]=0;
	for(int i=1;i<=1000000;i++)
	{
		if(i%3!=0 && i%5!=0)
		a[i]=i;

		else
		a[i]=0;
	}


}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	precomp();


	int t;
	cin >> t;
	long long int ans=0;
	for(int i=0;i<=t;i++)
	ans+=a[i];

	cout<<ans<<"\n";





	return 0;
}


Measured memory_bytes: 7552
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<queue>

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

#define ARRAY_MAX 1005

int main(){


    ll a,b,c;
    cin >> a >> b >> c;
    if(a == b && b == c){
        if(a == 1){
            cout << "0" << endl;
        }else{
            cout << "-1" << endl;
        }
        return 0;
    }

    bool flag = true;
    ll cnt = 0;
    while(flag){

        ll tmp_a = a;
        ll tmp_b = b;
        ll tmp_c = c;
        if(a % 2 == 1 || b % 2 == 1 || c % 2 == 1){
            flag = false;
        }else{

            a = tmp_b/2+tmp_c/2;
            b = tmp_a/2+tmp_c/2;
            c = tmp_a/2+tmp_b/2;
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    X, Y = map(int, input().split())

    if X == 1 and Y == 1:
        print(1000000)
        exit()

    if X == 1 and Y == 2:
        print(500000)
    elif X == 1 and Y == 3:
        print(400000)
    elif X == 1:
        print(300000)
    elif X == 2 and Y == 1:
        print(500000)
    elif X == 2 and Y == 2:
        print(400000)
    elif X == 2 and Y == 3:
        print(300000)
    elif X == 2:
        print(200000)
    elif X == 3 and Y == 1:
        print(400000)
    elif X == 3 and Y == 2:
        print(300000)
    elif X == 3 and Y == 3:
        print(200000)
    elif X == 3:
        print(100000)
    elif Y == 1:
        print(300000)
    elif Y == 2:
        print(200000)
    elif Y == 3:
        print(100000)
    else:
        print(0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define sws ios_base::sync_with_stdio(false)
#define MOD 1000000007
#define ll long long
#define sd(a) scanf("%d", &a)
#define sd2(a,b) scanf("%d%d", &a, &b)
#define sd3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sld(a) scanf("%lld", &a)
#define sld2(a,b) scanf("%lld%lld", &a, &b)
#define sld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define pd(a) printf("%d", a)
#define pld(a) printf("%lld", a)
#define sp printf(" ")
#define nl printf("\n")
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define clr(a, val) memset((a), (val), sizeof(a))
#define pb push_back
#define endl "\n"
#define mp(a, b) make_pair(a, b)
#define pii pair<int, int>
#define pll pair<long long,long long>
#define xx first
#define yy second
#define mx 100001
int main()
{
	int n,a,b;cin>>n>>a>>b;
	if(abs(a-b)%2==0) printf("Alice\n");
	else printf("Borys\n");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  while(cin >> n >> m && n) {
    int a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    vector<int> b(m);
    for(int i=0; i<m; i++) {
      if(i<a[0]) b[i]=1;
      else b[i]=0;
    }
    sort(b.begin(),b.end());
    bool ok=0;
    do{
      int cnt=a[0];
      string s="";
      for(int i=0; i<m; i++) {
    if(b[i]) s+='1';
    else s+='0';
      }
      bool ck=1;
      for(int i=1; i<n; i++) {
    if(s[i-1]=='1') cnt--;
    if(cnt<a[i]) {
      s+='1';
      cnt++;
    } else s+='0';
    if(cnt!=a[i]) ck=0;
      }
      if(ck) {
    ok=1;
    cout << s << endl;
    break;
      }
    } while(next_permutation(b.begin(),b.end()));
    if(!ok) cout << "Goofy" << endl;
  }
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) cin >> B[i];
    
    reverse(B.begin(), B.end());
    int dup = -1;
    vector<int> dup_idx, avail_idx;
    for(int i=0; i<N; i++) if(A[i] == B[i]){
        dup = A[i];
        dup_idx.push_back(i);
    }
    for(int i=0; i<N; i++) if(A[i] != dup && B[i] != dup) avail_idx.push_back(i);
    
    if(dup_idx.size() > avail_idx.size()){
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    for(int i=0; i<int(dup_idx.size()); i++) swap(B[dup_idx[i]], B[avail_idx[i]]);
    for(int i=0; i<N; i++) cout << B[i] << " \n"[i==N-1];
    return 0;
}


Measured memory_bytes: 6156
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int hp = sc.nextInt();
        int[] arrA = new int[n];
        int[] arrB = new int[n];
        for(int i = 0; i < n ; i++) {
            arrA[i] = sc.nextInt();
            arrB[i] = sc.nextInt();
        }

        Arrays.sort(arrA);
        Arrays.sort(arrB);
        int count = 0;
        for (int i = n-1; i >= 0; i--){
            if(arrA[n-1] < arrB[i]){
                hp -= arrB[i];
                count++;
                if (hp <= 0){
                    break;
                }
            }
        }
        while(hp > 0){
            hp -=arrA[n-1];
            count++;
        }


        System.out.println(count);
    }


}

Measured memory_bytes: 76476
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    string S, T;
    cin >> S >> T;
    int N = S.size(), M = T.size();
    vector<int> SAsum(N + 1), SBsum(N + 1), TAsum(M + 1), TBsum(M + 1);
    rep(i, N) {
        if(S[i] == 'A')
            SAsum[i + 1]++;
        else
            SBsum[i + 1]++;
    }
    rep(i, M) {
        if(T[i] == 'A')
            TAsum[i + 1]++;
        else
            TBsum[i + 1]++;
    }
    rep(i, N) {
        SAsum[i + 1] += SAsum[i];
        SBsum[i + 1] += SBsum[i];
    }
    rep(i, M) {
        TAsum[i + 1] += TAsum[i];
        TBsum[i + 1] += TBsum[i];
    }
    int q;
    cin >> q;
    rep(i, q) {
        int l1, r1, l2, r2;
        cin >> l1 >> r1 >> l2 >> r2;
        int a = SAsum[r1] - SAsum[l1 - 1];
        int b = SBsum[r1] - SBsum[l1 - 1];
        int c = TAsum[r2] - TAsum[l2 - 1];
        int d = TBsum[r2] - TBsum[l2 - 1];
        int diff = a - c;
        b += diff * 2;
        if(abs(b - d) % 3 == 0) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 5088
import java.io.*;
import java.util.*;
 
/**
 * Only By Abhi_Valani
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Unstoppable solver = new Unstoppable();
	//	int t=in.nextInt();
	//	while(t-->0)
        solver.solve(in, out);
        out.close();
    }
 
    static class Unstoppable {
        public void solve(InputReader in, PrintWriter out) {
          //from here...
		  //int[] a = readArray(in, n);
		  int n=in.nextInt();
		  int m=in.nextInt();
		  if(2*m >= n) out.println("0");
		  else out.println(n-2*m);
        }
 
    }
 
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
 
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
 
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
 
        public int nextInt() {
            return Integer.parseInt(next());
        }
 
    }
}
 

Measured memory_bytes: 20692
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
LL n,m,f[2010];
struct node{
	LL l,r,a;
}a[200010];
bool cmp(node a,node b) {return a.r<b.r;}
struct trnode{
	LL lc,rc,c,u;
}tr[400010];LL tot=0;
LL bt(LL l,LL r)
{
	LL x=++tot;
	if(l!=r)
	{
		LL mid=(l+r)/2;
		tr[x].lc=bt(l,mid);
		tr[x].rc=bt(mid+1,r);
	}
	return x;
}
void update(LL x)
{
	LL lc=tr[x].lc,rc=tr[x].rc,c=tr[x].u;
	tr[lc].c+=c;tr[rc].c+=c;
	tr[lc].u+=c;tr[rc].u+=c;
	tr[x].u=0;
}
void change(LL x,LL l,LL r,LL fl,LL fr,LL c)
{
	//printf("change:%lld %lld\n",fl,fr);
	//if(x==1) printf("change:%lld %lld %lld %lld %lld\n",l,r,fl,fr,c);
	if(l==fl&&r==fr) {tr[x].c+=c;tr[x].u+=c;return;}
	LL mid=(l+r)/2;
	if(tr[x].u!=0) update(x);
	if(fr<=mid) change(tr[x].lc,l,mid,fl,fr,c);
	else if(fl>mid) change(tr[x].rc,mid+1,r,fl,fr,c);
	else change(tr[x].lc,l,mid,fl,mid,c),change(tr[x].rc,mid+1,r,mid+1,fr,c);
	tr[x].c=max(tr[tr[x].lc].c,tr[tr[x].rc].c);
}
LL findans(LL x,LL l,LL r,LL fl,LL fr)
{
	//printf("findans:%lld %lld\n",fl,fr);
	if(l==fl&&r==fr) return tr[x].c;
	LL mid=(l+r)/2;
	if(tr[x].u!=0) update(x);
	if(fr<=mid) return findans(tr[x].lc,l,mid,fl,fr);
	if(fl>mid) return findans(tr[x].rc,mid+1,r,fl,fr);
	return max(findans(tr[x].lc,l,mid,fl,mid),findans(tr[x].rc,mid+1,r,mid+1,fr));
}
int main()
{
	scanf("%lld %lld",&n,&m);
	for(LL i=1;i<=m;i++) scanf("%lld %lld %lld",&a[i].l,&a[i].r,&a[i].a);
	sort(a+1,a+m+1,cmp);
	LL p=0;bt(0,n);
	for(LL i=1;i<=n;i++)
	{
		change(1,0,n,i,i,findans(1,0,n,0,i-1));
		while(p<m&&a[p+1].r==i) p++,change(1,0,n,a[p].l,a[p].r,a[p].a);
		//for(int j=0;j<=i;j++) printf("%lld ",findans(1,0,n,j,j));printf("\n");
	}
	printf("%lld",findans(1,0,n,0,n));
}

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

int main(){
  int X; cin >> X;
  if (X>=400 && X <= 599) {cout << 8 << endl;}
  else if (X>=600 && X <= 799) {cout << 7 << endl;}
  else if (X>=800 && X <= 999) {cout << 6 << endl;}
  else if (X>=1000 && X <= 1199) {cout << 5 << endl;}
  else if (X>=1200 && X <= 1399) {cout << 4 << endl;}
  else if (X>=1400 && X <= 1599) {cout << 3 << endl;}
  else if (X>=1600 && X <= 1799) {cout << 2 << endl;}
  else {cout << 1 << endl;}
}
  
  

Measured memory_bytes: 3644
#include<stdio.h>

int main(){
  int n, k, count = 0;
  char s[51];
  scanf("%d", &n);
  scanf("%s", s);
  for(int i = 0; i < n - 2; ++i){
    int f = 1;
    for (int j = 0; j < 3; ++j){
      if(s[i + j] != 'A' + j) f = 0;
    }
    if(f) count++;
  }
  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 128
fn main() {
    let v = read_vec::<usize>();
    let (k, q) = (v[0], v[1]);
    let d = read_vec::<i64>();
    let mut queries = vec![];
    for _ in 0..q {
        let v = read_vec::<i64>();
        let (n, x, m) = (v[0], v[1], v[2]);
        queries.push((n, x % m, m));
    }

    for (n, x, m) in queries {
        let mut d_mod = d.iter().map(|&v| v % m).collect::<Vec<_>>();
        let mut increment = d_mod.iter().sum::<i64>() * ((n - 1) / k as i64);
        for i in 0..((n - 1) % k as i64) as usize {
            increment += d_mod[i];
        }
        let mut eq = 0;
        for i in 0..k {
            if d_mod[i] == 0 {
                eq += 1;
            }
        }
        eq *= ((n - 1) / k as i64);
        for i in 0..((n - 1) % k as i64) as usize {
            if d_mod[i] == 0 {
                eq += 1;
            }
        }
        let dec = (x + increment) / m;
        println!("{}", n - 1 - dec - eq);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4476
#include <iostream>
#include <map>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  int a;
  map<int,int> b;
  for(int i=1;i<=n;i++){
    b[i]=0;
  }
  for(int i=2;i<=n;i++){
    cin>>a;
    b.at(a)++;
  }
  for(int i=1;i<=n;i++){
    cout<<b[i]<<endl;
  }
}

Measured memory_bytes: 12544
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define INF 1000000000000
typedef long long ll;

int gcd(int a,int b) {
	if (a < b) {
		int temp;
		temp = a;
		a = b;
		b = temp;
	}
	int rem = 0;
	while (true) {
		rem = a % b;
		if (rem == 0) {
			return b;
		}
		a = b;
		b = rem;
	}
}

int main() {
	int k, sum = 0, temp;
	cin >> k;
	REP(i, k) {
		REP(j,k) {
			REP(t,k) {
				temp = gcd(i+1, j+1);
				sum += gcd(temp, t+1);
			}
		}
	}
	cout << sum;
}

Measured memory_bytes: 3548
#include<iostream>
#include<fstream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<deque>
#include<set>
#include<map>
#include<bitset>
#include<ctime>
#include<queue>
using namespace std;
#define int long long
#define mn 100005
#define inf 4444444444444444444
#define mod 1000000009
#define FLN "test"
#define pii pair <int, int>
#define XX first
#define YY second

char ans[105][105];
int A, B;

signed main()
{
#ifdef lowie
	freopen(FLN".inp", "r", stdin);
	freopen(FLN".out", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>A>>B;
	for (int i=1; i<=100; i++) for (int j=1; j<=100; j++)
	{
		if (i<51) ans[i][j]='.';
		else ans[i][j]='#';
	}
	
	int W=100, H=100;
	A--, B--;
	
	for (int i=1; i<50; i+=2) for (int j=1; j<100; j+=2)
	{
		if (B==0) break;
		B--, ans[i][j]='#';
	}
	for (int i=52; i<101; i+=2) for (int j=2; j<101; j+=2)
	{
		if (A==0) break;
		A--, ans[i][j]='.';
	}
	
	cout<<"100 100\n";
	for (int i=1; i<101; i++) 
	{
		for (int j=1; j<101; j++) cout<<ans[i][j];
		cout<<"\n";
	}
}

// PLEASE REMOVE "cout" AND "cerr" DEBUG LINES BEFORE SUBMITTING PROBLEMS
// Code by low_
// Contact me via mail: dung.totuan01@gmail.com
// ...or codeforces: www.codeforces.com/profiles/low_
// ...or if you're interested in food: www.instagram.com/lowie_review/


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	long long n;
	int sum=0,t;
	int min=100;
	scanf("%d",&t);
	while(t--)
	{
		sum=0;
		scanf("%lld",&n);
		while(1)
		{
			if(n%2==0)
			{
				sum++;
				n/=2;
			}
			if(n%2!=0)
			break;
		}
		if(sum<min)
		min=sum;
	}
	printf("%d\n",min); 
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <set>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(long long A, long long B, long long K){
    set<long long> num;
    REP(i, K)
        if (A + i <= B)
            num.insert(A + i);
    REP(i, K)
        if (B - i >= A)
            num.insert(B - i);
    for (auto itr = num.begin(); itr != num.end(); itr++)
        cout << *itr << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long K;
    scanf("%lld",&K);
    solve(A, B, K);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <set>
#include <climits>

using namespace std;

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

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
int main() {
  int n, m, k;
  for(;;) {
    scanf("%d", &n);
    if(n == 0) break;
    vector<P> v(n);
    //first: y, second: x                                                                                                                   
    v[0] = make_pair(0, 0);
    for(int i = 1; i < n; ++i) {
      scanf("%d %d", &m, &k);
      switch(k) {
      case 0: v[i] = make_pair(v[m].first, v[m].second - 1); break;
      case 1: v[i] = make_pair(v[m].first + 1, v[m].second); break;
      case 2: v[i] = make_pair(v[m].first, v[m].second + 1); break;
      case 3: v[i] = make_pair(v[m].first - 1, v[m].second); break;
      }
    }
    int maxx = v[0].second, minx = v[0].second, maxy=v[0].first, miny=v[0].first;
    for(int i = 0; i < n; ++i) {
      maxx = max(maxx, v[i].second);
      minx = min(minx, v[i].second);
      maxy = max(maxy, v[i].first);
      miny = min(miny, v[i].first);
    }
    printf("%d %d\n", abs(maxx - minx) + 1,abs(maxy - miny) + 1);
  }
  return 0;
}

Measured memory_bytes: 3192
from sys import stdin
X,Y,Z,K = [int(x) for x in stdin.readline().rstrip().split()]
A = [int(x) for x in stdin.readline().rstrip().split()]
B = [int(x) for x in stdin.readline().rstrip().split()]
C = [int(x) for x in stdin.readline().rstrip().split()]

AB = []
for a in A:
    for b in B:
        AB.append(a+b)
        
AB.sort(reverse=True)
C.sort(reverse=True)
ABC = []

for ab in AB[:K]:
    for c in C[:K]:
        ABC.append(ab+c)
        
ABC.sort(reverse=True)

for abc in ABC[:K]:
    print(abc)

Measured memory_bytes: 143436
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] al = new long[n];
        long[] bl = new long[n];
        for(int i = 0; i < n; i++){
            al[i] = sc.nextLong();
            bl[i] = sc.nextLong();
        }
        long ans = 0;
        for(int i = n-1; i >= 0; i--){
            long tmp = (al[i] + ans) % bl[i];
            ans += tmp == 0 ? 0 : bl[i] - tmp;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 89864
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  char s;
  cin >> s;
  if (isupper(s)) {
    cout << "A" << endl;
  } else {
    cout << "a" << endl;
  }
}

Measured memory_bytes: 3628
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n=s.nextInt();
        List<Double> l = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            l.add(s.nextDouble());
        }
        double ans=0;
        for(int i=0;i<n;i++){
            ans+=(1/l.get(i));
        }
        System.out.println(1/ans);
    }
}

Measured memory_bytes: 23252
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int x1=s.nextInt();
		int y1=s.nextInt();
		int x2=s.nextInt();
		int y2=s.nextInt();
		int dx=x2-x1;
		int dy=y2-y1;
		System.out.println((x2-dy)+" "+(y2+dx)+" "+(x1-dy)+" "+(y1+dx));
	}
}


Measured memory_bytes: 23508
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

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

    int N;
    cin >> N;
    if (N == 1) {
        cout << "Hello World" << endl;
    } else {
        int A, B;
        cin >> A >> B;
        cout << A + B << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
 
int main(){
    int a, b;
    int d, r;
    double f;
 
    cin >> a >> b;
 
    d = a/b;
    r = a%b;
    f = double(a)/double(b);
 
    printf("%d %d %.5f", d, r, f);
 
    return(0);
}

Measured memory_bytes: 3172
#include <iostream>
#include <string.h>
using namespace std;
int main(){
    string A,B,C;
    cin>>A >>B >>C;
    if((A[A.length()-1]==B[0])&&(B[B.length()-1]==C[0]))
    {cout<<"YES"<<endl;}
    else cout<<"NO"<<endl;
 
    }

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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int N, K;
  cin >> N >> K;
  int ans = K;
  for (int i = 1; i < N; i++)
    ans *= K-1;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll Mod = 1000000007;
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if (A == B && B == C) {
    cout << "No" << endl;
  } else if (A != B && B == C) {
    cout << "Yes" << endl;
  } else if (A == B && B != C) {
    cout << "Yes" << endl;
  } else if (A == C && A != B) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;

namespace abc166
{
    class Program
    {
        static void Main()
        {
            var nm = Console.ReadLine().Split(' ');
            var n = int.Parse(nm[0]);
            var m = int.Parse(nm[1]);
            var hStrList = Console.ReadLine().Split(' ');
            var h = new int[n];
            for (var i = 0; i < n; ++i)
            {
                h[i] = int.Parse(hStrList[i]);
            }
            var good = new bool[n];
            for (var i = 0; i < n; ++i)
            {
                good[i] = true;
            }
            for (var i = 0; i < m; ++i)
            {
                var ab = Console.ReadLine().Split(' ');
                var a = int.Parse(ab[0]) - 1;
                var b = int.Parse(ab[1]) - 1;
                if (h[a] > h[b])
                {
                    good[b] = false;
                }
                else if (h[a] < h[b])
                {
                    good[a] = false;
                }
                else
                {
                    good[a] = false;
                    good[b] = false;
                }
            }
            var result = 0;
            for (var i = 0; i < n; ++i)
            {
                if (good[i])
                {
                    ++result;
                }
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 48568
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin.bytes().map(|c| c.expect("faild") as char).skip_while(|c| c.is_whitespace()).take_while(|c| !c.is_whitespace()).collect();
    token.parse().ok().expect("faild parse")
}
fn main(){
    loop{
        let a: i32 = read();
        let b: i32 = read();
        if a==0 && b==0{
            break;
        }
        for i in 0..a{
            for i2 in 0..b{
                if i > 0 && i < a-1 && i2 > 0 && i2 < b-1{
                    print!(".");
                } else{
                    print!("#");
                }
            }
            println!("");
        }
        println!("");
    }
}


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

using namespace std;
using ll = long long;


int n;
vector<vector<int>> G(100005);
vector<pair<int,int>> vp;

void input(){
  cin >> n;

  for(int i = 1; i < n; ++i){
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    vp.emplace_back(a,b);
  }
}

void solve(){
  int k = 0;
  map<pair<int,int>,int> I;
  vector<int> cs(n,0);
  vector<int> used(n,0);
  queue<int> Q;
  used[0] = 1;
  Q.emplace(0);
  while (!Q.empty())
  {
    /* code */
    int v = Q.front();
    Q.pop();
    if(k < G[v].size()){
      k = G[v].size();
    }
    int cur = 1;
    for(int u:G[v]){
      if(used[u])continue;
      if(cur == cs[v])cur++;
      cs[u]=I[make_pair(u,v)]=I[make_pair(v,u)]=cur++;
      used[u]=1;
      Q.emplace(u);
    }
  }
  cout << k << endl;
  for(auto p:vp) cout<<I[p]<<endl;
}

int main(){
  input();
  solve();
}

Measured memory_bytes: 20084
#include <iostream>
#include<string>
#include <math.h>
using namespace std;

int main() {
    int num;
    scanf("%d",&num);
    int amida[num+1];
    for(int i = 0;i <= num; i++){
        amida[i] = i;
    }
    
    int bars;
    scanf("%d",&bars);
    int a,b;
    
    for(int i = 0; i < bars;i++){
        (cin>>a).ignore()>>b;
        swap(amida[a], amida[b]);
    }
    
    for(int i = 1; i <= num;i++){
        cout<<amida[i]<<endl;
    }
    return 0;

}

Measured memory_bytes: 3160
#include <iostream>
#include <stdio.h>
using namespace std;
 
void bubble_sort(int a[], int n)
{
    bool flag=1;
    int temp;
    int change_count=0;
 
    while(flag){    //if??????????????????????????°???????????¶????????????????????±????????????
        flag=0;
        for (int j = n-1; j > 0; j--)
        {
            if (a[j]<a[j-1])
            {
                change_count++;
                temp=a[j];    a[j]=a[j-1];    a[j-1]=temp;
                flag=1;
            }
        }
    }
 
    //??????
    for (int i = 0; i < n; i++)    //???????????????????????¢????????????????????????????????????
    {
        if (i==n-1)
        {
            cout << a[i] << endl;
        }
        else
        {
            cout << a[i] << " ";
        }
    }
    cout << change_count << endl;
}
 
int main(int argc, char const *argv[])
{
    int n;
 
    //??\???
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
 
    bubble_sort(a,n);
    
    return 0;
}

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    // int n;
    // cin >> n;
    // vector<string> str(n);
    // rep(i, n) { cin >> str[i]; }
    // rep(i, n) { cout << str[i] << "\n"; }

    //入力
    int n;
    cin >> n;
    vector<string> str(n);
    for (int i = 0; i < n; i++) cin >> str[i];

    //処理
    string s, t;
    // t（次の単語）まで調べているのでn-1まで
    for (int i = 0; i < n - 1; i++) {
        s = str[i];      //単語
        t = str[i + 1];  //次の単語
        // 末尾と次の単語の先頭 ||
        // すべての文字列の中からsが複数個含まれているかどうか
        if (s[s.length() - 1] != t[0] || count(all(str), s) != 1)
            return cout << "No" << endl, 0;
    }

    //出力
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#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[i];
  long long ans=0;
  for(int i=1;i<n;i++){
    if(a[i-1]<=a[i])continue;
    ans+=a[i-1]-a[i];
    a[i]+=a[i-1]-a[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4024
#include<iostream>
#include<iomanip>
#include<cstdio>

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

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;
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;}
const ll INF = 1e9+1;

//A ~ B を二進数表記したとき、1が奇数回現れる桁は1、1が偶数回現れる桁は0となる

//2 ^ n けたが1になるまでの回数は 2 ^ n
//そっから0になるまでの回数は2 ^ n 
//合計期間は 2 ^ n
//10100 から　10101 に進んだとき、 XORで 00001
//10100 から　10101 から 10110 に進んだとき 10111
//10100 から　10101      10110    10111   00000
// 20         21          22        23

//2^nで割った商のAとBでの差が偶数のけたは0,奇数のけたは1??

//A-Bが1の時、a->Bで位が変わったらそこまでの0がすべて1、それいがい0
//           変わらないなら1のくらいだけ1
//A-Bが2の時、AとA+1のXORとBのXOR 

// 1 10  ->  11           1 2 3
// 1 10 11 -> 00          1 3 0
// 1 10 11 100 -> 100     1 4 4
// 1 10 11 100 101 -> 001 1 5 1

// 1 10 11 100 101 110 111  7 0

//下の位の差が偶数なら0?
//

// XORの性質から, F(A,B) = F(0,A-1) XOR F(0,B)
// nが偶数の時 n XOR n+1 = 1


long long oddsolve(long long a) { return (a+1)/2 % 2; }
long long solve(long long a) {
    if (a % 2 == 1) return oddsolve(a);
    else return oddsolve(a+1) ^ (a+1);
}
int main() {
    long long A, B; cin >> A >> B;
    cout << (solve(B) ^ solve(A-1)) << endl;
}

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

using namespace std;

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

	int A,B,C;

	cin >> A >> B >> C;

	C-=abs(A-B);
	C = max(C,0);

	cout << C << '\n';
	
	return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <map>

int main() {
  int n, m;
  std::cin >> n;
  std::map<std::string, int> ss;
  for (int i = 0; i < n; ++i) {
    std::string s;
    std::cin >> s;
    if (ss.count(s) == 0) {
        ss[s] = 1;
    } else {
        ss[s] += 1;
    }
  }
    
  std::cin >> m;
  std::map<std::string, int> tt;
  for (int i = 0; i < m; ++i) {
    std::string t;
    std::cin >> t;
    if (tt.count(t) == 0) {
        tt[t] = 1;
    } else {
        tt[t] += 1;
    }
  }
  int ret = 0;
  for (auto& s : ss) {
      int tval = (tt.count(s.first) == 0) ? 0 : tt[s.first];
      ret = std::max(ret, s.second - tval);
  }
  std::cout << ret;
    
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [[0, 0] for _ in range(M)]
for i in range(M):
    AB[i][0], AB[i][1] = map(int, input().split())

root = list(range(N+1))
comp_size = [1] * (N+1)


def find_root(x):
    y = root[x]
    if x == y:
        return x
    z = find_root(y)
    root[x] = z
    return z


def merge(x, y):
    rx = find_root(x)
    ry = find_root(y)
    if rx == ry:
        return 0
    sx = comp_size[rx]
    sy = comp_size[ry]
    if sy < sx:
        root[ry] = rx
        comp_size[rx] += sy
    else:
        root[rx] = ry
        comp_size[ry] += sx
    return sx * sy


def solve():
    disconnect = []
    x = N * (N-1) // 2
    for a, b in AB[::-1]:
        disconnect.append(x)
        x -= merge(a, b)

    for ans in disconnect[::-1]:
        print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 27144
N = int(input())
Ss = {}
for _ in range(N):
  s = input()
  if s in Ss:
    Ss[s] += 1
  else:
    Ss[s] = 1

max_value = max(Ss.values())  # maximum value
max_keys = [k for k, v in Ss.items() if v == max_value]
for k in sorted(max_keys):
  print(k)
  

Measured memory_bytes: 32988
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif

using P = pair<ll,ll>; using vp = V<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
//////////

void solve(){
  ini(N);
  vp a(N); in(a);
  sort(all(a) , [](P x,P y){
    return x.fi - x.se < y.fi - y.se;
  });
  int ans = 0;
  P cur;
  rep(i , N){
    if(i == 0) ans++ , cur = a[0];
    else {
      // かぶっている？
      if(cur.fi + cur.se > a[i].fi - a[i].se){
        cur = (cur.fi + cur.se < a[i].fi + a[i].se ? cur : a[i]);
      }
      else{
        ans++;
        cur = (cur.fi + cur.se < a[i].fi + a[i].se ? a[i] : cur);
      }
    }
  }
  out(ans);
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)


int main(){
    ll N, M;
    cin >> N >> M;

    char S[N + 2];
    cin >> S;

    ll p = N;
    ll t;
    stack<ll> ans;
    while(p > M){
        t = 0;
        for(ll i = M; i > 0; i--){
            if(S[p - i] == '0'){
                t = p - i;
                ans.push(i);

                break;
            }
        }
        if(t == 0){
            cout << -1 << endl;
            return 0;
        }
        p = t;
    }
    ans.push(p);

    ll steps = ans.size();
    rep(i, steps){
        if(i != 0){
            cout << " ";
        }
        cout << ans.top();
        ans.pop();
    }
    cout << endl;

    return 0;
}




Measured memory_bytes: 4320
# coding:utf-8
import math
import itertools

N = int(input())
l = []
for _ in range(N):
    x, y = map(int, input().split(' '))
    l.append([x, y])

ave = float(0)
cnt = 0
for r in itertools.permutations(l):
    tmp = float(0)
    for i in range(N-1):
        tmp += math.sqrt(((r[i][0] - r[i+1][0])**2) + ((r[i][1] - r[i+1][1])**2))
    ave += tmp
    cnt += 1
print(ave/cnt)

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var n = long.Parse(Console.ReadLine());
        var rs = new long[5];
        for (int i = 0; i < rs.Length; i++)
        {
            rs[i] = long.Parse(Console.ReadLine());
        }

        var t = 0L;
        var narrowest = long.MaxValue;
        var greedyTraffic = 0L;
        for (int i = 0; i < rs.Length; i++)
        {
            if (rs[i] < narrowest)
            {
                greedyTraffic = (n + rs[i] - 1) / rs[i];
                narrowest = rs[i];
            }
        }
        Console.WriteLine(4 + greedyTraffic);
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
        #define ll long long
        #define rep(i,a,b) for(i=a;i<b;i++)
        #define pb push_back
        #define all(v) v.begin(),v.end()
        #define F first
        #define S second
        #define hell 1000000007
        using namespace std;
        const int N=500;
        void solve()
        {
            ll i,j,k,n,m,c=0,ans=0;
            string s;
            cin>>n>>m;
            if(abs(n-m)<=16-n-m)
                cout<<"Yay!";
            else cout<<":(";




    }

        int main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
            solve();
        }


Measured memory_bytes: 3644
#include<stdio.h>
#define N 100000
#define Q 50000

int binarysearch(int);
void sort(void);
int S[N];
int n;
main(){
  
  int q,T[N],i,j,x,count=0;
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
 
  for(i=0;i<q;i++){
    x= binarysearch(T[i]);
    if(x!=n){
      count++;
    }
  } 
  printf("%d\n",count);
  return 0;
}

void sort(void){
  int flag,i,j,x,minj;
  for(i=0;i<=n-1;i++){
    minj=i;
    flag=0;
    for(j=i;j<=n-1;j++){
      if(S[j]<S[minj]){
	minj=j;
	flag=1;
      }
    }
    if(flag==1){
      x=S[i];
      S[i]=S[minj];
      S[minj]=x; 
    }
  }
}

int binarysearch(int key){
  int left=0,right=n;
  int mid;
  while(left<right){
    mid=(left+right)/2;
    if(S[mid]==key)
      return mid;
    else if(key<S[mid])
      right=mid;
    else{
      left=mid+1;
    }
  } 
  return n;
}

Measured memory_bytes: 1188
MOD = 10**9+7
n,k = map(int,input().split())

L = [0]*(k+1)

for i in range(k,0,-1):    
  L[i] = pow(k//i,n,MOD)
  for j in range(2,k//i+1):        
    L[i] -= L[i*j]
  
ans = 0
for i in range(1,k+1):  
  ans = (ans + i*L[i]) % MOD
  
print(ans)  

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

public class MainClass
{
	public const long Giri = 1000000007;

	public class Node 
	{
		public int Index{get;set;}
		//public List<int> Connections {get;set;}
		public List<int> Edges {get;set;}
		public bool Seen {get;set;}
	}
	public class Edge
	{
		public int Color{get;set;}
		public int Connect1 {get;set;}
		public int Connect2 {get;set;}
		public bool Seen {get;set;}
		
	}
	
	public static void Main(string[] args)
	{
		var n = Console.ReadLine().ToInt();
		var nodes = new Node[n];
		var edges = new Edge[n-1];
		for(int i = 0; i < n; i++)
		{
			nodes[i] = new Node() { Index = i, Edges = new List<int>()};
		}
		for(int i = 0; i < n-1; i++)
		{
			var p = Input().ToInt();
			var a = p[0]-1;
			var b = p[1]-1;
			//nodes[a].Connections.Add(b);
			//nodes[b].Connections.Add(a);
			nodes[a].Edges.Add(i);
			nodes[b].Edges.Add(i);
			edges[i] = new Edge() { Color=-1, Connect1 = a, Connect2 = b};
		}
		//Array.Sort(nodes, (s, t) => t.Edges.Count - s.Edges.Count);
		
		int colorSize = nodes[0].Edges.Count;
		Check(nodes, edges, nodes[0], null, -1);
		//Array.Sort(nodes, (s, t) => t.Edges.Count - s.Edges.Count);
		//Console.WriteLine(colorSize);
		Console.WriteLine(maxcol);
		foreach(var ed in edges)
		{
			Console.WriteLine(ed.Color+1);
		}
	}
	public static int maxcol = 0;
	public static void Check(Node[] nodes, Edge[] edges, Node n, Node parent, int color)
	{
		if(n.Seen)
			return;
		n.Seen=true;
		int col = 0;
		foreach(var e in n.Edges)
		{
		//	Console.WriteLine(e);
		//	Console.WriteLine("{0}, {1}", edges[e].Connect1, edges[e].Connect2);
			if(edges[e].Seen)
				continue;
			edges[e].Seen=true;
			if(edges[e].Color != -1)
			{
				var text = nodes[edges[e].Connect2];
				if(text == n)
					text = nodes[edges[e].Connect1];
		//		
				Console.WriteLine("Fill {0}->{1} X", n.Index, text.Index);
				continue;
			}
				
			if(col == color)
				col++;
			edges[e].Color = col;
			var next = nodes[edges[e].Connect2];
			if(next == n)
				next = nodes[edges[e].Connect1];
			
			if(next != parent)
			{
				Check(nodes, edges, next, n, edges[e].Color);
			}
			else
			{
				//Console.Writ
			}
		//	Console.WriteLine("Fill {2}->{3} {0} {1}", col, e, n.Index, next.Index);
			
			col++;
			
			
		}
		maxcol = Math.Max(col, maxcol);
		
	}

	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}



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


int main()
{
    int N,M;
    cin>>N>>M;
    vector<pair<long long,long long>> P;
    for(int i=1;i<N+1;i++){
        long long A,B;
        cin>>A>>B;
        P.push_back(make_pair(A,B));
    }
    sort(P.begin(),P.end());
    
    long long ans=0;
    for(auto itr=P.begin();itr!=P.end();itr++){
        if(M-(*itr).second>=0){
            ans+=(*itr).first*(*itr).second;
            M-=(*itr).second;
        }
        else{
            ans+=M*(*itr).first;
            break;
        }
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 2548
#[allow(unused_imports)]
use {
    itertools::Itertools,
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::io::Write,
    std::ops::*,
};

macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

#[fastout]
fn main() {
    input! {
        n: usize,
        mut a: [usize; n],
        mut b: [usize; n],
    }

    let mut cnt_a = vec![0; n + 1];
    let mut cnt_b = vec![0; n + 1];
    for &a in a.iter() {
        cnt_a[a] += 1;
    }
    for &a in b.iter() {
        cnt_b[a] += 1;
    }
    let mut q = std::collections::BTreeSet::<_>::new();
    for i in 0..=n {
        if cnt_a[i] + cnt_b[i] > n {
            println!("No");
            return;
        }
        let c = cnt_a[i] + cnt_b[i];
        if c > 0 {
            q.insert((c, i, cnt_a[i], cnt_b[i]));
        }
    }

    let mut ch = vec![vec![]; n + 1];
    let mut stock = vec![];
    while let Some(&(c, i, an, bn)) = q.iter().rev().next() {
        q.remove(&(c, i, an, bn));
        if an == 0 {
            stock.push((i, bn));
            continue;
        }
        if let Some((j, d)) = stock.pop() {
            ch[i].push(j);
            if d > 1 {
                stock.push((j, d - 1));
            }
        } else {
            let mut x = (0, 0, 0, 0);
            let mut y = (0, 0, 0, 0);
            for &(c, j, am, bm) in q.iter().rev() {
                if bm > 0 {
                    ch[i].push(j);
                    x = (c, j, am, bm);
                    y = (c - 1, j, am, bm - 1);
                    break;
                }
            }
            q.remove(&x);
            if y.0 > 0 {
                q.insert(y);
            }
        }
        if c > 1 {
            if an == 1 {
                stock.push((i, bn));
            } else {
                q.insert((c - 1, i, an - 1, bn));
            }
        }
    }

    let mut ans = vec![0; n];
    for i in 0..n {
        ans[i] = ch[a[i]].pop().unwrap();
    }

    println!("Yes");
    println!("{}", ans.iter().join(" "));
}


Measured memory_bytes: 28336