akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N; i++)
typedef pair<int,int> Pi;
#define F first
#define S second
#define pb push_back
#define INF 1 << 28

inline void chmin(int &a,int b) {
  a = min(a,b);
}

inline void chmax(int &a,int b) {
  a = max(a,b);
}
int N;
int data[10005];

int calc(int p, int c)
{
  int left, right;
  int save = data[p];
  data[p] = c;
  left = p,right = p + 1;
  int ret = 0;
  while(true) {
    int cnt = 0;
    for(;left >= 0 && data[left] == c;left--,cnt++);
    for(;right < N && data[right] == c;right++,cnt++);
    if(cnt >= 4)ret += cnt;
    else break;
    if(left < 0 || right >= N)break;
    c = data[left];
  }
  data[p] = save;
  return ret;
}

int main()
{
  while(cin >> N,N) {
    int ans = N;
    Rep(i,N) {
      cin >> data[i]; --data[i];
    }
    Rep(i,N) Rep(j,3) chmin(ans,N - calc(i,j));
    cout << ans << endl;
  }
  return 0;
}

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

int main(){
	int A,B,C;
	int d;
	cin>>A>>B>>C;
	cin>>d;
	
	if(abs(A-B)<=d && abs(B-C)<=d){
		cout<<"Yes";
	}else if(abs(A-C)<=d){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int f[1000005];
int v[1000005];
int find(int x){
	if(f[x]==x){
		return x;
	}else{
		int fx=f[x];
		f[x]=find(f[x]);
		v[x]+=v[fx];
		return f[x];
	}
//	return f[x]==x?x:f[x]=find(f[x]);
}
void join(int x,int y,int z){
	// x->y z
	int fx=find(x);
	int fy=find(y);
	if(fx!=fy){
		v[fx]=z+v[y]-v[x];
		f[fx]=fy;
	}
}
int main(){
	int n,q,t,l,r;
	cin>>n>>q;
	for(int i=0;i<=n;i++)f[i]=i;
	while(q--){
		cin>>t>>l>>r;
		if(t){
			int fx=find(l);
			int fy=find(r);
			if(fx==fy){
				cout<<v[l]-v[r]<<endl;
			}else cout<<"?"<<endl;
		}else{
			int z;cin>>z;
			join(l,r,z);
		}
	}
	return 0;
}


Measured memory_bytes: 5004
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll = long long;                    // seq 1 128 | factor   100333 ~2^16.61
using vl = vector<ll>;                   //   | grep -v ' .* '  1300111 ~2^20.31
using vvl = vector<vl>;                  //                    10300777 ~2^23.30
using pll = pair<ll,ll>;                 //                   100400999 ~2^26.58
using vb = vector<bool>;                 //                  1300400999 ~2^30.28
const ll oo = 0x3f3f3f3f3f3f3f3fLL;      //                 10200500333 ~2^33.25
const double eps = 1e-9;                 //                100200400777 ~2^36.54
#define sz(c) ll((c).size())             //               1200300700111 ~2^40.13
#define all(c) begin(c),end(c)           //              10200300500777 ~2^43.21
#define mp make_pair                     //             100200300400777 ~2^46.51
#define mt make_tuple                    //            1200300400600999 ~2^50.09
#define pb push_back                     //           10200300400600111 ~2^53.18
#define eb emplace_back                  //          100200300400600333 ~2^56.48
#define xx first                         //         1200300400500800999 ~2^60.06
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

vector<vector<bool> > allowed;
vvl dp;

int main() {

    ll mod_n = 1000000007;
    ll n_rows, n_cols;
    cin >> n_rows >> n_cols;
    allowed.assign(n_rows, vector<bool>(n_cols, true));
    dp.assign(n_rows, vl(n_cols, 0));

    FOR(i, 0, n_rows){
        string tmp;
        cin >> tmp;
        FOR(j, 0, n_cols){
            if(tmp[j] == '#'){
                allowed[i][j] = false;
            }
        }
    }
    
    dp[0][0] = 1;

    FOR(i, 0, n_rows){
        FOR(j, 0, n_cols){
            if(!allowed[i][j]) {continue;}
            if(i > 0){
                dp[i][j] += dp[i-1][j];
                dp[i][j] = dp[i][j] % mod_n;
            } 
            if(j>0){
                dp[i][j] += dp[i][j-1];
                dp[i][j] = dp[i][j] % mod_n;
            }
        }
    }

    cout << dp[n_rows-1][n_cols-1] << endl;

    return 0;
}



Measured memory_bytes: 8320
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

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

func main() {
	a, _ := strconv.Atoi(input())
	b, _ := strconv.Atoi(input())
	c, _ := strconv.Atoi(input())

	if a == b && b == a {
		if a%2 == 0 && b%2 == 0 && c%2 == 0 {
			fmt.Println(-1)
			return
		}
		fmt.Println(0)
		return
	}

	count := 0
	for {
		x := a
		y := b
		z := c
		if x%2 == 1 || y%2 == 1 || z%2 == 1 {
			break
		}
		a = (y + z) / 2
		b = (z + x) / 2
		c = (x + y) / 2

		count++
	}

	fmt.Println(count)
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main ()
{
	int a, result=0;
	string slime;
	cin>>a;
	cin>>slime;
	for (int i=0; i<a; i++)
	{
		if (i==0 || slime[i]!=slime[i-1]) result++;
	}
	cout<<result<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x <= 1) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
ll n,d,a,ans;
ll diff[maxn]; //差分数组 d[i]：第i只怪物轰炸次数-第i-1只怪物轰炸次数 
pll p[maxn];
int main(){
 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> d >> a;
	for(int i = 1;i <= n;i++) cin >> p[i].fi >> p[i].se;
	sort(p + 1,p + n + 1);
	for(int i = 1;i <= n;i++){
		diff[i] += diff[i-1]; //前缀和,统计该点实际轰炸次数
		ll h = p[i].se;
		h -= diff[i] * a;
		if(h <= 0) continue;
		ll cnt = (h + a - 1) / a;
		diff[i] += cnt;
		ans += cnt;
		ll l = 1,r = n,nx = r;
		while(l <= r){
			ll mid = (l + r) >> 1;
			if(p[mid].fi <= p[i].fi + 2 * d) l = mid + 1,nx = mid;
			else r = mid - 1;
		} 
		diff[nx + 1] -= cnt;
	}
	cout << ans << endl;
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

Measured memory_bytes: 4992
#![allow(unused_imports)]

use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::{i32, i64, i128, u32, u64, u128, f64};
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!{
        c: char,
    }
    if c.is_uppercase() { println!("A") }
    else { println!("a") }
}


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

using namespace std;
int main() {
    int group[12] = {0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};
    int x, y;

    cin >> x >> y;

    if ( group[x-1] == group[y-1] ) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}



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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<string> xs = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string s;
    cin >> s;
    int i = 0;
    while (xs[i] != s) ++i;
    cout << (7 - i) << endl;
    return 0;
}


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

int main() {
    unsigned char c;
    cin >> c;

    const unsigned char C = toupper(c);
    const auto ret = C == c ? 'A' : 'a';

    cout << ret << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    string s,t;
    cin >> s >> t;
    map<char,char> mp,mp2;
    rep(i,s.size()){
        if(!mp[s[i]])mp[s[i]]=t[i];
        else if(mp[s[i]]!=t[i]){
            cout << "No" << endl;
            return 0;
        }
        if(!mp2[t[i]])mp2[t[i]]=s[i];
        else if(mp2[t[i]]!=s[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 776
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e15;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    string S; cin >> S;
    if(S=="SUN") cout << 7 << endl;
    else if(S=="MON") cout << 6 << endl;
    else if(S=="TUE") cout << 5 << endl;
    else if(S=="WED") cout << 4 << endl;
    else if(S=="THU") cout << 3 << endl;
    else if(S=="FRI") cout << 2 << endl;
    else cout << 1 << endl;
}

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

typedef pair<int,int> pii;
vector<vector<pii> > v;
int tab[16][16];
int m[16][16];
int ans[16][16];
int x, y, N;

int search(int n) {
	if(n > N) {
		for(int i = 0; i < y; i++) {
			for(int j = 0; j < x; j++) {
				ans[i][j] = tab[i][j];
			}
		}
		return 1;
	}

	int res = 0;
	int sx = -1, sy = -1;
	for(int i = 0; i < y; i++) {
		for(int j = 0; j < x; j++) {
			if(m[i][j] == n) {
				/*
				if(sx != -1 || sy != -1)
					abort();
				// */
				sx = j;
				sy = i;
			}
		}
	}

	for(int i = 0; i < v[n-1].size(); i++) {
		int wi, hi;
		wi = v[n-1][i].second;
		hi = v[n-1][i].first;
		for(int by = 0; by < hi; by++) {
			for(int bx = 0; bx < wi; bx++) {
				if(sy-by >= 0 && sx-bx >= 0 && sy-by + hi <= y && sx-bx + wi <= x) {
					/*
					cout << "hoge:" << n << endl;
					cout << "i:" << i << endl;
					cout << sy-by << "," << sx-bx << endl;
					// */
					bool flg = true;
					for(int j = sy-by; j < sy-by+hi && flg; j++) {
						for(int k = sx-bx; k < sx-bx+wi && flg; k++) {
							if(tab[j][k] != 0 || (m[j][k] != 0 && m[j][k] != n)) {
								flg = false;
							}
						}
					}

					if(flg) {
						//cout << sy << "," << sx << endl;
						for(int j = sy-by; j < sy-by+hi && flg; j++) {
							for(int k = sx-bx; k < sx-bx+wi && flg; k++) {
								tab[j][k] = n;
							}
						}
						int tmp;
						tmp = search(n+1);
						res += tmp;
						for(int j = sy-by; j < sy-by+hi && flg; j++) {
							for(int k = sx-bx; k < sx-bx+wi && flg; k++) {
								tab[j][k] = 0;
							}
						}
					}
				}
			}
		}
	}

	//cout << n << endl;
	return res;
}

int main() {
	while(cin >> x >> y >> N, x || y || N) {
		v.clear();
		v.resize(N);
		for(int i = 0; i < N; i++) {
			int b, k;
			cin >> b >> k;
			for(int j = 1; j <= k; j++) {
				if(k % j == 0 && j <= y && k / j <= x) {
					v[b-1].push_back(pii(j,k/j));
				}
			}
		}

		/*
		for(int i = 0; i < v.size(); i++) {
			for(int j = 0; j < v[i].size(); j++) {
				cout << v[i][j].first << "," << v[i][j].second << endl;
			} cout << endl;
		} cout << endl;
		// */

		for(int i = 0; i < 16; i++) {
			for(int j = 0; j < 16; j++) {
				tab[i][j] = 0;
				m[i][j] = 0;
				ans[i][j] = 0;
			}
		}
		for(int i = 0; i < y; i++) {
			for(int j = 0; j < x; j++) {
				cin >> m[i][j];
			}
		}

		if(search(1) != 1)
			cout << "NA" << endl;
		else {
			for(int i = 0; i < y; i++) {
				cout << ans[i][0];
				for(int j = 1; j < x; j++) {
					cout << " " << ans[i][j];
				}
				cout << endl;
			}
		}
	}
}

Measured memory_bytes: 1208
# coding: utf-8
 
 
def main():
 
    in_data = input()
 
    if (in_data == 'AAA' or
        in_data == 'BBB'):
        print('No')
    else:
        print('Yes')
 
    return 0
  
  
if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
//#include<iostream>
//#include<cstdlib>
//#include<cstring>
//#include<cmath>
//#include<cstdio>
//using namespace std;
//int upluck(int n)
//{
//    int q,m=0;
//    int j=0;
//    if(n>=0)
//    {
//        for(int i=1; i<11; i++)
//        {
//            m=n+i;
//            while(m)
//            {
//                if((m%10)==8)
//                {
//                    return i;
//                }
//                else
//                {
//                    m=m/10;
//                }
//            }
//        }
//    }
//    else if(n<0)
//    {
//        q=abs(n);
//        if(q<=8)
//        {
//            return (q+8);
//        }
//        if(q>8)
//        {
//            for(int i=1; i<11; i++)
//            {
//                m=q-i;
//                while(m)
//                {
//                    if((m%10)==8)
//                    {
//                        return i;
//                    }
//                    else
//                    {
//                        m=m/10;
//                    }
//                }
//            }
//        }
//    }
//}
//int main()
//{
//    int a;
//    cin>>a;
//    int b=upluck(a);
//    cout<<b;
//}






#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
    int e;
    int a,b,c,d;
    cin>>e;
    d=e%10;
    c=(e/10)%10;
    b=(e/100)%10;
    a=(e/1000);
    if((a+b+c+d)==7)
    {
        cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7";
    }
    else if((a+b+c-d)==7)
    {
        cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7";
    }
    else if((a+b-c+d)==7)
    {
        cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7";
    }
    else if((a-b+c+d)==7)
    {
        cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7";
    }
    else if((a+b-c-d)==7)
    {
        cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7";
    }
    else if((a-b-c+d)==7)
    {
        cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7";
    }
    else if((a-b+c-d)==7)
    {
        cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7";
    }
    else if((a-b-c-d)==7)
    {
        cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7";
    }
}


Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	string s;
	cin >> s;

	vector<int> abc(26,0);
	for(int i=0; i<s.size(); i++){
		abc.at(s.at(i)-'a')++;
	}
	for(int i=0; i<26;i++){
		if(abc.at(i)==0){
			char ans='a'+i;
			cout << ans << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
	
}

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


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


Measured memory_bytes: 3076
#include <iostream>

using namespace std;

int main(){
	int n;
  	cin >> n;
  	int a[n];
  	for(int i = 0; i < n; i++) cin >> a[i];
  	for(int i = 0; i < n; i++) {
    	if (a[i] % 2) {
          cout << "first";
          return 0;
        }
    }
  	cout << "second";
}

Measured memory_bytes: 640
//https://atcoder.jp/contests/code-festival-2017-qualb/tasks/code_festival_2017_qualb_e

#include<bits/stdc++.h>
const int N = 2005;
const int mod = 1e9 + 7;
using namespace std;

int a, b, c[N][N], f[N][N], ans;

void add(int&a, int b){
    a += b; if (a >= mod) a -= mod;
}

int po(int n, int k){
    if (k < 0) return 0;
    int ans = 1;
    while (k){
        if (k&1) ans = 1LL * ans * n % mod;
        n = 1LL * n * n % mod;
        k >>= 1;
    }
    return ans;
}

int C(int k, int n){
    if (k > n || k < 0) return 0;
    return c[n][k];
}

int main(){
    for (int i = 0; i < N; i++) for (int j = 0; j <= i; j++) c[i][j] = (j == 0 ? 1 : (c[i-1][j] + c[i-1][j-1]) % mod);
    cin >> a >> b;
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++){
        f[i][j] = c[i][j];
        if (j > 0) add(f[i][j], f[i][j-1]);
    }
    for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) if (j > 0) add(f[i][j], f[i][j-1]);
    for (int s = 0; s <= a; s++){
        for (int i = 0; i < b && i+s <= a; i++){
            int A = a - s - i, B = i;
            add(ans, 1LL * ((B) ? f[B-1][A] : 1) * C(i, b-1) % mod);
//            cout << A << " " << B << " " << ((B) ? f[B-1][A] : 1) << " " << i << " " << b-1 << "\n";
        }
    }
    cout << ans;
}


Measured memory_bytes: 31616
import numpy as np
x=int(input())
def is_prime(n):
    if n == 1: return False

    for k in range(2, int(np.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True
while True:
    if is_prime(x)==True:
        print(x)
        break
    else:
        x+=1

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

int gcd(int a, int b){
    assert(a>=0 && b >=0);
    if(a < b){
        // return gcd(b,a);
        swap(a,b);
    }
    if(b == 0){
        return a;
    } else {
        return gcd(b,a%b);
    }
}

int lcm(int a, int b){
    assert(a>=0 && b >=0);
    if(b == 0){
        return a;
    } else {
        return gcd(b,a%b);
    }
}

int main(){
    int a,b;
    while(cin >> a >> b){
        int g =gcd(a,b);
        cout << g << " " << (a / g) * b << endl;
    }
}

Measured memory_bytes: 3060
import sys
readline = sys.stdin.readline
N, K = map(int, input().split())
W = tuple(map(int, sys.stdin.readlines()))
ma = max(W)
def check(x):
    if x < ma:
        return False
    use = 1
    rest = x
    for w in W:
        if rest >= w:
            rest -= w
        else:
            rest = x - w
            use += 1
    return use <= K
l = 0
r = sum(W)
while r - l > 1:
    m = (r + l) // 2
    if check(m):
        r = m
    else:
        l = m
print(r)



Measured memory_bytes: 15892
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define inf (int)(3e18)
#define P pair<int,int>
#define mod (int)(1e9+7)
using ll = long long;
using Graph = vector<vector<int>>;
template<class T> inline void chmin(T &a, T b) {
	a = min(a, b);
}
template<class T> inline void chmax(T &a, T b) {
	a = max(a, b);
}
 
int N,M;
vector<vector<int>>G;
bool flag=true;
int co[100005];
int wh,bl;
void dfs(int x){
    if(co[x]==1)wh++;
    else bl++;
    for(int i:G[x]){
        if(co[i]&&co[i]==co[x]){
            flag=false;return;
        }
        if(co[i])continue;
        co[i]=co[x]*-1;
        dfs(i);
    }
}
signed main(){
    cin>>N>>M;G.resize(N);
    rep(i,M){
        int a,b;cin>>a>>b;a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    co[0]=1;
    dfs(0);
    if(flag){
        //二部グラフでない場合
        cout << wh*bl-M << "\n";
        return 0;
    }else {
        //二部グラフの場合
        cout << N*(N-1)/2-M << "\n";
        return 0;
    }
}

Measured memory_bytes: 7296
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	      	  cin.tie(0);  ios_base::sync_with_stdio(false);

	      	  int N;
	      	  cin >> N;
	      	  map<int,int> mp;
	      	  for(i=1;i<=N;i++){
	      		  int d;
	      		  cin >> d;
	      		  mp[d]++;
	      	  }

	      	  int M;
	      	  cin >> M;
	      	  for(i=1;i<=M;i++){
	      		  int t;
	      		  cin >> t;
	      		  if(mp[t]>=1) mp[t]--;
	      		  else{
	      			  cout << "NO" << endl;
	      			  return 0;
	      		  }
	      	  }

	      	  cout << "YES" << endl;


	          return 0;
}


Measured memory_bytes: 9600
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int[] d = new int[6];
		for(int i = 0; i < 6; i++){
			d[i] = scan.nextInt();
		}

		Dice dice = new Dice(d);
		String dirs = scan.next();
		int len = dirs.length();
		for(int i = 0; i < len; i++){
			char ch = dirs.charAt(i);
			switch(ch){
				case 'E' :
					dice.rollEast();
					break;
				case 'W' :
					dice.rollWest();
					break;
				case 'S' :
					dice.rollSouth();
					break;
				case 'N' :
					dice.rollNorth();
					break;
				default :
					break;
			}
		}
		System.out.println(dice.show(Dice.TOP));
	}
}

class Dice{
	int[] d_ = new int[6];
	public static final int
		TOP = 0, SOUTH = 1, EAST = 2,
		WEST = 3, NORTH = 4, BOTTOM = 5;

	public Dice(int[] d){
		for(int i = 0; i < 6; i++){
			d_[i] = d[i];
		}
	}

	public int show(int side){
		return d_[side];
	}

	public void rollEast(){
		int work = d_[TOP];
		d_[TOP] = d_[WEST];
		d_[WEST] = d_[BOTTOM];
		d_[BOTTOM] = d_[EAST];
		d_[EAST] = work;
	}

	public void rollWest(){
		int work = d_[TOP];
		d_[TOP] = d_[EAST];
		d_[EAST] = d_[BOTTOM];
		d_[BOTTOM] = d_[WEST];
		d_[WEST] = work;
	}

	public void rollSouth(){
		int work = d_[TOP];
		d_[TOP] = d_[NORTH];
		d_[NORTH] = d_[BOTTOM];
		d_[BOTTOM] = d_[SOUTH];
		d_[SOUTH] = work;
	}

	public void rollNorth(){
		int work = d_[TOP];
		d_[TOP] = d_[SOUTH];
		d_[SOUTH] = d_[BOTTOM];
		d_[BOTTOM] = d_[NORTH];
		d_[NORTH] = work;
	}
}

Measured memory_bytes: 26172
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>

#define REP(i,n) for(i=0; i < (n); i++)
#define REPONE(i, n) for(i=1; i <= (n); i++)
#define LOOP(n) for(int loopCount=1; loopCount <= (n); loopCount++)
#define ITER(c) __typeof((c).begin())
#define EACH(c,it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define SZ(c) ((int) (c).size())
#define ALL(c) c.begin(), c.end()
#define SUM(c) accumulate(ALL(c), 0)
#define EXIST(c,v) (find(ALL(c), (v)) != (c).end())
#define PB push_back
#define MP make_pair

using namespace std;
static const double EPS = 1e-9;
static const double PI = 3.141592653589793238462643383279;
typedef long long ll;

int main(){
    int m, y, z, e;

    while(scanf("%d",&e)){
        if(!e) break;
        m = 1<<30;
        for(z=0;z*z*z <= e; z++)
            for(y=0; y*y+z*z*z <= e; y++)
                m = min(e-y*y-z*z*z+y+z, m);
        printf("%d\n",m);
    }

    return 0;
}

Measured memory_bytes: 876
n, m = gets.chomp.split.map(&:to_i)

h = Hash.new(0)

m.times do |i|
  a, b = gets.chomp.split.map(&:to_i)
  h[a] += 1
  h[b] += 1
end

flag = true

h.each do |_, v|
  flag = false if v.odd?
end

puts flag ? 'YES' : 'NO'

Measured memory_bytes: 7420
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<int> a(n);
    for(auto&i:a) cin>>i;
    sort(a.rbegin(),a.rend());
    ll ans{};
    Fr(i,n-1) ans+=a[i/2];
    cout<<ans<<'\n';
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)

const int MOD = 1e9 + 7;

int main(){
    int N; cin >> N;
    string S1, S2;
    cin >> S1 >> S2;
    bool pre = 0;
    ll ans = 1;
    rep(i, 0, N){
        ans %= MOD;
        if(i == 0){
            if(S1[i] == S2[i]){
                ans *= 3;
                pre = 0;
            }else{
                i++;
                ans *= 6;
                pre = 1;
            }
            continue;
        }
        if(S1[i] == S2[i]){
            if(pre == 1){
                ans *= 1;
            }else{
                ans *= 2;
            }
            pre = 0;
        }else{
            i++;
            if(pre == 1){
                ans *= 3;
            }else{
                ans *= 2;
            }
            pre = 1;
        }
    }
    ans %= MOD;
    cout << ans << endl;
}

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    int n;
    cin >> n;
    vector<ll> f(100000, 0);
    ll tot;
    for (int x = 1; x <= 100;x++)
    {
        for (int y = 1; y <= 100; y++)
        {
            for (int z = 1; z <= 100; z++)
            {
                tot = x * x + y * y + z * z + x * y + y * z + z * x;
                if(tot > 10000)
                    continue;
                f[tot]++;
            }
        }
    }
    for (int i = 1; i <= n; i++){
        cout << f[i] << endl;
    }
        return 0;
}

Measured memory_bytes: 3916
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void N(int a[], int t) {
	t = a[1];
	a[1] = a[2];
	a[2] = a[6];
	a[6] = a[5];
	a[5] = t;
}

void S(int a[], int t) {
	t = a[1];
	a[1] = a[5];
	a[5] = a[6];
	a[6] = a[2];
	a[2] = t;
}

void E(int a[], int t) {
	t = a[1];
	a[1] = a[4];
	a[4] = a[6];
	a[6] = a[3];
	a[3] = t;
}

void W(int a[], int t) {
	t = a[1];
	a[1] = a[3];
	a[3] = a[6];
	a[6] = a[4];
	a[4] = t;
}

int main(void) {
	int a[10],b[10],t=0,p=0,c=0;
	char NEWS[100];
	a[0] = 0;
	b[0] = 0;
	for (int i = 1; i <= 6; i++) {
		scanf("%d", &a[i]);
	}
	for (int i = 1; i <= 6; i++) {
		scanf("%d", &b[i]);
	}
		while ((a[1] != b[1]) || (a[2] != b[2])) {
			
			p = rand() % 4 + 1;
			if (p == 1) {
				N(a, t);
			}
			else if (p == 2) {
				E(a, t);
			}
			else if (p == 3) {
				W(a, t);
			}
			else if (p == 4) {
				S(a, t);
			}
		}
		if ((a[3] == b[3]) && (a[4] == b[4])) {
			printf("Yes\n");
		}else{
			printf("No\n");
		}
}


Measured memory_bytes: 2140
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep1(i,n) for(ll i=1;i<(ll)n;i++)
#define repf(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repr(i,a,b) for(ll i=(ll)a-1;i>=(ll)b;i--)
#define Fi first
#define Se second
typedef pair<ll, ll> pll;
const ll MAX = 1000000000000000000;
const char END = '\n';

ll N, A[1000000], Ans = 0;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	cin >> N;
	rep(i, N)
		cin >> A[i];

	rep1(i, N) {
		if (A[i - 1] > A[i]) {
			Ans += A[i - 1] - A[i];
			A[i] = A[i - 1];
		}
	}

	cout << Ans << END;
	return 0;
}

Measured memory_bytes: 5200
import heapq
n,m,*a = map(int,open(0).read().split())
a = list(map(lambda x: x*(-1), a))
heapq.heapify(a)
for _ in range(m):
  heapq.heappush(a,-(-heapq.heappop(a)//2))
print(-sum(a))

Measured memory_bytes: 20116
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0);
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(ll x=j;x<n;x++)
#define repr(x,j,n)for(ll x=j;x>n;x--)
#define mod 1000000007
typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
    if(b&1)
    r=(r*a)%m;
    b=b/2;
    a=(a*a)%m;
    }
    return r%m;
}


int main()
{
    string s,t;
    cin>>s>>t;
    int ans=INT_MAX;
    for(int i=0;i<s.length();i++)
    {
        if(i+t.length()-1>=s.length())break;
        int x=0;
        for(int j=0;j<t.length();j++)if(s[i+j]!=t[j])x++;
        ans=min(ans,x);

    }
    cout<<ans;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define MOD 1000000007

int main(void){
    ll n,d,a;
    cin >> n >> d >> a;
    vector<pair<ll,ll>> mon(n);
    ll x,h;
    rep(i,n){
        cin >> x >> h;
        mon[i] = make_pair(x,ceil(h/(double)a));
    }
    sort(all(mon));
    vector<ll> right(n);
    rep(i,n){
        ll r = mon[i].first + d*2;
        ll ok = i;
        ll ng = n;
        while(ng-ok>1){
            ll mid = (ok+ng)/2;
            if(mon[mid].first > r) ng=mid;
            else ok=mid;
        }
        right[i] = ok;
    }
    ll ans=0;
    ll dam = 0;
    vector<ll> cum(n,0);
    rep(i,n){
        if(mon[i].second > dam){
            ll p = mon[i].second - dam;
            ans += p;
            cum[i] += p;
            cum[right[i]] -= p;
        }
        dam += cum[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[1000];
    cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
    int b=1000;
    int c=0;
    int d;
    for(int i=0;i<5;i++){
		if(a[i]%10!=0){
			b=min(b,a[i]%10);
			
		}
	}
	for(int i=0;i<5;i++){
		if(b==a[i]%10){
			c=c+a[i];
			b=0;
			continue;
		}
		if(a[i]%10!=0){
		d=(a[i]-a[i]%10)/10;
			c=c+10*(d+1);
		}
		else{
			c=c+a[i];
		}
	}
	cout<<c<<endl;
}

Measured memory_bytes: 256
var
	s:String[100];
	i,f:Longint;
	c:array[0..25]of Longint;
begin
	readln(s);
	for i:=1 to length(s)do inc(c[ord(s[i])-97]);
	for i:=0 to 25 do if c[i]mod 2=1 then f:=1;
	if f>0 then write('No')else write('Yes');
end.

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define mem(x,y) memset(x,y,sizeof(x)) //memset array
#define fo(i,r,k)  for((i) = r; (i) < (k); i=i+1)
#define fok(i,k,n) for((i) = k; (i) > n; i=i-1)
#define deb(x) cout << #x << " = " << x << endl
#define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define deb3(x, y, z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define bug puts("Hello");
#define mp make_pair
#define pb push_back
#define pi pair<int,int>
#define pl pair<long long,long long>
#define vi vector<int>
#define vl vector<long long>
#define vpl vector<pair<long long,long long>>
#define vpi vector<pair<int,int>>
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define br cout<<"\n";
#define sortall(x) sort(x.begin(),x.end())
#define modexpo poww
ll modexpo(ll x,ll y,ll m){x=x%m;if(y==0){return 1;}if(y%2==0){return modexpo(x*x,y/2,m); }else{return (x*modexpo(x*x,y/2,m))%m; }}
void io();
const int mod  = 1e9+7;
const int maxn = 2e5 + 10;
int n,k,a[maxn]; 
int dp[maxn]; 
int rec(int n)
{   
    if(dp[n]!=-1) return dp[n]; 
    
    int ans = INT_MAX;
    int i; 
    for(i=max(1,n-k);i<n;i++)
    {
        ans = min(ans,abs(a[n]-a[i]) + rec(i)); 
    }
    return dp[n] = ans;
}

int main()
{
int i,j;
cin>>n;
k=2; 
//>>k;
fo(i,1,n+1) cin>>a[i]; 
mem(dp,-1);
dp[0] = 0;
dp[1] = 0;
dp[2] = abs(a[1]-a[2]); 
rec(n);
cout<<dp[n]; 
return 0;
}

void io()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
}


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

typedef long long ll;
const int INF = 1000000000;
const long INF64 = 9223372036854775807;
const int MOD = 1000000007;

int main(){
	int n,m,xx,yy;
	std::cin >> n>>m>>xx>>yy;
	std::vector<int> x(n);
	rep(i,n)std::cin >> x[i];
	std::vector<int> y(m);
	rep(i,m)std::cin >> y[i];
	int maxx=xx,miny=yy;
	bool han=false;
	rep(i,n){
		maxx=max(maxx,x[i]);
	}
	rep(i,m){
		miny=min(miny,y[i]);
	}
	if(maxx<miny)std::cout << "No War" << std::endl;
	else	std::cout << "War" << std::endl;
}

Measured memory_bytes: 256
from collections import deque
H, W = map(int, input().split())
S = [input() for x in range(H)]


def bfs(h, w):  # h,wは縦、横の値
    dist = [[-1] * W for iii in range(H)]  # スタートからの距離
    check_que = deque()
    dist[h][w] = 0
    check_que.append((i, j))
    d = 0
    for m in range(H):
        for n in range(W):
            if S[m][n] == "#":
                dist[m][n] = -2
    while check_que:
        h, w = check_que.popleft()
        d = dist[h][w]
        for dh, dw in ((0, 1), (0, -1), (1, 0), (-1, 0)):
            h_prime, w_prime = h + dh, w + dw

            if 0 > h_prime or h_prime >= H or 0 > w_prime or w_prime >= W:
                continue
            if dist[h_prime][w_prime] == -1:
                dist[h_prime][w_prime] = d + 1
                check_que.append((h_prime, w_prime))
    return d


ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            dis = bfs(i, j)
            if ans < dis:
                ans = dis
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
   
int dp[2001][2001][2];
int main(void){
  int    M, N;
  string S, T;
  cin >> M >> N >> S >> T;
   
  //for(int i=0; i < M; i++) for(int j=0; j < N; j++) dp[i][j][1] = -INT_MAX;

  for(int i=0; i < M; i++){
      if(S[i] == 'I'){
        dp[i+1][0][0] = max(dp[i+1][0][0], dp[i][0][1]+1);
      }
      if(S[i] == 'O'){
        if(dp[i][0][0] != 0){
          dp[i+1][0][1] = max(dp[i+1][0][1], dp[i][0][0]+1);
        }
      }
  }
  for(int j=0; j < N; j++){
      if(T[j] == 'I'){
        dp[0][j+1][0] = max(dp[0][j+1][0], dp[0][j][1]+1);
      }
      if(T[j] == 'O'){
        if(dp[0][j][0] != 0){
          dp[0][j+1][1] = max(dp[0][j+1][1], dp[0][j][0]+1);
        }
      }
  }
   
  for(int i=0; i < M; i++){
    for(int j=0; j < N; j++){
      if(S[i] == 'I'){
        dp[i+1][j+1][0] = max(dp[i+1][j+1][0], dp[i][j+1][1]+1);
      }
      if(S[i] == 'O'){
        if(dp[i][j+1][0] != 0){
          dp[i+1][j+1][1] = max(dp[i+1][j+1][1], dp[i][j+1][0]+1);
        }
      }

      if(T[j] == 'I'){
        dp[i+1][j+1][0] = max(dp[i+1][j+1][0], dp[i+1][j][1]+1);
      }
      if(T[j] == 'O'){
        if(dp[i+1][j][0] != 0){
          dp[i+1][j+1][1] = max(dp[i+1][j+1][1], dp[i+1][j][0]+1);
        }
      }
    }
  }

  /*
  for(int j=0; j <= N; j++){
    printf("%7d ", j);
  }
  printf(" --->%s\n", T.c_str());
  for(int i=0; i <= M; i++){
    for(int j=0; j <= N; j++){
      printf("(%2d,%2d)", dp[i][j][0], dp[i][j][1]);
      if(j != N) printf(" ");
    }
    printf("\n");
  }
  */
   
  int ans = 0;

  for(int i=0; i <= M; i++){
    for(int j=0; j <= N; j++){
      ans = max(ans, dp[i][j][0]);
    }
  }

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

Measured memory_bytes: 32496
def solve():
  t = [[] for _ in range(4)]
  for _ in range(3):
    a, b = map(int, input().split())
    if b-1 in t[a-1]:
      print("NO")
      return
    if a-1 in t[b-1]:
      print("NO")
      return
    t[a-1].append(b-1)
    t[b-1].append(a-1)

  for i in range(4):
    if len(t[i]) == 0:
      print("NO")
      return
    if len(t[i]) == 3:
      print("NO")
      return

  print("YES")
solve()

Measured memory_bytes: 8960
n = int(input())
a_ls = [int(i) for i in input().split()]
last = a_ls[-1]
for i, a in enumerate(a_ls[:-1]):
    if i % 2 == 0:
        last -= a
    else:
        last += a
a_ls[-1] = last // 2
for i in range(n-2, -1, -1):
    a_ls[i] -= a_ls[i+1]
print(" ".join([str(i*2) for i in a_ls]))

Measured memory_bytes: 15180
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    use std::collections::HashMap;
    let mut map: HashMap<usize, usize> = HashMap::new();
    for _ in 0..N {
        let v: usize = read();
        let entry = map.entry(v).or_insert(0);
        *entry += 1;
    }
    let mut ans = 0;
    for (key, value) in map {
        use std::cmp::Ordering;
        match key.cmp(&value) {
            Ordering::Equal => continue,
            Ordering::Less => ans += value - key,
            Ordering::Greater => ans += value,
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 12540
#include <iostream>
using namespace std;
int main(){
	long long int a, b, c, k, sum;
	cin >> a >> b >> c >> k;
	if(k <= a){
		cout << k;
		return 0;
	}
	else{
		k -= a;
		sum = a;
	}
	if(k <= b){
		cout << sum;
		return 0;
	}
	else
		k -= b;
	if(k <= c){
		cout << sum-k;
		return 0;
	}
} 


Measured memory_bytes: 3624
#include <stdio.h>
int search(int S[], int n, int key){
  S[n]=key;
  int i, j;
  i=0;
  while(S[i]!=key){
	++i;
}
  return i!=n;
}
int main(){
  int n, q;
  scanf("%d", &n);
  int S[10005], T[505];
  int i, j;
  int key;
  int count=0;
  for(i=0; i<n; ++i){
	scanf("%d", &S[i]);
}
  scanf("%d", &q);
  for(i=0; i<q; ++i){
	scanf("%d",&key);
	if(search(S, n, key)==1)
	  ++count;
}
  printf("%d\n", count);
  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    vector<ll> x(n);
    REP(i,n) cin>>x[i];
    ll ans=1e18;
    for(int i=0;i<n-k+1;i++){
        ll tmp1,tmp2;
        tmp1 = abs(x[i])+abs(x[i]-x[i+k-1]);
        tmp2 = abs(x[i+k-1])+abs(x[i]-x[i+k-1]);
        ans = min({ans,tmp1,tmp2});
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;

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

  double sum = 0;
  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < i; ++j) {
      sum += sqrt(pow(x[i]-x[j], 2)+pow(y[i]-y[j], 2));
    }
  }
  
  double num = 1;
  for(int i = n-1; i > 0; --i) {
    num *= i;
  }
  double fact = 1;
  for(int i = n; i > 0; --i) {
    fact *= i;
  }
  
  printf("%.10f\n", sum*num*2/fact);
  return 0;
}

Measured memory_bytes: 256
from itertools import permutations

N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))

counter = 0
a = 0
b = 0
for i in permutations(range(1,N+1)):
    if i == P:
        a = counter
    if i == Q:
        b = counter
    counter += 1
print(abs(a-b))


Measured memory_bytes: 73208
#include "bits/stdc++.h"
using namespace std;

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

const int INF = 1000000007;

int main(){
	int n,k;
	cin>>n>>k;
	int a[220000]={0};
	int arr[220000]={0};
	int cnt=0,kind=0;
	for(int i=0;i<n;i++)cin>>a[i];

	for(int i=0;i<n;i++){
		arr[a[i]-1]++;
	}
	for(int i=0;i<n;i++){
		if(arr[i] != 0) kind++;
	}
	sort(arr, arr+n);
	int i=0;
	while(kind>k){
		if(arr[i] == 0) {
			i++;
			continue;
		}
		cnt += arr[i];
		kind--;
		i++;
	}

	cout<< cnt <<endl;

	return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

struct Edge{
  int to, cost;

  Edge(int t, int c = 0): to(t), cost(c)
  {}
  bool operator>(const Edge& rhs) const{
	return cost > rhs.cost;
  }
  bool operator<(const Edge& rhs) const{
	return cost < rhs.cost;
  }

};
typedef vector< vector<Edge> > Graph;

void add_edge(Graph& graph, int u, int v, int cost){
  graph[u].push_back(Edge(v,cost));
  graph[v].push_back(Edge(u,cost));
}

PII diameter_(int prv, int now, const Graph& g){
  PII res(0, now);
  for(auto& e: g[now]){
	if(prv == e.to) continue;
	PII tmp = diameter_(now, e.to, g);
	tmp.first += e.cost;
	if(res.first < tmp.first)
	  res = tmp;
  }
  return res;
}
PII diameter(const Graph& g, int& r, int rt){
  PII u = diameter_(-1, rt, g);
  PII v = diameter_(-1, u.second, g);
  r = v.first;
  return PII(u.second, v.second);
}

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

  int N;
  while(cin>>N,N){
	int S = 0;
	VI ps(N), ds(N);
	REP(i,N-1){
	  cin >> ps[i];
	  --ps[i];
	}
	REP(i,N-1){
	  cin >> ds[i];
	  S += ds[i];
	}
	if(N == 3){
	  cout << S << endl;
	  continue;
	}

	VI in(N);
	REP(i,N-1){
	  in[i+1]++;
	  in[ps[i]]++;
	}

	int ans = 0;
	Graph G(N);
	int rt = -1;
	REP(i,N-1){
	  if(in[i+1] != 1 && in[ps[i]] != 1){
		rt = i+1;
		add_edge(G, i+1, ps[i], ds[i]);
		ans += ds[i];
	  }
	}
	
	int n = 0;
	REP(i,N) if(in[i] > 1) ++n;
	int r = 0;
	if(n > 1) diameter(G, r, rt);
	cout << ans*2 - r + S << endl;
  }

  return 0;
}

Measured memory_bytes: 3284
N = gets.to_i
As = readlines.map{|l| l.split.map(&:to_i)}

as = [nil] + As
q, x = [*1 .. N], 0
loop do
  d = q.each_with_object([]){|a, o| b = as[a].first; o << a << b if b && as[b].first == a}
  break if d.empty?
  x += 1
  q = d.uniq
  q.each{|a| as[a].shift}
end
puts as.compact.flatten.empty? ? x : -1

Measured memory_bytes: 40188
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		boolean flag=false;
exit:	for(int i=0;i<26;i++) {
			for(int j=0;j<15;j++) {
				if(i*4+j*7==N) {
					flag = true;
					break exit;
				}
			}
		}
		if(flag) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

void solve() {
  ll X, Y, Z, K; cin >> X >> Y >> Z >> K;
  vector<ll> a(X), b(Y), c(Z);
  rep(i, X) cin >> a[i];
  rep(i, Y) cin >> b[i];
  rep(i, Z) cin >> c[i];
  sort(a); sort(b); sort(c);
  vector<ll> ab(K*K);
  ll abi = 0;
  rep(i, min(X, K))rep(j, min(Y, K)){
    // debug2(a[X-1-i], b[Y-1-j]);
    ab[abi++] = a[X-1-i] + b[Y-1-j];
  }
  sort(ab);
  vector<ll> abc(K*K);
  ll abci = 0, r = K*K-1;
  rep(i, K)rep(j, min(Z, K)) {
    // debug2(ab[r-i], c[Z-1-j]);
    abc[abci++] = ab[r-i] + c[Z-1-j];
  }
  sort(abc);
  rep(i, K) {
    outl(abc[r-i]);
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 140928