akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>

void searchdel(int w,int h,int *mp,int y,int x){
  int res;
  res=mp[y*100+x];
  mp[y*100+x]=0;
  if(y>0&&mp[(y-1)*100+x]==res)searchdel(w,h,mp,y-1,x);
  if(y<h-1&&mp[(y+1)*100+x]==res)searchdel(w,h,mp,y+1,x);
  if(x>0&&mp[y*100+x-1]==res)searchdel(w,h,mp,y,x-1);
  if(x<w-1&&mp[y*100+x+1]==res)searchdel(w,h,mp,y,x+1);
}


int search(int w,int h,int *mp){
  int i,j,res;
  res=0;
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(mp[i*100+j]!=0){
        res++;
        searchdel(w,h,mp,i,j);
      }
    }
  }
  return res;
}


int main(){
  int w,h;
  int i,j;
  char* s;
  int *mp;
  s=(char*)malloc(sizeof(char)*105);
  mp=(int*)malloc(sizeof(int)*100*100);
  while(1){
  gets(s);
  sscanf(s,"%d %d",&h,&w);
  if(w==0&&h==0){
  	free(s);
  	free(mp);
	return 0;
  }

  for(i=0;i<h;i++){
    gets(s);
    for(j=0;j<w;j++){
      mp[i*100+j]=s[j]=='@'?1:(s[j]=='*'?2:s[j]=='#'?3:0);
    }
  }
  printf("%d\n",search(w,h,mp));
  }
  return 0;
}

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

function main()
    n=parseInt(readline())
    soinsu=Vector{Int}()
    MOD=10^9+7
    for i in 2:n
        num=i
        for j in 2:i
            while num%j==0
                num÷=j
                push!(soinsu,j)
            end
        end
    end
    cnt=Dict{Int,Int}()
    for i in soinsu
        if haskey(cnt,i)
            cnt[i]+=1
        else
            cnt[i]=1
        end
    end
    ans=1
    for i in keys(cnt)
        ans=(ans*(cnt[i]+1))%MOD
    end
    print(ans)
end
main()

Measured memory_bytes: 167852
l, r = map(int, input().split())
mod = 2019
l0 = l % mod
r0 = r % mod

a = []
if r - l >= mod:
    a = [0,0]
elif l0 <= r0:
    a = list(range(l0, r0+1))
else:
    a = list(range(0, l0+1)) + list(range(r0, mod))

m = 10000
for i in range(len(a)-1):
    for j in range(i+1, len(a)):
        x = (a[i] * a[j]) % mod
        if x < m:
            m = x
print(m)



Measured memory_bytes: 3064
h,w=map(int,input().split())
if h%3==0 or w%3==0:
    print(0)
else:
    if w%2==0:
        a=w*(h//3)
        b=(h-h//3)*(w//2)
        c=w*(h//3+1)
        d=(h-h//3-1)*(w//2)
    else:
        a=w*(h//3)
        b=(h-h//3)*(w//2+1)
        c=w*(h//3+1)
        d=(h-h//3-1)*(w//2)
    ans=min(b-a,c-d,h,w)
    if h%2==0:
        a=h*(w//3)
        b=(w-w//3)*(h//2)
        c=h*(w//3+1)
        d=(w-w//3-1)*(h//2)
    else:
        a=h*(w//3)
        b=(w-w//3)*(h//2+1)
        c=h*(w//3+1)
        d=(w-w//3-1)*(h//2)
    ans=min(ans,b-a,c-d)
    print(ans)

Measured memory_bytes: 3064
#include <iostream>
 
using namespace std;
 
int main(void) {
  long int A, B, C, K;
  cin >> A >> B >> C >> K;

  if(A >= K){
    cout << K << endl;
  }else if(A + B >= K){
    cout << A << endl;
  }else{
    cout << A - (K - (A + B)) << endl;
  }
  return 0;
}

Measured memory_bytes: 3572
s = input()
t = input()

len_s = len(s)
len_t = len(t)

dp = [ [0 for _ in range(len_t+1)] for _ in range(len_s+1) ]

for i in range(len_s):
        for j in range(len_t):
                if s[i] == t[j]:
                    dp[i+1][j+1] = max( dp[i+1][j+1], dp[i][j]+1 )
                dp[i+1][j+1] = max( dp[i+1][j+1], dp[i+1][j] )
                dp[i+1][j+1] = max( dp[i+1][j+1], dp[i][j+1] )

i = len_s
j = len_t
str = ''

while i > 0 and j > 0:
        if dp[i-1][j] == dp[i][j]:
            i -= 1
        elif dp[i][j-1] == dp[i][j]:
            j -= 1
        else:
            str += s[i-1]
            i -= 1
            j -= 1
            
print(str[::-1])


Measured memory_bytes: 121564
R = lambda: list(map(int, input().split()))
n = int(input())
a, b = R(), R()
r = 0
for i in range(n):
    x = min(a[i], b[i])
    b[i] -= x
    y = min(a[i + 1], b[i])
    a[i + 1] -= y
    r += x + y
print(r)


Measured memory_bytes: 18624
from collections import deque
n , m = map(int, input().split())
r = [[0]*(9) for i in range(9)]
ans = 0
c = 0
for i in range(m):
    a , b = map(int, input().split())
    r[a][b]=1
    r[b][a]=1
d = deque([[1,[0,1,0,0,0,0,0,0,0]]])
while d:
    p=d.popleft()
    for i in range(1,n+1):
        if r[p[0]][i]==1 and p[1][i]==0:
            t=p[1].copy()
            t[i]=1
            if sum(t)==n:
                c+=1
            d.append([i,t])
            p[1][i]=0
print(c)


Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define tc int t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>
#define vpi vector<pair<int,int> > 
#define vpll vector<pair<lli,lli> >
#define vvpi vector < vector<pair<int,int> > > 
#define vvpll  vector < vector<pair<lli,lli> > >
#define vvi vector<vector<int> >
#define vvll vector<vector<lli> >
#define maxn 1000001
#define mod 1000000007
#define inf 10000000000000000


int main()
{
    fastio;
    int n,m;
    cin>>n>>m;
    int n1;
    cin>>n1;
    map<int,int> rsum,csum;
    map <pair<int,int> , int > mp;
    int maxr=0,maxc=0;
    for(int i=0;i<n1;i++)
    {
        int x,y;
        cin>>x>>y;
        mp[{x-1,y-1}]++;
        rsum[x-1]++;
        csum[y-1]++;
        maxr=max(maxr,rsum[x-1]);
        maxc=max(maxc,csum[y-1]);
    }
    vi vr,vc;
    for(auto x : rsum)
    {
        if(x.s==maxr){vr.pb(x.f);}
    }
    for(auto x : csum){
        if(x.s==maxc){vc.pb(x.f);}
    }
    lli n2=vr.size(),n3=vc.size();
    int ans=0;
    if(n2*n3>n1)
    {
        cout<<maxr+maxc<<"\n";
    }
    else{
        for(int x : vr)
        {
            for(int y : vc)
            {
                int tot=0;
                if(mp[{x,y}]) tot--;
                tot+=rsum[x]+csum[y];
                ans=max(ans,tot);
            }
        }
        cout<<ans<<"\n";
    }
    return 0;
}


Measured memory_bytes: 54220
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define Max(_A,_B) (_A>_B?_A:_B)
#define Min(_A,_B) (_A<_B?_A:_B)
#define maxn 5007
#define md 1000000007
#define V e[i].v
#define ull unsigned long long
#define R register
int n, m, k, tot;
inline int read(){
    R int s = 0, f = 1; R char c = getchar();
        while (c > '9' || c < '0') { c = getchar();}
            while (c >= '0' && c <= '9') {s = s * 10 + c - '0'; c = getchar();}
                return s * f;
                }
char s[5007];
ll f[maxn][maxn], ans;   //f[i][j]表示i次操作构成序列j的 方案数
ll ksm(ll a, int b){
    ll res = 1;
    while (b) {
        if (b & 1) res = res * a % md;
        a = a * a % md;
        b >>= 1;
    }
    return res;
}
int main() {
    f[0][0] = 1ll;
    for (int i = 0; i <= 5000; i++)
        for (int j = 0; j <= 5000; j++) {
            if (f[i][j]){
                f[i + 1][j + 1] = (f[i + 1][j + 1] + 2ll * f[i][j] % md) % md;
                f[i + 1][Max(0, j - 1)] = (f[i + 1][Max(0, j - 1)] + f[i][j] % md) % md;
            }
        }
    while (scanf("%d\n%s", &n, s) != EOF){
        m = strlen(s);
        ans = f[n][m];
        ans = (ans * ksm(ksm(2ll, m), md - 2)) % md;
        printf ("%lld\n", ans);
    }
    return 0;
}

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

int main()
{
	int a,b,k;
	cin >> a >> b >> k;
	for(int i = a; i <= b; i++){
		if(abs(a-i) < k || abs(b-i) < k){
			cout << i << " ";
		}
	}
	cout << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <memory>
#include <math.h>
#include <algorithm>
#include <queue>

using namespace std;
int main()
{
    int N, M;
    int day = 0;

    cin >> N >> M;
    vector<int> shukulist( M );

    for (auto i = 0; i < M; i++) 
    {
        cin >> shukulist[i];
        day += shukulist[i];
    }
    if (N < day) {
        cout << "-1" << endl;
    } else {
        cout << (N - day) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)

// return the minimum number of t s.t., d*(2**t)>=x
int f(int d, int x) {
  int t = 0;
  while((ll)d * (1LL << t) < (ll)x) t++;
  return t;
}

int main() {
  int n, k;
  cin >> n >> k;
  double ans = 0.0;
  rep(i, n) {
    int dice = i + 1;
    ans += (1.0) / (double)(1LL << f(dice, k));
  }
  ans /= (double)n;
  printf("%.20f\n", ans);
  return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <complex>
#include <iterator>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rtr(c, i) for(auto i = (c).rbegin(); i != (c).rend(); i++)
#define repfn(i, a, cont, next) \
  for(auto i = (a); [=](){return(cont);}(); i = [=](){return(next);}())
#define repby(i, a, b, step) repfn(i, a, i < b, i + step)
#define repab(i, a, b) repby(i, (a), (b), 1)
#define rep(i, n) repab(i, 0, (n))
#define pb push_back
#define sz(c) int((c).size())

int gcd_h(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd_h(b, a % b);
}

int gcd(int a, int b) {
  if (a < b)
    return gcd_h(b, a);
  else
    return gcd_h(a, b);
}

int lcm(int a, int b) {
  int g = gcd(a, b);
  if (g) {
    return (a / g) * b;
  } else {
    return 0;
  }
}

int main(int argc, char **argv)
{
  int a, b;
  while (cin >> a >> b) {
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }
  return 0;
}

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

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

int main() {
  string o, e;
  cin >> o >> e;
  rep(i, min(o.size(), e.size())) { cout << o[i] << e[i]; }
  if (o.size() > e.size()) cout << o[o.size() - 1];
  if (o.size() < e.size()) cout << e[e.size() - 1];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList =  readLine()!!.split(" ").map(String::toFloat)
    val a2List = aList.map { if(it != 0f) 1/it else 0f }.sum()
    println(if(a2List !=0f) 1/a2List else 0)
}

Measured memory_bytes: 37688
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const ll mod = 1e9+7;

int main() {
	string s,t;
	cin>>s>>t;
	ll mx=t.length();
	ll n=s.length(), m=t.length();
	for(ll i=0;i<=(n-m);i++) {
		ll c=0;
		for(ll j=0;j<m;j++) {
			if(s[j+i] != t[j])
				c++;
		}
		mx =min(mx, c);
	}
	cout<<mx;
	return 0;
}

Measured memory_bytes: 3624
n = int(input())
S = [list(input()) for i in range(n)]
e = [[] for i in range(n)]
count = [0]*n
for i in range(n):
    count[i] = S[i].count("1")
    for j in range(i+1,n):
        if S[i][j] == "1":
            e[i].append(j)
            e[j].append(i)

m = min(count)
ans = 0
for i in range(n):
    dis = [float("INF")]*n
    dis[i] = 0
    check = True
    l = [i]
    d = 0
    while check:
        nl = []
        for j in l:
            for nex in e[j]:
                if dis[nex] < d-1 or dis[nex] == d:
                    check = False
                    break
                if dis[nex] == float("INF"):
                    nl.append(nex)
                    dis[nex] = d+1
            if check == False:
                break
        if check == False:
            d = float("INF")
            break
        if nl:
            l = nl
            d += 1
        else:
            break
    if d != float("INF"):
        ans = max(ans,d+1)
print(ans if ans != 0 else -1)

Measured memory_bytes: 9768
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
m = 1000001

count = 0
cnt = [0] * m
for i in range(n):
  if cnt[a[i]] == 0:
    for j in range(a[i], m, a[i]):
      cnt[j] += 1
  else:
    cnt[a[i]] = 2
for i in range(n):
  if cnt[a[i]] == 1:
    count += 1
print(count)

Measured memory_bytes: 103968
#include <bits/stdc++.h>
using namespace std;
//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << p.first << " " << p.second;return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if (it != v.begin())os << " ";os << *it;
  }return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void print(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void print(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
//typedef
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;



bool prime[10000001], dp[10000001];
int a[30];
void eras(){
	fill(prime, prime+10000001, true);
	prime[0] = prime[1] = false;
	repi(i,2,10000001){
		if(prime[i])for(int j = 2;i*j <= 1000000;j++){
			prime[i*j] = false;
		}
	}
}

signed main(){
	eras();
	while(1){
		int n, x;
		cin >> n >> x;if(n == 0 and x == 0)break;
		rep(i,n)cin >> a[i];
		rep(i,x+1)dp[i] = false;
		dp[0] = true;
		rep(i,n){
			rep(j,x+1){
				if(j-a[i] < 0)continue;
				dp[j] = dp[j] | dp[j-a[i]];
			}
		}
		int ans = -1;
		drep(i,x,2){
			if(prime[i] and dp[i]){ans = i;break;}
		}
		cout << (ans == -1 ? "NA" : to_string(ans)) << endl;
	}
	return 0;
}







Measured memory_bytes: 13916
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int pop();
void push();
int top, A[1000];
 
int main(){
  int a,b;
  char c[100];
   
  top=0;
  while(scanf("%s",c)!=-1){
    if(c[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(c[0]=='-'){
      a=pop();
      b=pop();
      push(b-a);
    }
    else if(c[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else
      push(atoi(c));
  }
 
  printf("%d\n",pop());
  
  return 0;
}

int pop(){
  top--;
  return A[top+1];
}

void push(int x){
  A[++top]=x;
}

Measured memory_bytes: 548
def e_colorful_blocks(MOD=998244353):
    N, M, K = [int(i) for i in input().split()]

    class Combination(object):
        """素数 mod に対する二項係数の計算"""
        __slots__ = ['mod', 'fact', 'factinv']

        def __init__(self, max_val_arg: int = 10**6, mod: int = 10**9 + 7):
            fac, inv = [1], []
            fac_append, inv_append = fac.append, inv.append

            for i in range(1, max_val_arg + 1):
                fac_append(fac[-1] * i % mod)

            inv_append(pow(fac[-1], -1, mod))
            for i in range(max_val_arg, 0, -1):
                inv_append((inv[-1] * i) % mod)

            self.mod, self.fact, self.factinv = mod, fac, inv[::-1]

        def combination(self, n, r):
            return (0 if n < 0 or r < 0 or n < r
                    else self.fact[n] * self.factinv[r] * self.factinv[n - r] % self.mod)

    ans = 0
    comb = Combination(max(N, M), MOD).combination
    for x in range(K + 1):
        a = (M * pow(M - 1, N - 1 - x, MOD)) % MOD
        b = comb(N - 1, x)
        ans = (ans + a * b) % MOD
    return ans

print(e_colorful_blocks())

Measured memory_bytes: 26336
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<30;
const ll LLINF = 1LL<<62;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

int CountDigits(int n){
   if (n==0)return 0;
   int sum = 0;
   while(n>0){
       sum ++;
       n /= 10;
   }
   return sum;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b;
  cin >> a >> b;
  int sm = a*pow(10,CountDigits(b))+b;
  //cout << sm << endl;
  for (int i=0;i*i<=sm;i++){
      if (i*i==sm){
          cout << "Yes" << endl;
          return 0;
      }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
n,x = gets.split.map(&:to_i)
x_ary = gets.split.map(&:to_i)
sa_ary = []
sa_ary[0] = (x_ary[0] - x).abs
(1..n-1).each do |i|
  sa_ary[i] = (x_ary[i] - x_ary[i-1]).abs
end
gcd = sa_ary[0]
sa_ary.each do |i|
  gcd = gcd.gcd(i)
end
puts gcd

Measured memory_bytes: 9420
#include <iostream>

const int N = 100;

int main(void) {
  int n = 0;
  int x = 0;

  std::cin >> n >> x;

  while (!((n == 0) && (x == 0))) {
    int count = 0;
    bool generated[N + 1][N + 1][N + 1] = {false};
    
    for (int i = 1; i <= n - 2; i++ ) {
      for (int j = 1; j <= n - 1; j++) {
	for (int k = 1; k <= n; k++) {
	  if ((i == j) || (j == k) || (i == k)) {
	    continue;
	  }

	  if (generated[i][j][k]) {
	    continue;
	  }

	  if ((i + j + k) == x) {
	    count++;

	    generated[i][j][k] = true;
	    generated[i][k][j] = true;
	    generated[j][i][k] = true;
	    generated[j][k][i] = true;
	    generated[k][i][j] = true;
	    generated[k][j][i] = true;
	  }
	}
      }
    }

    std::cout << count << std::endl;

    std::cin >> n >> x;  
  }
  
  return 0;
}

Measured memory_bytes: 2172
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <iomanip>
#include <vector>
#include <queue>
#include <functional>
#include <random>
#include <ctime>

using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define RN cout << "\r\n";
#define fi first
#define se second
typedef long long int ll;
typedef pair<ll, ll> P;


// start combination mod n
const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

int main() {
    int a;
    cin >> a;
    int ans = 0;
    int lastColor = 0;
    int continuityNumber = 1;
    REP(i, a) {
        int currentColor;
        cin >> currentColor;
        if (currentColor == lastColor) {
            continuityNumber++;
        } else {
            ans += continuityNumber / 2;
            continuityNumber = 1;
        }
        lastColor = currentColor;
    }
    ans += continuityNumber / 2;
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define eps 0.000000001
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+5;
int main(){
	int n=5;
	int a;
	rep(i,1,n){
		int x;cin>>x;
		if(x==0) a=i;
	}
	cout<<a<<endl;
}


Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
ll k,n;
cin>>n>>k;
ll a[n];
ll x=0;
for(ll i=0;i<n;i++){
cin>>a[i];
if(a[i]==1)
x=i;
}

if(n==k)
cout<<1<<endl;
else{
n--;
if(n%(k-1)==0)
cout<<n/(k-1)<<endl;
else
cout<<n/(k-1)+1<<endl;
}
return 0;
}

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


int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int xa = min(a, k);
	k -= xa;
	int xb = min(b, k);
	k -= xb;
	int xc = k;
	cout << xa - xc << endl;
	return 0;
}






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

using namespace std;

int main()
{
	int n, x, y, z;
	map<int, bool> ga, gb, gc;
	cin >> n;
	cin >> x;
	for (int i = 0; i < x; i++)
	{
		int a;
		cin >> a;
		ga[a] = true;
	}
	cin >> y;
	for (int i = 0; i < y; i++)
	{
		int b;
		cin >> b;
		gb[b] = true;
	}
	cin >> z;
	for (int i = 0; i < z; i++)
	{
		int c;
		cin >> c;
		gc[c] = true;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		if ((!ga[i] && gc[i]) || (gb[i] && gc[i]))
			ans++;
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3108
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();

    if (a+b >= 10) {
      System.out.println("error");
    } else {
      System.out.println(a+b);
    }
  }

}


Measured memory_bytes: 21716
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main() {
	int n;
	double debt = 100000;
	cin >> n;
	for (int i = 0; i < n; i++) {
		debt *= 1.05;
		debt /= 1000;
		debt = ceil(debt);
		debt *= 1000;
	}
	printf("%ld\n", (long)debt);
	return 0;
}

Measured memory_bytes: 1140
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;
int main(){
	int n, m;
	while(1){
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		int i, j, temp = 0, k, count = 0;
		int t[n], h[m], sum1 = 0, sum2 = 0;
		int d[10000], e[10000];
		bool cando = false;
		for(i = 0;i < n;i++){
			cin >> t[i];
		}
		for(i = 0;i < m;i++){
			cin >> h[i];
		}
		
		sort(t, t+n);
		sort(h, h+m);
		
		for(i = 0;i < n;i++){
			sum1 += t[i];
		}
		for(i = 0;i < m;i++){
			sum2 += h[i];
		}
		for(i = 0;i < n;i++){
			for(j = 0;j < m;j++){
				if(sum1 - t[i] + h[j] == sum2 - h[j] + t[i]){
					cando = true;
					d[count] = t[i];
					e[count] = h[j];
					count++;
				}
			}
		}
		if(!cando){
			cout << "-1" << endl;
		}
		else if(cando){
			for(i = 0;i < count;i++){
				for(j = i+1;j < count;j++){
					if(d[i] + e[i] > d[j] + e[j]){
						temp = d[i];
						d[i] = d[i+1];
						d[i+1] = temp;

						temp = e[i];
						e[i] = e[i+1];
						e[i+1] = temp;
					}
				}
			}
			cout << d[0] << " " << e[0] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1256
#include<iostream>
#include<string>

using namespace std;

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

	int cs=0,ct=0,ans=0;

	for(int i=1;i<=s.size();i++)
	{
		if(s[i-1]=='S')
			cs++;
		else
		{
			if(ct==cs)ans++;
			else ct++;
		}
	}
	ans*=2;
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <cmath>
#include <iomanip> //cout << fixed << setprecision(15) << << endl;
#include <cassert>


using namespace std;


#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define P pair<int,int>

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;


int main(){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n, m; ll k;
    cin >> n >> m >> k;
    vector<ll> a(n), b(m),A(n+1);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    rep(i,n-1) a[i+1] += a[i];
    rep(i,m-1) b[i+1] += b[i];
    a.insert(a.begin(),0);

    int ans = 0;
    for(int i = 0; i < n+1; ++i){
        if(k-a[i] < 0) break;

        auto itr = lower_bound(b.begin(),b.end(), k-a[i]);
        int cnt = distance(b.begin(),itr);
        if(*itr == k-a[i]) cnt++;
        ans = max(ans, cnt + i);
    }

    cout << ans << endl;
}



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

int main(){
  ll n, m;
  cin >> n >> m;
  cout <<  (2 * n < m ? n + (m - 2 * n) / 4 : m / 2) << endl;
  return 0;
} 

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

void leave(string message) {
    cout << message << endl;
    exit(0);
}

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

    if(s == "SUN")  leave("7");
    if(s == "MON")  leave("6");
    if(s == "TUE")  leave("5");
    if(s == "WED")  leave("4");
    if(s == "THU")  leave("3");
    if(s == "FRI")  leave("2");
    if(s == "SAT")  leave("1");
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T>& v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

using Graph = vector<vector<int>>;
const int N_MAX = 100010;

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

  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  Graph g(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> d(n, INF), par(n, -1);
  queue<int> que;
  d[v] = 0;
  que.push(v);
  while (!que.empty()) {
    int cur = que.front();
    que.pop();
    for (auto nxt : g[cur]) {
      if (d[nxt] != INF) continue;
      d[nxt] = d[cur] + 1;
      par[nxt] = cur;
      que.push(nxt);
    }
  }
  int pos = u;
  for (int i = 0; i < (d[u] - 1) / 2; i++) {
    pos = par[pos];
  }
  int ret = d[u] / 2;
  vector<int> d2(n, INF);
  d2[pos] = 0;
  que.push(pos);
  while (!que.empty()) {
    int cur = que.front();
    que.pop();
    for (auto nxt : g[cur]) {
      if (d2[nxt] != INF) continue;
      d2[nxt] = d2[cur] + 1;
      que.push(nxt);
    }
  }
  int tmp = 1 - d[u] % 2;
  for (int i = 0; i < n; i++) {
    if (d[i] != d[pos] + d2[i]) continue;
    ret = max(ret, (d[u] - 1) / 2 + d2[i] + tmp);
  }
  cout << ret << endl;
}


Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_end=(a);i>=i##_end;--i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define foe(i,a) for(__typeof(a.begin())i=a.begin();i!=a.end();++i)
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef double ld;
typedef long long L;
typedef vector<int> VI;
typedef pair<int,int> pa;
#ifdef flukehn
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif
const int N=10011;
int n,d[N];
VI e[N];
int c[N],q[N],va[N],an[N];
int main(){
#ifdef flukehn
	freopen("a.in","r",stdin);
#endif
	ios::sync_with_stdio(0);
	int x,y;
	cin>>n;
	For(i,1,n){
		cin>>x>>y;
		e[x].pb(y);
		e[y].pb(x);
		++d[x],++d[y];
	}
	rep(i,1,n)cin>>c[i];
	sort(c+1,c+n+1);
	int h=1,t=1;
	rep(i,1,n)if(d[i]==1)q[t++]=i,va[i]=1;
	rep(i,1,n){
		x=q[i];
		an[x]=c[i];
		for(int y:e[x]){
			if(!va[y] && (--d[y])==1){
				q[t++]=y;
				va[y]=1;
			}
		}
	}
	L ans=0;
	rep(x,1,n)for(int y:e[x])ans+=min(an[x],an[y]);
	ans/=2;
	printf("%lld\n",ans);
	rep(i,1,n)printf("%d%c",an[i]," \n"[i==n]);
}

Measured memory_bytes: 1152
n=int(input())
s=input()
E=[0]*n
W=[0]*n

for i in range(n):
      if s[i]=="E":
            E[i]=E[i-1]+1
      else:
            E[i]=E[i-1]
for i in reversed(range(n)):
      if i==n-1:
            if s[i]=="W":
                  W[i]=1
            else:
                  W[i]=0
      else:
            if s[i]=="W":
                  W[i]=W[i+1]+1
            else:
                  W[i]=W[i+1]
ans=float("inf")
for i in range(n):
      ans=min(n-(E[i]+W[i]),ans)
print(ans)


Measured memory_bytes: 17616
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  rep (i, m) cin >> a[i];
  const vector<int> match{0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
  rep (i, m) b[i] = match[a[i]];
  unordered_map<int, int> num;
  rep (i, m) num[b[i]] = max(num[b[i]], a[i]);
  sort(all(b));
  b.erase(unique(all(b)), b.end());
  const int bs = b.size();
  vector<map<int, int>> dp(n + 1);
  auto comp =
    [&](map<int, int> &x, map<int, int> &y) {
      if (x[0] != y[0]) {
        return x[0] < y[0];
      } else {
        for (auto xitr = x.rbegin(), yitr = y.rbegin(); xitr != x.rend() && yitr != y.rend(); ++xitr, ++yitr) {
          int xf = xitr->first, xs = xitr->second, yf = yitr->first, ys = yitr->second;
          if (xf != yf) {
            return xf < yf;
          } else {
            if (xs != ys) return xs < ys;
          }
        }
        return true;
      }
    };
  dp[0][0] = 0;
  rep (i, n + 1) {
    if (dp[i].empty()) continue;
    rep (j, bs) {
      if (i + b[j] > n) continue;
      auto tmp = dp[i];
      ++tmp[0];
      ++tmp[num[b[j]]];
      if (comp(dp[i + b[j]], tmp)) dp[i + b[j]] = tmp;
    }
  }
  string ans;
  for (auto itr = dp[n].rbegin(); itr != --dp[n].rend(); ++itr) {
    ans += string(itr->second, itr->first + '0');
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2048
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from sys import stdin
import math

# 標準入力をスペースで区切って、intに変換 listに収納
int_list  = [int(x) for x in stdin.readline().rstrip().split()]


a = int_list[0] 
b = int_list[1] 
c = int_list[2] 

insert_amount_of_water = a - b

surplus = c - insert_amount_of_water 

if surplus <= 0:
    surplus = 0

print(surplus)



Measured memory_bytes: 2940
import java.util.*;

// Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail

public class Main {
    public static void main(String args[] ) throws Exception {
        Scanner in = new Scanner(System.in);
        
        
        int a = in.nextInt();
        in.nextLine();
        String s =  in.nextLine();
        if(a<3200) {
        	System.out.println("red");
        	
        }
        else {
        	System.out.println(s);
        }
    }
            
        


    
    
   
}


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

int main(){
  int s;
  cin >> s;
  int a = s%60;
  s -= a;
  s/=60;
  int b = s%60;
  s -= b;
  s/=60;
  int c = s%60;
  cout << c << ":" << b << ":" << a << endl;
}


Measured memory_bytes: 3080
n, m = gets.to_s.split.map{|t|t.to_i}

edges = Array.new(n){ []}
m.times do
  u, v = gets.to_s.split.map{|t|t.to_i-1}
  edges[u] << v
end

s, t = gets.to_s.split.map{|i|i.to_i-1}

inf = 10 ** 9
dist = Array.new(n){ Array.new(3){ inf } }
dist[s][0] = 0

q = [[s,0]]
while q.any?
  
  u, x = q.shift
  y = (x+1) % 3
  edges[u].each do |v|
    next if dist[v][y] != inf# || dist[u][x] == inf
    dist[v][y] = dist[u][x] + 1
    if v == t && y == 0
      puts dist[v][y] / 3
      exit
    end
    q.push([v, y])
  end
end

puts dist[t][0] == inf ? -1 : dist[t][0] / 3

Measured memory_bytes: 18044
max = 50000
prime = [2]
list = Array.new(max){|i| i}
list[0] = 0
list[1] = 0
loop do
  a = prime[-1]
  break if a >= Math.sqrt(max)
  i = a
  while i <= max
    list[i] = 0
    i += a
  end
  while list[a] == 0
    a += 1
  end
  prime << list[a]
  list[a] = 0
end
prime += list - [0]

p = {}
prime.each{|i|
  p[i] = true
}

while n = gets.to_i
  break if n == 0
  count = 0
  i = 0
  loop do
    break if prime[i] > n / 2
    if p[n - prime[i]]
      count += 1
    end
    i += 1
  end
  puts count
end

Measured memory_bytes: 9540
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from  collections import defaultdict
from collections import Counter
import bisect
def main():
     N = I()
     A = LI()
     c = Counter(A)
     if len(c.values()) == N:
         print('YES')
     else:
         print('NO')
if __name__ == "__main__":
    main()



Measured memory_bytes: 115364
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int a = 0,b = 0;
    string s;
    cin >> s;
    rep(i, s.size()){
        a += s[i] - 48;
        b = b * 10 + s[i] - 48;
    }
    if(b % a == 0){
        Yes
    }else{
        No;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <iomanip>

#include <map>
#include <set>
#include <queue>
#include <stack>

#define ALL(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdbl vector<double>
#define vstr vector<string>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll X,Y;
	cin >> X >> Y;
	if(abs(X-Y) <= 1) cout << "Brown" << endl;
	else cout << "Alice" << endl;
}

Measured memory_bytes: 256
program test03
 implicit none
 integer,allocatable :: a(:)
 integer N
 integer i, j, jj
 integer mina
 integer :: js=1
 integer :: yesf=0
 integer :: no=0

 read(5,*) N
 allocate(a(N))

 read(5,*) (a(i), i=1,N)

mina=a(1)
 do j=1,N
  if ( j/=1 ) then
    if ( mina < a(j) ) then
     no=1
    else
    mina=a(j)
    end if
  end if
!print *,mina
 if ( no==0 ) then
  yesf=yesf+1
 end if
 no=0
end do

 write (*,fmt='(i0)',advance='no') yesf

endprogram test03


Measured memory_bytes: 1536
p=55555 
l=[1]*p 
i=2 
while i*i<=p:
    if l[i]:
        for j in range(i*i,p,i):
            l[j]=0 
    i+=1 
l[0]=l[1]=0 
prms=[i for i in range(p) if l[i]]
n=int(input())
mod1=[i for i in prms if i%5==1]
if len(mod1)>=n:
    print(*(mod1[:n]))
    exit()
mod2=[i for i in prms if i%5==2]
if len(mod2)>=n:
    print(*(mod2[:n]))
    exit()
mod3=[i for i in prms if i%5==3]
if len(mod3)>=n:
    print(*(mod2[:n]))
    exit()

Measured memory_bytes: 3700
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;

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

const LL  INF=1<<31;
const LL MOD=1000000007;



int main(){
    int w,a,b;
    cin>>w>>a>>b;
    if(a==b)cout<<0<<endl;
    else if(a<b){
        if(a+w>=b)cout<<0<<endl;
        else cout<<b-a-w<<endl;
    }
    else {
        if(b+w>=a)cout<<0<<endl;
        else cout<<a-w-b<<endl;
    }
}

Measured memory_bytes: 256
fun main(args:Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val posList = readLine()!!.split(" ").map { it.toInt() }.sorted()
    if(n >= m) {
        println(0)
        return
    }
    val areaList = (1..posList.lastIndex).map { posList[it] - posList[it-1] }.sorted()
    val ans = areaList.take(m - n).sum()?:0
    println(ans)
}


Measured memory_bytes: 56224
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
 
const ll MOD = 1000000007;
const ll INF = 100000;
 
 

int main(void){
  int n,m,ans=0;

  cin>>n>>m;


    for(int i=1;i<=sqrt((double)m);i++){
        if(m%i!=0||(i<n&&m/i<n)) continue;
        
        if(i>=n&&m/i>=n) ans = max(ans,max(i,m/i));
        else i>=n?ans=max(ans,m/i):ans=max(ans,i);
    }
  
  
  
 cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin >> a>>b;
    if(a+b==4)
    {
        cout << 2 <<endl;
    }
    if(a+b==3)
    {
        cout << 3 <<endl;
    }
    if(a+b==5)
    {
        cout << 1 <<endl;
    }
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
a,b=map(int,input().split())
cnt=''
if a>b:
    for i in range(a):
        cnt+=str(b)
    print(cnt)
elif a<b:
    for i in range(b):
        cnt+=str(a)
    print(cnt)
else:
    for i in range(a):
        cnt+=str(a)
    print(cnt)

Measured memory_bytes: 38256
import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

X,N = mips()
P = [i for i in mips()]
A = []
c1 = -1
c2 = -1
for i in range(100):
    if c1 == 1 and c2 == 1:
        break
    a1 = X-i
    a2 = X+i
    if c1 == -1 and a1 not in P:
        A.append(a1)
        c1 = 1
    if c2 == -1 and a2 not in P:
        A.append(a2)
        c2 = 1
ans = 1000
B = []
for el in A:
    if abs(ans-X) >= abs(el-X):
        ans = el
        B.append(ans)
print(min(B))

Measured memory_bytes: 9236
package main

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

const (
	separator = "#"
)

type office struct {
	building int
	floor    int
	room     int
	people   int
}

var scan = bufio.NewScanner(os.Stdin)

func main() {
	scanWords()
	itemNum := readNextInt()

	roomList := resetBuildingInfo()

	for i := 0; i < itemNum; i++ {
		b := readNextInt()
		f := readNextInt()
		r := readNextInt()
		v := readNextInt()

		for i := 0; i < len(roomList); i++ {
			if roomList[i].building == b && roomList[i].floor == f && roomList[i].room == r {
				roomList[i].people += v
				break
			}
		}
	}

	printBuildingInfo(roomList)

}

func resetBuildingInfo() []office {
	slice := make([]office, 0)
	for building := 1; building <= 4; building++ {
		for floor := 1; floor <= 3; floor++ {
			for room := 1; room <= 10; room++ {
				slice = append(slice, office{building: building, floor: floor, room: room})
			}
		}
	}
	return slice
}

func printBuildingInfo(slice []office) {
	currentBuilding := 1
	for _, info := range slice {
		if currentBuilding != info.building {
			fmt.Println(strings.Repeat(separator, 20))
			currentBuilding = info.building
		}

		fmt.Print(" ")
		fmt.Print(info.people)

		if info.room == 10 {
			fmt.Println()
		}
	}
}

func scanWords() {
	scan.Split(bufio.ScanWords)
}

func readNextInt() int {
	scan.Scan()

	input, err := strconv.Atoi(scan.Text())
	if err != nil {
		panic(err)
	}
	return input
}



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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    int N; cin >> N;

    if(N/100 == N%10) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;

}

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

int main() {
  pair<int, int> p, q, n;
  cin >> p.first >> p.second;
  cin >> q.first >> q.second;
  n.first = -(q.second - p.second);
  n.second = q.first - p.first;
  p.first += n.first;
  p.second += n.second;
  q.first += n.first;
  q.second += n.second;
  cout << q.first << ' ' << q.second << ' ';
  cout << p.first << ' ' << p.second << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    char a; cin >> a;
    int d = a-'a';
    if(0 <= d and d < 26){
        cout << 'a' << endl;
    }else{
        cout << 'A' << endl;
    }

}

Measured memory_bytes: 3636
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Wed Dec 19 22:03:02 2018
//
package main

import "fmt"

type point struct {
	x, y, h int
}

func abs(a int) int {
	if a < 0 {
		return -a
	}

	return a
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func main() {
	var N int
	fmt.Scan(&N)

	arr := make([]point, N)
	for i := range arr {
		fmt.Scan(&arr[i].x, &arr[i].y, &arr[i].h)
	}

	for x := 0; x <= 100; x++ {
		for y := 0; y <= 100; y++ {
			valid := true
			h := 0
			for _, p := range arr {
				if p.h > 0 {
					h = p.h + abs(p.x-x) + abs(p.y-y)
				}
			}

			for _, p := range arr {
				if max(h-abs(x-p.x)-abs(y-p.y), 0) != p.h {
					valid = false
				}
			}
			if valid {
				fmt.Println(x, y, h)
				return
			}
		}
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
using namespace std;
int main(){
  string s; cin>>s;
  int a = int(s[5]-'0');
  int b = int(s[6]-'0');
  //cout << a <<endl;
  if(a==0&&b<=4) cout << "Heisei" << endl;
  else cout << "TBD" << endl;

}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};//RDLU
int main(){
	int n,m,q;
	cin>>n>>m>>q;
	vvi in(n);
	rep(i,m){
		int a,b;
		scanf("%d %d",&a,&b);
		a--;b--;
		in[a].pb(b);
	}
	rep(i,n)sort(all(in[i]));
	while(q--){
		int a,b;
		scanf("%d %d",&a,&b);
		a--;b--;
		int out=0;
		loop(i,a,b+1)out+=upper_bound(all(in[i]),b)-in[i].begin();
		cout<<out<<endl;
	}
}



Measured memory_bytes: 3456
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


int main() {
    ll N;
    cin >> N;
    vector<ll> H(N);
    REP(i, N) cin >> H[i];

    for(ll i = N - 2; i >= 0; i--){
        if (H[i] - 1 > H[i + 1]) {
            cout << "No" << endl;
            //cout << i;
            return 0;
        }else if (H[i] - 1 == H[i + 1]) H[i]--;
    }
    cout << "Yes" << endl;
    //REP(i, N) cout << H[i];
    return 0;
}


Measured memory_bytes: 1024
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

fun <A : Comparable<A>> min(a: A, b: A) = if (a < b) a else b
fun <A : Comparable<A>> max(a: A, b: A) = if (a > b) a else b

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val X = Array(5) { sc.next().toInt() }
        for (i in 0 until 5) {
            if (X[i] != i +1) {
                pw.println(i+1)
                return
            }
        }
    }
}


Measured memory_bytes: 36424