akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

struct UnionFind {
	vector<int> v;
	UnionFind(int n) : v(n)  { for (int i = 0; i < n; i++) v[i] = i; }
	int  find(int x)         { return v[x] == x ? x : v[x] = find(v[x]); }
	void unite(int x, int y) { v[find(x)] = find(y); }
};

int main() {
	int n;while (cin >> n, n) { vector<int> v(n);REP(i, n) cin >> v[i];SORT(v);int ans = 1e9;REP(i, n - 1)ans = min(ans, v[i + 1] - v[i]);cout << ans << endl; }
}

Measured memory_bytes: 3088
n,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
cnt = [0] * n
a.each do |aa|
  cnt[aa-1] += 1
end

rm = cnt.count{|v| v > 0}
ans = 0

rm = [0, rm-k].max
cnt.sort.each do |c|
  break if rm < 1
  next if c == 0
  ans += c
  rm -= 1
end

puts ans

Measured memory_bytes: 19968
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
		sc.close();
		System.out.println((a<=b+c)?(b+c-a):0);
	}

}


Measured memory_bytes: 23252
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
d = {}
for i in s:
    if i not in d:
        d[i] = 1
    else:
        d[i] += 1
for j in t:
    if j not in d:
        d[j] = -1
    else:
        d[j] -= 1

d = sorted(d.items(), key=lambda x:x[1], reverse=True)
ans = d[0][1]
print(ans if ans > 0 else 0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<60;
const ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int a=1;
  for(int i=1;i<n;i++){
      if(s[i-1]!=s[i]) a++;
  }
  cout<<a<<endl;
}


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

int main()
{
    int a,b,e;
    while(~scanf("%d%d",&a,&b))
    {
        if(a>=2&&a<=100&&b>=2&&b<=100)
        {
            e=0;
            e=a*b-((1*a)+(1*b)-1);
                printf("%d\n",e);
        }
    }
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  string s;
  cin >> s;
  int a;
  cin >> a;
  rep(i, 0, s.length()) {
    if(i % a == 0) cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 256
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


if __name__ == '__main__':
    H, W, K = map(int, input().split())
    S = [[s for s in input()] for _ in range(H)]

    ans = [[0 for _ in range(W)] for _ in range(H)]
    cnt = 1
    for i in range(H):
        for j in range(W):
            if S[i][j] == '#':
                ans[i][j] = cnt
                cnt += 1

    for i in range(H):
        res = 0
        for j in range(W):
            if ans[i][j] == 0:
                ans[i][j] = res
            else:
                res = ans[i][j]
        res = 0
        for j in range(W - 1, -1, -1):
            if ans[i][j] == 0:
                ans[i][j] = res
            else:
                res = ans[i][j]

    for i in range(W):
        res = 0
        for j in range(H):
            if ans[j][i] == 0:
                ans[j][i] = res
            else:
                res = ans[j][i]
        res = 0
        for j in range(H - 1, -1, -1):
            if ans[j][i] == 0:
                ans[j][i] = res
            else:
                res = ans[j][i]

    for a in ans:
        print(*a)


Measured memory_bytes: 52568
Q = input()
for i in range(Q):
    #num of c, a, n
    num = map(int, raw_input().split())
    team = 0
    #c a n
    while True:
        if 0 in num:
            break
        else:
            num = map(lambda x: x - 1, num)
            team += 1
    #c c a
    while True:
        if 0 in num[0:2] or num[0] == 1:
            break
        else:
            num[0] -= 2
            num[1] -= 1
            team += 1
    #c c c
    while True:
        if 0 <= num[0] <= 2:
            break
        else:
            num[0] -= 3
            team += 1

    print "%d" % team

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

int main() {
    string s;
    int n, k;
    cin >> n >> k >> s;
    if (s.at(k - 1) == 'A') s.at(k - 1) = 'a';
    else if (s.at(k - 1) == 'B') s.at(k - 1) = 'b';
    else s.at(k - 1) = 'c';
    cout << s << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int i, j, d[50], N;
  int total;
  
  scanf("%d", &N);
  for ( i=0;i<N;i++ )
    scanf("%d", &(d[i]));
  total = 0;
  for ( i=0; i<N-1; i++ ) {
    for ( j=i+1; j<N; j++ )
      total += d[i]*d[j];
  }
  printf("%d\n", total);
}


Measured memory_bytes: 128
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import qualified Data.Set  as S
import qualified Data.IntMap.Strict as IM
import Data.Char


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> [(Int, Int)] -> String
solve n m = 
    let
        nums = if n == 1 then show <$> [0..9] else show <$> [10 ^ (n - 1)..(10 ^ n - 1)]
        takeKeta keta num 
            | keta > n = Nothing
            | otherwise =  Just $ digitToInt $ num !! (keta - 1)
        satisfy number = all (\(keta, num) -> takeKeta keta number == Just num) m
        ans = filter satisfy nums
    in
    case ans of
        [] -> "-1"
        (x:xs) -> x



main = do
    hi <- getLine
    putStrLn $  case hi of
        "hi" -> "Yes"
        "hihi" -> "Yes"
        "hihihi" -> "Yes"
        "hihihihi" -> "Yes"
        "hihihihihi" -> "Yes"
        _ -> "No"




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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    vector<int> cnt(62, 0);
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    for (auto x : a) {
        for (int i = 0;i < 62;i++) {
            int q = 1ll << i;
            if (x&q) {
                cnt[i]++;
            }
        }
    }

    int ans = 0;

    int cntt = n - 1;

    for (auto x : a) {
        for (int i = 0;i < 62;i++) {
            if (x&(1ll << i)) {
                cnt[i]--;
            }
        }
        for (int i = 0;i < 62;i++) {
            int q = 1ll << i;
            if (x&q) {
                q %= mod;
                (ans += (cntt - cnt[i])*q) %= mod;
            }else {
                q %= mod;
                (ans += cnt[i]*q) %= mod;
            }
        }
        cntt--;
    }

    cout << ans;


    return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

int x, a, b;
int main()
{
    cin >> x >> a >> b;
    if (abs(x - a) < abs (x - b))
        puts("A");
    else
        puts("B");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    ll a[110];
    ll b[110];
    rep(i, N) {
        ll temp;
        cin >> temp;
        a[i] = temp;
    }
    rep(i, N) {
        ll temp;
        cin >> temp;
        b[i] = temp;
    }
    for (int i = 1; i < N;i++) {
        a[i] += a[i - 1];
        b[i] += b[i - 1];
    }
    ll ans = a[0] + b[N - 1];
    for (int i = 1; i < N; i++) {
        ans = max(ans, a[i] + (b[N - 1] - b[i - 1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int x;  cin >> x;
    int v[] = {100, 101, 102, 103, 104, 105};
    bool *dp = new bool[x+1];
    for (int i = 0; i <= x; i++)
        dp[i] = false;
    dp[0] = true;
    for (int i = 0; i < x; i++) {
        for (int j = 0; j < 6; j++) {
            if (v[j] <= i+1) {
                if (dp[i+1-v[j]] == true)
                    dp[i+1] = true;
            }
        }
    }

    if (dp[x])
        cout << 1 << endl;
    else 
        cout << 0 << endl;
    return 0;
}

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

typedef long long ll;
using namespace std;

void solve(){
    int n, m, x;
    cin >> n >> m >> x;

    vector<vector<int>> a(n, vector<int>(m));
    vector<int> val(n);
    for (int i = 0; i < n; i++) {
        cin >> val[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    int it = 0;
    int ans = (int)1e9;
    while (it < (1 << n)) {

        //cout << it << endl;

        int i = 0;
        vector<int> b(m);
        int mask = it;
        int inn = 0;
        while (mask) {
            if (mask & 1) {
                for (int j = 0; j < m; j++) {
                    b[j] += a[i][j];
                }
                inn += val[i];
            }
            mask /= 2;
            i++;
            //cout << "here" << endl;
        }

        bool fl = true;
        for (auto bb : b) {
            if (bb < x) {
                fl = false;
                break;
            }
        }
        if (fl) {
            ans = min(ans , inn);
        }
        it++;
    }
    cout << (ans == (int)1e9 ? -1 : ans) << endl;
}

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

    solve();

    return 0;
}

//3 3 10
//60 2 2 4
//70 8 7 9
//50 2 3 9

Measured memory_bytes: 3632
// AOJ Volume 5 Problem 0544 Sugoroku

#include <stdio.h>

int main(void)
{
	int n, m;
	int masu[1001];
	int i;
	int p;
	int d;
    int ans;
	
    while (1){
    	scanf("%d%d", &n, &m);
    
    	if (n == 0 && m == 0){
            break;
    	}
        
    	for (i = 1; i <= n; i++){
    		scanf("%d", &masu[i]);
    	}
    	
    	p = 1;
        ans = -1;
    	for (i = 1; i <= m; i++){
    		scanf("%d", &d);
    		
    		if (ans == -1){
                if (d != 0){
        			p = p + d + masu[p + d];
        			
        			if (p >= n){
                        ans = i;
        			}
                }
    		}
    	}
    	
        printf("%d\n", ans);
    }
    
	return (0);
}

Measured memory_bytes: 604
#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;
    cin >> a >> b;

    if (a <= 8 && b <= 8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
    return 0;
}

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

vector<int>v[200];

int main()
{
   int n; cin>>n; long long sum=0; long long  x= n-1;
   
   for( int i=1;i<n;i++)
   {
   	sum= sum +  (x/i) ;
   }
   
   cout<<sum<<endl;
   
}

Measured memory_bytes: 3636
#!/usr/bin/env python3

"""Compute the prime factorization of the given integer by trial division.

Verification: [NTL_1_A](https://example.com)
"""

import math


def factorize_trial_division(n):
    """Compute the prime factorization of the given integer `n` by trival division.

    Returns: the prime factors as a list.
    """
    factors = []
    if n < 2:
        return factors
    for p in range(2, math.ceil(math.sqrt(n)) + 1):
        if p * p > n:
            break
        while n % p == 0:
            factors.append(p)
            n //= p
    if n > 1:
        factors.append(n)
    return factors


def main():
    n = int(input())
    fs = factorize_trial_division(n)
    print("{}:".format(n), *fs)


if __name__ == '__main__':
    main()


Measured memory_bytes: 5680
/*
LANG: JAVA
TASK: 
*/

import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String[] args) throws IOException
	{
		Scanner c = new Scanner(System.in);
		int x = c.nextInt(), a = c.nextInt(), b = c.nextInt();
		System.out.println((Math.abs(x-a) < Math.abs(x-b))?"A":"B");
	}
}


Measured memory_bytes: 21204
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  ans = 0
  a = sorted(a,reverse = True)
  query = []
  flag = False
  for i in range(n-1):
    if flag:
      flag = False
      continue
      
    if a[i] == a[i+1]:
      query.append(a[i])
      flag = True

  if len(query)>=2:
    ans = query[0]*query[1]
  print(ans)
solve()

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;

#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define sz size()
#define all(A)    A.begin(), A.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define f0(i,b)   for(int i=0;i<(b);i++)
#define f1(i,b)   for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))
#define mod 1000000007

#define forr(i,n)    for(i=0; i<n; i++)
#define whilee(i,t)  while(i!=t)
#define  sl(a)  scanf("%lld",&a)
#define  pl(a)  printf("%lld",a)

//for(auto it =A.begin(); it!=A.end(); it++)
//sort(A.begin(),A.end());
//binary_search(A.begin(),A.end(),x);
//reverse(A.begin(), A.end());
//cout << *max_element(A.begin(), A.end());
//cout << *min_element(A.begin(), A.end());
//count(A.begin(), A.end(), X); //counts the occurrences of X
//distance(A.begin(),A.end());  //distance between first to last element
//accumulate(A.begin(), A.end(), 0); //add
//next_permutation(A.begin(), A.end());
//prev_permutation(A.begin(), A.end());
//swap(S[0], T[0]);
//scanf("%d",&x);
//printf("%d\n",x);

//vector <int> A;
//deque <int> A;
//queue <int> A;
//stack <int> A;
//set <int> A;
//map <int,int> A;
//pair <int,int> A ;
//vector <pair <int,int>> A ;
//char ch;
//string S, T, U;
ll factorial(ll n)
{
    if(n==1)
    {
        return 1;
    }
    else
    {
        return n*factorial(n-1);
    }
}
ll i, j, k, a, b, c, d, f, g, h, l, m, n, p, q, r, s, t, w, x, y, z, maxx=INT_MIN, minn=INT_MAX, ans=0, sum=0, cnt=0;

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

    scanf("%lld",&n);
    printf("%lld\n", factorial(n));

    return 0;
}





Measured memory_bytes: 3168
N = int(input())

AC = 0
WA = 0
TLE = 0
RE = 0

for i in range(N):
    S = input()
    if S == 'AC':
        AC+=1
    elif S == 'WA':
        WA+=1
    elif S =='TLE':
        TLE+=1
    elif S =='RE':
        RE+=1

print('AC x '+str(AC))
print('WA x '+str(WA))
print('TLE x '+str(TLE))
print('RE x '+str(RE))

Measured memory_bytes: 9216
#include <iostream>
#include <string>
int main(void){
	int K,T;
	int a[100];
	int max=0;
	std::cin>>K>>T;
	for(int i=0;i<T;i++){
		std::cin>>a[i];
		max=std::max(max,a[i]);
	}
	if(T!=1){
		if((max-1)-(K-max)>0){
			std::cout<<((max-1)-(K-max))<<std::endl;
		}else {
			std::cout<<'0'<<std::endl;
		}
		//std::cout<<(K-1-max)<<std::endl;
	}else {
		std::cout<<(K-1)<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 550
typedef long long ll; 
using namespace std;
ll n;
int h[N], htot;
inline void Insert(int p) {
  for (int i = htot; i > p; --i) swap(h[i], h[i + 1]);
  h[p + 1] = ++htot;
}
int main() {
  scanf("%lld", &n); ++n;
  int j = 0;
  while ((1ll << j) <= n) ++j;
  --j;
  for (int i = 1; i <= j; ++i) h[i] = i;
  htot = j;
  for (int i = j - 1; ~i; --i) if (n & (1ll << i)) {
    Insert(i);
  }
  printf("%d\n", htot + 100); 
  for (int i = 1; i <= htot; ++i)  printf("%d ", h[i]);
  for (int i = 1; i < 100; ++i) printf("%d ", i); 
  puts("100");
  return 0;
}


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

int main(){
  vector<string> s(3);
  cin >> s[0] >> s[1] >> s[2];
  int turn = 0;
  char tmp;
  while(true){
    tmp = s[turn][0];
    s[turn].erase(0, 1);
    switch(tmp){
      case'a':
        turn = 0;
        break;
      case'b':
        turn = 1;
        break;
      case'c':
        turn = 2;
        break;
      default:
        break;
    }
    if(s[turn].empty()){
      break;
    }
  }
  char ans[3] = {'A', 'B', 'C'};
  cout << ans[turn] << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(N: int, M: int):
    if N == M:
        yes()
    else:
        no()
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
[N,A,B]=[int(i) for i in input().split()]
x=[int(i) for i in input().split()]
a=0
for i in range(N-1):
  if (x[i+1]-x[i])*A>B:
     a+=B
  else:
     a+=(x[i+1]-x[i])*A
print(a)

Measured memory_bytes: 14252
#include<iostream>
#include<vector>

using namespace std ;

void lsb(vector<long long> *v, long long a)
{
    int i;
    
    for(i=0; i<60; i++)
    {
        if(a & 1LL<<i)
        {   
            if((*v)[i])
                a ^= (*v)[i];
            else
            {
                (*v)[i] = a;
                break;
            }
        }
    }
}

bool test(vector<long long> *v, long long a)
{
    int i;
    
    for(i=0; i<60; i++)
    {
        if(a & 1LL<<i)
        {   
            if((*v)[i])
                a ^= (*v)[i];
            else
                break;
        }
    }
    
    if(i == 60)
        return true;
    else
        return false;
}

int main(void)
{
    int i, j;
    int t, n;
    long long a[200];
    char s[201];
    vector<long long> v;
    bool ans;
    
    
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d", &n);
        for(i=0; i<n; i++)
            scanf("%lld", &a[i]);
        scanf("%s", s);
        
        v.clear();
        v.resize(60);
        ans = true;
            
        for(i=n-1; i>=0; i--)
        {
            if(s[i] == '0')
                lsb(&v, a[i]);
            else
                if(!test(&v, a[i]))
                {
                    ans = false;
                    break;
                }
        }
        
        printf("%d\n", !ans);
    }
    
    //system("pause");
    
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	static ll n;
	static ll a[100010],b[100010];
	scanf("%lld",&n);
	rep(i,n)scanf("%lld",&a[i]);
	rep(i,n)scanf("%lld",&b[i]);
	
	ll loc,p;
	priority_queue<ll,vector<ll>,greater<ll>> que;
	rep(i,100010)que.push(0);
	loc = 0; p = a[0];
	ll sum = 0;
	ll ret = 0;
	int k = 0;
	rep(i,n-1){
		sum += b[i];
		ll x = sum-p;
		que.push(x); que.push(x);
		ret += x-que.top();
		loc = que.top()+p;
		que.pop();
		p += a[i+1];
	}
	sum += b[n-1];
	ll t = 0;
	while(que.top()+p < sum){
		ret += t*(que.top()+p-loc);
		loc = que.top()+p;
		que.pop();
		t ++;
	}
	ret += t*max((ll)0,sum-loc);
	cout << ret << endl;
}



Measured memory_bytes: 3956
from sys import stdin

N = int(stdin.readline().rstrip())
A = stdin.readline().rstrip().split()

B = A[::-1]

ans = []

if N % 2 == 0:
  for i in range(0,N,2):
    ans += [B[i]]
  for i in range(0,N,2):
    ans += [A[i]]
  
else:
  for i in range(0,N,2):
    ans += [B[i]]
  for i in range(1,N,2):
    ans += [A[i]]

print(*list(ans))

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

using namespace std;

#define ll long long

#define DEBUG (0)

int main()
{
  int K = 0;
  int A = 0;
  int B = 0;

  cin >> K;
  cin >> A >> B;

  int ret = 0;  //0:NG,1:OK

  for(int i = 0; i < 1000; i++){
    int C = K*i;
    if(A<= C && C <= B){
      ret = 1;
      break;
    }
  }

  if(ret == 1){
    cout << "OK" << "\n";
  }else{
    cout << "NG" << "\n";
  }
#if DEBUG
  cout << "K:" << K << ", A:" << A << ", B:" << B << endl;
#endif
}


Measured memory_bytes: 3644
import java.io.*;

public class Main {

    public static void main(String[] args){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
           String str;
           int i = 0;
           while((str = br.readLine())!=null&&i<30){
               int x = Integer.parseInt(str);
               int count = 0;
               if(0<x&&x<1000000){
                   int [] prime = new int[x];
                   if(1<x) prime[count++]=2;
                   if(2<x) prime[count++]=3;
                   if(4<x){
                       for(int n=5;n<x+1;n+=2){
                           boolean bo = false;
                           for(int j = 1;Math.pow(prime[j], 2)<=n;j++){
                               if(n%prime[j]==0){
                                   bo = true;
                                   break;
                               }
                           }
                           if(!bo){
                               prime[count++]=n;
                           }
                       }
                   }
                   System.out.println(count);
               }
               i++;
           }
        } catch (IOException ex) {
            System.out.println("error");
        }
    }
}

Measured memory_bytes: 56780
#include <iostream>
#include <algorithm>
#include <vector>

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    std::vector<lint> xs(n), ys(n);
    for (int i = 0; i < n; ++i) {
        lint x, y;
        std::cin >> x >> y;
        xs[i] = x + y;
        ys[i] = x - y;
    }

    lint ans = std::max(*std::max_element(xs.begin(), xs.end()) - *std::min_element(xs.begin(), xs.end()),
                        *std::max_element(ys.begin(), ys.end()) - *std::min_element(ys.begin(), ys.end()));
    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 6348
import java.util.*;
import java.io.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] d = new int[n];
		for(int i = 0 ; i < n ; i++) d[i] = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[] t = new int[m];
		for(int i = 0 ; i < m ; i++) t[i] = Integer.parseInt(sc.next());
		sc.close();
		Arrays.sort(d);
		Arrays.sort(t);
		boolean fin = true;
		boolean che = false;
		int tt = 0 , dd = 0;
		while(fin){
			if(d[dd] > t[tt]){
				fin = false;
			}else if(d[dd] < t[tt]){
				dd++;
			}else{
				dd++;
				tt++;
			}
			if(tt == m){
				che = true;
				fin = false;
			}
			if(dd == n) fin = false;
		}
		if(che) ou.print("YES\n");
		else ou.print("NO\n");
		ou.flush();
    }
}

Measured memory_bytes: 62336
def Level(S):
    A=[0]
    for i in range(len(S)):
        if S[i]=="(":
            A.append(A[-1]+1)
        else:
            A.append(A[-1]-1)
    return A

N=int(input())
S=input()

A=Level(S)
X=-min(A)
T="("*X+S

B=Level(T)
Y=B[-1]
U=T+")"*Y

print(U)

Measured memory_bytes: 61768
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[]s = new int[N];
		for(int i = 0; i < N; i++) {
			s[i] = sc.nextInt();
		}
		sc.close();
		Arrays.sort(s);
		boolean flag = true;
		int sum = 0;
		for(int i = 0; i < N; i++) {
			if(s[i] % 10 != 0) {
				flag = false;
			}
			sum += s[i];
		}
		if(flag) {
			System.out.println(0);
			System.exit(0);
		}
		if(sum % 10 != 0) {
			System.out.println(sum);
			System.exit(0);
		}
		for(int i = 0; i < N; i++) {
			if(s[i] % 10 != 0) {
				System.out.println(sum - s[i]);
				System.exit(0);
			}
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

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

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////


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

	bool b[4] = {};

	rep(i, S.size()) {
		if (S[i] == 'N') { b[0] = 1; }
		if (S[i] == 'W') { b[1] = 1; }
		if (S[i] == 'S') { b[2] = 1; }
		if (S[i] == 'E') { b[3] = 1; }
	}

	if (b[0] == 0 && b[2] != 0) { cout << "No"; }
	else if (b[1] == 0 && b[3] != 0) { cout << "No"; }
	else if (b[2] == 0 && b[0] != 0) { cout << "No"; }
	else if (b[3] == 0 && b[1] != 0) { cout << "No"; }
	else { cout << "Yes"; }

	system("PAUSE");

}





Measured memory_bytes: 504
#include <iostream>
using namespace std;
int main()
{
  int A, B;
  cin >> A >> B;
  if (A==1) A+=13;
  if (B==1) B+=13;
  if (A==B) {
    cout << "Draw" << endl;
  } else if (A>B) {
    cout << "Alice" << endl;
  } else {
    cout << "Bob" << endl;
  }
  return 0;
}


Measured memory_bytes: 3564
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

vector<int> g[SIZE];

int bfs(int start, int goal){
  bool visited[SIZE] = {};
  queue<int> que;

  for(int p : g[start])
    que.push(p);

  int res = 0;

  while(que.size()){
    int now = que.front(); que.pop();

    if (visited[now]) continue;

    if(now == start) continue;

    if(now == goal) {
      res++;
      continue;
    }

    visited[now] = true;

    for(int p : g[now]){
      que.push(p);
    }
  }

  return res <= 2;
}

int main(){
  int n, m;
  int inedge[SIZE] = {};

  scanf("%d%d", &n, &m);

  for(int i=0;i<m;i++){
    int a, b;
    scanf("%d%d", &a, &b);
    a--; b--;
    inedge[a]++;
    inedge[b]++;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  bool ok = true, ok2 = false;
  int counter = 0;

  vector<int> vec;

  for(int i=0;i<n;i++){
    ok &= inedge[i] % 2 == 0;
    counter += inedge[i] / 2 - 1;
    ok2 |= inedge[i] >= 6;

    if(inedge[i] / 2 >= 2) vec.push_back(i);
  }

  debug(vec);

  bool ok3 = counter >= 2 && vec.size() >= 2 && bfs(vec[0], vec[1]);

  if(ok && (ok2 || counter >= 3 || ok3)){
    puts("Yes");
  } else {
    puts("No");
  }

  return 0;
}


Measured memory_bytes: 9088
use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_owned()
}

fn main() {
    let s = read_line();
    let t = "CODEFESTIVAL2016";

    let ans = s.chars().zip(t.chars()).filter(|&(c, d)| c != d).count();

    println!("{}", ans);
}


Measured memory_bytes: 380
#include <stdio.h>


int main()
{
    unsigned long long ones = 0;
    unsigned long long result;
    unsigned long long i;
    unsigned long long least_one;
    unsigned long long H;
    ones = ~ones;
    scanf("%lld",&H);
    for(i=0 ; i< 8*sizeof(unsigned long long) ;i++)
    {
        if((H>>i)&&1 == 1)
        {
            least_one = i;
        }
    }
    result = (~(ones<<(least_one+1)));
    printf("%llu\n",result);
    return 0;
}

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

int main() {
  int A, B, C, D;
  
  cin >> A >> B >> C >> D;
  
  int l = A +B;
  int r = C +D;

  
  if( l > r){
    cout << "Left" << endl;
  }
 if( l == r){
    cout << "Balanced" << endl;
  }
  if( l < r){
    cout << "Right" << endl;
  }
    
  // ここにプログラムを追記
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<int, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

int main(){
    fastIO;
    ll a, b, c;
    cin >> a >> b >> c;
    if(a + b < c)
        cout << a + 2 * b + 1 << "\n";
    else
        cout << b + c;
    return 0;
}

Measured memory_bytes: 256
a=[]
b=int(input())
n=0
nn=0
nnn=0
mnn=0
hnn=0
hmnn=0
h=0
m=0
for x in input().split(" "):
    a.append(int(x))
for x in a:
    n+=x
for x in a:
    mnn=nn
    nn+=x
    if nn>=n/2:
        break
hnn=nn-n/2
hmnn=n/2-mnn
if hmnn>=hnn:
    h=hnn
else:
    h=hmnn
print(int(h*2))

Measured memory_bytes: 26024
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  unordered_map<string, int> mp;
  int n; cin >> n;
  REP(i, n) {
    string s; cin >> s;
    if (!mp[s]) mp[s] = 1;
    else ++mp[s];
  }
  int m; cin >> m;
  REP(i, m) {
    string s; cin >> s;
    if (!mp[s]) mp[s] = -1;
    else --mp[s];
  }
  int ans = -1;
  for (auto p : mp) ans= max(ans, p.second);
  cout << max(ans, 0) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <string>
#include <cmath>
#include <complex>
#include <numeric>
#include <cassert>

#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <utility>

#define PI 3.14159265358979323846
#define int64 long long
#define uint64 unsigned long long
using namespace std;

int main()
{
	string ss;
	cin >> ss;
	int64 kk;
	cin >> kk;
	set<string> memo;
	for(int64 ii = 0;ii < ss.length();ii++)
	{
		for(int64 jj = 1;jj <= kk + 2;jj++)
		{
			memo.insert(ss.substr(ii, jj));
		}
	}
	set<string>::iterator ite = memo.begin();
	for(int64 ii = 1;ii < kk;ii++)
	{
		ite++;
	}
	cout << *ite << endl;
	return 0;
}


Measured memory_bytes: 5556
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
int cut=0;
int A=0;
int B=0;
int C=0;
int K=0;
vector <int> Ai(100); 

cin >> A >> B >> C >> K;
if(K-A>0){
    cut+=A;
    if((K-A)-B==0||((K-A)-B<0)){
        
    }
    else{
        cut-=(K-A-B);
    }

}
else{
    cut=K;
}

cout <<cut<<endl;

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

int main(){
	int a, b, k;
	cin >> k >> a >> b;
	bool flag = false;
	for(int i = a; i <= b; i++){
		if(i % k == 0){
			flag = true;
		}
	}
	if(flag){
		cout << "OK";
	}
	else{
		cout << "NG";
	}
} 

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
const int MAXN=100;

char grid[MAXN+5][MAXN+5];

int main() {
  int A,B;
  cin>>A>>B;
  for (int i=0; i<MAXN/2; i++) {
    for (int j=0; j<MAXN; j++) {
      grid[i][j]='.';
    }
  }
  for (int i=MAXN/2; i<MAXN; i++) {
    for (int j=0; j<MAXN; j++) {
      grid[i][j]='#';
    }
  }
  A--,B--;
  for (int i=MAXN-1; A; i-=2) {
    for (int j=0; j<MAXN && A; j+=2) {
      grid[i][j]='.';
      A--;
    }
  }
  for (int i=0; B; i+=2) {
    for (int j=0; j<MAXN && B; j+=2) {
      grid[i][j]='#';
      B--;
    }
  }
  cout<<MAXN<<" "<<MAXN<<endl;
  for (int i=0; i<MAXN; i++) {
    cout<<grid[i]<<endl;
  }
  cout<<endl;
  return 0;
}



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

#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define dl          '\n'
#define mod         (ll)1000000007
//#define mod         (ll)998244353
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll hell;
// ll expo(ll base, ll exponent, ll mod) {                                //return base^exponent modulo modulus
//     ll ans = 1;
//     while(exponent !=0 ) {
//         if((exponent&1) == 1) {
//             ans = ans*base ;
//             ans = ans%mod;
//         }
//         base = base*base;
//         base %= mod;
//         exponent>>= 1;
//     }
//     return ans%mod;
// }

ll solve(){ 
    ll a,b,c; cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b;
}   

int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;

int main () {
  string h;
  cin >> h;
  int ans = 0;
  char before = 'a';
  for (int i = 0; i < h.size(); i++) {
    if (i == 0) {
      before = h[0];  
    }    
    else {
      if (before != h[i]) {
        before = h[i];
        ans++;    
      }  
    }
  }    
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int> vec(4);
    vec.at(3) = N%10;
    vec.at(2) = N/10 %10;
    vec.at(1) = N/100 %10;
    vec.at(0) = N/1000;

    for(int bit=0; bit < (1<< 3); bit++){
        int sum = vec[0];
        string siki = to_string(vec[0]);

        for(int i=0; i<3; i++){
            if (bit & (1 << i) ){ 
                sum += vec[i+1];
                siki = siki + "+" + to_string(vec[i+1]);
            }
            else{
                sum -= vec[i+1];
                siki = siki + "-" + to_string(vec[i+1]);
            }
        }
        if(sum ==7){
            cout << siki << "=7" << endl;
            return 0;
        }
    }
    return 0;
}

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

#define sd1(a) scanf("%d",&a)
#define sd2(a,b) scanf("%d %d",&a,&b)

using namespace std;
using Graph = vector<vector<int>>;

// 深さ優先探索
Graph G(200005);
vector<int> Fennec(200005);
vector<int> Sunuke(200005);
void dfs(int v,int before,int step,bool f) {
		if(f) Fennec[v]=step;
		else Sunuke[v]=step;
    for(int i=0;i<G[v].size();i++)
			if(G[v][i]!=before) dfs(G[v][i],v,step+1,f);
}

int main()
{
	int a,b;
	int N;
	int ans=0;
	sd1(N);
	for(int i=0;i<N-1;i++){
		sd2(a,b);
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0,-1,0,true);
	dfs(N-1,-1,0,false);

//	for(int i=0;i<N;i++) cout<<Fennec[i]<<" ";
//	cout<<endl;
//	for(int i=0;i<N;i++) cout<<Sunuke[i]<<" ";
	for(int i=0;i<N;i++) ans+=(Fennec[i]<=Sunuke[i])?1:-1;
	printf("%s",(ans>0)?"Fennec":"Snuke");
}


Measured memory_bytes: 15872
use std::io::{self, BufRead, BufWriter, Write};

fn solve<R, W>(reader: R, mut writer: W)
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let r: i32 = lines.next().unwrap().unwrap().parse().unwrap();

    writeln!(&mut writer, "{}", r * r).unwrap();
}

fn main() {
    let stdio = io::stdin();
    let input = stdio.lock();

    let stdout = io::stdout();
    let output = BufWriter::new(stdout.lock());

    solve(input, output);
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"2", br"4
",
        ),
        (
            br"100", br"10000
",
        ),
    ];

    #[test]
    fn test_a() {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output);
            let expected_str = String::from_utf8(expected.to_vec()).unwrap();
            let output_str = String::from_utf8(output).unwrap();
            assert_eq!(expected_str, output_str);
        }
    }
}


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

using namespace std;

int main() {
  int n,q,m;
  while(cin>>n>>q && (n || q)){
    int d,cnt[105]={};
    pair<int,int> ans=make_pair(1000,0);
    for(int i=0;i<n;++i){
      cin >> m;
      for(int j=0;j<m;++j) {
	cin >> d;
	cnt[d]++;
      }
    }
    for(int i=0;i<105;++i)
      if(cnt[i]>ans.second) ans=make_pair(i,cnt[i]);
    if(ans.second  && q<=ans.second) cout << ans.first << endl;
    else cout << 0 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 2980
#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;
int main(void){
    int M, N;
    cin>>N>>M;
    int L, R;
    map<int, int> card;
    int mL = 0, mR = N - 1;
    for(int i = 0; i < N; i++){
        
        cin>>L>>R;
        mL = max(L - 1, mL);
        mR = min(R - 1, mR);
        
    }
    int ans = mR - mL + 1;
    ans = max(0, ans);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
 
using namespace std; 
 
int n1, n2, n3;
 
int main()
{
  cin >> n1;
  cin >> n2;
  cin >> n3;
  
  if (n1 + n2 >= n3){
    cout << n2+n3 << endl;
  } else {
    cout << n2 + n1 + n2 + 1 << endl;
  }
}

Measured memory_bytes: 256
/// You just can't beat the person who never gives up
/// ICPC next year

#include<bits/stdc++.h>
using namespace std ;
const int N = 1e5+5 ;
const long long mx = 1e18 ;

long long a,b;
long double x ;
int main(){
    cin >> a >> x ;
    b = (x+0.009)*100 ;
    long long ans = a*b ;
    cout << ans/100 ;
    return 0;
}


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

int main() {
    vector<int> sieve(1e5 + 9);
    sieve[0] = sieve[1] = true;
    for (int i = 2; i * i <= 1e5 + 5; ++i) {
        if (sieve[i]) continue;
        int d = 2 * i;
        while (d < 1e5 + 5) {
            sieve[d] = true;
            d += i;
        }
    }

    vector<int> cnt(1e5 + 9);
    int c = 0;
    for (int i = 1; i < 1e5 + 5; ++i) {
        if (i % 2 == 0) cnt[i] = c;
        else if (!sieve[i] && !sieve[(i + 1) / 2]) cnt[i] = ++c;
        else cnt[i] = c;
    }

    int Q;  cin >> Q;
    for (int i = 0; i < Q; ++i) {
        int l, r;  cin >> l >> r;
        cout << cnt[r] - cnt[l - 1] << endl;
    }
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
#pragma comment (linker, "/STACK:526000000")
#define  _CRT_SECURE_NO_WARNINGS

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

void solve(){
	int n;
	cin >> n;
	set<string> hoge;
	REP(i, n) {
		string a;
		cin >> a;
		hoge.insert(a);
	}
	int m;
	cin >> m;
	int now = 0;
	REP(i, m) {
		string s;
		cin >> s;
		if (hoge.count(s) == 0) {
			cout << "Unknown ";
		}
		else {
			now++;
			if (now % 2 == 1) {
				cout << "Opened by ";
			}
			else {
				cout << "Closed by ";
			}
		}
		cout << s << endl;
	}
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3252
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORL(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	LL A, B, C, K;
	cin >> A >> B >> C >> K;
	LL ans = 0;

	if (K == 0) {
		ans = A - B;
	}
	else if (K == 0 || K % 2 == 0) {
		ans = A - B;
	}
	else {
		ans = B - A;
	}
	if (abs(ans) > 1000000000000000000) {
		O("Unfair");
	}
	else {
		O(ans);
	}

	return 0;
}

Measured memory_bytes: 256