akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =2147483647;//32bit 2*1e+9
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int main(void){
	int number,numbers[11]={};
	REP(i,3){
		cin>>number;
		numbers[number]++;
	}
	if(numbers[5]==2&&numbers[7]) puts("YES");
	else puts("NO");
	return 0; 
}



Measured memory_bytes: 256
N,K = map(int,input().split())
S = input()

ans = 0
dif = 0
for i in range(1,N):
    if S[i] != S[i-1]: dif += 1
    else: ans += 1

if K <= dif//2:
    ans += 2*K
else:
    ans = N-1

print(ans)

Measured memory_bytes: 3316
def main():
    N=int(input())
    RDictionary={}
    index=1
    for i in range(N):
        SP=input().split()
        S=SP[0]
        P=int(SP[1])
        if (S in RDictionary.keys()):
            RDictionary[S].append((P,index))
        else:
            RDictionary[S]=[(P,index)]
        index+=1

    Names=list(RDictionary.keys())
    Restaurants=list(RDictionary.values())

    Rest_Town=zip(Names,Restaurants)

    Rest_Town=sorted(Rest_Town)

    Names,Restaurants=zip(*Rest_Town)
    Restaurants=list(Restaurants)

    #Restraurants => [[(),(),()],[(),()],...]

    for i in range(len(Restaurants)):
        Restaurants[i]=sorted(Restaurants[i],reverse=True)

    for town in Restaurants:
        for rest in town:
            print(rest[1])


if __name__=="__main__":
    main()


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

#define endl '\n'
#define ll  long long
#define modd(a,b) ((a+2*b)%b)
#define ioso ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define debug(a) cout << #a << ": " << (a) << "\n"
#define ffe freopen("input.txt","r",stdin), freopen("output.txt","w",stdout)
vector<ll> ed[100010];
int vis[100010];

int main() {
	ioso;
	#ifndef ONLINE_JUDGE
	ffe;
	#endif

	ll n,e;
	cin >> n >> e;

	int h[100010];

	for(int i=1;i<=n;i++) {
		cin >> h[i];
	}
	int u,v;
	for(int i=0;i<e;i++) {
		cin >> u >> v;
		ed[u].push_back(v);
		ed[v].push_back(u);

	}
	int cn=0;
	for(int i=1;i<=n;i++) {
		int b=0;
		for(auto j:ed[i]) {
			if(h[j]>=h[i]) {
				b=1;break;
			}
		}
		if(b==0) {cn++;} 
	}
	cout << cn << endl;		
}

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

int main() {
    int N;
    cin >> N;
    vector<double> vec(N);
    for (int i = 0; i < N; i++)
    {
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    double sum = vec.at(0);
    for (int i = 0; i < N; i++)
    {
        sum = (sum + vec.at(i)) / 2;
    }
    cout << sum;
}

Measured memory_bytes: 256
# include<stdio.h>
int main()
{
int a[10],i,j,temp;
for(i=0;i<10;i++)
scanf("%d",&a[i]);
for(i=1;i<10;i++)
{
temp=a[i];
j=i-1;
while(temp<a[j]&&j>=0)
	{
	a[j+1]=a[j];
	j--;
	}
a[j+1]=temp;
}
for(i=9;i>=7;i--)
printf("%d\n",a[i]);
return 0;
}

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

int main() {
    string a, b, c;
    cin >> a >> b >> c;
    cout << a[0] << b[0] << c[0] << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int kugyu(const void* asumisu, const void* kitaeri) {
	int tomatu = *(const int*)asumisu, iguti = *(const int*)kitaeri;
	return tomatu < iguti ? -1 : tomatu > iguti;
}

int n;
int a[114514];

int main(void) {
	int i;
	int score = 0;
	int value = 0;
	if (scanf("%d", &n) != 1) return 1;
	for (i = 0; i < n; i++) {
		if (scanf("%d", &a[i]) != 1) return 1;
	}
	qsort(a, n, sizeof(*a), kugyu);
	value = a[0];
	for (i = 0; i < n - 1; i++) {
		int curScore = a[i];
		if (a[n - 1] - a[i] < curScore) curScore = a[n - 1] - a[i];
		if (curScore > score) {
			score = curScore;
			value = a[i];
		}
	}
	printf("%d %d\n", a[n - 1], value);
	return 0;
}

/*

大きい方の数を決めたら、できるだけ真ん中に近い方が有利

今、仮に数のペアが決まっているとする

選択肢は多いほど選び方が多い → 大きい方の数を大きくすればもっと選び方を多くできる

*/


Measured memory_bytes: 892
from itertools import permutations
n, m = map(int, input().split())
path = []
for i in range(m):
    a, b = map(int, input().split())
    path.append([a,b])
    path.append([b,a])
import itertools
per = [i for i in range(2,n+1)]
data = list(itertools.permutations(per, n-1))    
flg = 0
for k in range(len(data)):
    tmp = [[1, data[k][0]]]
    for i in range(n-2):
        tmp.append([data[k][i],data[k][i+1]])
    cnt = 0
    for var in tmp:
        if var in path:
            cnt += 1
    if cnt == len(tmp):
        flg += 1
print(flg)  

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

#define REP(A, H) for(int A = 0; A < H; A++)
#define RREP(A, B, H, W) for(int A = 0; A < H; A++) for (int B = 0; B < W; B++)
#define MAX(A, B) (A = std::max(A, B))
#define MIN(A, B) (A = std::min(A, B))

typedef long long ll;

struct POINT {
  int x; int y;
  POINT(int x, int y) : x(x), y(y) {}
};

POINT operator +(const POINT& a, const POINT& b) {
  return POINT(a.x + b.x, a.y + b.y);
}

POINT operator -(const POINT& a, const POINT& b) {
  return POINT(a.x - b.x, a.y - b.y);
}

/* std::cout << ;*/
/* std::cout << << std::endl; */

ll mulcnt(ll mul, ll upper) {
  return (upper / mul) + 1;
}

ll mulcnt_from_to(ll mul, ll lower, ll upper) {
  return mulcnt(mul, upper) - mulcnt(mul, lower);
}

ll lcd(ll a, ll b) {
  ll tmp;
  ll x = a * b;
  if (a < b) {
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r;
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

  return x / b;
}

int main(void) {
  ll a, b, c, d; std::cin >> a >> b >> c >> d;

  // std::cout << mulcnt(c, a - 1) << mulcnt(c, b) << mulcnt_from_to(c, a - 1, b)  << std::endl;
  // std::cout << mulcnt(d, a - 1) << mulcnt(d, b) << mulcnt_from_to(d, a - 1, b)  << std::endl;
  // std::cout << mulcnt(lcd(c, d), a - 1) << mulcnt(lcd(c, d), b) << mulcnt_from_to(lcd(c, d), a - 1, b) << std::endl;

  ll cnt = (b - a + 1) - mulcnt_from_to(c, a - 1, b) 
    - mulcnt_from_to(d, a - 1, b) 
    + mulcnt_from_to(lcd(c, d), a - 1, b);

  std::cout << cnt << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
#include <string.h>
#include <queue>
#include <map>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i != int(e); i++)
#define REP(i,e) for (int i = 0; i != int(e); i++)
#define FORIT(i, A) for (auto i : A)
#define ISEQ(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << endl
#define SZ(x) ((int)(x).size())

int main(int argc, char const *argv[])
{
	int w, h;
	char world[21][21];
	while(1)
	{
		scanf("%d %d", &w, &h);
		if (w == 0 && h == 0) break;
		int sx = -1, sy = -1;
		int memo[20][20];
		memset(memo, 0, 20 * 20 * sizeof(int));
		REP(i, h)
		{
			scanf("%s", world[i]);
			if (sx == -1)
			{
				REP(j, w)
					if (world[i][j] == '@')
					{
						sx = j;
						sy = i;
					}
			}
		}
		std::queue<std::pair<int, int> > q;
		q.push(std::make_pair(sx, sy));
		memo[sy][sx] = 1;
		int area = 0;
		while(!q.empty())
		{
			std::pair<int, int> p = q.front();
			q.pop();
			area++;
			int x = p.first;
			int y = p.second;
			// left
			if (x > 0 && world[y][x-1] == '.' && memo[y][x-1] == 0)
			{
				memo[y][x-1] = 1;
				q.push(make_pair(x-1, y));
			}
			if (x < (w-1) && world[y][x+1] == '.' && memo[y][x+1] == 0)
			{
				memo[y][x+1] = 1;
				q.push(make_pair(x+1, y));
			}
			// up
			if (y > 0 && world[y-1][x] == '.' && memo[y-1][x] == 0)
			{
				memo[y-1][x] = 1;
				q.push(make_pair(x, y-1));
			}
			if (y < (h-1) && world[y+1][x] == '.' && memo[y+1][x] == 0)
			{
				memo[y+1][x] = 1;
				q.push(make_pair(x, y+1));
			}
		}
		printf("%d\n", area);
	}
	return 0;
}

Measured memory_bytes: 3240
memo=[1]*10
def fac(N):
    if N==0:return 1
    elif memo[N]==1:
        memo[N]=N*fac(N-1)
    return memo[N]

def dic(S,N):
    res=0
    nums=list(range(N+1))
    for i in range(N-1):
        res+=(nums.index(S[i])-1)*fac(N-i-1)
        nums.pop(nums.index(S[i]))
    return res+1

N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
print(abs(dic(P,N)-dic(Q,N)))

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

int main()
{
	char s[16];
	scanf("%s", s);

	int res = 999;
	for(int i=2; s[i]!='\0'; i++){
		int a2 = s[i-2] - '0';
		int a1 = s[i-1] - '0';
		int a0 = s[i-0] - '0';
		int diff = abs(a2 * 100 + a1 * 10 + a0 - 753);
		if(diff < res){
			res = diff;
		}
	}

	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 128
//============================================================================
// Name        : template.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE // suppress some compilation warning messages (for VC++ users)
// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
// To simplify repetitions/loops, Note: define your loop style and stick with it!
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define forn(i,n) \
for (int i =0; i<(n); i++)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

int main() {
int x ;
cin >> x;
cout << x * x;
return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]
mod = 998244353

dp = [0] * N
dp[0] = 1

now = 0

for i in range(1, N):
    for l, r in LR:
        if i - l >= 0:
            now += dp[i - l]
            now %= mod
        if i - r - 1 >= 0:
            now -= dp[i - r - 1]
            now %= mod
        dp[i] = now
    #print(dp)
print(dp[-1])


Measured memory_bytes: 75352
#include <stdio.h>          // printf(), scanf()
#include <stdbool.h>

#define N_ID 1000
#define MAX_N 4000

typedef struct
{
	bool done;
	long proceeds;
} sales_t;

int
main(int argc, char **argv)
{
	sales_t sales[MAX_N + 1];
	int id[N_ID];
	int n_id;
	int e, p, q;
	int n, i;

	while (true)
	{
		scanf("%d", &n);
		if (n == 0)
			break;

		for (i = 0; i <= MAX_N; ++i)
		{
			sales[i].done = false;
			sales[i].proceeds = 0;
		}

		n_id = 0;
		for (i = 0; i < n; ++i)
		{
			scanf("%d %d %d", &e, &p, &q);
			id[n_id++] = e;
			sales[e].proceeds += p * q;
		}

		bool b_none = true;
		for (i = 0; i < n_id; ++i)
		{
			if (sales[id[i]].proceeds >= 1000000 && !sales[id[i]].done)
			{
				printf("%d\n", id[i]);
				sales[id[i]].done = true;
				b_none = false;
			}
		}

		if (b_none)
			printf("NA\n");
	}

	return 0;
}

Measured memory_bytes: 676
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <unordered_map>
#include <iterator>
#include <functional>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	while(cin >> n, n){
		vector<string> s(n);
		vi plv(1001, -1);
		REP(i, n){
			cin >> s[i];
			int lv = 0;
			for(int j=0;s[i][j]=='.';j++){
				lv++;
				s[i][j] = ' ';
			}
			if(lv){
				s[i][lv-1] = '+';
				if(plv[lv] >= 0){
					for(int j=plv[lv]+1;j<i;j++) s[j][lv-1] = '|';
				}
			}
			for(int j=lv+1;j<i;j++) plv[j] = -1;
			plv[lv] = i;
		}
		REP(i, n) cout << s[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
 using namespace std;
const int N=2e5+20;
int n,a[N],mn=INT_MAX,x;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]<mn) x++;
        mn=min(mn,a[i]);
    }
    cout<<x;
}


Measured memory_bytes: 4428
/*
* @Author: Kabid
* @Date:   2020-04-26 18:01:07
* @Last Modified by:   Kabid
* @Last Modified time: 2020-05-17 18:13:09
*/
#include<bits/stdc++.h>

#define ll long long
#define  in(x) scanf("%d",&x);
#define out(x) printf("%d",x);
#define  ins(x)  scanf("%s",x);
#define outs(x) printf("%s",x);
#define lin puts("");
#define _ putchar(' ');
using namespace std;
set<ll> s;
int t;       //test cases
ll  n = 0, m,i; //variables
ll a[200002], b[200002], c, k;
int main() {
	cin >> n ;
	

	if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9){
		puts("hon");
	}
	if(n%10==0||n%10==1||n%10==6||n%10==8){
		puts("pon");
	}
	if(n%10==3){
		puts("bon");
	}






	return 0;
}




Measured memory_bytes: 3636
n,k=map(int, input().split())
p=[int(x) for x in input().split()]
s=0
for c in range(k):
    s+=p[c]
t=s
for c in range(n-k):
    t+=p[c+k]-p[c]
    if t>s:
        s=t
print((s+k)/2)

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

class WeightedUnionFind {
public:
    WeightedUnionFind(int n) : parent(n), rank(n, 0), value(n, 0) {
        rep(i, 0, n) parent[i] = i;
    }

    int root(int x) {
        if (parent[x] == x) {
            return x;
        } else {
            int root_x = root(parent[x]);
            value[x] += value[parent[x]];
            return parent[x] = root_x;
        }
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int weight(int x) {
        root(x);
        return value[x];
    }

    int diff(int x, int y) {
        return weight(y) - weight(x);
    }

    bool unite(int x, int y, int w) {
        w += weight(x);
        w -= weight(y);

        x = root(x);
        y = root(y);
        if (x == y) return false;

        if (rank[x] < rank[y]) {
            swap(x, y);
            w = -w;
        }

        if (rank[x] == rank[y]) rank[x]++;

        parent[y] = x;
        value[y] = w;
        
        return true;
    }

private:
    vector<int> parent, rank, value;
};

int main() {
    int n, m;
    cin >> n >> m;

    WeightedUnionFind uf(n);
    rep(i, 0, m) {
        int l, r, d;
        cin >> l >> r >> d;
        l--, r--;

        if (uf.same(l, r) && d != uf.diff(l, r)) {
            cout << "No" << endl;
            return 0;
        } else {
            uf.unite(l, r, d);
        }
    }
    
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <vector>
using std::cout;
using std::cin;
using std::endl;
using std::vector;

int main()
{
    int N;
    vector<int> D;
    int result = 0;

    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int dnow;
        cin >> dnow;
        D.push_back(dnow);
    }

    for (int i = 0; i < D.size(); i++)
    {
        for (int j = i + 1; j < D.size(); j++)
        {
            result += D[i] * D[j];
        }
    }
    cout << result << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define fo(i,a,n) for (i = a; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;



void solve(){
    set<int> s;
    int a, b, c;
    cin>>a>>b>>c;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if(s.size() == 2)cout<<"Yes";
    else cout<<"No";
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


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

int main(){
  vector<long long> X(5);
  long long index = 0;
  for (long long i = 0; i < 5; i++){
    cin >> X.at(i);
    if (X.at(i) == 0){
      index = i + 1;
    }
  }
  cout << index;
}

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

int main() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for(int i = 0; i < 1000; i++){
		char a[3];
		a[0] = (char) ((i/100)%10 + '0');
		a[1] = (char) ((i/10)%10 + '0');
		a[2] = (char) (i%10 + '0');
		int now = 0;
		rep(j, n){
			if(s[j] == a[now]){
				now++;
				if(now == 3) break;
			}
		}
		if(now == 3) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
w = [input() for i in range(n)]
a = 'Yes'
for i in range(n-1):
    if w.count(w[i]) > 1:
        a = 'No'
        break
    elif w[i][-1] != w[i+1][0]:
        a = 'No'
        break    
print(a)

Measured memory_bytes: 2940
def get_prime(N):
    if N < 2:
        return {1:1}
    prime = dict()
    prime[1] = 1

    i = 2
    while i*i <= N:
        while N % i == 0:
            if i in prime.keys():
                prime[i] += 1
            else:
                prime[i] = 1
            N = N//i
        i += 1
    if N != 1:
        prime[N] = 1
    return prime


n, p = [int(i) for i in input().strip().split()]


prims = get_prime(p)

ans = 1


if n == 1:
    print(p)
    quit()

for p, cnt in prims.items():
    _tmp = cnt//n
    ans *= p**(cnt//n)

print(ans)

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

#define NUM 100000

int prime[NUM + 1];
int counts[NUM + 1];

void init_prime() {
  int i, j;
  int sq_num = (int)sqrt((double)NUM);

  for (i = 0; i < NUM; i++) {
    prime[i] = i % 2;
  }
  prime[0] = prime[1] = 0;
  prime[2] = 1;

  for (i = 3; i < sq_num; i++) {
    if (prime[i] == 0) {
      continue;
    }
    for (j = i; i * j <= NUM; j += 2) {
      prime[i * j] = 0;
    }
  }
}

void init_counts() {
  int i;

  counts[0] = counts[1] = 0;
  for (i = 2; i <= NUM; i++) {
    counts[i] = counts[i - 1];
    if (prime[i] && prime[(i + 1) / 2]) {
      counts[i]++;
    }
  }
}

void solv(int q) {
  int i, l, r;

  for (i = 0; i < q; i++) {
    scanf("%d %d", &l, &r);
    printf("%d\n", counts[r] - counts[l - 1]);
  }
}

int main(int argc, char **argv) {
  int q;

  init_prime();
  init_counts();
  while (scanf("%d", &q) != EOF) {
    solv(q);
  }

  return 0;
}


Measured memory_bytes: 1280
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split();
        int N = int.Parse(input[0]);
        int M = int.Parse(input[1]);
        bool []flag=new bool[N];
        int[] wa_hidden = new int[N];
        for (int i = 0; i < N; i++)
        {
            flag[i] = false;
            wa_hidden[i] = 0;
        }
        int ac = 0;
        int wa = 0;
        for (int i = 0; i < M; i++)
        {
            string[] temp = Console.ReadLine().Split();
            int p = int.Parse(temp[0])-1;
            string S = temp[1];
            if (flag[p] == false && S == "AC") { ac++;flag[p] = true;wa += wa_hidden[p]; }
            if (flag[p] == false && S == "WA") { wa_hidden[p]++; }
        }
        Console.WriteLine(ac+" "+wa);
    }
}


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

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  if(A+B<=N){
    if(A>=B){
      cout << B << " 0" << endl;
      return 0;
    }
    cout << A << " 0" << endl;
    return 0;
  }
  if(A>=B){
    cout << B << ' ' << A+B-N << endl;
    return 0;
  }
  cout << A << ' ' << A+B-N << endl;
  return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
#ifdef LOCAL
#define debug(x) cerr << #x << ": " << x << endl
#else
#define debug(x)
#endif
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

ll N;
ll c[10][10] ={};
ll ans = 0;

signed main(){
	cin >> N;
	for(ll i=1; i<=N; i++){
		string S = to_string(i);
		c[S[0]-'0'][S[S.size()-1]-'0']++;
	}
	for(ll i=1; i<=N; i++){
		string S = to_string(i);
		ans += c[S[S.size()-1]-'0'][S[0]-'0'];
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  string S;
  cin >> S;
  for (i64 i = 0; i < S.size(); i++)
    if (i + 1 != S.size() && S.substr(i, 2) == "hi")
      i++;
    else
    {
      cout << "No" << endl;
      return 0;
    }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define pb push_back
 
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vvi a(3001,vi(3001,0)),b(3001,vi(3001,0));
    for(int i = 0 ; i < n ; i++)
        cin >> a[0][i];
    
    for (int i = 1 ; i < n ; i++)
    {
        for(int j = 0 ; j < n - i ; j++)
        {
            ll t = a[0][j] + a[i - 1][j + 1] + b[i - 1][j + 1];
            a[i][j] = max(a[0][j] + b[i - 1][j + 1], a[0][j + i] + b[i - 1][j]);
            b[i][j] = t - a[i][j];
        }
    }
    cout << a[n-1][0] - b[n-1][0] << endl;
    return 0;
}

Measured memory_bytes: 141184
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
#define MAXN 1010
#define FI first
#define SE second
pair<int,pair<int,int> > years[MAXN];
pair<int,int> que[MAXN];
int ans[MAXN],ans2[MAXN];
char name[MAXN][20];
int main()
{
    //freopen("/home/moor/Code/input","r",stdin);
    int n,q;
    while(scanf("%d%d",&n,&q)&&(n||q))
    {
        for(int i=0;i<n;++i)
        {
            int a,b;
            scanf("%s%d%d",name[i],&a,&b);
            years[i].FI=b-a+1,years[i].SE.FI=i,years[i].SE.SE=b;
        }
        sort(years,years+n);
        for(int i=0;i<q;++i)
            scanf("%d",&que[i].FI),que[i].SE=i;
        sort(que,que+q);
        for(int i=0,j=-1;i<q;++i)
        {
            while(j+1<n&&years[j+1].FI<=que[i].FI)  ++j;
            if(j==-1||years[j].SE.SE<que[i].FI)
                ans[que[i].SE]=-1;
            else
                ans[que[i].SE]=years[j].SE.FI,ans2[que[i].SE]=que[i].FI-years[j].FI+1;
        }
        for(int i=0;i<q;++i)
            if(ans[i]==-1)  printf("%s\n","Unknown");
            else    printf("%s %d\n",name[ans[i]],ans2[i]);
    }
    return 0;
}

Measured memory_bytes: 1252
s = input()
if (s[0]=="R" and s[1]=="R" and s[2]=="R"):
    print(3)
elif (s[0]=="R" and s[1]=="R"):
    print(2)
elif(s[1]=="R" and s[2]=="R"):
    print(2)
elif "R" in s:
    print(1)
else:
    print(0)

Measured memory_bytes: 9112
N = int(input())
a = [int(input()) for _ in range(N)]

cnt, i = 0, 0
for j in range(10 ** 6):
    cnt += 1
    if a[i] == 2:
        print(cnt)
        #break
        quit()
    else:
        i = a[i] - 1
print(-1)

Measured memory_bytes: 7084
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    res1 = []
    res2 = []
    for i in range(n):
        a = A[i] // 400
        if a < 8:
            res1.append(a)
        else:
            res2.append(a)

    ma = len(set(res1)) + len(res2)
    mi = len(set(res1)) + 0 if len(set(res1)) != 0 else 1
    print(mi, ma)


if __name__ == '__main__':
    resolve()


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

char mp[60][30];
int w,h;
int cal(){
  bool used[2][60][30]={};
  int dx[9]={1,1,1,1,1,2,2,2,3},dy[9]={2,1,0,-1,-2,1,0,-1,0};
  priority_queue<P,vector<P>,greater<P> > q;
  for(int i=0;i<w;i++)
    if(mp[h-1][i]=='S')q.push(P(p(0,0),p(i,h-1))),q.push(P(p(0,1),p(i,h-1)));
  while(!q.empty()){
    int s=q.top().first.first,l=q.top().first.second;
    int x=q.top().second.first,y=q.top().second.second;
    q.pop();
    if(mp[y][x]=='T')return s;
    used[l][y][x]=1;
    int f=1,c=0;
    if(l)f=-1;
    if(isdigit(mp[y][x]))c=mp[y][x]-'0';
    for(int d=0;d<9;d++){
      int nx=x+f*dx[d],ny=y+f*dy[d];
      if(nx<0||w<=nx||ny<0||h<=ny||mp[ny][nx]=='X'||used[!l][ny][nx])continue;
      q.push(P(p(s+c,!l),p(nx,ny)));
    }
  }
  return -1;
}

int main(){
  while(cin>>w>>h,w){
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin>>mp[i][j];
    cout<<cal()<<endl;
  }
  return 0;
}

Measured memory_bytes: 9932
k = int(input())
a = list(map(int,input().split()))

l = 2
r = 2
for i in a[::-1]:
    if i > r:
        print(-1)
        exit()
    l = (l+i-1)//i*i
    r = r//i*i+i-1
    if r < l:
        print(-1)
        exit()
print(l,r)

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


int main() {

int x,n;
cin>>x>>n;
int p[n];
map<int,bool> m;
for(int i=0;i<n;i++){
	cin>>p[i];
	m[p[i]]=true;
}
int a=x,b=x;
int f=0;
while(1){
	if(!m[a]) break;
	if(!m[b]){
		f=1;break;
	}
	a--;b++;
}
if(f==0) cout<<a;
else cout<<b;
}


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

int main() {
  int count = 0;
  string S;
  cin >> S;
  rep(i,S.size()) {
    if(S.at(i) == 'R') count++;
  }
  if(count == 2 && S.at(1) == 'S') count = 1;
  cout << count << endl;
}

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


int main(){
    char a,b;
    cin>>a>>b;

    if(a=='H'){
        if(b=='H') cout<< 'H' <<endl;
        else cout<< 'D' <<endl;
    }
    else{
        if(b=='H') cout<< 'D' <<endl;
        else cout<< 'H' <<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
{
  const main = (input: string): void | string | number => {
    const r = _reader(input)
    const [s, t] = r.ss()

    return t + s
  }

  const _reader = (str: string, i = 0) => {
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')
    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map(v => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  const _getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  const _res = main(_getInput())

  if (typeof _res === 'number' || typeof _res === 'string') console.log(_res)
}


Measured memory_bytes: 7372
import sys
# input = sys.stdin.readline

N, L = map(int, input().split())

Lsum = sum([L + i for i in range(N)])

for i in range(N):
    if L + i == 0:
        ans = i
        break
else:
    if L + N - 2 < 0: ans = N - 1
    else: ans = 0

print(Lsum - (L + ans))

Measured memory_bytes: 3060
#include <stdio.h>

int main (int argc, char* argv[]) {
  char n[3];
  scanf("%s", n);

  for (int i = 0; i < 3; i++) {
    if (n[i] == '1') {
      n[i] = '9';
    } else if (n[i] == '9') {
      n[i] = '1';
    }
  }

  printf("%s\n", n);

  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >> s;
  string s5,s6,s7;
  int n = s.size()-1;
  while(n>=0){
    if(n<4){
      cout << "NO" << endl;
      return 0;
    }else{
      for(int i = n-4;i<=n;i++){
        s5.push_back(s[i]);
      }
      if(s5 == "dream" || s5 == "erase"){
        n-=5;
      }else{
        if(n<5){
          cout << "NO" << endl;
          return 0;
        }else{
          for(int i = n-5;i<=n;i++){
            s6.push_back(s[i]);
          }
          if(s6 == "eraser"){
            n-=6;
          }else{
            if(n<6){
              cout << "NO" << endl;
              return 0;
            }else{
              for(int i= n-6;i<=n;i++){
                s7.push_back(s[i]);
              }
              if(s7 == "dreamer"){
                n-=7;
              }else{
                cout << "NO" << endl;
                return 0;
              }
            }
          }
        }
      }
    }
    s5 = s6 = s7 = "";
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 512
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
using namespace std;

int main(){
int w,h,x,y;
cin>>w>>h>>x>>y;
double ans=(double)w*h/2;
cout<<fixed<<setprecision(10)<<ans<<endl;
if(x+x==w&&y+y==h)cout<<"1";
else cout<<"0";
return 0;

}

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

#define ll 					long long
#define db					double
#define ull 				unsigned long long
#define pii 				pair<int,int>
#define fi 					first
#define se 					second
#define vi 					vector<int>
#define vl					vector<ll>
#define psb 				push_back
#define ppb 				pop_back
#define all(x)			 	(x).begin(),(x).end()
#define sz(x)				(int)(x).size()
#define endln 				printf("\n")
#define gc					getchar_unlocked
#define setmin(x)			memset((x), -1, sizeof((x)))
#define setnul(x)			memset((x), 0, sizeof((x)))
#ifndef getchar_unlocked
#define getchar_unlocked 	getchar
#endif
const int inf = 1e9 + 5;
const ll infll = 1e18+5;
const int mod = 1e9 + 7;

template <typename T>
void gi(T &ret) {
	ret = 0; char inp=gc(); int kl=1;
	while (inp<'0' || inp>'9') {if (inp=='-') kl=-1; inp=gc();}
	while ('0'<=inp && inp<='9') ret=(ret<<3)+(ret<<1)+(inp-'0'), inp=gc();
	if (kl<1) ret=-ret;
}

int count (int x) {
	int ret = 0;
	while (x) {
		ret += x%10;
		x /= 10;
	}
	return ret;
}

int main() {
	int n; gi(n);
	int ans = inf;
	for (int i=1; i<n; i++) ans = min(ans, count(i)+count(n-i));
	printf ("%d\n", ans);
	return 0;
}

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

typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define rep_r(i,s,n)for(ll i = n-1;i>=s;i--)
using namespace std;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;

set<ll> s;
int main() {
	ll n; cin >> n;
	rep(i, 0, n) {
		ll a; cin >> a;
		if (s.count(a) > 0) {
			cout << "NO" << endl;
			return 0;
		}
			
		s.insert(a);
	}
			cout << "YES" << endl;

	return 0;
}



Measured memory_bytes: 9600
n, m = map(int, input().split())
if n == 1:
    a = 0
    b = 10
else:
    a = 10**(n-1)
    b = 10**n
s = []
c = []
for i in range(m):
    ss, cc = map(int,input().split())
    s.append(ss)
    c.append(cc)
for i in range(a,b):
    ans = str(i)
    for j in range(m):
        if ans[s[j]-1] != str(c[j]):
            break
    else:
        print(ans)
        exit()
else:
    print(-1)

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
int main()
{
    int n,m;
    cin>>n>>m;
    int sum=0;
    while(n--)
    {
        int t;
        cin>>t;
        sum+=min(t,(int)fabs(m-t));
    }
    cout<<sum*2<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}



int main(){
  cout << fixed << setprecision(12);
  int n;
  cin >> n;
  double p[3005];
  FOR(i,n){
    cin >> p[i+1];
  }
  double ans;
  double dp[3005][3005];
  dp[0][0]=1;
  for(int i=1;i<=n;i++){
    for(int j=0;j<=i;j++){
      if(j==0){
        dp[i][j]=dp[i-1][j]*(1-p[i]);
      }else{
        dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*(p[i]);
      }
    }
  }

  ans=0.0;
  for(int i=0;i<=n;i++){
    if(i>n-i){
      ans+=dp[n][i];
    }
  }
  cout << ans << endl;


}


Measured memory_bytes: 70016
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <stack>
#include <queue>
#include <cmath>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)

const int INF = 100000000;

using namespace std;


int main() {
	int v[13];
	for (int i = 1; i < 13; i++)v[i] = i - 1;
	v[0] = 12;

	int a, b;
	cin >> a >> b;
	a--; b--;
	if (v[a] > v[b])cout << "Alice" << endl;
	else if (v[a] < v[b])cout << "Bob" << endl;
	else cout << "Draw" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define mp make_pair
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll a,b,c,d,x,y,w,z;
	cin>>a>>b>>c>>d;
	x=b-a+1;
	y=b/c-a/c;
	if(a%c==0)
	{
	    y++;
	}
	z=b/d-a/d;
	if(a%d==0)
	{
	    z++;
	}
	c=c*d/__gcd(c,d);
	w=b/(c)-a/(c);
	if(a%(c)==0)
	{
	    w++;
	}
	//cout<<x<<" "<<y<<" "<<z<<" " <<w<<endl;
	cout<<x-y-z+w;
	return 0;
}

Measured memory_bytes: 256
import sys

def solve():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    A = [int(a) for a in input().split()]

    low, high = 0, max(A)
    while high - low > 1:
        mid = (high + low) // 2
        count = 0
        for a in A:
            if a % mid == 0:
                count += (a // mid - 1)
            else:
                count += (a // mid)
        if count <= K: high = mid
        else: low = mid
    print(high)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 31092
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main()
{
    int n,m,i;
    cin >> n >> m;
    if(n >= m){
        cout << 0 << endl;
        return 0;
    }
    vector<int> x(m);
    for(i = 0;i < m;++i){
       cin >> x.at(i);
    }
    sort(x.begin(),x.end());
    vector<int> y(m-1);
    for(i = 0;i < m-1;++i){
        y.at(i) = x.at(i+1) - x.at(i);
    }
    sort(y.begin(),y.end());
    int ans = x.at(m-1) - x.at(0);
    for(i = m-2;i >= m-n;--i){
        ans -= y.at(i);
    }
    cout << ans << endl;
    return 0;
}

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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main(){
  ll n; cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<ll> forward(n);
  forward[0] = a[0];
  rep(i,n-1){
    forward[i+1] = gcd(a[i+1], forward[i]);
  }
  vector<ll> backward(n);
  backward[n-1] = a[n-1];
  rep(i,n-1){
    backward[n-i-2] = gcd(a[n-i-2], backward[n-i-1]);
  }

  ll ans = 0;
  rep(i,n-2){
    ll tmp = gcd(forward[i],backward[i+2]);
    ans = max(ans, tmp);
  }
  ans = max(ans, forward[n-2]);
  ans = max(ans, backward[1]);
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 2560
import sys
from bisect import bisect_right

def solve():
    def getINearests(ss, ts):
        iNearests = [-1] * len(ss)
        for iS, s in enumerate(ss):
            iT = bisect_right(ts, s)
            if iT == len(ts):
                iNearests[iS] = iT-1
            elif iT == 0:
                iNearests[iS] = 0
            else:
                d1 = abs(s - ts[iT-1])
                d2 = abs(s - ts[iT])
                if d1 <= d2:
                    iNearests[iS] = iT-1
                else:
                    iNearests[iS] = iT
        return iNearests


    A, B, Q = map(int, input().split())
    ss = [int(sys.stdin.readline()) for _ in range(A)]
    ts = [int(sys.stdin.readline()) for _ in range(B)]
    xs = [int(sys.stdin.readline()) for _ in range(Q)]

    iTNearests = getINearests(ss, ts)
    iSNearests = getINearests(ts, ss)

    anss = [0] * Q
    for iX, x in enumerate(xs):
        ans = float('inf')

        # 初手: 神社
        iS = bisect_right(ss, x)
        if iS > 0:
            cost = abs(x - ss[iS-1])
            cost += abs(ss[iS-1] - ts[iTNearests[iS-1]])
            if cost < ans: ans = cost
        if iS < A:
            cost = abs(x - ss[iS])
            cost += abs(ss[iS] - ts[iTNearests[iS]])
            if cost < ans: ans = cost

        # 初手: 寺
        iT = bisect_right(ts, x)
        if iT > 0:
            cost = abs(x - ts[iT-1])
            cost += abs(ts[iT-1] - ss[iSNearests[iT-1]])
            if cost < ans: ans = cost
        if iT < B:
            cost = abs(x - ts[iT])
            cost += abs(ts[iT] - ss[iSNearests[iT]])
            if cost < ans: ans = cost

        anss[iX] = ans

    print('\n'.join(map(str, anss)))

solve()


Measured memory_bytes: 113116
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

const double pie = acos(-1.0);

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a * b / gcd(a, b);
}

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

void solve() {
    ll n; cin >> n;
    Vl a(n);
    rep(i, 0, n) cin >> a[i];
    map<ll, ll> mp;
    rep(i, 0, n) mp[a[i]]++;
    ll ans = 0;
    for(auto p : mp){
        if(p.first < p.second) ans += p.second - p.first;
        if(p.first > p.second) ans += p.second;
    }
    cout << ans << endl;
}

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

    solve();
    return 0;
}


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


int main(){
    ll N, ans =0;
    cin >> N;
    vector<ll> a(N, 0);
    for(int i = 0; i < N; i++){
        cin >> a[i];
        while(a[i] % 2 == 0){
            if(a[i] % 2 == 0){
                ans++;
                a[i] = a[i] / 2;
            }  
            
        }
    } 
    cout << ans << endl;
}


Measured memory_bytes: 384
N = gets.to_i
Ws = gets.split.map(&:to_i)

sum = []

s = 0

sum_reverse = []

s_reverse = 0


sum.push(0)
sum_reverse.push(0)

Ws.each do |w|
  s += w
  sum.push(s)
end

Ws.reverse_each do |w|
  s_reverse += w
  sum_reverse.push(s_reverse)
end

results = []

(N + 1).times do |i|

  results << (sum[i] - sum_reverse[sum_reverse.length  - 1 - i]).abs

end


ans = results.min

puts ans


Measured memory_bytes: 1788
def main():
    N, M = map(int, input().split())
    L, R = 0, 1001001
    for i in range(M):
        l, r = map(int, input().split())
        L = max(L, l)
        R = min(r, R)
    print(max(0, R - L + 1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 44888
import sys

def main():
    N = int(input())
    A = list(map(int,input().split()))

    t = 0
    while True:
        for i in range(N):
            if A[i] % 2 == 0:
                A[i] //= 2
            else:
                print(t)
                sys.exit()
        t += 1

main()


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

int main() {
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(auto &e : A) cin >> e;
    sort(A.begin(), A.end());
    cout << accumulate(A.begin(), A.begin() + K, 0LL) << '\n';
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main()
{
	char a[10];
	cin>>a;
	if(a[0]=='A'&&a[1]=='B'&&a[2]=='C')			cout<<"ARC"<<endl;
	else if(a[0]=='A'&&a[1]=='R'&&a[2]=='C')	cout<<"ABC"<<endl;
    return 0;
}


Measured memory_bytes: 3068
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.p = [e for e in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    def same(self, u, v):
        return self.find_set(u) == self.find_set(v)

    def unite(self, u, v):
        u = self.find_set(u)
        v = self.find_set(v)

        if u == v:
            return

        if self.rank[u] > self.rank[v]:
            self.p[v] = u
            self.size[u] += self.size[v]
        else:
            self.p[u] = v
            self.size[v] += self.size[u]
            if self.rank[u] == self.rank[v]:
                self.rank[v] += 1

    def find_set(self, u):
        if u != self.p[u]:
            self.p[u] = self.find_set(self.p[u])

        return self.p[u]

    def update_p(self):
        for u in range(self.n):
            self.find_set(u)

    def get_size(self, u):
        return self.size[self.find_set(u)]


n = int(input())
xy = [list(map(int, input().split())) for _ in range(n)]
MAX = 10 ** 5

uf = UnionFind(MAX * 2)

for x, y in xy:
    x -= 1
    y -= 1
    uf.unite(x, y + MAX)

x_size = [0] * MAX * 2
y_size = [0] * MAX * 2
for i in range(MAX * 2):
    root = uf.find_set(i)
    if i < MAX:
        x_size[root] += 1
    else:
        y_size[root] += 1

ans = -n
for i in range(MAX * 2):
    ans += x_size[i] * y_size[i]

print(ans)


Measured memory_bytes: 42372
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
string str,ans;
int d;
char c;

int main()
{
  while(cin>>str){
    for(int i = 0;i <str.length();i++){
      if(str[i] =='@'){
	d = str[i+1]-'0';
	c =str[i+2];
	i+=2;
	for(int j = 0;j < d;j++){
	  cout<<c;
	}
      }else{
	cout <<str[i];
      }
    }
    cout<<endl;
  }
  return 0;
}

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

int main() {
    int H, W; cin >> H >> W;
    int h, w; cin >> h >> w;

    vector<vector<string>> hw(H+1, vector<string>(W+1, "."));
    for(int i=1; i<=H; i++){
        for(int j=1; j<=w; j++){
            hw.at(i).at(j) = "#";
        }
    }

    for(int i=1;i<=h;i++){
        for(int j=1; j<=W; j++){
            hw.at(i).at(j) = "#";
        }
    }

    int cnt=0;
    for(int i=1; i<=H; i++){
        for(int j=1; j<=W; j++){
            if(hw.at(i).at(j)=="."){
                cnt++;
            }
        }
    }

    cout << cnt << endl;

}

Measured memory_bytes: 256
#include<stdio.h>

void check(int s,int n,int c,int m,int t,int *ans);

int main(void){
	int n,s,ans;
	
	while(scanf("%d %d",&n,&s)){
		if(n==0 && s==0)break;
		ans=0;
		check(s,n,0,0,0,&ans);
		
		printf("%d\n",ans);
		
	}
	
	return 0;
}

void check(int s,int n,int c,int m,int t,int *ans){
	//c個数、m現在の数字、tここまでの合計
	int i;
	
	if(n==c){
		if(t==s)*ans+=1;
		//printf("%d %d\n",c,m);
		return;
	}
	
	for(i=m;i<10;i++)check(s,n,c+1,i+1,t+i,ans);
	
	return;
}
	

Measured memory_bytes: 0