akhauriyash/Code-Regression huggingface dataset:
import sys

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline


def main():
    N = int(input())
    en = [[] for _ in range(N)]
    on = [[] for _ in range(N)]
    for i in range(N - 1):
        u, v, w = map(int, input().split())
        if w % 2:
            on[u - 1].append(v - 1)
            on[v - 1].append(u - 1)
        else:
            en[u - 1].append(v - 1)
            en[v - 1].append(u - 1)

    color = [None] * N
    stack = [(0, -1, 0)]
    while stack:
        node, parent, col = stack.pop()
        if color[node] is not None:
            continue
        color[node] = col
        for k in en[node]:
            if k != parent:
                stack.append((k, node, col))
        for k in on[node]:
            if k != parent:
                stack.append((k, node, (col + 1) % 2))

    print(*color, sep="\n")


if __name__ == "__main__":
    main()


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

int main(){
    long long n;
    cin >> n;
    vector<long long> A(n), cnt(n+1);
    for(int i = 0; i < n; i++){
        cin >> A[i];
        cnt[A[i]]++;
    }
    long long sum = 0;
    for(int j = 1; j < n+1; j++){
        sum += cnt[j] * (cnt[j]-1) / 2;
    }
    for(int i = 0; i < n; i++){
        cout << sum - cnt[A[i]] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#include <cmath>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5+2;

int main(){
	int N;
	cin>>N;
	int a[MAX];
	a[0]=0;
	rep1(i,N){
		a[i]=a[i-1]+1;
		int t=i;
		int p6=1;
		while(t>=1){
			a[i]=min(a[i],a[i-p6]+1);
			t=t/6;
			p6=p6*6;
		}
		int u=i;
		int p9=1;
		while(u>=1){
			a[i]=min(a[i],a[i-p9]+1);
			u=u/9;
			p9=p9*9;
		}
	}
	cout<<a[N];
}

Measured memory_bytes: 640
/**
 Insertion Sort 
 <Prints out intermediate sequence>
 
 Shunji Lin
 5/12/2015
 **/

#include <iostream>
#include <vector>

using namespace std;

void print_sequence(const vector<int> &sequence, int n) {
  for (int i = 0; i < n - 1; i++) {
    cout << sequence[i] << " ";
  }
  cout << sequence[n-1] << endl;
}

int main() {
  int n;
  cin >> n;
  vector<int> sequence(n);
    
  for (int i = 0; i < n; i++) {
    int entry;
    cin >> entry;
    sequence[i] = entry;
  }

  for (int i = 1; i < n; i++) {
    
    print_sequence(sequence, n);
        
    int key = sequence[i];
    int j = i - 1;
    while (j >= 0 && sequence[j] > key) {
      sequence[j+1] = sequence[j];
      j--;
    }
    sequence[j+1] = key;
  }
  print_sequence(sequence, n);
}
    
    
  

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

int main() {
  int n;
  cin >> n;
  int k=0;
  vector<int> a(n),b(n),c(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    k += a.at(i);
  }
  for(int i=0;i<n;i++){
    b.at(i) = max(k - n*a.at(i),n*a.at(i) -k);
    c.at(i) = b.at(i);
  }
  sort(c.begin(),c.end());
  
  for(int i=0;i<n;i++){
    if(b.at(i) == c.at(0)){
    cout << i << endl;
      break;
      
    }
  }
  
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

lis=[]
sa=list(reversed(list(input().rstrip())))
sb=list(reversed(list(input().rstrip())))
sc=list(reversed(list(input().rstrip())))
lis.append(sa)
lis.append(sb)
lis.append(sc)
k=0
while True:
    if len(lis[k])==0:
        if k==0:
            print("A")
        if k==1:
            print("B")
        if k==2:
            print("C")
        break
    u=lis[k].pop()
    #print(u)
    if u=="a":
        k=0
    if u=="b":
        k=1
    if u=="c":
        k=2

Measured memory_bytes: 3316
# ITP1_5_C: Print a Chessboard

def make_line(width, is_even)
  line = (is_even ? '#.' : '.#') * width
  line[0, width]
end

while true
  height, width = gets.split.map &:to_i
  break if height == 0 && width == 0

  even_line = make_line width, true
  odd_line  = make_line width, false

  (height / 2).times do
    puts even_line, odd_line
  end
  puts even_line if height.odd?
  puts
end

Measured memory_bytes: 8628
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
typedef long long ll;

ll G[310][310];
ll nG[310][310];
const ll INF = 1e17;

int main() {
    ll N, M, L;
    cin >> N >> M >> L;
    rep(i, N) rep(j, N) {
        if(i == j) {
            G[i][j] = 0;
            nG[i][j] = 0;
        } else {
            G[i][j] = INF;
            nG[i][j] = INF;
        }
    }
    rep(i, M) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a][b] = min(G[a][b], c);
        G[b][a] = min(G[b][a], c);
    }
    rep(k, N) rep(i, N) rep(j, N) { G[i][j] = min(G[i][j], G[i][k] + G[k][j]); }

    rep(i, N) rep(j, N) {
        if(i == j)
            continue;
        if(G[i][j] <= L) {
            nG[i][j] = min(nG[i][j], 1LL);
        }
    }
    rep(k, N) rep(i, N) rep(j, N) {
        nG[i][j] = min(nG[i][j], nG[i][k] + nG[k][j]);
    }

    int Q;
    cin >> Q;
    rep(i, Q) {
        ll s, t;
        cin >> s >> t;
        s--;
        t--;
        if(nG[t][s] == INF)
            cout << -1 << endl;
        else
            cout << nG[t][s] - 1 << endl;
    }

    return 0;
}

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

int main() {
	string s; 
  	cin >> s;
  int num2= (s.at(5)-48)*10+(s.at(6)-48);
  if(num2<=4)cout<<"Heisei"<<endl;
  else cout<<"TBD"<<endl;
}
 

Measured memory_bytes: 256
#include<stdio.h>
int dat[100];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%d",dat+i);
		int count=0;
		int left=0;
		int right=a-1;
		int n;
		scanf("%d",&n);
		while(1){
			int M=(left+right)/2;
			count++;
			if(dat[M]==n)break;
			if(dat[M]>n){
				right=M-1;
			}
			if(dat[M]<n){
				left=M+1;
			}
			if(right<left)break;
		}
		printf("%d\n",count);
	}
}

Measured memory_bytes: 0
/* ex3_4
    riverstone*/

#include <stdio.h>
 
int main(void){
    //Nをnumberとする。
    int number;
    int factor=0;

    // number の入力を取得
    scanf("%d",&number);

    // iを総当たり
    // 割り切れるものがあればyes、なければNoを出力
    for(factor=1;factor<10;factor++){
        //numberがiで割り切れてかつ商が9以下ならいい。
        if(number % factor == 0 && number/factor < 10){
            printf("Yes");
            return 0;
        } 
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#define rep(i,a) for(int i=0;i<a;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
#define INF 1145141919810
#define ll long long
using namespace std;
 
int main(){
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll sum=0;
    ll ans_1=0;
    ll ans_2=0;
    bool plus=true;
    rep(i,n){
        sum+=a[i];
        if(plus){
            if(sum>=0){
                ans_1+=abs(sum)+1;
                sum=-1;
            }
        }else{
            if(sum<=0){
                ans_1+=abs(sum)+1;
                sum=1;
            }
        }plus=!plus;
    }plus=false;
    sum=0;
    rep(i,n){
        sum+=a[i];
        if(plus){
            if(sum>=0){
                ans_2+=abs(sum)+1;
                sum=-1;
            }
        }else{
            if(sum<=0){
                ans_2+=abs(sum)+1;
                sum=1;
            }
        }plus=!plus;
    }
    cout<<min(ans_1,ans_2)<<endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    
    if ( n < 1200 ) {
        cout << "ABC\n";
    } else if ( n < 2800 ) {
        cout << "ARC\n";
    } else {
        cout << "AGC\n";
    }
    
    return (0);
}

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

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

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

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

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

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

    // 入力
    string s;
    cin >> s;

    // 処理
    bool ans = true;
    int  cnt = 0;
    if (s[0] != 'A') {
        ans = false;
    }

    for (int i = 1; i < s.size(); i++) {
        if (isupper(s[i])) {
            if (i == 1 || i == s.size() - 1 || s[i] != 'C') {
                ans = false;
            } else if (s[i] == 'C') {
                cnt++;
            }
        }
    }

    // 出力
    cout << (cnt == 1 && ans == true ? "AC" : "WA") << endl;

    return 0;
}


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

#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define int long long
#define ll long long

ll INF = (1LL << 60);
int mod = 998244353;
using P = pair<int, int>;

signed main() {
	int n, m; cin >> n >> m;
	vector<int>a(n), b(m);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	vector<int> c = convolution(a, b);
	for (int i = 0; i < n + m - 1; i++) {
		cout << c[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 27252
{-# LANGUAGE Strict #-}
import qualified Data.ByteString.Char8 as B
import           Data.IntMap.Strict    ((!))
import qualified Data.IntMap.Strict    as M
import           Data.List             (unfoldr)

main :: IO ()
main = do
  n <- readLn
  as <- readIntsLn
  putStr . unlines . map show $ solve n as

readIntsLn :: IO [Int]
readIntsLn = unfoldr (B.readInt . B.dropWhile (== ' ')) <$> B.getLine

solve :: Int -> [Int] -> [Int]
solve _ as = map (\a -> s - xs ! a + 1) as
  where xs = M.fromListWith (+) [(a, 1) | a <- as]
        s = M.foldr' (\x y -> x * (x - 1) `div` 2 + y) 0 xs


Measured memory_bytes: 49500
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a==b)
	printf("Draw");
	else if((a==1)||(a>b&&b!=1&&b!=1))
	printf("Alice");
	else 
	printf("Bob");

}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

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

    int a[n];
    int i;
    map<int, int> num;
    for(i=0; i<n; i++) {
        cin >> a[i];
        num[a[i]] += 1;
    }

    int b[n];
    int count=0;
    for(auto itr=num.begin(); itr!=num.end(); itr++) {
        b[count] = itr->second;
        count++;
    }

    sort(b, b+count);

    int ans=0;
    for(i=0; i<(count-k); i++) {
        ans += b[i];
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 11136
N,T = list(map(int,input().split()))
CT   = [tuple(map(int,input().split())) for i in range(N)]
MIN = 9999999
for i in CT:
    if MIN > i[0]:
        if T >= i[1]:
            MIN = i[0]
print(MIN if not MIN == 9999999 else "TLE")


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

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

  vector<int> num = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  for(int i=0; i<32; i++){
  	cin >> num.at(i);
  }

  cout << num.at(K-1) << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A1;
  int A2;
  int A3;
  cin >> A1 >> A2 >> A3;
 
  if ( A1 + A2 + A3 >= 22 ) {
    cout << "bust" << endl;
  } 
  else{ 
    cout << "win" << endl;
  }
}

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

using namespace std;

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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    
    if(n % 2 != 0){
        cout << "No";
        return 0;
    }
    string sub_1 = s.substr(0, n/2);
    string sub_2 = s.substr(n/2);
    if(sub_1 == sub_2) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;
int main(){
    int n,b,c,q,a;
    int A[100005]={};
    ll ans=0;
    cin>>n;
    REP(i,n){
        cin>>a;
        A[a]++;
        ans+=a;
    }
    cin>>q;
    REP(i,q){
        cin>>b>>c;
        ans+=(c-b)*(A[b]);
        A[c]+=A[b];
        A[b]=0;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3892
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String s = sc.next();
		String split[] = s.split("");
		int i;
        int count = 0,ans = 0;
        
      	for(i = 0;i < s.length();i++){
          if(split[i].equals("A") || split[i].equals("C") || split[i].equals("G") || split[i].equals("T") ){
            count += 1;  
          }else{
            if(ans < count){
              ans = count;
            }
            count = 0;
          }
        }
        if(ans < count){
              ans = count;
        }
        System.out.println(ans);   
    }
}

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

int main() {
  vector<vector<int>> c(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> c.at(i).at(j);
    }
  }
  vector<int> a(3),b(3);
  b.at(0) = c.at(0).at(0);
  for(int i=1;i<3;i++){
    a.at(i) = c.at(i).at(0) - b.at(0);
    b.at(i) = c.at(0).at(i);
  }
  int ans = 0;
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      if(a.at(i) + b.at(j) == c.at(i).at(j)){
        ans++;
      }
      else {
        ans = -1;
        break;
      }
    }
    if(ans == -1){
      break;
    }
  }
  if(ans == -1){
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
       
  return 0;
}

Measured memory_bytes: 256
import collections
import sys

N = int(input())
A = list(map(int, input().split()))
c = collections.Counter(A)
two = [k for k, v in c.items() if v > 1]
four = [k for k, v in c.items() if v > 3]
if len(two) < 2 and not four:
    print(0)
    sys.exit(0)

St = 0
Sf = 0
if two:
    two.sort(reverse=True)
    St = 1
    for i in range(2):
        St *= two[i]
if four:
    Sf = max(four) ** 2
print(St if St > Sf else Sf)


Measured memory_bytes: 18600
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

namespace FastFourierTransform
{
	using C = complex< double >;

	void DiscreteFourierTransform(vector< C > &F, bool rev)
	{
		const int N = (int)F.size();
		const double PI = (rev ? -1 : 1) * acos(-1);
		for (int i = 0, j = 1; j + 1 < N; j++) {
			int k=N>>1;
			for (; k > (i ^= k); k >>= 1);
			if (i > j) {
				swap(F[i], F[j]);
			}
		}
		C w, s, t;
		for (int i = 1; i < N; i <<= 1) {
			for (int k = 0; k < i; k++) {
				w = polar(1.0, PI / i * k);
				for (int j = 0; j < N; j += i * 2) {
					s = F[j + k];
					t = C(F[j + k + i].real() * w.real() - F[j + k + i].imag() * w.imag(),
						F[j + k + i].real() * w.imag() + F[j + k + i].imag() * w.real());
					F[j + k] = s + t, F[j + k + i] = s - t;
				}
			}
		}
		if (rev) for (int i = 0; i < N; i++) F[i] /= N;
	}

	vector< long long > Multiply(const vector<long long int > &A, const vector<long long int > &B)
	{
		int sz = 1;
		while (sz <= A.size() + B.size()) sz <<= 1;
		vector< C > F(sz), G(sz);
		for (int i = 0; i < A.size(); i++) F[i] = A[i];
		for (int i = 0; i < B.size(); i++) G[i] = B[i];
		DiscreteFourierTransform(F, false);
		DiscreteFourierTransform(G, false);
		for (int i = 0; i < sz; i++) F[i] *= G[i];
		DiscreteFourierTransform(F, true);
		vector< long long > X(A.size() + B.size() - 1);
		for (int i = 0; i < A.size() + B.size() - 1; i++) X[i] = F[i].real() + 0.5;
		return (X);
	}
};

long long int comb(long long int a, long long int k) {
	if(k==0)return 1;
	if(k==a)return 1;
	return comb(a-1,k-1)+comb(a-1,k);
}

long long int solve(int k,const vector<int>&v,vector< int>nums, const int now) {
	if (now == 10) {
		long long int ans=1;
		int sum=accumulate(nums.begin(),nums.end(),0);
		int rest=sum;
		for (int i = 0; i < 10; ++i) {
			if (nums[i]) {
				ans*=comb(rest,nums[i]);
				rest-=nums[i];
			}
		}
		if (nums[0]) {
			long long int nans=1;
			int rest=sum-1;
			for (int i = 0; i < 10; ++i) {
				if (nums[i]) {
					if(i==0)nans*=comb(rest,nums[i]-1);
					else nans*=comb(rest,nums[i]);

					if(i==0)rest-=nums[i]-1;
					else rest-=nums[i];
				}
			}
			ans-=nans;
		}
		return ans;
	}
	else {
		if (v[now]) {
			long long int ans=0;

			for (int x = 1; x <= v[now];++x) {
				nums[now]=x;
				ans += solve(k, v, nums, now + 1);
			}
			return ans;
		}
		else {
			nums[now]=0;
			return solve(k,v,nums,now+1);
		}
	}
}

int main()
{
	while (true) {
		int T,D,L;cin>>T>>D>>L;
		if(!T)break;
		int ans=0;
		int k=0;
		for (int i = 0; i < T; ++i) {
			int a;cin>>a;
			if(i==T-1)break;
			if (a >= L) {
				k=D;
			}
			if (k > 0) {
				ans++;
				k--;
			}

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



Measured memory_bytes: 3084
// Written by Cesur
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define all(var) var.begin(),var.end()
#define f(i,l,n) for(int i=l;i<n;i++)
#define revloop(var,l,n) for(int var=l;var>=n;var--)
#define scan(var) scanf("%d",&var)
#define scan2(var,var2) scanf("%d %d",&var,&var2)
#define scanvector(var,n) f(i,0,n)scanf("%d",&var[i])
#define printvector(var,n) f(i,0,n)printf("%d ",var[i])
#define scanvectorlong(var,n) f(i,0,n)scanf("%lld",&var[i])
#define printvectorlong(var,n) f(i,0,n)printf("%lld ",var[i])
#define print(var) printf("%d\n",var)
#define print2(var,var2) printf("%d %d\n",var,var2)
#define mp(var,var2) make_pair(var,var2)
#define ll long long 
#define pairint pair<int,int>
#define pairlong pair<long long,long long>
#define debug(zz) cout<<#zz<<" == "<<zz<<endl;
#define M 1000000007

void printer(vector<int>&v,int n)
{
	for(int i=0;i<n-1;i++)
	{
	    printf("%d ",v[i]);
	    
	}
	cout<<v[n-1]<<endl;
}

void insertionSort(vector<int>&v,int n)
{
	printer(v,n);

	for(int i=1;i<n;i++)
	{
		int curr=v[i];
		int j=i;
		while(j && v[j-1]>curr)
		{
			v[j]=v[j-1];
			j--;
		}
		v[j]=curr;
		printer(v,n);
	}

}

int main()
{
	int n;
	scan(n);
	vector<int>v(n);
	scanvector(v,n);
	insertionSort(v,n);

}


Measured memory_bytes: 3208
#include <stdio.h>

int main(void)
{
        int n,m,i = 0,j = 0,k = 0,a,ans = 0;
        scanf("%d %d",&n,&m);
        int M[m];

        for(i = 0;i < m;i++) {
                M[i] = 0;
        }

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

                for(j = 0;j < k;j++) {
                        scanf("%d",&a);
                        M[a - 1]++;
                }

        }

        i = 0;
        for(i = 0;i < m;i++) {

                if(M[i] == n) ans++;

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


Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int count = 0;
		int twoCount = 0;
		for (int i = 0; i < N; i++) {
			int val = sc.nextInt();
			if (val % 4 == 0) {
				count++;
			} else if (val % 2 == 0) {
				twoCount++;
			}
		}
		
		String ans = N / 2 <= count + (twoCount / 2) ? "Yes" : "No"; 
		System.out.println(ans);
	}
}

Measured memory_bytes: 49068
n = int(input())
p = int("".join(input().split()))
q = int("".join(input().split()))

from itertools import permutations
per = permutations(list(map(str, range(1,n+1))), n)
per = [int("".join(list(pi))) for pi in per]

a, b = 0, 0
for i in range(len(per)):
  if per[i] == p:
    a = i
    
  if per[i] == q:
    b = i
print(abs(a - b))

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

int n,flag=1;
int a[100005];

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++)  cin>>a[i];
	for (int i=1;i<=n;i++)
	{
		if (a[i]%2==1)  continue;
		else
		{
			if (a[i]%3!=0&&a[i]%5!=0)
			{
				flag=0;
				break;
			}
		}
	}
	if (flag==1)  cout<<"APPROVED"<<endl;
	else cout<<"DENIED"<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			if(n==0){
				break;
			}
			int[][] map=new int[n+1][n+1];
			for(int i=0;i<n;i++){
				int sum=0;
				for(int j=0;j<n;j++){
					map[i][j]=sc.nextInt();
					sum+=map[i][j];
				}
				map[i][n]=sum;
			}
			for(int i=0;i<n+1;i++){
				int sum=0;
				for(int j=0;j<n;j++){
					sum+=map[j][i];
				}
				map[n][i]=sum;
			}
			for(int i=0;i<n+1;i++){
				for(int j=0;j<n+1;j++){
					System.out.printf("%5d",map[i][j]);
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 22168
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;

void main() {
    string s = readln.chomp;
    int w = readln.chomp.to!(int);

    string ans = "";
    for (int i = 0; i < s.length; i += w) {
        ans ~= s[i];
    }

    writeln(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    
using namespace std;
    
#define endl "\n"
#define ll unsigned long long
#define int long long int
#define vi vector <int >
#define vii vector < pii >
#define vll vector <ll >
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
//#define double long double
#define a first
#define b second

double dp[3005][3005];
double arr[3005];
int n;

double f(int pos, int h){
    if(pos == n){
        return double(h > n/2);
    }
    if(dp[pos][h] != -1) return dp[pos][h];

    return dp[pos][h] = arr[pos]*f(pos + 1, h + 1) + (double(1 - arr[pos])*f(pos + 1, h));
}



int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);	
    
    cin >> n;
    for(int i = 0; i <= n + 2; i++) 
        for(int j = 0; j <= n +2; j++)
            dp[i][j] = -1;
    
    for(int i = 0; i < n; i++){
        cin >> arr[i];
    }
        
    cout << setprecision(10) << f(0, 0) << endl;
    
    return 0;
}

Measured memory_bytes: 70912
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ppp pair<ll,pp >
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define sz(v) (ll)(v.size())
#define hell (ll)998244353
#define slld(x) scanf("%lld",&x)
ll t=1, tt;
const ll N=1000005, inf=1e18;
void solve(){
	ll n, m, x, y;
	set<ll> seta;
	cin>>n>>m;
	rep(i,0,m){
		cin>>x;
		rep(j,0,x){
			cin>>y;
			seta.insert(y);
		}
	}
	cout<<n-sz(seta);
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   	//cin>>t;
   	tt=t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


Measured memory_bytes: 3664
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<iterator>
//#include<bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 5;
#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
#define endl '\n'
//int a[maxn];
//int b[maxn][maxn];
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T, a,b,c;
	cin >> a >> b >> c;
	if (b * c >= a)puts("Yes");
	else puts("No");

}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

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

  int n; cin >> n;
  cout << n * (n+1) / 2 << endl;

}


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

int main(){
  int n,d;
  cin >> n >> d;
  vector<vector<int>> x(n,vector<int>(d));
  for(int i = 0;i<n;i++){
    for(int j = 0;j<d;j++){
      cin >> x.at(i).at(j);
    }
  }
  vector<int> sqdis(n*(n-1)/2);
  int c = 0;
  int count = 0;
  for(int i = 0;i<n-1;i++){
    for(int j = 1+i;j<n;j++){
      for(int k = 0;k<d;k++){
        sqdis.at(c) += (x.at(i).at(k)-x.at(j).at(k))
                      *(x.at(i).at(k)-x.at(j).at(k));
        
      }
      c++;
    }
  }

  for(int i = 0;i<n*(n-1)/2;i++){
    for(int j = 0;j<20000;j++){
      if(sqdis.at(i) == j*j) count++;     
    }
  }
  cout << count << endl;
}


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

#define ll long long
#define ld long double
using namespace std;

int  main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,k;
    cin >> a >> b>> k;
    for (ll i = 0; i <= a; i++){
        for (ll j = 0; j <= b; j++){
            ll s = i*j + (a-i)*(b-j);
            if (s == k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
//    if ((k % a == 0 && k >= a) || (k % b == 0 && k >= b) || k == 0){
//        cout << "Yes" << endl;
//    } else {
        cout << "No" << endl;
//    }
	return 0;
}

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

using namespace std;

void check(string str, int w) 
{
  bool isCloud = false;
  int count = -1;

  for(int i = 0; i < w; i += 1) {
    if(str[i] == 'c') {
      count = 0;
      isCloud = true;
    } else if(isCloud){
      count += 1;
    }

    if(i == w-1) {
      cout << count << endl;
    } else {
      cout << count << " ";
    }
  }

  return;
}

int main()
{
  int h, w;
  string alea;

  while(cin >> h >> w) {
    for(int i = 0; i < h; i += 1) {
      cin >> alea;
      check(alea, w);
    }
  }

  return 0;
}

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

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

  bool possible = false;
  rep(i,N+1){
    rep(j,M+1){
      if (K == (N-i)*j + i*(M-j)) {
        possible = true;
        break;
      }
    }
  }
  cout << (possible? "Yes" : "No") << endl;
  return 0;
}

 

Measured memory_bytes: 256
n = int(input())
a = list(int(input()) for i in range(n))
a.sort()
b = []

if n % 2 == 0:
    for i in range(n//2):
        b.append(a[i])
        b.append(a[-(i+1)])
else:
    for i in range(n//2):
        b.append(a[i])
        b.append(a[-(i+1)])
    b.append(a[n//2])

ans = 0
for i in range(n-1):
    ans += abs(b[i] - b[i+1])
ans += abs(b[0] - b[n-1])
b.sort()
if n % 2 == 0:
    ans -= abs(b[n // 2] - b[n // 2 - 1])
else:
    ans -= min(abs(b[n//2] - b[n//2-1]), abs(b[n//2] - b[n//2+1]))

print(ans)

Measured memory_bytes: 8144
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<queue>
#define PI 3.141592653589793238
#define ll long long
using namespace std;

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

int main()
{
	int x, y;
	ll int ans;
	

	cin >> x >> y;

	ans = (ll int)x * (ll int)y / (ll int)gcd(x, y);

	printf("%lld", ans);

	return 0;
}

Measured memory_bytes: 256
# Product
# シカのAtCoDeerくんは二つの正整数a,bを見つけました。aとbの席が偶数か奇数か判定してください。
# 1<a,b<10000
# a.bは整数

a,b = map(int, input().split())
x = int(a * b)
# print(a,b,x)

# 積が奇数なら"Odd"、偶数なら"Even"と表示
if x % 2 == 0:
    print("Even")
else:
    print("Odd")


Measured memory_bytes: 9068
n, x, y = map(int,input().split())
x -= 1
y -= 1
ans = [0] * (n-1)
for i in range(n-1):
    for j in range(i+1,n):
        ans[min(j-i,abs(x-i)+abs(j-y)+1)-1] += 1
print(*ans,sep="\n")

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

typedef long long ll;

int main() { 
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
	}
	int cnt = 0;
	while (1) {
		bool d = 1;
		for (int i = 0; i < n; ++i) {
			if (v[i] % 2 == 1) {
				d = 0;
				break;
			}
		}
		//cout << d << endl;
		if (!d) {
			cout << cnt;
			return 0;
		}
		for (int i = 0; i < n; ++i) {
			v[i] = v[i] / 2;
		}
		cnt++;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rng(a) a.begin(),a.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll M = 998244353;


int main() {
  int n;
  cin >> n;
  vector<int> dis(n);
  rep(i,n) {
    int x;  cin >> x;
    if(i==0&&x!=0) {
      cout << 0 << endl;
      return 0;
    } 
    dis[x]++;
  }
  if(dis[0]!=1) {
    cout << 0 << endl;
    return 0;
  }
  ll ans = 1;
  bool zero=false;
  for(int i=1; i<n; i++) {
    if(zero&&dis[i]==0) continue; 
    if(dis[i]==0) {
      zero=true;
      continue;
    }
    rep(j,dis[i]) {
      ans*=dis[i-1];
      ans%=M;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3736
#!/usr/bin/env python2

import sys

input = iter(sys.stdin.readlines()).next

def main():
   A, B, C, K = map(int, input().split())
   res = 0
   if A >= K:
      res = 1*K
   else:
      res += A
      K -= A
      if B >= K:
         res += 0*K
      else:
         res += 0*B
         K -= B
         res += -1*K

   print(res)

   return 0

if __name__ == '__main__':
   sys.setrecursionlimit(10000)
   main()


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

int main(){
 bool flag = true;
char prev,curr;
  scanf("%c",&prev);
  for(int i = 0 ; i < 3 ; i++){
   scanf("%c",&curr);
    if(curr==prev)
      	flag = false;
    prev = curr;
    
  }
 cout << (flag?"Good":"Bad") << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int main(){
	int g[13] = {0, 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0};
	int x, y; scanf("%d %d", &x, &y);
	puts(g[x] == g[y] ? "Yes" : "No");
	return 0;
}

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

int main() {
  int n, r;

  cin >> n >> r;
  if (n >= 10){
    cout << r << endl;
  } else {
    cout << r+100*(10-n) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// base: https://atcoder.jp/contests/agc036/submissions/7937408
// hint: https://www.youtube.com/watch?v=eFQGwwdAVWg

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 998244353;

ll powmod(ll x, ll n) { // like pow(x, n)
  ll r = 1;
  while (n) {
    if (n & 1) {
      r = r * x % MOD;
    }
    x = x * x % MOD;
    n >>= 1;
  }
  return r;
}

// Mod int
// cf. https://www.youtube.com/watch?v=1Z6ofKN03_Y
struct mint {
  ll x;
  mint(ll x = 0) : x((x + MOD) % MOD) {}
  mint& operator+= (const mint a) {
    if ((x += a.x) >= MOD) x %= MOD;
    return *this;
  }
  mint operator+ (const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint& operator-= (const mint a) {
    if ((x += MOD - a.x) >= MOD) x %= MOD;
    return *this;
  }
  mint operator- (const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint& operator*= (const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator* (const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) { return 1; }
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(MOD-2);
  }
  mint& operator/= (const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/ (const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

// Combination mod prime.
// cf. https://www.youtube.com/watch?v=1Z6ofKN03_Y
struct Combination {
  vector<mint> fact, ifact;
  Combination(int n) { init(n); }
  void init(int n) {
    assert(n < MOD); // n must be lower than MOD.

    fact.resize(n + 1);
    ifact.resize(n + 1);

    fact[0] = 1;
    for (int i = 1; i <= n; ++i) { fact[i] = fact[i-1] * i; }
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) { ifact[i-1] = ifact[i] * i; }
  }
  mint operator() (int n, int k) const {
    if (k < 0 || k > n) { return 0; }
    return fact[n] * ifact[k] * ifact[n-k];
  }
  mint perm(int n, int k) const {
    if (k < 0 || k > n) { return 0; }
    return fact[n] * ifact[n-k];
  }
};

Combination c(0);

// The number of even is n, the sum is m, the variaety of the number of odd is 0..k.
mint f(ll n, ll m, ll k) {
  mint res = 0;
  for (int a = m % 2; a <= k; a += 2) {
    res += c(n, a) * c((m-a)/2+n-1, n-1);
  }
  return res;
}

int main(int argc, char** argv) {
  int N, M;
  cin >> N >> M;

  c.init(3 * M + N);

  mint ans = f(N, 3 * M, M) - (f(N, M, M) - f(N-1, M, M)) * N;
  cout << ans.x << endl;
}


Measured memory_bytes: 39296
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

int main()
{
    string W, str;
    cin >> W;

    int counter = 0;

    while(1)
    {
        cin >> str;
        if(str == "END_OF_TEXT") break;
        for(int i=0; i<str.length(); i++)
        {
        if('A' <= str[i] && str[i] <= 'Z') str[i]+='a'-'A';
        }
        if (W == str) counter++;
    }

    cout << counter << endl;

    return 0;
}


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

using ll = long long;

constexpr int mod = 1000003;

ll inv(ll n) {
    ll a = n, b = mod, u = 1, v = 0;
    while(b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if(u < 0) u += mod;
    return u;
}

int main() {
    int n, k;
    while(cin >> n >> k, n) {
        if(n == 1) {
            cout << 2 << endl;
            continue;
        }
        ll ans = 0;
        if(k >= n) {
            ans += 2;
            k = n - 1;
        }

        vector<vector<vector<int>>> dp1(n + 1, vector<vector<int>>(k + 1, vector<int>(2)));
        dp1[1][1][0] = 1; // start with A
        for(int i = 1; i < n; ++i) {
            for(int j = 1; j <= k; ++j) {
                for(int pre = 0; pre < 2; ++pre) {
                    if(j + 1 <= k) {
                        (dp1[i + 1][j + 1][pre] += dp1[i][j][pre]) %= mod;
                    }
                    (dp1[i + 1][1][!pre] += dp1[i][j][pre]) %= mod;
                }
            }
        }

        vector<ll> dp2(n + 1), sum(n + 1);
        for(int i = 1; i <= n; ++i) {
            for(int j = 0; j <= k; ++j) {
                (dp2[i] += dp1[i][j][1]) %= mod; // ends with B
                (sum[i] += dp1[i][j][0]) %= mod;
            }
            for(int loop = 2; loop <= min(k, i); ++loop) {
                (dp2[i] += 1LL * sum[i - loop] * (loop - 1)) %= mod;
            }
            (dp2[i] += dp2[i]) %= mod; // consider starting with B
        }

        vector<int> dp3(n + 1);
        for(int i = 1; i <= n; ++i) {
            dp3[i] = dp2[i];
            for(int j = 1; j < i; ++j) {
                if(i % j == 0) {
                    (dp3[i] += mod - dp3[j]) %= mod;
                }
            }
        }
        for(int i = 1; i <= n; ++i) {
            if(n % i != 0) continue;
            (ans += dp3[i] * inv(i)) %= mod;
        }

        cout << ans << endl;
    }
}



Measured memory_bytes: 57700
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"sort"
	"strconv"
)

func main() {
	sc = initScanner(os.Stdin)
	A, B, M := scanInt(sc), scanInt(sc), scanInt(sc)

	a := scanIntSlice(sc, A)
	b := scanIntSlice(sc, B)

	min := math.MaxInt64
	for i := 0; i < M; i++ {
		tmp := a[scanInt(sc)-1] + b[scanInt(sc)-1] - scanInt(sc)

		if min > tmp {
			min = tmp
		}

	}

	sort.Ints(a)
	sort.Ints(b)
	tmp := a[0] + b[0]
	if min > tmp {
		min = tmp
	}

	fmt.Println(min)
}

// --------------- BASE DEFINITIONS ---------------

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}

func scanIntSlice(sc *bufio.Scanner, n int) []int {
	is := make([]int, n)
	for i:=0; i<n; i++ {
		is[i] = scanInt(sc)
	}

	return is
}


Measured memory_bytes: 5932
#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eps 1e-12
#define int long long
const int mod = 1e9 + 7;
inline int ksm(int a, int b)
{
    int ans = 1;
    for (; b; b >>= 1, a = a * a % mod)
        if (b & 1)
            ans = ans * a % mod;
    return ans;
}

signed main()
{
    io;
    string s;cin>>s;
    int c1=0,c2=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A')c1++;
        else c2++;
    }
    if(c1 && c2)cout<<"Yes";
    else cout<<"No";
    getchar(); //
    getchar();
}


Measured memory_bytes: 256
//NAME-DEEPESH BHATT
//Institute-IIT Dhanbad
//MOTTO-THINK FIRST,CODE LATER

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007  ;
#define pb push_back
#define mp make_pair

//Check for signed int overflow

ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a ,ll b)
{
    return a/gcd(a,b)*b;
}
ll power(ll a,ll n)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p);
    if (n % 2)
        return (p * a);
    else
        return p;
}
/*vector<bool>is_prime(1000001,true);
void sieve(){
    is_prime[0]=is_prime[1]=false;
    is_prime[2]=true;
    for(int i=2;i*i<=1000000;i++){
        if(is_prime[i]){
            for(int j=i*i;j<=1000000;j+=i){
                is_prime[j]=false;
            }
        }
    }
}*/

/*bool is_sorted(int *arr,int n){
    for(int i=0;i<n-1;i++){
        if(arr[i+1]<arr[i]){
            return false;
        }
    }
    return true;
}*/

void solve(){
    int x,n;
    cin>>x>>n;
    map<int,int>mp;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        mp[x]++;
    }
    int diff=INFINITY;
    int ans=0;
    for(int i=0;i<=101;i++){
        if(mp[i]==0){
            if(diff>abs(x-i)){
                diff=(x-i);
                ans=i;
            }
        }
    }
    cout<<ans;
}

int32_t main()
{
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(NULL);
    ll test=1;
    /*cin>>test;*/
    while(test--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3624
/*
 * ABC96B.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<cstdio>
#include<algorithm>

using namespace std;

int a, b, c, k;

int main() {
	scanf("%d%d%d", &a, &b, &c);
	scanf("%d", &k);
	int max3 = max(a,b);
	max3 = max(c, max3);
	int max2 = max3;
	while(k--) {
		max3 *= 2;
	}
	printf("%d", a+b+c + max3 - max2);

}




Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define PRINTD(n) printf("%d\n",n)
#define DEBUG printf("%s\n","debug")
using namespace std;
//////////////////////////////////////////////////////
int main(){
	int Q,H,S,D;
	long long N;
	SCD(Q);SCD(H);SCD(S);SCD(D);
	scanf("%lld",&N);
	
	int cpQ,cpH,cpS,cpD;
	long long ans = 0;
	cpD = D;
	cpS = 2 * S;
	cpH = 4 * H;
	cpQ = 8 * Q;
	
	int cp = min({cpQ,cpH,cpS,cpD});
	if (cp == cpQ){
		ans = 4*Q*N;
	}else if(cp == cpH){
		ans = 2*H*N;
	}else if(cp == cpS){
		ans = S*N;
	}else{
		int cpp = min({cpQ,cpH,cpS});
		ans = ans + (N/2)*D;
		N = N%2;
		if (cpp == cpQ){
			ans += 4*Q*N;
		}else if(cpp == cpH){
			ans += 2*H*N;
		}else if(cpp == cpS){
			ans += S*N;
		}
	}
	printf("%lld\n",ans);
	return 0;
}








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

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}


map<pair<string, string>, ll> s1l, s2l;



int main() {
	
	ll N, L;

	cin >> N >> L;

	ll ans = inf, sum = 0, ans2 = 0;
	rep(i, N) {
		sum += L + i;
		if (ans > min(ans, abs(L + i))) {
			ans = min(ans, abs(L+i));
			ans2 = L + i;
		}
	}

	
	cout << sum -  ans2 << endl;

	return 0;
}

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

int main(){
	// sengen
	long long n,k;
	// nyuryoku
	cin >> n >> k;
	long long a[n];
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	// keisan
	int comec[n] = {};
	int sain = 1;
	int kiseki[n] = {};
	int rep = 0;
	int first = 0;
	vector<vector<int>> come;
	come.assign(n,vector<int>());
	if(k>n){
		for(int i=0;i<n;i++){
			kiseki[i] = sain;
			comec[sain-1]++;
			come[sain-1].push_back(i+1);
			if(comec[sain-1] == 2){
				rep = come[sain-1][1] - come[sain-1][0];
				first = come[sain-1][0];
				break;
			}
			sain = a[sain -1];
		}
		long long amari = (k - first)%rep;
		cout << kiseki[first+amari];
	}else{
		for(int i = 0;i<k;i++){
			sain = a[sain -1];
			if(i == k-1){
				cout << sain;
			}
		}
	}
	// syutsuryoku
}

Measured memory_bytes: 16028
/*
AuThOr GaRyMr
技巧:
1.区别对待大数据&小数据！
2.Dp难推时算贡献！
3.long long (尤其乘法)！
4.long long INF 要大
5.Dp on trees: 换根法，每次清空当前的节点和换到的子节点
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n,m,l;LL dis[305][305],dp[305][305];
void flyd(){
	for (int k = 1; k <=n; k++)
		for (int i = 1; i <=n; i++)
			for (int j = 1; j <=n; j++)
			{
				if (dis[i][j] > dis[i][k] + dis[k][j])
				{
					dis[i][j] = dis[i][k] + dis[k][j];
				}
			}
}
int used[305][305]={0};
int main(){
	cin>>n>>m>>l;
	rb(i,1,304)
		rb(j,1,304) dp[i][j]=dis[i][j]=(LL)(1000000000)*(300)*(300+100);
	rb(i,1,m){
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);
		dis[a][b]=dis[b][a]=min((LL)dis[a][b],(LL)c);
	}
	flyd();
//	cout<<dis[1][2]<<endl;
	priority_queue<pair<int,mp> > q;
	rb(i,1,n) dp[i][i]=-1,q.push(II(1,II(i,i)));
	while(!q.empty()){
		while(used[q.top().SEC.FIR][q.top().SEC.SEC]) q.pop();
		int now1=q.top().SEC.FIR,now2=q.top().SEC.SEC;
		q.pop();
		used[now1][now2]=1;
//		cout<<now1<<" "<<now2<<endl;
		rb(i,1,n){
			if(dis[i][now1]<=l){
				if(dp[i][now2]>dp[now1][now2]+1){
					dp[i][now2]=dp[now1][now2]+1;
					q.push(II(-dp[i][now2],II(i,now2)));
				}
			}
		}
	}
//	cout<<dp[2][3]<<endl;
	int q_;
	cin>>q_;
	while(q_--){
		int a,b;
		scanf("%d %d",&a,&b);
		printf("%lld\n",(dp[a][b]>n? -1:max((LL)0,dp[a][b])));
	}
	return 0;
}


Measured memory_bytes: 3704
#include<iostream>
using namespace std;
void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}
int main(){
    int a;
    cin>>a;
    call(a);
}


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

typedef long long LL;

int main(void){
    int n, x, y;
    cin >> n >> x >> y;
    int dis1, dis2;
    int ans[2005] = {};
    for(int i = 1;i <= n;i++){
        for(int j = i + 1;j <= n;j++){
            if(i <= x && y <= j){
                dis1 = j - y + x - i + 1;
                ans[dis1]++;
            }else if (i <= x && j < y){
                dis1 = j - i;
                dis2 = y - j + x - i + 1;
                ans[min(dis1, dis2)]++;
            }else if(x < i && j >= y){
                dis1 = j - i;
                dis2 = i - x + j - y + 1;
                ans[min(dis1, dis2)]++;
            }else{
                dis1 = j - i;
                dis2 = i - x + y - j + 1;
                ans[min(dis1, dis2)]++;
            }
        }
    }
    for(int i = 1;i <= n - 1;i++){
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 256