akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define trace(x)     cerr<<#x<<":"<<x<<endl;
#define trace2(x,y) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<endl;
#define trace3(x,y,z) cerr<<#x<<":"<<x<<"|"<<#y<<":"<<y<<"|"<<#z<<":"<<z<<endl;
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)

int main(){
	fast_io;
	ll n,m;
	cin>>n>>m;
	vl a(m);
	ll sum =0;
	for(int i=0;i<m;i++){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>n)cout<<"-1";
	else{
		cout<<n-sum;
	}

	
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3740
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;

int main() {
	int N;
	cin >> N;
	vector<double>data(N);
	for (int i = 0; i < N; i++) {
		cin >> data[i];
	}
	sort(data.begin(), data.end());
	double ans = 0;
	ans += data[0] + data[1];
	ans /= pow(2, N - 1);
	for (int i = 2; i < N; i++) {
		ans += data[i] * pow(2, i - 1) / pow(2, N - 1);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
//Loopで使う文字列の長さは固定！
//intで大丈夫？オーバーフローしない？
//Loop回数は本当に10⁹以内になってる？Loopは回る？？
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(in);
        int n=sc.nextInt();
        int W=sc.nextInt();
        long[][] dp=new long[n+1][W+1];
        dp[0][0]=0;
        int[] v=new int[n];
        int[] w=new int[n];
        for (int i = 0; i < n; i++) {
            v[i]=sc.nextInt();
            w[i]=sc.nextInt();
        }
        int weight=0;
        long ans=0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j <=W ; j++) {
                if(j>=w[i]){
                    dp[i+1][j]=max(dp[i][j-w[i]]+v[i],dp[i][j]);
                }else{
                    dp[i+1][j]=dp[i][j];
                }
            }
        }
        out.println(dp[n][W]);
    }
}


Measured memory_bytes: 35080
#include<stdio.h>

int main(){
	int C = 100000,n;
	scanf("%d",&n);
	for(int i = 0;i < n;i++){
		C = (C*21)/20;
		if(C%1000 > 0)
			C += 1000-C%1000;
	}
	printf("%d\n",C);
	return 0;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin >> N >> K;
    int H[N];
    for(int i=0; i<N; i++){
        cin >> H[i];
    }
    long long ans=0;
    if(N>K){
        sort(H,H+N);
        for(int i=0; i<N-K; i++){
            ans+=H[i];
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
N=int(input())
S=list(map(str,input().split()))
bucket=[0*i for i in range(4)]
for i in range(N):
    if S[i]=='P':
        bucket[0]+=1
    elif S[i]=='W':
        bucket[1]+=1
    elif S[i]=='G':
        bucket[2]+=1
    else:
        bucket[3]+=1
if 4 - bucket.count(0)==3:
    print('Three')
else:
    print('Four')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

int i,j,k,l,m,n;
/////////////////////////////////////////////////////

int N;


int main(){
    cin>>N>>i;
    cout<<(N-i+1)<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try { st = new StringTokenizer(br.readLine()); }
                catch (IOException e) { e.printStackTrace(); }
            }
            return st.nextToken();
        }
        int nextInt() { return Integer.parseInt(next()); }
        long nextLong() { return Long.parseLong(next()); }
        double nextDouble() { return Double.parseDouble(next()); }
        String nextLine() { String str = "";
            try { str = br.readLine(); }
            catch (IOException e) { e.printStackTrace(); }
            return str;
        }
    }

    public static void main(String[] args)
    {
        FastReader in=new FastReader();

        int n = in.nextInt() ;
        int x = in.nextInt() ;

       int[] a = new int[n] ;
        int d =0 , count=1 ;
       for(int i=0  ; i<n ; i++){
           a[i] = in.nextInt() ;
           d = d + a[i] ;
           if (d<=x) {
               count++;
           }
       }
        System.out.println(count);

    }
}


Measured memory_bytes: 21332
def main():
    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
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = list(map(int, input().split()))
    res = []
    for i, x in enumerate(a):
        res.append([x, i])
    res.sort()
    ans = []
    for x, i in res:
        ans.append(i+1)
    print(*ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 71004
package main

import (
	"fmt"
)

func main() {
	var n, i int

	fmt.Scan(&n)
	arry := make([]int, n)
	for i = 0; i < n; i++ {
		fmt.Scan(&arry[i])
	}

	ans := 0
	for {
		for j := 0; j < n; j++ {
			if arry[j]%2 == 0 {
				arry[j] = arry[j] / 2
			} else {
				goto finish
			}
		}
		ans++
	}
finish:
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<LP> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

void solve() {
	int a, b, c; cin >> a >> b >> c;
	int num = 0;
	if (a % 2)num++;
	if (b % 2)num++;
	if (c % 2)num++;
	if (num<=1) {
		cout << "Tem" << endl;
	}
	else {
		cout << "Hom" << endl;
	}
}

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

	//cout << fixed << setprecision(10);
	//init();
	solve();
	//stop
	return 0;
}




Measured memory_bytes: 3236
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S;
    cin >> S;
    int n = S.length();
    long long res = 0;
    for(int i = 0; i < 1 << (n - 1); i++) {
        long long tmp = 0;
        for(int j = 0; j < n; j++) {
            tmp = tmp * 10 + (S[j] - '0');
            if(i & (1 << j)) {
                res += tmp;
                tmp = 0;
            }
        }
        res += tmp;
    }
    cout << res << endl;
    return 0;
}

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

template <class T>
inline void swapa(T& a,T& b);
template <class T>
void sort(T* x,int left,int right);

template <class T>
inline void swapa(T& a,T& b){
    T tmp=a;
    a=b;
    b=tmp;
}

template <class T>
void sort(T* x,int left,int right){
    if(right-left<=1) return;
    int pivod=x[(right+left)/2];

    swapa(x[(right+left)/2],x[right-1]);
    int i=left;
    for(int j=left;j<right-1;j++){
        if(x[j]<pivod){
            swapa(x[i++],x[j]);
        }
    }
    swapa(x[i],x[right-1]);

    sort(x,left,i);
    sort(x,i+1,right);
}

int min(int a[],int begin,int end){
    int min=100100100;
    for(int i=begin;i<end;i++){
        if(a[i]<min) min=a[i];
    }
    return min;
}

int main(){
    int A,B,M;
    cin>>A>>B>>M;
    int a[100100];
    int b[100100];
    for(int i=1;i<=A;i++){
        cin>>a[i];
    }
    for(int j=1;j<=B;j++){
        cin>>b[j];
    }
    int x[100100];
    int y[100100];
    int c[100100];
    int coupon[100100];
    for(int i=1;i<=M;i++){
        cin>>x[i]>>y[i]>>c[i];
        coupon[i]=a[x[i]]+b[y[i]]-c[i];
    }

    int aa=min(a,1,A+1);
    int bb=min(b,1,B+1);
    int co=min(coupon,1,M+1);

    if(aa+bb>co){
        cout<<co<<endl;
    }else{
        cout<<aa+bb<<endl;
    }
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <cmath>
#include <array>
#include <functional>
#include <algorithm>
#include <numeric>
#include <string>
#include <stack>

int main()
{
	int A, B;
	std::cin >> A >> B;

	if (1 <= A && A <= 9 && 1 <= B && B <= 9)
	{
		std::cout << A * B << std::endl;
	}
	else
	{
		std::cout << -1 << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e18);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

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

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

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

ll power(ll a, ll b){
    ll ans = 1;
    a %= mod;
    while(b) {
        if(b & 1LL) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans % mod;
}

//modの値の確認をすること
int main(){
    long double a,b;
    cin >> a >> b;
    ll ans = a * b;
    pf(ans);
    return 0;
}


Measured memory_bytes: 3780
// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

use std::cmp::*;

fn main() {
    let nm: Vec<u64> = read_vec();
    let mut lmax: u64 = 0;
    let mut rmin: u64 = 100000;

    for i in 0..nm[1]
    {
        let lr: Vec<u64> = read_vec();
        lmax = max(lmax, lr[0]);
        rmin = min(rmin, lr[1]);
    }

    if lmax > rmin { println!("0"); return; }

    let mut result = rmin - lmax + 1;
    println!("{}", result);
}


Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);



int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    
    freopen("output.txt", "w", stdout);
    #endif

    
    string s1,s2;
    cin>>s1>>s2;
    ll n1 = s1.length(), n2=s2.length(),i,j;

    ll dp[n1+1][n2+1];

    memset(dp,0,sizeof(dp));


    for(i=1;i<=n1;i++)
    {
        for(j=1;j<=n2;j++)
        {
            if(s1[i-1]==s2[j-1])
            {
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else 
            {
                dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
            }
        }
    }

    string ans="";

    ll ii=n1,jj=n2;
    while(ii>0 && jj>0)
    {
        if(s1[ii-1]==s2[jj-1])
        {
            ans+=s1[ii-1];
            ii--;
            jj--;
        }
        else 
        {
            if(dp[ii-1][jj]>dp[ii][jj-1])
            {
                ii--;
            }
            else 
            {
                jj--;
            }
        }
    }


    //cout<<dp[n1][n2]<<endl;
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;

}



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

int main(){
    long long N, A, B;
    cin >> N >> A >> B;

    long long i = N / (A + B);
    long long mod = N % (A + B);
    long long ans;
    ans = min(i * A + mod, i * A + A);
    cout << ans << endl;
}


Measured memory_bytes: 3608
c,t,d[4010]={1};char s[4010];i;main(j){for(gets(s);s[i/2];d[j]=!++i)for(j=c+=s[i]?t+=2,s[i]-48:0;j>i+c-t&&~j;d[j--]%=998244353)d[j]+=d[j-1];printf("%d",d[c]);}

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

int main(void){
	int N;
	scanf("%d", &N);
	int a[10];
	for(int i=0; i<N; i++){
		scanf("%d", a+i);
	}

	int num=0; // にている列の数
	int odd=0, even=0; // a内の偶数、奇数の数
	int extra=1; // 似ている列のうち積が奇数のもの

	num = (int) pow(3.0, N);

	for(int i=0; i<N; i++){
		if(a[i]%2==0){
			even++;
		}
		else{
			odd++;
		}
	}

	extra = (int) (pow(1.0, odd) * pow(2.0, even));

	/*for(int i=0; i<N; i++){
		printf("%d\n", a[i]);
	}
	printf("%d %d %d\n", num, odd, even);*/

	printf("%d\n", num-extra);
	return 0;
}


Measured memory_bytes: 384
N = int(input())
ts = list(map(int, input().split()))
vs = list(map(int, input().split()))


tt = 0
lim = []

for i in range(N):
    for j in range(ts[i]):
        lim.append(vs[i])
        tt += 1

up = [False for i in range(tt)]
v = 0
for i in range(tt):
    if lim[i] > v:
        v += 1
        lim[i] = v
        up[i] = True
    else:
        v = lim[i]

down = [False for i in range(tt)]
v = 0
for i in range(tt - 1, -1, -1):
    if lim[i] > v:
        v += 1
        if lim[i] > v:
            up[i] = False
        lim[i] = v
        down[i] = True
    else:
        v = lim[i]

ans = 0
for i in range(tt):
    ans += lim[i]
    if up[i] and down[i]:
        ans -= 0.75
    elif up[i] or down[i]:
        ans -= 0.5
    
print(ans)

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

int main(){
    int a=0;
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++){
        if(a==1)break;
        int count =0;
        for (int j=0;j<s.size();j++){
            if(s[i]==s[j])count++;
            if((j==s.size()-1) && count%2==1)a = 1;
        }
    }
    if(a==0)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
	long long n,cnt=0;
    cin>>n;
    vector<long long>mon(n+1),kill(n);
    rep(i,n+1)cin>>mon[i];
    rep(j,n)cin>>kill[j];
    rep(k,n){
        if(kill[k]<=mon[k])cnt+=kill[k];
        else if(kill[k]<=mon[k]+mon[k+1]){
            cnt+=kill[k];
            mon[k+1]-=kill[k]-mon[k];
        }
        else{
            cnt+=mon[k]+mon[k+1];
            mon[k+1]=0;
        }
    }
    cout<<cnt;
	return 0;
}

Measured memory_bytes: 1792
require 'pp'

def insertion_sort(g)
  g.upto(@n-1).each do |i|
    v = @a[i]
    j = i - g
    while j >= 0 && @a[j] > v
      @a[j+g] = @a[j]
      j = j - g
      @cnt += 1
    end
    @a[j+g] = v
  end
end

def shell_sort
  @g = init_g
  0.upto(@g.length-1).each{ |i| insertion_sort(@g[i]) }
end

def init_g
  acc = []
  i = 1
  loop do
    break if i > @n
    acc << i
    i = 3*i+1
  end
  acc.reverse
end

@n = gets.to_i
@cnt = 0
@a = []
@g = []
@n.times do
  @a << gets.to_i
end

shell_sort

puts @g.length
puts @g.join(' ')
puts @cnt
puts @a



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


int main(){   
    int n; cin >> n;
    int ans=0;
    for(int i=0;i<10000;++i){
        if(1000*i >= n){
            ans = 1000*i - n;
            cout << ans << endl;
            return 0;
        } 
    }
}


Measured memory_bytes: 3668
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>

using namespace std;

int main(){

    int N;
    cin >> N;

    int flag = 0;
    for(int i=0; i<=999; i++){
        if(i == N){
            if(flag == 2 || flag == 4 || flag == 5 || flag == 7 || flag == 9){
                cout << "hon";
            }
            else if(flag == 0 || flag == 1 || flag == 6 || flag == 8){
                cout << "pon";
            }
            else{
                cout << "bon";
            }
        }

        if(flag == 9){
            flag = 0;
        }
        else{
            flag = flag + 1;
        }
        
    }
   
}

Measured memory_bytes: 3128
import sys,queue,math,copy,itertools,bisect,collections
LI = lambda : [int(x) for x in sys.stdin.readline().split()]

X,Y,Z,K = LI()
A = LI()
B = LI()
C = LI()

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

h = A[0] + B[0] + C[0]
l = 0
while h > l+1:
    m = (h+l) // 2

    num = 0
    for a in A:
        j = len(C) - 1
        for i in B:
            while i + C[j] < m - a:
                j -= 1
                if j < 0: break
            else:
                num += j + 1
                continue
            break
    if num > K:
        l = m
    else:
        h = m

ans = []
for a in A:
    j = len(C) - 1
    for i in B:

        while i + C[j] <= l - a:
            j -= 1
            if j < 0: break
        else:
            for k in range(j+1):
                ans.append(a+i+C[k])
            continue
        break

ans.sort(reverse=True)
for _ in range(K-len(ans)):
    ans.append(l)
print(*ans[:K], sep='\n')



Measured memory_bytes: 196128
N=int(input())
A=list(map(int,input().split()))
kind=0
c=[]
d=[0]*(10**5)
count=0
for i in range(N):
  if(d[A[i]-1]==0):
    kind+=1
  d[A[i]-1]+=1
for i in range(N):
  if(d[i]>0 and d[i]%2==0):
    count+=1
print(kind-(kind+1)%2)


Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  string S;
  cin >> S;
  
  string year, month, day;
  year = S.substr(0, 4);
  month = S.substr(5, 2);
  day = S.substr(7, 2);
  
  if (stoi(year) < 2019) {
    cout << "Heisei" << endl;
  } else if (stoi(year) == 2019) {
    if (stoi(month) <= 4) {
      cout << "Heisei" << endl;
    } else {
      cout << "TBD" << endl;
    }
  } else {
    cout << "TBD" << endl;
  }
  
}

Measured memory_bytes: 256
# 未完成
import fractions
import numpy as np
A, B, C, D = map(int, input().split())  # aaaaa
lcmofCD = int(C * D / fractions.gcd(C, D))
divofAbyC = (A-1) // C
divofAbyD = (A-1) // D
divofBbyC = B // C
divofBbyD = B // D  # aaaaa
divofBbylcm = B // lcmofCD
divofAbylcm = (A-1) // lcmofCD
ansofA = (A-1) - (divofAbyC + divofAbyD - divofAbylcm)
ansofB = B-(divofBbyC + divofBbyD - divofBbylcm)
ans = ansofB-ansofA

print("{}".format(ans))


Measured memory_bytes: 13672
n = int(raw_input())
sqr = map(int, raw_input().split())

d = {}

i = n - 1
aux = 0

while (i > 0):
    if sqr[i - 1] < sqr[i]:
        d[i] = aux
        aux = 0
    else:
        aux += 1
    
    i -= 1

d[0] = aux

maior = -1
for k in d.keys():
    if d[k] > maior:
        maior = d[k]

print maior

Measured memory_bytes: 17128
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        List<Integer> hatenum = new ArrayList<>();
        List<Integer> oneToTen = new ArrayList<Integer>(Arrays.asList(0,1,2,3,4,5,6,7,8,9));
        int paymoney = in.nextInt();
        int n = in.nextInt();
        int i = 0;
        while(i < n){
            hatenum.add(in.nextInt());
            i++;
        }
        oneToTen.removeAll(hatenum);
        //System.out.println(oneToTen);
        int[] ud = {1, 10, 100, 1000, 10000};
        int[] di = {0, -1, -1, -1, -1};
        while (true) {
            int total = 0;
            for(int k = 0;k < 5;k++) {
                if(di[k] != -1){
                total += ud[k] * oneToTen.get(di[k]);
                //System.out.println(total);
                }else{
                    break;
                }
                ///di[k] += 1;
                //System.out.println(total);
            }
            if(paymoney == total || paymoney < total) {
                System.out.println(total);
                break;
            }
            di[0] += 1;
            for (int k = 0;k < 5;k++) {
                if (oneToTen.size() == di[k]) {
                    di[k] = 0;
                    di[k+1] += 1;
                } else {
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 23124
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int count1 = 0;
		int count2 = 0;
		int count3 = 0;
		int count4 = 0;
		for(int i = 0 ; i < 6; i++) {
			switch(sc.nextInt()) {
			case 1:
				count1++;
				break;
			case 2:
				count2++;
				break;
			case 3:
				count3++;
				break;
			case 4:
				count4++;
				break;
			}
		}

		String Ans="NO";
		if(count1==1 && count2 == 1 && count3 == 2 && count4 == 2) {
			Ans = "YES";
		}else if(count1==1 && count2 == 2 && count3 == 1 && count4 == 2) {
			Ans = "YES";
		}else if(count1==1 && count2 == 2 && count3 == 2 && count4 == 1) {
			Ans = "YES";
		}else if(count1==2 && count2 == 1 && count3 == 1 && count4 == 2) {
			Ans = "YES";
		}else if(count1==2 && count2 == 2 && count3 == 1 && count4 == 1) {
			Ans = "YES";
		}else if(count1==2 && count2 == 1 && count3 == 2 && count4 == 1) {
			Ans = "YES";
		}

		System.out.println(Ans);
	}



}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 22612
#include "iostream"
#include "vector"
#include "list"
using namespace std;

void set_max(int &x, list<int> args) {
	for (auto i : args) {
		x = max(x, i);
	}
}

int main() {
	int n;
	cin >> n;
	vector < vector <int> > points(n+1, vector <int> (4));
	for (int i=1; i<=n; i++) {
		cin >> points[i][1] >> points[i][2] >> points[i][3];
	}
	vector < vector <int> > dp(n+1, vector <int> (4, 0));
	for (int i=1; i<=3; i++) {
		dp[1][i] = points[1][i];
	}
	for (int i=2; i<=n; i++) {
		for (int j=1; j<=3; j++) {
			for (int k=1; k<=3; k++) {
				if (k == j) {
					continue;
				}
				set_max(dp[i][j], {points[i][j] + dp[i-1][k]});
			}
		}
	}
	int ans = 0;
	for (int i=1; i<=3; i++) {
		set_max(ans, {dp[n][i]});
	}
	cout << ans << endl;
}


Measured memory_bytes: 11136
#include <stdio.h>
#include <string.h>
#include <map>
using namespace std;

#define MOD 2019

map<int, int> M;
char s[222222];
int dp[222222], t[222222], d[11];

int make_digit(int x)
{
	int cnt = 0;
	while (x)
	{
		d[++cnt] = x % 10;
		x /= 10;
	}

	return cnt;
}

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

	scanf("%s", &s[1]);
	n = strlen(&s[1]);

	t[0] = 1;
	for (i = 1; i <= n; i++)
		t[i] = t[i - 1] * 10 % MOD;

	for (i = n; i >= 1; i--)
	{
		dp[i] = (dp[i + 1] + (s[i] - '0') * t[n - i]) % MOD;
		M[dp[i]]++;
	}

	M[0]++;
	for (i = 0; i < MOD; i++)
		ans += M[i] * (M[i] - 1) / 2;

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

Measured memory_bytes: 5176
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let mut p = Vec::with_capacity(n);
    for _ in 0..n {
        let w: usize = it.next().unwrap().parse().unwrap();
        let s: usize = it.next().unwrap().parse().unwrap();
        let v: u64 = it.next().unwrap().parse().unwrap();
        p.push((w, s, v));
    }
    p.sort_by_key(|p| p.0 + p.1);
    let m = 20000;
    let mut dp = vec![0; m + 1];
    for (w, s, v) in p {
        for i in (0..(s + 1)).rev() {
            dp[i + w] = std::cmp::max(dp[i + w], dp[i] + v);
        }
    }
    let ans = *dp.iter().max().unwrap();
    println!("{}", ans);
}

fn main() {
    run();
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll dp[114][114514];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, W, w;
	ll v;
	cin>>n>>W;
	REP(i, n){
		cin>>w>>v;
		REP(j, W+1){
			if(j<w){
				dp[i+1][j]=dp[i][j];
			}
			else{
				dp[i+1][j]=max(dp[i][j], dp[i][j-w]+v);
			}
		}
	}
	cout<<dp[n][W]<<'\n';
	return 0;
}


Measured memory_bytes: 91392
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
typedef long int lint;
typedef vector<char> vchar;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
#define vsort(v) sort((v).begin(), (v).end())
#define vreverse(v) reverse((v).begin(), (v).end())
#define pb(a) push_back(a)
#define INF 1000000007
int main(){
  lint n,k,i,g;cin>>n>>k;vchar s(n);vint ps(n);
  for(i=0;i<n;i++){
    cin>>s[i];
    if(s[i] =='0'){
      ps[i]=0;
    }else if(s[i] =='1'){
      ps[i]=1;
    }
  }
  vint q;lint cnt;i=0;
  while(i<n){
    cnt=0;
    if(ps[i]==0){
      while((ps[i]==0)&&(i<n)){i++;cnt++;}
    }else{
      while((ps[i]==1)&&(i<n)){i++;cnt++;}
    }
    q.pb(cnt);
  }
  lint siz=q.size();lint mini;lint sum;
  if((2*k)+1>siz){cout<<n<<endl;return 0;}
  for(g=1;g<siz;g++){q[g]+=q[g-1];}
  //bool flag=true;//q[g]:consist of 1;
  if(ps[0]==0){
    sum=q[2*k-1];mini=sum;
    for(g=1;g+2*k<=siz;g+=2){
      sum=q[g+2*k]-q[g-1];if(mini<sum){mini=sum;}
    }
    if(!ps[n-1]){lint y=q[siz-1]-q[siz-2*k-1];mini=max(y,mini);}
  }else{
    sum=q[2*k];mini=sum;
    for(g=2;g+2*k<=siz;g+=2){
      sum=q[g+2*k]-q[g-1];if(mini<sum){mini=sum;}
    }
    if(!ps[n-1]){lint y=q[siz-1]-q[siz-2*k-1];mini=max(y,mini);}
  }
  cout<<mini<<endl;
}


Measured memory_bytes: 1404
N = int(input())
A_map = map(int, input().split())
A = list(A_map)
syain_n = [0]*N
for i in range(N-1):
    syain_n[A[i]-1] = syain_n[A[i]-1] + 1
for i in range(N):
    print(syain_n[i])


Measured memory_bytes: 32360
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			T = (S = buf) + fread(buf, 1, L, stdin);
			return (S == T ? EOF : *S++);
		}
		return *S++;
	}
	
	int inp() {
		int x = 0, f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	ll inp_ll() {
		ll x = 0; int f = 1; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar())
			if(ch == '-') f = -1;
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x * f;
	}
	
	char B[25], *outs=B+20, *outr=B+20;
	template<class T>
	inline void print(register T a,register char x=0){
		if(x) *--outs = x, x = 0;
		
		if(!a)*--outs = '0';
		else 
			while(a)
				*--outs = (a % 10) + 48, a /= 10;
		
		if(x)
			*--outs = x;
		
		fwrite(outs, outr - outs , 1, stdout);
		outs = outr;
	}
};

using io :: print;
using io :: inp;
using io :: inpu;
using io :: inp_ll;

using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

const int MAXN = 10010;
const int MAXP = 10000000;
const u64 MOD = 998244353;
const f80 MI = f80(1)/MOD;
const ll INF = 10000000000000000LL;
const ll inf = 5000000000000LL;

int c[11] = {0,2,5,5,4,5,6,3,7,6};
int u[11];


struct number
{
	string v;
	number (const string &v = "") : v(v) {}
	bool operator < (const number &A) const
	{
		return (v.size() < A.v.size()) || (v.size() == A.v.size() && v < A.v);
	}
	friend number operator + (int k, const number& A)
	{
		return (char)(k+'0')+A.v;
	}
}F[MAXN];

number solve(int n)
{
	if (n < 0)
		return string("-");
	if (n == 0)
		return string("");
	if (!F[n].v.empty())
		return F[n];
	F[n] = string("-");
	for (int k = 0; k < 10; ++ k) if (u[k])
	{
		if (n-c[k] >= 0)
		{
			auto t = solve(n-c[k]);
			if (t.v != "-")
				F[n] = max(F[n], k+t);
		}
	}
	return F[n];
}

int main()
{
	
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++ i)
	{
		int x;
		scanf("%d", &x);
		u[x] = 1;
	}
	cout << solve(n).v << endl;
	
	return 0;
}


Measured memory_bytes: 33152
#include <bits/stdc++.h>
 
#define forn(i, n) for (llong i = 0ll; i < (llong) n; ++i)
#define fornn(i, l, r) for (llong i = (llong) l; i < (llong) r; ++i)
#define size(x) ((int) (x.size()))
 
using namespace std;
 
typedef long long llong;
const llong inf = (llong) 1e+9 + 7ll;
const llong linf = (llong) 1e+18 + 7ll;
const long double eps = (long double) 1e-9;
const long double pi = acosl((long double) -1.0);
const int alph = 26;

mt19937 mrand(random_device{} ()); 

template<typename T, typename U> inline llong umin(const T& a, const U& b) { return a < b ? a : b; }
template<typename T, typename U> inline llong umax(const T& a, const U& b) { return a > b ? a : b; }
 
static char buff[(int) 2e6 + 17]; // reads std::string
const int maxn = (int) 2e5 + 17;

int n, T;
int t[maxn];

bool read()
{
	if (scanf("%d %d", &n, &T) != 2)
		return false;

	forn (i, n)
		scanf("%d", t + i);

	return true;
}

void solve()
{
	int l = t[0], r = t[0] + T, ans = 0;

	forn (i, n - 1)
		if (t[i + 1] >= r)
		{
			ans += r - l;
			l = t[i + 1];
			r = t[i + 1] + T;
		}
		else
			r = t[i + 1] + T;

	printf("%d\n", ans + r - l);
}

int main()
{
#if SEREZHKA
	freopen("file.in", "r", stdin);
#endif

	while (read())
		solve();

	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?9e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	bool h=false;
	rep(i,s.size()-1)if(s[i]=='A'&&s[i+1]=='C')h=true;
	if(h)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
















Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+10;
const int mod=998244353;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

void inc(int &a,int b) { a=a+b>=mod?a+b-mod:a+b; }
void dec(int &a,int b) { a=a-b<0?a-b+mod:a-b; }

int n,a[N];

int qpow(int a,int b) {
	int ret=1;
	while(b) {
		if(b&1) ret=1ll*ret*a%mod;
		a=1ll*a*a%mod,b>>=1;
	}
	return ret;
}

void fwt() {
	for(int i=1;i<n;i<<=1)
		for(int p=i<<1,j=0;j<n;j+=p)
			for(int k=0;k<i;k++) {
				int x=a[j+k],y=a[j+k+i];
				a[j+k]=x,inc(a[j+k],y);
				a[j+k+i]=x,dec(a[j+k+i],y);
			}
}

int main() {
	cin>>n;n=1<<n;int s=0;
	for(int i=0;i<n;i++) a[i]=gi(),s+=a[i];
	s=qpow(s,mod-2);
	for(int i=0;i<n;i++) a[i]=1ll*a[i]*s%mod;
	fwt();a[0]=0;
	for(int i=1;i<n;i++) a[i]=qpow(a[i]-1,mod-2);
	fwt();
	puts("0");
	for(int i=1;i<n;i++) dec(a[i],a[0]),cout<<a[i]<<'\n';
	return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
char word_start(string s){
return s.at(0);
}
char word_end(string s){
return s.at(s.size()-1);
}
bool shiritori(vector<string>Y){
bool f=true;
  for(int i=1;i<Y.size();i++){
  if(word_start(Y.at(i))!=word_end(Y.at(i-1))){
  f=false;
  break;
  }
  }
return f;  
}
bool saim(vector<string>X){
bool k=true;  
for(int i=0;i<X.size();i++){
  for(int j=i+1;j<X.size();j++){
    if(X.at(i)==X.at(j)){
    k=false;
    break;
    } 
  }
  if(k==false){
  break;
  }  
}
return k;  
}
int main() {
  int a,i;
  cin >> a;
  vector<string>A(a);
  for(i=0;i<a;i++){
  cin >> A.at(i);
  }
if(saim(A)==false){
  cout << "No" << endl; 
}
else if(shiritori(A)==false){
  cout << "No" << endl;
}
else{
  cout << "Yes" << endl;
}   
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
int main(){
    char s1[200];
    char p[100];
    scanf("%s %s",s1,p);
    char s2[100];
    strcpy(s2,s1);
    strcat(s1,s2);

    if(strstr(s1,p)) printf("Yes\n");
    else printf("No\n");

    return 0;
}


Measured memory_bytes: 2744
#include <iostream>
int main()
{
    int n;
    std::cin >> n;
    if (n <= 111) {
        std::cout << 111 << std::endl;
    } else if (n <= 222) {
        std::cout << 222 << std::endl;
    } else if (n <= 333) {
        std::cout << 333 << std::endl;
    } else if (n <= 444) {
        std::cout << 444 << std::endl;
    } else if (n <= 555) {
        std::cout << 555 << std::endl;
    } else if (n <= 666) {
        std::cout << 666 << std::endl;
    } else if (n <= 777) {
        std::cout << 777 << std::endl;
    } else if (n <= 888) {
        std::cout << 888 << std::endl;
    } else if (n <= 999) {
        std::cout << 999 << std::endl;
    }
    return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    
    int ans = 1;
    for (int i = 0; i < n; i++) {
        if (ans <= k)
            ans *= 2;
        else
            ans += k;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3616
#include <vector>
#include <iostream>
#include <functional>
#include <utility>
#include <algorithm>
#include <set>

using namespace std;

/*void solve(int n) {
	vector<int> parent(n);
	for (int i = 0; i < n; i++) {
		parent[i] = -1;
	}
	function<int(int)> find = [&parent, &find](int x) {
		if (parent[x] < 0) {
			return x;
		}
		int root = find(parent[x]);
		parent[x] = root;
		return root;
	};
	auto uni = [&parent, &find](int x, int y) {
		int root_x = find(x);
		int root_y = find(y);
		if (root_x != root_y) {
			int size_x = -parent[root_x];
			int size_y = -parent[root_y];
			if (size_x > size_y) {
				parent[root_x] += parent[root_y];
				parent[root_y] = root_x;
			}
			else {
				parent[root_y] += parent[root_x];
				parent[root_x] = root_y;
			}
		}
	};
	auto finished = [&parent, &find]() {
		int r = find(0);
		for (int i = 1; i < parent.size(); i++) {
			if (r != find(i)) {
				return false;
			}
		}
		return true;
	};
	vector<vector<int>> available_people(31, vector<int>());

	for (int i = 0; i < n; i++) {
		int f;
		cin >> f;
		for (int j = 0; j < f; j++) {
			int day;
			cin >> day;
			available_people[day].push_back(i);
		}
	}
	for (int i = 1; i < 31; i++) {
		if (!available_people[i].empty()) {
			int root = available_people[i][0];
			for (int j = 1; j < available_people[i].size(); j++) {
				uni(root, available_people[i][j]);
			}
		}
		if (finished()) {
			cout << i << endl;
			return;
		}
	}
	cout << -1 << endl;
}
*/

void solve(int n) {
	vector<vector<int>> available_people(31, vector<int>());

	for (int i = 0; i < n; i++) {
		int f;
		cin >> f;
		for (int j = 0; j < f; j++) {
			int day;
			cin >> day;
			available_people[day].push_back(i);
		}
	}

	vector<set<int>> maps(n, set<int>());
	for (int i = 0; i < n; i++) {
		maps[i].insert(i);
	}

	auto check = [&maps, n]() {
		for (auto const& m : maps) {
			if (m.size() == n) {
				return true;
			}
		}
		return false;
	};

	for (int i = 1; i < 31; i++) {
		set<int> map;
		for (auto const& p : available_people[i]) {
			auto const& other = maps[p];
			map.insert(other.begin(), other.end());
		}
		for (auto const& p : available_people[i]) {
			maps[p] = map;
		}
		if (check()) {
			cout << i << endl;
			return;
		}
	}
	cout << -1 << endl;
}

int main() {
	int n;
	while (cin >> n && n) {
		solve(n);
	}
}

Measured memory_bytes: 3136
#include <iostream>

int main() {
  std::string s, t;
  std::cin >> s >> t;

  int32_t count = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s.at(i) != t.at(i)) {
      count++;
    }
  }

  std::cout << count << std::endl;
  return 0;
}


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

using namespace std;

string solve(string s, string t,int n){
	int num;

	for (int i = 0; i <= n; i++){
		//cout << s.substr(n - i, n) << " " << t.substr(0, i) << endl;
		if (s.substr(n - i , s.size()) == t.substr(0, i)){
			num = i;
		}
	}
	return s + t.substr(num, n);

}

int main(){
	int n;
	string s, t;

	cin >> n >> s >> t;

	cout << solve(s, t, n).size() << endl;
	//cin >> s;

	return 0;


}

Measured memory_bytes: 256
#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 n;cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    int odd=0;
    rep(i,n){
        if(a[i]%2==1) odd++;
    }
    if(odd%2==1) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}

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

const int N=300100;
pair<int,int>a[N],L[N],R[N];
int mx[N*4],tag[N*4],q1,q2,q3,n,W,H; 

void mdf(int o,int l,int r){
	if(q1<=l&&r<=q2){tag[o]+=q3;mx[o]+=q3;return;}
	int mid=(l+r)/2;
	if(q1<=mid)mdf(o*2,l,mid);
	if(q2>mid)mdf(o*2+1,mid+1,r);
	mx[o]=max(mx[o*2],mx[o*2+1])+tag[o];
}
int ans;
void solve(){
	memset(mx,0,sizeof mx);memset(tag,0,sizeof tag);
	sort(a+1,a+n+1);
	for(int i=1,jl=0,jr=0;i<n;++i){
		if(a[i].second*2<=H){
			int la=i-1;
			for(;jl&&L[jl].second<a[i].second;--jl){
				q1=L[jl].first;q2=la;q3=L[jl].second-a[i].second;
				mdf(1,1,n);la=q1-1;
			}
			if(la!=i-1)L[++jl]=make_pair(la+1,a[i].second);
		}else{
			int la=i-1;
			for(;jr&&R[jr].second>a[i].second;--jr){
				q1=R[jr].first;q2=la;q3=a[i].second-R[jr].second;
				mdf(1,1,n);la=q1-1;
			}
			if(la!=i-1)R[++jr]=make_pair(la+1,a[i].second);
		}
		L[++jl]=make_pair(i,0);R[++jr]=make_pair(i,H);
		q1=q2=i;q3=H-a[i].first;mdf(1,1,n);
		ans=max(ans,mx[1]+a[i+1].first);
	}
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>W>>H>>n;
	for(int i=1;i<=n;++i)cin>>a[i].first>>a[i].second;
	a[++n]=make_pair(0,0);a[++n]=make_pair(W,H);
	solve();
	for(int i=1;i<=n;++i)swap(a[i].first,a[i].second);swap(W,H);
	solve();
	cout<<(ans+ans)<<'\n';
	return 0;
}


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

using namespace std;

int a[202020];
int n,k;

int check(int x) {
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		cnt += (a[i] / x) - (a[i] % x == 0);
	}
	return cnt <= k;
}

int main() {
	scanf("%d%d",&n,&k);
	for (int i = 1; i <= n; i++) scanf("%d", a + i);

	int l = 1, r = 1000000000;

	while (l < r) {
		int ans = (l+r)/2;
		if (check(ans)) r = ans;
		else l = ans + 1;
	}

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


Measured memory_bytes: 4500
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
int main(){
    int a,b;
    cin >> a >> b;
    int x=min(a,b);
    int y=max(a,b);
    rep(i,y) cout << x;
    cout << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

#define MOD (int)1e9+7
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()

ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b>0)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }

return ans;
}



int main()
{

ll n,q;
cin>>n>>q;

string s;cin>>s;

vl dp(n+1,0);

s.insert(s.begin(),'B');

for(int i=1;i<=n;i++)
{
  dp[i]=dp[i-1];
  if(s[i]=='C'&&s[i-1]=='A')dp[i]++;

}



while(q--)
{
  ll a,b;
  cin>>a>>b;
  ll ans=dp[b]-dp[a];

  cout<<ans<<"\n";
}


return 0;

}


Measured memory_bytes: 1792
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

ll arr[100005];
map < ll, ll > mp;

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> n)
    {
		mp.clear();

		ans = 0;

		for(i = 1; i <= n; i++)
		{
			slld(arr[i]);

			ans += arr[i];

			mp[arr[i]]++;
		}

		slld(m);

		for(i = 1; i <= m; i++)
		{
			ll u, v;
			cin>> u >> v;

			ans -= mp[u] * u;

//			cout << ans << " " << mp[u] << " ";

			mp[v] += mp[u];

			ans += mp[u] * v;

			mp[u] = 0;

//			cout << ans << " " << mp[v] << " ";

			printf("%lld\n", ans);
		}


    }


}





Measured memory_bytes: 10460