akhauriyash/Code-Regression huggingface dataset:
#include "stdio.h"

int parts[3]={};
int query;
int flag[301] = {};
int first[1000] = {};
int second[1000] = {};
int third[1000] = {};
int result[1000] = {};
int num[3];
int box;
int dif;

int main() {
	scanf("%d %d %d", &parts[0], &parts[1], &parts[2]);
	while (parts[0] != 0) {
		scanf("%d", &query);
		for (int i = 1; i <= parts[0] + parts[1] + parts[2]; i++) flag[i] = 2;
		for (int i = 0; i < query; i++) {
			scanf("%d %d %d %d", &first[i], &second[i], &third[i], &result[i]);
			if (result[i] == 1) {
				flag[first[i]] = 1;
				flag[second[i]] = 1;
				flag[third[i]] = 1;
			}
		}
		for (int i = 0; i < query; i++) {
			if (result[i] == 0) {
				box = 0;
				if (flag[first[i]] == 1)box++;
				if (flag[second[i]] == 1)box++;
				if (flag[third[i]] == 1)box++;
				if (box == 2) {
					if (flag[first[i]] == 2)  flag[first[i]] = 0;
					if (flag[second[i]] == 2) flag[second[i]] = 0;
					if (flag[third[i]] == 2)  flag[third[i]] = 0;
				}
			}
		}
		for (int i = 1; i <= parts[0] + parts[1] + parts[2]; i++) {
			printf("%d\n", flag[i]);
		}
		scanf("%d %d %d", &parts[0], &parts[1], &parts[2]);
	}
	return 0;
}

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

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

const int INF = 1e9 + 7;

using namespace std;

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

    int x;
    cin >> x;

    if (x == 3 || x == 5 || x == 7)
	cout << "YES" << endl;
    else
	cout << "NO" << endl;
    
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_left
a, b, q = map(int, input().split())
INF = 10 ** 12
S = [int(input()) for i in range(a)]
S.append(INF)
T = [int(input()) for i in range(b)]
T.append(INF)
for _ in range(q):
    x = int(input())
    i = bisect_left(S, x)
    j = bisect_left(T, x)
    ans = []
    for y in [S[i-1],S[i]]:
        for z in [T[j - 1], T[j]]:
            ans.append(abs(x - y) + abs(y - z))
            ans.append(abs(x - z) + abs(z - y))
    print(min(ans))

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

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++)
    {
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    int cnt = 0;
    for (int k = 0; k <= d[n - 1]; k++)
    {
        int x = lower_bound(d.begin(), d.end(), k) - d.begin();
        if (x == n / 2)
            cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 768
//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
//#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
#define base 1000000000000000000ll
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=mul(ans,a,c);a=mul(a,a,c),b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ld pi = acos(-1);
const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=100000+10,maxn=2000000+10,inf=0x3f3f3f3f;

tuple<int,int,int>p[N];
int fa[N];
int Find(int x){return fa[x]==x?x:fa[x]=Find(fa[x]);}
int main()
{
    int n,m,q;scanf("%d%d%d",&n,&m,&q);
    for(int i=1;i<=n;i++)fa[i]=i;
    for(int i=1;i<=q;i++)
    {
        int a,b,c;scanf("%d%d%d",&a,&b,&c);
        a++,b++;
        p[i]=mt(a,b,c);
        if(!c)
        {
            a=Find(a),b=Find(b);
            if(a!=b)fa[a]=b;
        }
    }
    int num=0;
    for(int i=1;i<=q;i++)
    {
        int a,b,c;
        tie(a,b,c)=p[i];
        if(c)
        {
            num++;
            a=Find(a),b=Find(b);
            if(a==b)return 0*puts("No");
        }
    }
    int c=0;
    for(int i=1;i<=n;i++)c+=(fa[i]==i);
    if(!num)
    {
        if(c-1<=m-n+c&&m-n+c<=1ll*c*(c-1)/2)puts("Yes");
        else puts("No");
    }
    else
    {
        if(max(3,c)<=m-n+c&&m-n+c<=1ll*c*(c-1)/2)puts("Yes");
        else puts("No");
    }
    return 0;
}
/********************

********************/


Measured memory_bytes: 1792
//  Created by conan1024hao on 2019/11/19.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    vector<int> l(q),r(q);
    for(int i=0;i<q;i++){
        cin>>l[i]>>r[i];
    }
    int dp[100005];
    memset(dp,0,sizeof(dp));
    for(int i=0;i<n;i++){
        if(i)
        dp[i]+=dp[i-1];
        if(i==n-1)
            break;
        if(s[i]=='A'&&s[i+1]=='C'){
            dp[i+1]++;
        }
    }
    for(int i=0;i<q;i++){
        l[i]--;r[i]--;
        int ans=dp[r[i]]-dp[l[i]];
        cout<<ans<<endl;
    }
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


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

int main() {
  int N;
  cin >> N;
  int x = 0;
  
  for ( int i = 0 ; i < N ; i++ ) {
    int r , l ;
    cin >> l >> r;
    x += r - l + 1;
  }
  cout << x << endl;
}


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

int main(){
  string a;
  cin>>a;
int b,c,d;
  b=a.size();
  c=0;
  d=0;
  for(int i=0;i<b;i++){
  c=c*10+(a[i]-'0');
    d=d+(a[i]-'0');
  }
  
  if(c%d==0){
      cout<<"Yes"<<endl;
    }
else{
        cout<<"No"<<endl;
      }

}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n, i, j, l, m, s;

  
  int Adj[100][100];

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      Adj[i][j] = 0;
    }
  }

  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&l,&m);
    l--;
    for(j = 0 ; j < m ; j++){
      scanf("%d",&s);
      s--;
      Adj[l][s] = 1;
    }
  }

  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      if(j > 0) printf(" ");
      printf("%d",Adj[i][j]);
    }
    printf("\n");
  }

  return 0;
}



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

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

    int ans = 0;
    for (int i = 0; i < s.length(); i++){
        if (s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G'){
            int base = i;
            while (i < s.length()){
                if (s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G'){
                    ans = max(ans, i - base + 1);
                    i += 1;
                }
                else
                    break;
            }
        }
    }

    cout << ans << '\n';

    return 0;
}


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


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

  string s;
  cin >> s;
  
  int n=s.size();
  if(s[0]!='1' || s[n-1]!='0'){
    cout << -1 << endl;
    return 0;
  }
  rep(i,n){
    if(i>n-i-2) break;
    if(s[i]!=s[n-i-2]){
      cout << -1 << endl;
      return 0;
    }
  }
  int p=n;
  for(int i=n-1;i>=1;i--){
    cout << p << " " << i << endl;
    if(s[i-1]=='1') p=i;    
  }
  
  return 0;
    

}


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

int main(){
    int N, X, T;
    cin >> N >> X >> T;

    if (N % X  != 0)
    {
        cout << (N / X + 1)  * T;
    }else
    {
        cout << (N / X) * T;
    }
}


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

int main(){
  int N,M;
  int ppp, pp;
  cin >> N >> M;
  if (M==0){
    if(N==1){
      cout << 0 << endl;
    }
    else{
      cout << pow(10,N-1) << endl;
    }
    return 0;
  }
  vector<int> s(M);
  vector<int> c(M);
  for (int i=0; i<M; i++){
    cin >> s.at(i) >> c.at(i);
  }
  if (N==1){
    int c1 = c.at(0);
    for (int i=0; i<M; i++){
      c.at(i) -= c1;
      if (c.at(i)!=0){
        cout << -1 << endl;
        return 0;
      }
    }
    cout << c1 << endl;
  }
  else{
    int res = pow(10,N-1);
    int S,C;
    for (int i=0; i<M; i++){
      for (int j=0; j<M; j++){
        if (s.at(i)==s.at(j)){
          if (c.at(i)!=c.at(j)){
            cout << -1 << endl;
            return 0;
          }
        }
      }
    }
    for (int i=0; i<M; i++){
      S = s.at(i);
      C = c.at(i);
      if (S==1 && C==0){
        cout << -1 << endl;
        return 0;
      }
      ppp = pow(10,N-S+1);
      pp = pow(10,N-S);
      if (pp==0){
        cout << -1 << endl;
        return 0;
      }
      res = res - res%ppp/pp*pp + C*pow(10,N-S);
    }
    cout << res << endl;
  }
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, sum=0;
  cin >> A >> B;
  for(int i=A;i<B+1;i++){
    int a=i%10;
    int b=(i%100-a)/10;
    int c=(i%1000-i%100)/100;
    int d=(i%10000-i%1000)/1000;
    int e=(i-i%10000)/10000;
    if(a==e){
      if(b==d)
        sum+=1;
      else
        continue;
    }
    else
      continue;
  }
  cout << sum << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define fr first
#define sc second
#define pb push_back
const ll mod = 998244353;
const int N = 1e6+205;
void solve(){
	int n,k; 
	cin>>n>>k; 
	int idx = -1;
	for(int i=1;i<=n;i++){
		int x; 
		cin>>x; 
		if(x==1)idx = i;
	}
	int st = idx-1;
	int en = n-idx;
	int ans = st/(k-1);
	en+=st%(k-1);
	ans+=(en+k-2)/(k-1);
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


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

using namespace std;

typedef long long ll;

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

    for(int x = 1; x <= 100000; x++)
    {
        int a = (x * 8) / 100;
        int b = (x * 10) / 100;

        if(a == A && b == B)
        {
            return 0 * printf("%d\n", x);
        }
    }

    puts("-1");
}


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

using namespace std;

int main(){
  int n,k,x,y;
  int fee=0;
  cin>>n>>k>>x>>y;
  for(int i=0;i<n;i++){
    if(i>=k)fee+=y;
    else fee+=x;
  }
  cout<<fee<<endl;
  return 0;}


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

typedef long long ll;

ll N, a;

int main() {
  cin >> N;
  ll mi = 1LL<<60;
  for (int i = 0; i < 5; i++) {
    cin >> a;
    mi = min(mi, a);
  }

  cout << (N+mi-1)/mi + 4 << endl;
  return 0;
}


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

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;


//上から見ていく
//iからi+1が1以上増えているならiを1下げる

//最後に単非減少なら良い
int main() {
    int N;
    cin >> N;
    vector<int> H(N);
    for (int i = 0; i < N; i++) cin >> H[i];
    H[0]--;
    for (int i = 0; i < N - 1; i++) {
        if (H[i] + 1 <= H[i+1]) H[i+1]--;
    }
    bool flag = true;
    for (int i = 0; i < N-1; i++) {
        if (H[i] > H[i+1]) {
            flag = false;
            break;
        }
    }
    if (flag) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }


}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>

int main(int argc, char **argv)
{
    int N, L;
    std::cin >> N >> L;

    std::vector<std::string> S(N);

    for(int i = 0; i < N; i++){
        std::cin >> S.at(i);
    }

    std::sort(S.begin(), S.end());
    
    std::stringstream ss;
    for(int i = 0; i < N; i++){
        ss << S.at(i);
    }
    std::cout << ss.str() << std::endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define fi first
#define se second
#define fr(i,s,e) for(i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;

const int mxn=2e5+1;

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

  int t=1;
//  cin>>t;
  int tt=1;
  while(t--){
    int a,b;
    cin>>a>>b;
    if(a>9 or b>9)
      cout<<-1;
    else
      cout<<a*b;
      
   // cout<<"Case #"<<tt<<": ";
   // tt++;
    }
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ALL(n) n.begin(),n.end()
const ll MOD=1000000007;
const long double PI=3.14159265358979;

int main() {
  ll N,a,b,c,d,e;
  cin>>N>>a>>b>>c>>d>>e;
  ll m=min({a,b,c,d,e});
  ll ans=(N-1+m)/m;
  if(m>=N){
    cout<<5;
  }
  else{
    cout<<ans+4;
  }
  
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int modpow(int x, int n, int p)
{
    int ret = 1, m = x;
    while(n){
        if (n & 1){
            ret *= m;
            ret %= p;
        }
        m *= m;
        m %= p;
        n >>= 1;
    }
    return ret;
}

int modinv(int x, int p)
{
    return modpow(x, p-2, p);
}

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

    vector<vi> Power(p, vi(p, 1));
    rep(i, p)rep(j, p-1){
        Power[i][j+1] = Power[i][j]*i % p;
    }

    vector<int> fact(p), finv(p);
    fact[0] = fact[1] = 1;
    finv[0] = finv[1] = 1;
    for(int i=2; i<p; i++){
        fact[i] = fact[i-1]*i;
        fact[i] %= p;
        finv[i] = modinv(fact[i], p);
    }

    vi b(p, 0);
    rep(i, p){
        int a; cin>>a;
        if (a == 0) continue;
        b[0]++; b[0]%=p;
        rep(j, p){
            int C = (fact[p-1]*finv[j] % p)*finv[p-1-j] % p;
            C = -C; C += p;
            C *= Power[i][p-1-j]; C %= p;
            if ((p-1-j) % 2 == 1){
                C = -C; C += p;
            }
            b[j] += C; b[j] %= p;
        }
    }
    rep(i, p){
        cout << b[i] << " ";
    }
    cout << "\n";
	return 0;
}


Measured memory_bytes: 35584
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()

	ans := 100
	for i := 1; i*i <= N; i++ {
		if N%i == 0 {
			c := max(len(strconv.Itoa(i)), len(strconv.Itoa(N/i)))
			ans = min(ans, c)
			// out(i, N/i)
			// out(len(strconv.Itoa(i)), len(strconv.Itoa(N/i)))
		}
	}

	out(ans)
}


Measured memory_bytes: 640
using System;
using System.Linq;
class Program
{
    static void Main()
    {
        int[] input = Console.ReadLine().Split().Select(i => int.Parse(i)).ToArray(); 
        //int a=int.Parse(Console.ReadLine());
        //string a = Console.ReadLine();
        
        Console.WriteLine(input[0]-input[1]+1);
        Console.ReadLine();
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;
  cin >> n >> m;
  vector<int> k(m);
  vector<vector<int>> s(m,vector<int>(10));
  int tmp;
  int i,j;
  for(i=0;i<m;i++){
    cin >> k[i];
    for(j=0;j<k[i];j++){
      cin >> tmp;
      s[i][tmp-1] = 1;
    }
  }
  vector<int> p(m);
  for(i=0;i<m;i++){
    cin >> p[i];
  }
  int mp[10];
  int onoff = 0,ans = 0;
  int a,b,c,d,e,f,g,h,l;

  int y=0;

  for(a=0;a<2;a++){
    for(b=0;b<2;b++){
      if(n < 2 && b == 1){
        break;
      }
      for(c=0;c<2;c++){
        if(n < 3 && c == 1){
        break;
      }
        for(d=0;d<2;d++){
          if(n < 4 && d == 1){
        break;
      }
          for(e=0;e<2;e++){
            if(n < 5 && e == 1){
        break;
      }
            for(f=0;f<2;f++){
              if(n < 6 && f == 1){
        break;
      }
              for(g=0;g<2;g++){ 
                if(n < 7 && g == 1){
        break;
      }
                for(h=0;h<2;h++){    
                  if(n < 8 && h == 1){
        break;
      }
                  for(i=0;i<2;i++){
                  if(n < 9 && i == 1){
        break;
      }
                    for(j=0;j<2;j++){
                      if(n < 10 && j == 1){
        break;
      }
                        y=0;
                      
                      for(l=0;l < m;l++){
                        onoff = a * s[l][0] + b * s[l][1] + c * s[l][2] + d * s[l][3] + e * s[l][4] + f * s[l][5] + g * s[l][6] + h * s[l][7] + i * s[l][8] + j * s[l][9];

                        if(onoff % 2 == p[l]){
                          y++;
                        }
                        
                      }
                      if(y == m){
                        ans++;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  cout << ans << endl;
}

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

class Node{
private:
  int data;
  Node* next;
  Node* prev;
public:
  Node(int x){
    data=x;
  }
  void set_next(Node* n){next=n;}
  void set_prev(Node* p){prev=p;}
  int get_data(){return data;}
  Node* get_next(){return next;}
  Node* get_prev(){return prev;}
};

class Linked_List{
private:
  Node* first;
  Node* last;
public:
  Linked_List(){
    first=new Node(0);
    last=new Node(0);
    first->set_next(last);
    last->set_prev(first);
  }
  void insert(int x){
    Node* n=new Node(x);
    n->set_next(first->get_next());
    n->get_next()->set_prev(n);
    first->set_next(n);
    n->set_prev(first);
  }
  void LL_delete(int x){
    Node* p;
    p=first;
    while(p!=last->get_prev()){
      p=p->get_next();
      if(p->get_data()==x){
        p->get_next()->set_prev(p->get_prev());
        p->get_prev()->set_next(p->get_next());
        delete p;
        break;
      }
    }
  }
  void deleteFirst(){
    Node* p=first->get_next();
    first->set_next(first->get_next()->get_next());
    first->get_next()->set_prev(first);
    delete p;
  }
  void deleteLast(){
    Node* p=last->get_prev();
    last->set_prev(last->get_prev()->get_prev());
    last->get_prev()->set_next(last);
    delete p;
  }
  void out_all(){
    Node* p=first;
    while(p!=last->get_prev()){
      p=p->get_next();
      if(p!=last->get_prev())cout<<p->get_data()<<' ';
      else cout<<p->get_data();
    }
    cout<<endl;
  }
};
int main(){
  int n;string cmd;int key;
  cin>>n;
  Linked_List LL;
  for(int i=0;i<n;i++){
    cin>>cmd;
    if(cmd=="insert"){cin>>key;LL.insert(key);}
    else if(cmd=="delete"){cin>>key;LL.LL_delete(key);}
    else if(cmd=="deleteFirst")LL.deleteFirst();
    else if(cmd=="deleteLast")LL.deleteLast();
  }
  LL.out_all();
}



Measured memory_bytes: 34428
#include <iostream>
#include <cstring>
using namespace std;
const int INF = 1e9;
int m, n;
int c[21];
int dp[21][100005];

int dfs(int i, int sum) {
  if (i == m) return n == sum ?  0 : INF;
  if (dp[i][sum] != -1) return dp[i][sum];
  int ret = dfs(i + 1, sum);
  if (sum + c[i] <= n) ret = min(ret, dfs(i, sum + c[i]) + 1);
  return dp[i][sum] = ret;
}

int main() {
  for (int i = 0; i < 21; i++) for (int j = 0; j < 100005; j++) dp[i][j] = -1;
  cin >> n >> m;
  for (int i = 0; i < m; i++) cin >> c[i];
  cout << dfs(0, 0) << endl;
}

Measured memory_bytes: 13640
// template version 1.0
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

#define infile "../test/sample-1.in"
#define int long long
// #define INF 2147483647
#define INF 1000000000000000000LL
#define MOD 1000000007LL

// {{{ define basic macro
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)

#define foreach(x,a) for(auto& (x) : (a) )
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)

#define all(x) (x).begin(),(x).end()
#define sum(v) accumulate(all(v), 0)
#define sz(x) ((int)(x).size())
template<class T> inline void chmax(T &a, const T &b) { if(a < b) a = b; }
template<class T> inline void chmin(T &a, const T &b) { if(a > b) a = b; }
// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
#define fill(x,y) memset(x,y,sizeof(x))
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ten(n) ((int)1e##n)

template <class T = int>
T in() {T x; cin>>x; return (x);}

struct Fast {
  Fast(){
    std::cin.tie(0);
    ios::sync_with_stdio(false);
  }
} fast;
// }}}
//{{{ dump macro
#ifdef PCM
  #include "dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}
//{{{ others
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;
template<typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;

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


int solve(){
  int k;cin>>k;

  int a=0;
  int b=0;
  rep(i, 1, k+1){
    if (i%2) a++;
    else b++;
  }
  cout << a*b << endl;

  return 0;
}

int test(){ //{{{
  return 0;
}
//}}}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
#ifdef PCM
  test();
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 256
#include <cstdio>
#include <stdint.h>

int64_t sum, gcd;

void count(int64_t n, int64_t x) {
		
	if(x == 0) {
		gcd = n;
		return ;
	}
	else sum += (n / x) * 2 * x;
	
	count(x, n % x);
}

int main() {
	int64_t n, x;
	scanf("%lld%lld", &n, &x);
	
	count(n - x, x);
	
	printf("%lld\n", sum + n - gcd);
		
	return 0;
}

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

using namespace std;

typedef long long int64;

int main()
{
  int64 N, H[40001], A[40001], D[40001], S[40001];

  scanf("%lld", &N);
  for(int i = 0; i < N + 1; i++) {
    scanf("%lld %lld %lld %lld", H + i, A + i, D + i, S + i);
  }

  int64 ret = 0;
  int64 turn = 0;
  vector< pair< int64, int64 > > xs;
  for(int i = 1; i <= N; i++) {
    int64 GetDamage = A[i] - D[0];
    int64 AddDamage = A[0] - D[i];

    if(GetDamage <= 0) continue;
    if(S[i] > S[0]) ret += GetDamage;
    if(AddDamage <= 0) {
      puts("-1");
      return (0);
    }

    xs.emplace_back((H[i] + AddDamage - 1) / AddDamage, GetDamage);
    turn += GetDamage;
  }


  sort(begin(xs), end(xs), [](const pair< int64, int64 > &a,
                              const pair< int64, int64 > &b)
  {
    return (a.first * b.second < b.first * a.second);
  });

  for(auto &p : xs) {
    ret += turn * p.first - p.second;
    if(ret >= H[0]) {
      puts("-1");
      return (0);
    }
    turn -= p.second;
  }

  printf("%lld\n", max(-1LL, ret));
}

Measured memory_bytes: 4940
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0; i<n; i++) {
            a[i] = sc.nextInt();
        }
        long min = Long.MAX_VALUE;
        long tmp = 0;
        long cnt = 0;
        for(int i = 0; i<n; i++) {
            tmp+=a[i];
            System.err.println(i+" "+tmp);
            if(i%2==0) {
                if(tmp<=0) {
                    cnt += 1 - tmp;
                    tmp = 1;
                }
            }else {
                if(tmp>=0) {
                    cnt += tmp + 1;
                    tmp = -1;
                }
            }
        }
        min = cnt;
        cnt = 0;
        tmp = 0;
        System.err.println(min);
        for(int i = 0; i<n; i++) {
            tmp+=a[i];
            if(i%2==1) {
                if(tmp<=0) {
                    cnt += 1 - tmp;
                    tmp = 1;
                }
            }else {
                if(tmp>=0) {
                    cnt += tmp + 1;
                    tmp = -1;
                }
            }
        }
        min = Math.min(min, cnt);
        System.out.println(min);
    }
}


Measured memory_bytes: 65428
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
int main()
{
    int n,a,b;
    cin>>n>>a>>b;
    for(int i = a; i <= b; i++){
        if(i % n == 0){
            printf("OK");
            return 0;
        }
    } 
    printf("NG");
    return 0;
}


Measured memory_bytes: 3636
package main

import (
  "fmt"
)

func main() {
  solve()
}

func solve() {
  var n, m int
  fmt.Scan(&m, &n)
  
  var re int
  re += nCr(n,2)
  re += nCr(m,2)
  fmt.Println(re)
}

func nCr(n, r int) int {
  return n*(n-1) / (r * (r-1))
}

func factrial(n int) int {
  var fac int = 1
  for i:=1; i <= n; i++ {
    fac *= i
  }
  return fac
}

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

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] rank = new int[n];
			int[] point = new int[n];
			for(int i = 0 ; i < n ; i++) {
				rank[i] =  sc.nextInt();
				point[i] =  sc.nextInt();
			}
			Arrays.sort(rank);
			Arrays.sort(point);
			int top = rank[0] - 1;
			int bottom = point[0];
			int middlePoint = point[point.length - 1] - point[0] + 1;
			int middleRank = rank[rank.length - 1] - rank[0] + 1;
			int middle = Math.min(middlePoint, middleRank);
			System.out.println(top + bottom + middle);
		}

	}

}


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

int main(){
  char A,B;
  cin>>A>>B;
  if(A<B){
    cout<<'<'<<endl;
  }else if(A>B){
    cout<<'>'<<endl;
  }else{
    cout<<'='<<endl;
  }
}


Measured memory_bytes: 256
/* created   : 2019-08-29 00:22:08
 * accepted  : 2019-08-29 00:30:01
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int n; cin >> n;
  double ans = 0;
  for (int i = 0; i < n; i++) {
    int x; cin >> x;
    ans += 1.0 / x;
  }
  cout << 1.0 / ans << '\n';
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(20);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,suma=0;
		cin>>n;
		int o1[n],o2[n];
		for (int i=0;i<n;i++){
			cin>>o1[i];}
		for (int i=0;i<n;i++){
			cin>>o2[i];}
		
		for (int i=0;i<n;i++){
			if(o1[i]>o2[i]){
				suma=suma+(o1[i]-o2[i]);
			}
			}
		cout<<suma;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstring>
#include <deque>
#include <stack>
#include <stdio.h>
#include <map>
#include <set>
#include <time.h>
#include <string>
#include <fstream>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <assert.h>
#include <list>
#include <unordered_map>
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define pdd pair<double,double>
#define pii pair<ll,ll>
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD2 1000000009
#define INF ((ll)1e+18)
#define x1 fldgjdflgjhrthrl
#define x2 fldgjdflgrtyrtyjl
#define y1 fldggfhfghjdflgjl
#define y2 ffgfldgjdflgjl
#define SQ 317
#define MAG 33554431
#define RED 0
#define BLUE 1
#define ALP 26
typedef long long ll;
typedef long double ld;
using namespace std;
ll i,j,k,l,m,r,x,y,K,tot,sz,cur,sum,n,c, maxlvl,q,z,N,ans;
vector<ll> f;
ll a[45];
ll comb[45];
ll pre[22] = {1, 2, 6, 20, 70, 252, 924, 3432, 12870, 48620, 184756, 705432, 2704156, 10400600, 40116600, 155117520, 601080390, 2333606220, 9075135300, 35345263800, 137846528820, 5382578744400};
ll C(ll n, ll m)
{
    ll x = m, y = n-m;
    if (x > y)
        swap(x, y);
    ll ans = 1;
    for (int i = y+1; i <= n; i++)
        ans *= i;
    for (int i = 1; i <= x; i++)
        ans /= i;
    return ans;
}
int main() {
	//freopen("input.txt","r",stdin);
 	//freopen("input.txt","w",stdout);
    cin >> n;
    for (i = 40; i >= 1; i--)
        if ((1LL<<i-1)-1 <= n)
            break;
    m = i;
    if (n == (1LL<<m-1)-1)
    {
        cout << m << endl;
        for (i = 0; i < m; i++)
        {
            if (i != 0)
                cout << " ";
            cout << 1;
        }
        cout << endl;
        return 0;
    }
    n -= (1LL<<m-1)-1;
    for (i = 0; i <= m/2; i++)
    {
        for (j = 0; j <= min(i,m-i); j++)
            comb[i] += C(i,j)*C(m-i,j);
    }
    k = 1;
    for (i = m/2; i >= 0; i--)
    {
        while (n >= comb[i])
        {
            n -= comb[i];
            a[i]++;
            k++;
        }
    }
    x = k;
    for (i = 0; i < m; i++)
    {
        while (a[i])
        {
            a[i]--;
            f.push_back(k--);
        }
        f.push_back(1);
    }
    for (i = 2; i <= x; i++)
        f.push_back(i);
    //cout << m << endl;
    cout << f.size() << endl;
    for (i = 0; i < f.size(); i++)
    {
        if (i != 0)
            cout << " ";
        cout << f[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
K = int(input())
V = []
for i in range(1, 150):
    for j in range(15):
        val = str(i) + '9' * j
        V.append(int(val))
V = list(set(V))
V.sort()
# print(V)


# メモ化再起
from functools import lru_cache
@lru_cache(maxsize=10000000)
def f(n):
    s = sum([int(x) for x in list(str(n))])
    return n / s

ret = []
for n in range(len(V)):
    isOK = True
    for m in range(n + 1, len(V)):
        if f(V[n]) > f(V[m]):
            isOK = False
            break
    if isOK:
        ret.append(str(V[n]))

print(" ".join(ret[:K]))


Measured memory_bytes: 56536
#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>
#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<double,int,double> 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;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int MOD;
vvi mul(vvi A,vvi B){
	vvi C(A.size(),vi(B[0].size()));
	rep(i,A.size())rep(k,B.size())rep(j,B[0].size())
		(C[i][j]+=A[i][k]*B[k][j])%=MOD;
	return C;
}
vvi pow(vvi A,ll n){
	vvi B(A.size(),vi(A.size()));
	rep(i,A.size())B[i][i]=1;
	while(n){
		if(n&1)B=mul(B,A);
		A=mul(A,A);
		n>>=1;
	}
	return B;
}
int main(){
	int n,a,b,c,t;
	while(cin>>n>>MOD>>a>>b>>c>>t,n){
		vi in(n);
		rep(i,n)cin>>in[i];
		vvi A(n,vi(n));
		rep(i,n){
			if(i)A[i][i-1]=a;
			A[i][i]=b;
			if(i<n-1)A[i][i+1]=c;
		}
		A=pow(A,t);
		rep(i,n){
			if(i)cout<<" ";
			int sum=0;
			rep(j,n)(sum+=A[i][j]*in[j])%=MOD;
			cout<<sum;
		}
		cout<<endl;
	}
}

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

typedef uint32_t u32;
typedef uint64_t u64;
typedef std::pair<int, int> pii;

int t1[20000];
int t2[20000];
bool used[20000];
int n;

void solve(int t) {
  int mini = -1;
  int min = 1000000;
  for(int i = 0; i < n; ++i) {
    if( used[i] ) continue;
    if( t <= t1[i] ) {
      if( min > t1[i] ) {
        min = t1[i];
        mini = i;
      }
    }
  }
  if( mini != -1 ) {
    used[mini] = true;
    solve(t2[mini]);
  }
  return;
}
  
int main() {

  for(;;) {
    int h1, m1, s1, h2, m2, s2;
    scanf("%d", &n);
    if( n == 0 ) break;
    for(int i = 0; i < n; ++i) {
      scanf("%d:%d:%d %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
      t1[i] = h1 * 3600 + m1 * 60 + s1;
      t2[i] = h2 * 3600 + m2 * 60 + s2;
    }
    for(int i = 0; i < n; ++i) used[i] = false;
    int res = 0;
    for(;;) {
      for(int i = 0; i < n; ++i) {
        if( not used[i] ) {
          solve(0);
          res += 1;
          goto label_1;
        }
      }
      break;
    label_1:;
    }
    std::cout << res << std::endl;
  }      

  return 0;
}

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

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

  ll x;
  cin >> x;

  for (ll i = -1000; i <= 1000; i++) {
    for (ll j = -1000; j <= 1000; j++) {
      if(pow(i, 5) - pow(j, 5) == x) {
        cout << i << " " << j << '\n';
        return 0;
      }
    }
  }
}

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

int main() {

  int N;
  cin >> N;
 
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  for (int i = 0; i < N; i++) {
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  long long answer = A[0];

  for (int i = 1; i < N; i++) {
    long long a = 1000000000000000000 / answer;
    if (a < A[i]) {
      cout << -1 << endl;
      return 0;
    } else {
      answer *= A[i];
    }
  }

  cout << answer << endl;

}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
typedef long long ll;
int S, W;
int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin >> S >> W;
	if(S<=W){
		cout << "unsafe" << nl;
	}else{
		cout << "safe" << nl;
	}
	return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, B;
  int pl1, pl2;
  cin >> N >> A >> B;
  pl1 = A * N;
  pl2 = B;
  if (pl1 <= pl2){
    cout << pl1 << endl; 
  }
  else{
    cout << pl2 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int Inf = 1e9+7;
const int Mod = 1e9+7;

bool taken[2505][2505];

int main ()
{
	int k, s;
	cin >> k >> s;
	int cnt = 0;
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			int l = s-(i+j);
			if (l < 0 || l > k) {
				continue;
			}
			if (!taken[i][j]) {
				taken[i][j] = true;
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
#define INFTY 10000000000
typedef long long int ll;
const int MOD=1000000007;
using Graph = vector<vector<int>>;
using ipair = pair<ll,ll>;
bool operator< (const ipair a, const ipair b){return a.first < b.first;};
#define rep(i,n) for (ll i = 0; i < (n); ++i)
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
    int n;cin>>n;
    vector<int> a(n),cnt(100003,0);
    rep(i,n){cin>>a[i];cnt[a[i]]++;}
    int q;cin>>q;
    vector<int> b(q),c(q);
    rep(i,q){
        cin>>b[i]>>c[i];
    }
    ll sum = 0;
    rep(i,n)sum += a[i];
    
    rep(i,q){
        sum += (c[i]-b[i]) * cnt[b[i]];
        cnt[c[i]] += cnt[b[i]];
        cnt[b[i]] = 0;
        cout<<sum << endl; 
    }
    
    return 0;
}

Measured memory_bytes: 4828
a, b, c, k = [int(i) for i in input().split()]
ans = 0
if a > k:
    ans += k
    print(ans)
    exit()

ans += a
k -= a
if k < 0:
    print(ans)
    exit()

k -= b
if k < 0:
    print(ans)
    exit()

ans += (-1*k)
print(ans)


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define debug2(x,y) cout<<"("<<#x<<","<<#y<<") = ("<<(x)<<","<<(y)<<")\n"
using vi = vector<int>;
using vvi = vector<vi>;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define rep(i, n) for(int i=0; i<(int)n; i++)

namespace /*DAG.cpp*/{
  int N,M; //頂点と辺の数
  vector<vector<int>> G; //グラフ
  vector<int> h; //入次数 : topoBFS
  vector<int> l_depth; //最大経路長 //recDFSでは探索済みかどうかも示す
  vector<int> s_depth; //最短経路長
  vector<int> ans; //答えを格納(recDFSではreverse必要)

  void topoBFS(){    
    queue<int> unchecked;
    for(int i=0; i<N; i++){
      if(h[i]==0){
        unchecked.push(i);
        l_depth[i] = 0;
        s_depth[i] = 0;
      }
    }
    while(!unchecked.empty()){
      int current = unchecked.front();
      unchecked.pop();
      ans.push_back(current+1);
      for(int next: G[current]){
        h[next]--;

        l_depth[next] = max(l_depth[next], l_depth[current]+1); //最長経路長
        s_depth[next] = min(s_depth[next], s_depth[current]+1); //最短経路長

        if(h[next]==0){
          unchecked.push(next);
        }
      }
    }
  }
}


int main(){
  int n;
  cin>>n;
  vvi IDs(n, vi(n, -1));
  N = n*(n-1)/2;
  G.resize(N);
  h.resize(N, 0);

  int id = 0;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      IDs[i][j] = id;
      IDs[j][i] = id;
      id++;
    }
  }
  /*
  rep(i,n){
    rep(j,n){
      cout<<IDs[i][j]<<",";
    }
    cout<<endl;
  }
  debug(G.size());
  //*/
  int t, bufid, vsid;
  for(int i=0; i<n; i++){
    cin>>t;t--;
    bufid = IDs[i][t];
    for(int j=1; j<n-1; j++){
      cin>>t;t--;
      vsid = IDs[i][t];

      G[bufid].pb(vsid);
      h[vsid]++;

      bufid = vsid;
    }
  }

  /*
  for(int i=0; i<N; i++){
    debug2(i, h[i]);
  }
  */

  l_depth.resize(N, -1);
  s_depth.resize(N, N);
  topoBFS();
  /*
  for(int x: ans){
    cout<<x<<",";
  }cout<<" -> ";
  */
  bool isDAG = ans.size()==N;
  //cout<<(isDAG? "閉路なし": "閉路あり")<<endl;
  if(isDAG){
    int l_max = *max_element(l_depth.begin(), l_depth.end());
    cout<<l_max+1<<endl;
  }else{
    cout<<-1<<endl;
  }
}

Measured memory_bytes: 39544
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
    if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
    }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



int main() {

  int a,b,c,d,e;
  cin >> a>>b>>c>>d>>e;
  
  int x;
  if(a==c) x=d-b;
  else x=(60*c+d)-(60*a+b);

  cout << x-e << endl;

  
}


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

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

using ll = long long;
#define INF 1e9

double a, b, x;
int main(){
  cin >> a >> b >> x;
  int V = a*a*b;
  if(V == x){
    cout << 0 << endl;
    return 0;
  }
  double height = (double) x /(a*a);
  double sheight = (double) 2*height - b;
  if(sheight > 0){
    x -= a*a*sheight;
    b -= sheight;
    // cout << "sheight: " << sheight << endl;
    // cout << "b: " << b << endl;
  }
  else{
  }
  double ans = atan((double)2*x/(b*b*a));
  ans = 90 - 180 * (ans/M_PI);
  //cout << 90 - 180 * (ans / M_PI) << endl;
  printf("%.9f\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n,m) for(int i=n;i<(int)(m);i++)
#define rrep(i,n,m) for(int i=((int)(n)-1);i>=m;i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<pair<int,int>> vec(n);
    rep(i,0,n){
        int r,s;
        cin>>r>>s;
        vec[i]=make_pair(r,s);
    }
    sort(all(vec),greater<pair<int,int>>());
    
    cout<<vec[0].first+vec[0].second<<endl;
}


Measured memory_bytes: 1024
from functools import reduce

N, M = list(map(int,input().split()))

_dict={}

for i in range(N):
  _dict[i] = set(map(int, input().split()[1:]))
  
A = set(range(1, M+1))
A0 = set(range(1, M+1))

def aa(setA, setB):
  return setA & setB
  
print(len(reduce(aa, _dict.values(), A0)))

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int solve(string &s, string &t){
    int n = s.size(), m = t.size();
    int minCost = INT_MAX;
    for(int i=0; i<n; i++){
        int currCost = 0;
        int j;
        for(j=0; j<m and i+j<n; j++){
            if(s[i+j] != t[j])
                currCost++;
        }
        if(j==m and currCost < minCost)
            minCost = currCost;
    }
    return minCost;
}

int main()
{
 string s, t;
 cin>>s>>t;
 int ans = solve(s, t);
 cout<<ans;
 return 0;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define pb push_back
#define pi pair<int, int>
#define fastio  ios_base::sync_with_stdio(false);  cin.tie(NULL);

using namespace std;
const ll mod = 1e9+7;
/*
    c a b
*/
int g() {
    return puts("GREATER"), 0;
}
int l() {
    return puts("LESS"), 0;
}
int main() {
    fastio
    string a, b;
    cin >> a >> b;
    if(a.length() > b.length()) {
        cout << "GREATER";
        return 0;
    }
    else if(a.length() < b.length()) {
        cout << "LESS";
        return 0;
    }
    else {
        for(int i=0; i<a.length(); i++) {
            int x = a[i] - '0';
            int y = b[i] - '0';
            if(x > y) {
                cout << "GREATER";
                return 0;
            }
            else if(y > x) {
                cout << "LESS";
                return 0;
            }
        }
    }
    cout << "EQUAL";
}

/*

*/

Measured memory_bytes: 256
N = int(input())
dic = []
ls = [[] for i in range(N)]
for i in range(N):
  a = int(input())
  dic += [a]
  for j in range(a):
    x, y = map(int, input().split())
    ls[i] += [(x-1,y)]
ans = 0
for i in range(2**N):
  inf = []
  m = 0
  for j in range(N):
    if i%2==0:
      inf += [1]
      m += 1
    else:
      inf += [0]
    i >>= 1
  flag = False
  for j in range(N):
    if inf[j]==0:
      continue
    for h in range(dic[j]):
      x, y = ls[j][h]
      if inf[x]!=y:
        flag = True
        break
    if flag:
      break
  else:
    if ans<m:
      ans = m
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int k = sc.nextInt();
        
        int[] left = new int[n];
        for (int i = 0; i < n; i++) {
            left[i] = sc.nextInt();
        }
        int[] right = new int[m];
        for (int i = 0; i < m; i++) {
            right[i] = sc.nextInt();
        }
        
        long[] suml = new long[n+1];
        for (int i = 1; i <= n; i++) {
            suml[i] = suml[i-1] + left[i-1];
        }
        long[] sumr = new long[m+1];
        for (int i = 1; i <= m; i++) {
            sumr[i] = sumr[i-1] + right[i-1];
        }
        
        long tmpl = 0;
        int tmpi = -1;
        for (int i = 0; i < n; i++) {
            if (tmpl + left[i] <= k) {
                tmpl += left[i];
            } else {
                break;
            }
            tmpi = i;
        }
        
        long tmpr = 0;
        int tmpj = -1;
        for (int j = 0; j < m; j++) {
            if (tmpl + tmpr + right[j] <= k) {
                tmpr += right[j];
            } else {
                break;
            }
            tmpj = j;
        }
        
        
        int max = tmpi + 1 + tmpj + 1;
        if (tmpi != -1) {
            tmpl -= left[tmpi];
        }
        tmpi--;
        for (int i = tmpi; i >= -1; i--) {
            max = Math.max(max, i + 1 + tmpj + 1);
            
            for (int j = tmpj+1; j < m; j++) {
                if (tmpl + tmpr + right[j] <= k) {
                    tmpr += right[j];
                } else {
                    break;
                }
                tmpj = j;
                max = Math.max(max, i + 1 + j + 1);
            }
            
            if (i == -1) break;
            tmpl -= left[i];
        }
        
        System.out.println(max);
    }
}

Measured memory_bytes: 61348