akhauriyash/Code-Regression huggingface dataset:
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

int n;
int A[100005];
VI V[100005];
int flag = 1;

LL F(int at, int par) {
	if (V[at].size() == 1) {
		// leaf
		return A[at];
	}

	LL sum = 0;
	LL mx = 0;
	for (int u : V[at]) {
		if (par != u) {
			LL z = F(u, at);
			sum += z;
			mx = MAX(mx, z);
		}
	}

	LL P = mx;
	LL Q = sum - mx;
	LL ret = 0;
	if (P > Q) {
		ret += P - Q;
		A[at] -= P - Q;
		P = Q;
		mx = P;
		sum = 2 * Q;
	}

	if (sum % 2) {
		ret++;
		A[at]--;
		sum--;
	}

	if (A[at] < 0) {
		flag = 0; return 0;
	}
	LL ex = 2 * A[at] - sum;
	if (ex < 0 || A[at] > sum) {
		flag = 0;
		return 0;
	}

	ret += ex;
	if (par == -1) {
		if (ret) flag = 0;
		return 0;
	}

	return ret;
}

int solve(int nl) {
	int f = F(nl, -1);
	return flag;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &A[i]);
	}
	for (int i = 1; i < n; i++) {
		int u, v;
		scanf("%d %d", &u, &v);
		V[u].push_back(v);
		V[v].push_back(u);
	}

	if (n == 2) {
		if (A[2] == A[1]) {
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
		return 0;
	}

	int nonleaf = -1;
	for (int i = 1; i <= n; i++) if (V[i].size() != 1) nonleaf = i;

	if (solve(nonleaf)) printf("YES\n");
	else printf("NO\n");
	return 0;
}


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

#define N 100

int main() {
	int n;
	cin >> n;
	int score[N];
	int total = 0;
	int donotuseNumbers = 0;
	
	for (int i = 0; i < N; i++) {
		score[i] = 0;
	}

	for (int i = 0; i < n; i++) {
		cin >> score[i];
		total += score[i];
	}

	while (total % 10 == 0 && donotuseNumbers != n) {
		donotuseNumbers++;

		total = 0;
		for (int i = 0; i < n; i++) {
			int nowTotal = 0;
			for (int j = 0; j < n; j++) {
				if (i  !=  j) {
					nowTotal += score[j];
				}
			}
			if (nowTotal %10 != 0 && nowTotal > total) {
				total = nowTotal;
			}
		}
	}

	cout << total << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//CODE TONOY
	    string s;
        cin>>s;
        int a{};
        for(int i=0;i<s.size();i++){
            a^=s[i];
        }
        if(a==0){
            cout<<"Yes";
        }
        else{
            cout<<"No";
        }
	return 0;
}

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

using namespace std;
typedef long long ll;
const int MAXN = 1000050;
ll a[MAXN];
int main(){
	ll n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	ll x=0;
	for(int i=60;i>=0;i--){
		if(x+(1LL<<i)>k) continue;
		int n1=0;
		for(int j=1;j<=n;j++){
			n1+=(a[j]>>i)&1;
		}
		if(n1<n-n1) x+=(1LL<<i);
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		ans+=(x^a[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <list>
#include <string.h>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <utility>
#include <memory>
#include <sstream>
#include <complex>
#include <cassert>
#include <bitset>
#define rep(i, n) for(int i = 0; i < n; i++)
#define fi first
#define se second
//#include <Windows.h>
//#include "Library.h"
//#include "Math.h"
//#include "Othello.h"
using namespace std;
typedef long long int ll; typedef pair <ll, ll> P; typedef vector <int> vecint; typedef pair<int, P> P1; typedef pair<P1, int> P2;
const int inf = 1000000000;
const ll INF = 9000000000000000000;
const double EPS = 10e-9;
int main()
{
	ll a; cin >> a;
	int res = 0;
	bool flag = true;
	while (a > 9)
	{
		res += 9;
		if (a % 10 < 9) flag = false;
		a /= 10;
	}
	res += a - 1;
	if (flag) res++;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
H,N=map(int, input().split())
AB=[list(map(int, input().split())) for _ in range(N)]

INF=10**9

dp=[INF for _ in range(H+1)]
dp[H]=0
for h in range(H,0,-1):
    for n in range(N):
        A,B=AB[n]
        newH=max(0,h-A)
        dp[newH]=min(dp[newH], dp[h]+B)

print(dp[0])

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

#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair <int, int>
#define piii pair<int, pii>
#define vi vector<int>
#define vpii vector<pii>

#define read1(a) int a; scanf("%d", &a)
#define read2(a, b) int a, b; scanf("%d %d", &a, &b)
#define read3(a, b, c) int a, b, c; scanf("%d %d %d", &a, &b, &c)

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

#define readgi(n) F0R(i, n) { scanf("%d", &arr[i]); }
#define readgs(n) F0R(i, n) { scanf(" %c", &arr[i]); }

#define f first
#define s second

#define usaco(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout);

#define println1(a) printf("%d\n", a);
#define println2(a, b) printf("%d %d\n", a, b);
#define println3(a, b, c) printf("%d %d %d\n", a, b, c);
#define pv(v) for (int i : v) { printf("%d ", i); } printf("\n");

const int MOD = 1000000007;
const int MAX = 250005;

int arr[MAX];

int main() {
    read1(n);
    F0R(i, 2*n) { scanf("%d", &arr[i]); }
    sort(arr, arr+2*n);
    ll tot = 0;
    F0R(i, n) {
        tot += arr[2*i];
    }
    cout << tot << endl;
}


Measured memory_bytes: 256
t=list(input())
ans = 0
if len(t) != 1:
	for i in range(len(t)):
		if i != 0 and i != len(t)-1:
			if t[i] == "?":
				if t[i-1] == "P":
					t[i] = "D"
				elif t[i+1] == "D" or t[i+1] == "?":
					t[i] = "P"
				else:
					t[i] = "D"
		elif i==0:
			if t[i] == "?":
				if t[i+1] == "D" or t[i+1] == "?":
					t[i] = "P"
				else:
					t[i] = "D"
		else:
			if t[i] == "?":
				t[i] = "D"
else:
	if t[0] == "?":
		t[0] = "D"
print("".join(t))

Measured memory_bytes: 10888
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    t = 0
    for i in range(n + 1):
        if i % 3 != 0 and i % 5 != 0:
            t += i
    print(t)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 67272
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 924844033;
Int fac[2020];
Int dp[2020][4][2020];
int main() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i <= 2000; i++) fac[i] = (fac[i - 1] * i) % MOD;
    int N, K; cin >> N >> K;
    dp[0][0][0] = 1;
    int last = 0;
    for (int i = 0, j = 0; i < K; i++) {
        for (j = i + K; j < N; j += K) {
            int from = j - K;
            for (int t = 0; t < N; t++) {
                dp[j][0][t] += dp[from][0][t];
                dp[j][2][t+1] += dp[from][0][t];
                dp[j][1][t+1] += dp[from][0][t];
                dp[j][3][t+2] += dp[from][0][t];
                dp[j][0][t] += dp[from][1][t];
                dp[j][1][t+1] += dp[from][1][t];
                dp[j][0][t] += dp[from][2][t];
                dp[j][2][t+1] += dp[from][2][t];
                dp[j][0][t] += dp[from][3][t];
            }
            for (int s = 0; s < 4; s++) {
                for (int t = 0; t < N; t++) {
                    dp[j][s][t] %= MOD;
                }
            }
        }
        last = j - K;
        if (i == K - 1) break;
        for (int t = 0; t <= N; t++) {
            dp[i + 1][0][t] += dp[last][0][t] + dp[last][1][t] + dp[last][2][t] + dp[last][3][t];
            dp[i + 1][0][t] %= MOD;
        }
    }
    Int ans = 0;
    for (int t = 0; t <= N; t++) {
        Int v = (dp[last][0][t] + dp[last][1][t] + dp[last][2][t] + dp[last][3][t]) % MOD;
        ans += (t % 2 == 0 ? v : MOD-v) * fac[N-t] % MOD;
    }
    ans %= MOD;
    cout << ans << '\n';
    return 0;
}

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

using namespace std;


#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 rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define int long long

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

template <typename T>

void print(T x)
{
	std::cout << x << '\n';
}


signed main(void) {
	int N,D;
	cin >> N >> D ;
	vector<vector<int>> data(N, vector<int>(D));

	rep(i,N){
		rep(j,D) {
			cin >> data.at(i).at(j);
		}
	}
	int ans = 0;
	rep(i, N-1) {
		FOR(j,i+1,N){
			int sum = 0;
			rep(k,D){
				sum += pow(data[i][k] - data[j][k], 2);
			}
			int powint= 1;
			while (true) {
				if (pow(powint, 2) < sum) powint++;
				elif(pow(powint, 2) == sum) {
					ans++;
					break;
				}elif(pow(powint, 2) > sum)break;
			}
		}
	}
	print(ans);
}

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

int main(void) {
    int A,B,C,K;
    cin>>A>>B>>C>>K;
    if((A>=B)&&(A>=C)){
      cout << A*(int)pow(2,K)+B+C << endl;
      return 0;
    }
    if((B>=C)&&(B>=A)){
      cout << B*(int)pow(2,K)+A+C << endl;
      return 0;
    }
    if((C>=B)&&(C>=A)){
      cout <<C*(int)pow(2,K)+B+A << endl;
      return 0;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int N,M,C;
    int i,j;
    scanf("%d %d %d",&N,&M,&C);
    int B[M];
    int A[N][M];
    for(i=0;i<M;i++){
        scanf("%d",&B[i]);
    }//B代入
    for(j=0;j<N;j++){
        for(i=0;i<M;i++){
            scanf("%d",&A[j][i]);
        }
    }//A代入
    
    int count= 0;
    int judge;
    
    for(j=0;j<N;j++){
        judge=C;
        for(i=0;i<M;i++){
            judge+=B[i]*A[j][i];
        }
        if(judge>0){
            count++;
        }
    }//審査
    printf("%d\n",count); 
    
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define gfast std::ios::sync_with_stdio(false)
using namespace std;
int d,n;
int main()
{
	gfast;
	cin>>d>>n;
	if (d==0)
	{
		if (n==100)
		   cout<<101<<endl;
		else
		   cout<<n<<endl;
	}
	else if (d==1)
	{
		if (n==100)
		   cout<<101*100<<endl;
		else
		   cout<<n*100<<endl;
	}
	else if (d==2)
	{
		if (n==100)
		   cout<<101*10000<<endl;
		else
		   cout<<n*10000<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
using namespace std;
int main(){
bool prime[60000];
for(int i=0;i<60000;i++){
prime[i]=1;
}
prime[0]=prime[1]=0;
for(int i=0;i*i<60000;i++){
if(prime[i]==1){
for(int j=i*2;j<60000;j+=i){
prime[j]=0;
}
}
}
int n;
while(cin>>n){
int i;
for(i=1;prime[n-i]==0;i++);
cout<<n-i<<" ";
for(i=1;prime[n+i]==0;i++);
cout<<n+i<<endl;
}
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define F first 
#define S second 
#define pb push_back 

using namespace std;

void test(){
	ll n;
	cin>>n;
	ll a[n+1] = {0};
	ll cnt = 0;
	for(ll x = 1;x*x<=n;x++){
		ll sum = (x*x);
		for(ll y = 1;sum+(x*y) + (y*y)<=n;y++){
			ll temp = sum + (x*y) + (y*y);
			for(ll z = 1; temp + (x+y)*z + (z*z) <=n ; z++){
				a[temp + (x+y)*z + (z*z)]++;
			}
		}
	}
	f(i,n)cout<<a[i+1]<<"\n";
}

int main(){
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}


Measured memory_bytes: 3564
import java.util.Arrays;
import java.util.BitSet;
import java.util.NoSuchElementException;
import java.util.PrimitiveIterator;
import java.util.Scanner;

class Main{
	private static final int n=1000001;
	static Scanner s=new Scanner(System.in);
	static int gInt() {return Integer.parseInt(s.next());}
	static long gLong() {return Long.parseLong(s.next());}

	public static void main(String[]$){
		BitSet p=new PrimeIterator(n).bs;

		int[]a=new int[n];
		for(int i=1;i<n;i+=2)
			if(p.get(i)&&p.get((i+1)/2))
				a[i]=1;
		Arrays.parallelPrefix(a,Integer::sum);
		for(int q=gInt();q>0;--q)
			System.out.println(-a[gInt()-1]+a[gInt()]);
	}
	public static class PrimeIterator implements Iterable<Integer>,PrimitiveIterator.OfInt{
		private BitSet	bs;
		private int		curv,limit;

		public PrimeIterator(int limit){
			curv=0;
			bs=new BitSet(limit+1);
			this.limit=limit;
			constructBS();
		}
		private final void constructBS(){
			bs.set(0,limit+1);
			bs.clear(0);
			bs.clear(1);
			if(limit<2) return;

			int i=1;
			while(sieve(i=bs.nextSetBit(i+1)))
				;
		}
		protected boolean sieve(int v){
			if((long)v*v>limit)
				return false;
			for(int i=v*v;i<=limit;i+=v)
				bs.clear(i);
			return true;
		}
		@Override
		public boolean hasNext(){
			int r=getNextValue();
			return 0<=r&&r<=limit;
		}
		private int getNextValue(){
			return bs.nextSetBit(curv+1);
		}
		@Override
		public int nextInt(){
			int r=getNextValue();
			if(r<0||limit<r) throw new NoSuchElementException();
			return curv=r;
		}
		@Override
		public OfInt iterator(){
			return this;
		}
		public BitSet getClonedBitSet(){
			return (BitSet)bs.clone();
		}
	}
}


Measured memory_bytes: 56240
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

defeated_monster = 0

for i in range(N):
    if B[i] >= A[i] + A[i+1]:
        defeated_monster += A[i] + A[i+1]
        A[i+1] = 0
    else:
        defeated_monster += B[i]
        if B[i] > A[i]:
            A[i+1] = A[i+1] - (B[i]-A[i])
print(defeated_monster)

Measured memory_bytes: 19156
var obj={};
for(var i=0;i<=25;i++){
   for(var j=0;j<=16;j++){
      for(var k=0;k<=10;k++){
         var weight=200*i+300*j+500*k;
         if(weight>5000)continue;
         var money=0;
         money+=380*5*0.8*Math.floor(i/5);
         money+=550*4*0.85*Math.floor(j/4);
         money+=850*3*0.88*Math.floor(k/3);
         money+=380*(i%5);
         money+=550*(j%4);
         money+=850*(k%3);
         if(obj.hasOwnProperty(weight))obj[weight]=Math.min(obj[weight],money);
         else obj[weight]=money;
      }
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   console.log(obj[n]);
}

Measured memory_bytes: 8968
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

#define MIN(a,b) ((a)<(b)?(a):(b))
#define ALLOC(size,type) ((type*)calloc((size),sizeof(type)))

#define POS(i, j) ((i) * (n + 1) + (j))

void run (void) {
  i32 n;
  scanf ("%" SCNi32, &n);
  i64 *a = ALLOC (n + 1, i64);
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi64, a + i);
  }
  for (i32 i = n - 1; i >= 0; --i) {
    a[i] += a[i + 1];
  }
  i64 *dp = ALLOC ((n + 1) * (n + 1), i64);
  for (i32 len = 2; len <= n; ++len) {
    for (i32 l = 0; l <= n - len; ++l) {
      i32 r = l + len;
      i64 min = dp[POS(l, l + 1)] + dp[POS(l + 1, r)];
      for (i32 i = l + 2; i < r; ++i) {
        i64 x = dp[POS(l, i)] + dp[POS(i, r)];
        min = MIN (min, x);
      }
      dp[POS(l, r)] = min + a[l] - a[r];
    }
  }
  printf ("%" PRIi64 "\n", dp[POS(0, n)]);
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 1408
N = int(input())
xs, ys, hs = [],[],[]
for _ in range(N):
    x,y,h = map(int,input().split())
    if h != 0:
        xx,yy,hh = x,y,h
    xs.append(x)
    ys.append(y)
    hs.append(h)
for cx in range(101):
    for cy in range(101):
        H = hh+abs(xx-cx)+abs(yy-cy)
        if all([hs[i] == max(0,H-abs(cx-xs[i])-abs(cy-ys[i])) for i in range(N)]):
            print(cx,cy,H)
            exit(0)

Measured memory_bytes: 9216
n, m = [int(i) for i in input().split()]
lfix = 0
rfix = n + 1
for i in range(m):
    l, r = [int(i) for i in input().split()]
    lfix = max(lfix, l)
    rfix = min(rfix, r)
print(max(rfix - lfix + 1, 0))

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    s64 a;
    cin >> a;
    string b;
    cin >> b;

    s64 c = 0;
    int idx = 0;
    for (; idx < b.size(); ++idx)
    {
        if (b[idx] == '.')
        {
            b += string(MAX(0, 2 - b.size() + idx + 1), '0');
            break;
        }
    }

    if (idx == b.size())
    {
        c = stoi(b) * 100;
    }
    else
    {
        rep (i, b.size())
        {
            if (b[i] == '.') continue;
            c = c * 10 + b[i] - '0';
        }
    }

    cout << (s64)(a * c) / 100 << "\n";

    return 0;
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[200005],b[200005];


int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&a[i],&b[i]);
	}
	sort(a,a+n);
	sort(b,b+n);
	if(n%2==1){
		printf("%lld\n",(b[n/2]-a[n/2])+1LL);
	}else{
		printf("%lld\n",(b[n/2]+b[n/2-1]-(a[n/2]+a[n/2-1]))+1LL);
	}
	return 0;
}


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

int main() {
  int n,c,ans=0;
  cin >> n;
  for (int j = 1; j <= n; j+=2) {
    for (int i = 1; i <= j; i++) {
      if (j % i == 0) {
        c ++;
      }
    }
    if (c == 8) {
      //cout << j << c << endl;
      ans ++;
    }
    c = 0;
  }
  cout << ans << endl;
} 

Measured memory_bytes: 3624
class KMP:
    pattern = None
    length = -1
    failed = None
    def __init__(self, pattern):
        self.pattern = pattern
        self.length = len(pattern)
        self.failed = [-1 for i in xrange(self.length)]
        for i in xrange(1, self.length):
            prev = self.failed[i-1]
            while prev!=-1 and pattern[prev+1]!=pattern[i]:
                prev = self.failed[prev]
            if pattern[prev+1]==pattern[i]:
                prev += 1
            self.failed[i] = prev

def minimumLen(s, t):
    kmp = KMP(t)
    offset = -1
    for c in s:
        while offset!=-1 and kmp.pattern[offset+1]!=c:
            offset = kmp.failed[offset]
        if kmp.pattern[offset+1]==c:
            offset += 1
    return len(s)+len(t)-(offset+1)

def main():
    n = int(raw_input().strip())
    s = raw_input().strip()
    t = raw_input().strip()
    print minimumLen(s, t)

if __name__ == '__main__':
    main()

Measured memory_bytes: 2696
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    //データを扱いやすい形に変換
    vector<int> v;
    int flag=1;//逆立ちを数えているとき1、otherwise0
    int conti=0;
    int num=1;//逆立ちしている島の数
    for(int i=0;i<s.size();i++){
        if(s[i]=='0'){//直立
            if(flag==0){
                conti++;
            }
            else{
                v.push_back(conti);
                conti=1;
                flag=0;
            }
        }
        else{//逆立ち
            if(flag==1){
                conti++;
            }
            else{
                num++;
                v.push_back(conti);
                conti=1;
                flag=1;
            }
        }
    }
    if(flag==0){
        v.push_back(conti);
        v.push_back(0);
        num++;
    }
    else{
        v.push_back(conti);
    }
    /*for(int i=0;i<v.size();i++){
        cout<<v[i]<<' ';
    }
    cout<<num<<endl;*/

    //実際の処理、指示回数がk回の時距離がkの島の距離を比較する。
    int max=0;
    int sum=0;
    if(k>=num-1){//全てをつなげる場合
        cout<<n<<endl;
        return 0;
    }
    else{
        for(int i=0;i<2*k+1;i++){
            sum=sum+v[i];
        }
        max=sum;
        for(int i=0;i<num-k-1;i++){
            sum=sum-v[2*i]-v[2*i+1]+v[2*k+2*i+1]+v[2*k+2*i+2];
            if(max<sum){max=sum;}
        }
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
int main(){
	for (;;){
		int H, W;
		cin >> H >> W;
		if (H == 0 && W == 0){
          break;
		}
		
		for (int x = 0; x < H; x++){
			for (int y = 0; y < W; y++){
				cout << "#";
			}
			cout << "" << endl;
		}
		cout << "" << endl;
	}

	return 0;
}


Measured memory_bytes: 3128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    ll q;
    cin >> q;

    vl ans(q);
    rep(i, q) {
        ll a, b;
        cin >> a >> b;

        // 対称性より a <= b を仮定してよい
        if(a > b) {
            swap(a, b);
        }
        
        // 1問目が1～a-1位の人たちについて考える。
        // 2問目でb+(a-1)～b+1位を取ると
        // (a-i)*(b+i) = ab - i*(b - a) - i^2 < ab より条件を満たす。
        // 同様に2問目が1～a-1位の人たちは、1問目でb+(a-1)～b+1位を取ると条件を満たす。
        // よって、2*(a - 1)人は確定。

        // 以下、1問目がa+1～b位, 2問目がa～b-1位の人たちについて考える。
        // 判定問題「x組作れるか？」を二分探索で解く
        ll left = 0;
        ll right = b - a;
        while(right - left > 1) {
            ll x = (left + right)/2;
            if( (a + x/2)*(a + x - x/2) < a*b ) {
                left = x;
            }
            else {
                right = x;
            }
        }
        ans[i] = 2*(a-1) + left;
    }

    rep(i, q) {
        out(ans[i]);
    }
    
    re0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int h, w;
  int c[10][10];
  int a[210][210];
  int res=0;
  cin >> h >> w;

  rep(i,10) rep(j,10) cin >> c[i][j];
  rep(i,h) rep(j,w) cin >> a[i][j];

  int d[10][10];
  memset(d, INF, sizeof(d));
  rep(i, 10) {
    d[i][i] = 0;
    queue<int> q;
    q.push(i);
    while(q.size()) {
      int n = q.front();
      q.pop();
      rep(j, 10) {
        if(d[i][j] > d[i][n] + c[n][j]) {
          d[i][j] = d[i][n] + c[n][j];
          q.push(j);
        }
      }
    }
  }

  rep(i,h) {
    rep(j,w) {
      if(a[i][j] == -1 ) continue;
      res += d[a[i][j]][1];
    }
  }
  cout << res << endl;
}

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

int ans(int i)
{
  printf("%d\n",i);
  fflush(stdout);
  char s[100];
  scanf("%s",s);
  return s[0]=='M'?0:s[0]=='F'?1:2;
}
  

int main()
{
  int n;
  scanf("%d",&n);
  int L=0,R=n;
  int F1=ans(0),F2=F1;
  if(F1==2){
    return 0;
  }
  while(1){
    //printf("%d %d\n",L,R);
    int M=(L+R+1)/2;
    int G=ans(M);
    if(G==2){
      break;
    }
    if((F1^G)!=(M-L)%2){
      R=M;
      F2=G;
    }
    else{
      L=M;
      F1=G;
    }
  }
  return 0;
}


Measured memory_bytes: 852
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <queue>
#include <map>
using namespace std;
const int M=200010;
int n, m,r[M];
int root(int x){
    if (r[x] < 0) return x;
    return r[x] = root(r[x]);
}
bool Change(int x, int y) {
    x=root(x); y=root(y);
    if (x == y) return false;
    if (r[x] > r[y]) swap(x, y);
    r[x] += r[y]; r[y] = x;
    return true;
}
int size(int x){
	return -r[root(x)];
}
int main() {
    cin>>n>>m;
    memset(r,-1,sizeof r);
    for(int i=0;i<m;i++){
        int a, b;
        cin>>a>>b;
        a--; b--;
        Change(a,b);
    }
    int ans=0;
    for(int i=0;i<n;i++)  ans=max(ans,size(i));
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4424
#include<stdio.h>
#define N 100000

typedef struct{
  int parent;
  int left;
  int right;
}node;

node T[N];
int c[N];
int n;

int Depth(int );
void Judge(int );
void print(int );

int main(){
  int i,j;
  int id,k,z;
  int child,lastchild;

  scanf("%d",&n);
  for(i=0 ;i<n ;i++){
    T[i].parent = -1;
    T[i].right = -1;
    T[i].left = -1;
  }

  for(i=0 ; i<n ; i++){
    scanf("%d%d",&id,&k);

    for(j=0 ; j<k ; j++){
      scanf("%d",&child);
      T[child].parent = id;
      if(j == 0) T[id].left=child;
      else T[lastchild].right=child;
      lastchild = child;

    }
  }

  for(i=0 ; i<n ; i++){
    z=Depth(i);
    printf("node %d: parent = %d, depth = %d, ",i,T[i].parent,z);
    Judge(i);
  }

  return 0;
}


int Depth(int i){
  int count = 0;

  while(1){
    if(T[i].parent == -1) break;
    i=T[i].parent;
    count++;
  }
  return count;
}


void Judge(int i){
  int t;

  if(T[i].parent == -1) printf("root, [");
  else if(T[i].left == -1) printf("leaf, [");
  else printf("internal node, [");
  print(T[i].left);
  printf("]\n");
}

void print(int i){
  if(i == -1) return;
  if(T[i].right == -1)printf("%d",i);
  else
    {
      printf("%d, ",i);
      print(T[i].right);
    }
}

Measured memory_bytes: 1784
#include <iostream>
#include <unordered_map>

using namespace std;
using ll = long long;

int main(){
    int N;
    ll ans = 0;
    cin >> N;
    unordered_map<ll, ll> L;
    for(ll i=0; i<N; i++){
        ll a;
        cin >> a;
        ll l=i+1+a;
        ll r=i+1-a;
        auto itr=L.find(r);
        if(itr!=L.end()){
            ll& l_ = (*itr).second;
            ans += l_;
        }
        L[l]++;
    }

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



Measured memory_bytes: 11272
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;

const int MAXN = 1e5 + 100;
const int INF = 0x3FFFFFFF;
const ll MOD = 1e9+7;

int a[MAXN];

int main()
{
    int n;
    cin >> n;
    int cnt = 0;
    int even = 0;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if(a[i] % 4 == 0)   cnt++;
        else if(a[i] % 2 == 0)   even++;
    }
    if(cnt * 2 >= n - 1)
    {
        cout << "Yes" << endl;
        return 0;
    }
    else if(!cnt)
    {
        if(even == n)
            cout << "Yes" << endl;
        else    cout << "No" << endl;
        return 0;
    }
    else if(cnt * 2 + even >= n)
    {
        cout << "Yes" << endl;
        return 0;
    }
    else
    {
        cout << "No" << endl;
        return 0;
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define MOD 1000000007
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
inline ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
inline ll char_to_ll(char c) { return (int)(c - '0'); }
inline ll string_to_ll(string s) { return atoi(s.c_str()); }
inline bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

int main(){
    int n,ac=0, wa=0, tle=0, re=0;
    cin >> n;
    vector<string> a(n);
    rep(i,0,n) cin >> a.at(i);
    rep(i,0,n){
        if(a.at(i) == "AC"){
            ac++;
        }else if(a.at(i) == "WA"){
            wa++;
        }else if(a.at(i)=="TLE"){
            tle++;
        }else if(a.at(i) == "RE"){
            re++;
        }
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;


    return 0;
}



Measured memory_bytes: 6348
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n>=400&&n<=599)
	 cout<<8<<endl;
	 else if(n>=600&&n<=799)
	   cout<<7<<endl;
	 else if(n>=800&&n<=999)
	   cout<<6<<endl;
	else if(n>=1000&&n<=1199)
	   cout<<5<<endl;
	  else if(n>=1200&&n<=1399)
	   cout<<4<<endl;   
	   else if(n>=1400&&n<=1599)
	   cout<<3<<endl;
	   else if(n>=1600&&n<=1799)
	   cout<<2<<endl;
	   else if(n>=1800&&n<=1999)
	   cout<<1<<endl;
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<double> data(N);

  for(int i = 0; i < N; i++) {
    cin >> data.at(i);
  }
  
  for (double &c : data) {
    c = 1 / c;
  }
    
  double cnt = 0;
  
  for (double &c : data) {
    cnt += c;
  }
  
  cout << 1 / cnt << endl;
 
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x=0,n;
    cin >> n;
    string s;
    cin >> s;
    int m_ans = x;
    for(int i=0;i<s.length();i++){
        if(s[i]=='I')
            x++;
        else
            x--;
        m_ans = max(m_ans,x);
    }
    cout << m_ans;
    return 0;
}

Measured memory_bytes: 3632
def slove():
    import sys
    import collections
    input = sys.stdin.readline
    n, t = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    d = collections.defaultdict(list)
    m = 10 ** 10
    for v in a:
        if v < m:
            m = v
        else:
            d[v-m] += [m]
    d = sorted(d.items(), key=lambda x: x[0], reverse=True)
    print(len(d[0][1]))


if __name__ == '__main__':
    slove()


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

typedef long long ll;

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

  ll ans = 0, b = 0;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == 'B'){
      b++;
    }else{
      if(b){
        ans += b;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define ll long long
#define cst first
#define dur second
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int N = 1e5 + 5, M = 2 * N + 5;

int n, a[N];

int main(){
    scanf("%d", &n);
    for(int i = 0 ; i < n ; ++i)
        scanf("%d", a + i);
    for(int i = n - 1 ; i ; --i)
        if(a[i] < a[i - 1])
            --a[i - 1];
    for(int i = 1 ; i < n ; ++i){
        if(a[i] < a[i - 1]){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#define ll long long
using namespace std;
const int maxn=1e5+10;
ll inf=1e9+7;
ll a[900009];
ll ans[20];
int main()
{
    ll h,w,n;
    scanf("%lld%lld%lld",&h,&w,&n);
    memset(ans,0,sizeof(ans));
    int cnt=0;
    ll sum=(h-2)*(w-2);
    for(ll k=1; k<=n; k++)
    {
        ll x,y;
        scanf("%lld%lld",&x,&y);
        for(ll i=0; i<=2; i++)
            for(ll j=0; j<=2; j++)
            {
                if(x-i>=1&&x-i<=h-2&&y-j>=1&&y-j<=w-2)
                {
                    a[cnt++]=inf*(x-i)+(y-j);
                }
            }
    }
    sort(a,a+cnt);
    ll t=1;
    for(int i=0; i<cnt; i++)
    {
        if(a[i]==a[i+1])
            t++;
        else
        {
            ans[t]++;
            t=1;
            sum--;
        }
    }
    printf("%lld\n",sum);
    for(int i=1; i<=9; i++)
        printf("%lld\n",ans[i]);
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define INF 1e12


int main()
{
 ll v,x,y,e,a,b,in=0;
 pll h;
 cin>>v>>e;
 vector<vl > grafo(v,vl(0));
 for(int i=0;i<e;i++)
    {
        cin>>x>>y;
        grafo[x-1].push_back(y-1);
    }
    cin>>a>>b;a--;b--;


    ll p=0,inicio=a;
 vector<vector<bool> > visitado(v,vector<bool>(4,false));
 vector<vector<ll> > dist(v,vector<ll>(4,INF));
    dist[inicio][p]=0;
    if(!visitado[inicio][p]){
    queue<pll> q;
    q.emplace(inicio,p);
    while(!q.empty()){

      ll t=q.front().first,pos=q.front().second;
      q.pop();
      if(!visitado[t][pos%3]){

          visitado[t][pos%3]=true;
          for(ll i=0;i<grafo[t].size();i++){

              if(!visitado[grafo[t][i]][(pos+1)%3])
     {
         dist[grafo[t][i]][(pos+1)%3]=dist[t][pos%3]+1;
      q.emplace(grafo[t][i],(pos+1)%3);
     }
          }
      }
  }
  //u.

  }
    if(dist[b][0]!=INF)cout<<dist[b][0]/3<<"\n";
    else cout<<"-1\n";
 return 0; //
}

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

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

  char C; cin >> C;
  int c = C - 'a';
  char n = 'a' + (c + 1);
  cout << n << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main()
{
	int a, b, c, sum;
	scanf("%d %d %d", &a, &b, &c);

	if (a <= b) {
		if (b <= c) {
			sum = c * 10 + b + a;
		}
		else {
			sum = b * 10 + a + c;
		}
	}
	else {
		if (a<=c) {
			sum = c * 10 + b + a;
		}	
		else {
			sum = a * 10 + b + c;
		}
	}

	printf("%d\n", sum);

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
//next_permutation(ALL(p));
//typedef priority_queue<int> pque;//これは大きい順
//typedef priority_queue<int, vector<int>, greater<int>> pque;//これは小さい順
//factorizeは、素因数分解用の関数

int main(){
	int n,k;
  cin >> n >> k;
  set<int> t;
  rep(i,k){
    int d;
    cin >> d;
    rep(j,d){
      int a;
      cin >> a;
      t.insert(a);
    }
  }
  cout << n - t.size() << endl;

  return 0;
}


Measured memory_bytes: 3628
def b_grid_compression():
    H, W = [int(i) for i in input().split()]
    A = [list(input()) for _ in range(H)]

    def rotate_clockwise(matrix):
        return list(map(list, zip(*matrix)))[::-1]

    def rotate_counterclockwise(matrix):
        return list(map(lambda x: list(x[::-1]), zip(*matrix)))

    def remove_white_line(matrix):
        return [row for row in matrix if row.count('.') < len(row)]

    ans = rotate_counterclockwise(remove_white_line(rotate_clockwise(remove_white_line(A))))
    return '\n'.join([''.join(row) for row in ans])

print(b_grid_compression())

Measured memory_bytes: 3316
main = do
  [h,w] <- map read . words <$> getLine
  let pp = take (w + 2) $ repeat '#'
  putStrLn pp
  solve h
  putStrLn pp

solve :: Int -> IO()
solve 0 = return ()
solve x = do
  ('#' :) . (++ "#") <$> getLine >>= putStrLn
  solve $ x - 1


Measured memory_bytes: 1020
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	int n;
	HashMap<String,String> dictionary;
	public static void main(String args[]) {
		new Main().run();
	}
	Main() {
		dictionary = new HashMap<String,String>();
	}
	public void run() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		for (int i = 0; i < n; i++) {
			String order = scan.next();
			String str = scan.next();
			if (order.charAt(0) == 'i') {
				dictionary.put(str, str);
			} else {
				if (dictionary.get(str) != null) { 
					System.out.println("yes");
				} else {
					System.out.println("no");
				}
			}
		}
	}
}



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

int main(){
    
    while(1){
        double n,var = 0.0,sd;
        double num[1000];
        double ave = 0.0;
        cin >> n;
        if(n == 0) break;
        
        for(int i = 0; i < n; ++i){
            cin >> num[i];
            ave += num[i];
        }
        ave = ave / n;
        for(int i = 0; i < n; ++i){
            var += (num[i] - ave) * (num[i] - ave);
        }
        var = var / n;
        sd = sqrt(var);
        cout << sd << endl;    
    }
    
    return 0;
}

Measured memory_bytes: 3208
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

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

    vector<int> color(9, 0);

    int a;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(1<= a and a <= 399){
            //灰
            color[0] += 1;
        }
        else if(400 <= a and a <= 799){
            //茶
            color[1] += 1;
        }
        else if(800 <= a and a <= 1199){
            //緑
            color[2] += 1;
        }
        else if(1200 <= a and a <= 1599){
            //水
            color[3] += 1;
        }
        else if(1600 <= a and a <= 1999){
            //青
            color[4] += 1;
        }
        else if(2000 <= a and a <= 2399){
            //黄
            color[5] += 1;
        }
        else if(2400 <= a and a <= 2799){
            //オレンジ
            color[6] += 1;
        }
        else if(2800 <= a and a <= 3199){
            //赤
            color[7] += 1;
        }
        else if(a >= 3200){
            //最強
            color[8] += 1;
        }
    }

    int min_count = 0;//人がいる色の種類
    int zero_color = 0;
    for(int i = 0; i <= 7; i++){
        //printf("colcor i %d\n", color[i]);
        if(color[i] != 0){
            min_count++;
        }
        else{
            zero_color++;
        }
    }

    
    if(color[8] == 0){
        //色変がいない
        printf("%d %d\n", min_count, min_count);
    }
    else if(min_count != 0 and color[8] != 0){
        //色変がいる
        //最小値は色変が人がいる色になる場合
        //最大値は色変が人がいない色になる場合
        
            
        printf("%d %d\n", min_count, min_count+color[8]);
    
    }
    else if(min_count == 0 and color[8]){
        if(color[8] >= 8){
            printf("1 8\n");
        }
        else{
            printf("1 %d\n", color[8]);
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
using namespace std;
int N, a, b, ret, dist[100009]; vector<int> g[100009];
void dfs(int pos, int pre, int tp, int d) {
	if (tp == 1) ret += (dist[pos] <= d);
	else dist[pos] = d;
	for (int i : g[pos]) {
		if (i != pre) {
			dfs(i, pos, tp, d + 1);
		}
	}
}
int main() {
	cin >> N;
	for (int i = 1; i < N; i++) {
		cin >> a >> b; a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0, -1, 0, 0);
	dfs(N - 1, -1, 1, 0);
	cout << (ret * 2 > N ? "Fennec" : "Snuke") << endl;
	return 0;
}

Measured memory_bytes: 12416
/*
 *
 * Author: r3gz3n
 * 
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define fi first
#define se second


#define alli(a, n, k) (a+k),(a+n+k)
#define rep(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)


#define endl '\n'


typedef pair<int, int> pii;


class Solution {
public:
    const int static MAX = 1e2 + 5;
    pair<string, pii> p[MAX];

    bool static cmp (pair<string, pii> a, pair<string, pii> b) {
        if (a.fi < b.fi) return true;
        else if (a.fi > b.fi) return false;
        else {
            if (a.se.fi > b.se.fi) return true;
            else return false;
        }
    }
    void solve(std::istream& in, std::ostream& out) {
		int n;
        in >> n;
        rep(i, 0, n, 1) {
            in >> p[i].fi >> p[i].se.fi;
            p[i].se.se = i+1;
        }
        sort(alli(p, n, 0), cmp);
        rep(i, 0, n, 1) out << p[i].se.se << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

// π M_PI
// deg = rad*180/M_PI

int main() {
    ll n;
    cin >> n;
    if ( n%2 == 0 ) {
        cout << n/2 << endl;
    } else {
        cout << n/2+1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $N, $D);
$s = 0;
$D *= $D;

for ($i = 0; $i < $N; $i++) {
  fscanf(STDIN, "%f %f", $x, $y);
  if ((pow($x, 2.0) + pow($y, 2.0)) <= $D) $s++;
}

echo $s;


Measured memory_bytes: 16380
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

wa = 0
anslist = []
a_index = 0 #読めなかった本のindex
b_index = 0 #同上

for i in range(n+1):
  if i < n and k >= wa + a[i]:
    wa +=a[i]
    anslist.append(i+1)
  else:
    a_index = i
    break

for i in range(m+1):
  if i < m and k >= wa + b[i]:
    wa +=b[i]
    anslist.append(i + 1 + a_index)
  else:
    b_index = i
    break

for _ in range(m):
  if a_index !=0:
    wa -=a[a_index - 1] #Aを捨てる
    a_index -=1
  while b_index < m and k >= wa + b[b_index] :
    wa +=b[b_index]
    b_index +=1
  anslist.append(a_index + b_index)
print(max(anslist))

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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF 1e9


int main(){
  string S;
  cin >> S;

  vector<int> alph(27, 0);
  REP(i, S.size()){
    alph[S[i]-'a']++;
  }
  REP(i, 26){
    if(alph[i]==0){
      cout << (char)(i+'a') << endl;
      return 0;
    }
  }
  cout << "None" << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> s(H, vector<char>(W, '#'));
  REP(y, H) {
    REP(x, W) {
      cin >> s[y][x];
    }
  }

  vector<vector<long long>> dp(H, vector<long long>(W, INF));
  if (s[0][0] == '.') dp[0][0] = 0;
  else dp[0][0] = 1;
  REP(y, H) {
    REP(x, W) {
      if (y + 1 < H) {
        if (s[y][x] == '.' && s[y + 1][x] == '#') chmin(dp[y + 1][x], dp[y][x] + 1);
        else chmin(dp[y + 1][x], dp[y][x]);
      }
      if (x + 1 < W) {
        if (s[y][x] == '.' && s[y][x + 1] == '#') chmin(dp[y][x + 1], dp[y][x] + 1);
        else chmin(dp[y][x + 1], dp[y][x]);
      }
    }
  }
  cout << dp[H - 1][W - 1] << endl;
  return 0;
}

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

int main()
{
    int a;
    rep(i, 5) {
        cin >> a;

        if (a == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }

    return 0;
}

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

int main() {
	int p,q;
	int X,Y;
	cin>>X>>Y;
	q=Y/2-X;
	p=X-q;
	if(p>=0&&q>=0&&2*p+4*q==Y){cout<<"Yes"<<endl;}
	else{cout<<"No"<<endl;}
	
	return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>

int main(void){
	int n;
	long long cnt = 0, t_cnt;
	long long a[100001] = {}, b[100001] = {};
	int i;
	
	scanf("%d", &n);
	
	for (i = 0; i < n; i++){
		scanf("%lld %lld", &a[n-i-1], &b[n-i-1]);
	}
	
	for (i = 0; i < n; i++){
		
		a[i] += cnt;
		
		t_cnt = 0;
		
		if (a[i]%b[i] != 0) t_cnt = b[i] - a[i]%b[i];
		
		cnt += t_cnt;
	}
	
	printf("%lld\n", cnt);
	
	return 0;
}

Measured memory_bytes: 1664