akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

char a[128][128];
int cnt[1024];

vector<int> f(vector<int> v) {
	vector<int> ret;
	for (int u : v) if (u) ret.push_back(u);
	return ret;
}

void calc(int n, int m, vector<int> v) {
//	cerr << n << " " << m << endl;
//	for (int u : v) cerr << u << " "; cerr << endl << endl;
	if (n % 2 == 0 && m % 2 == 0) {
		for (int u : v) if (u % 4 != 0) return;
		cout << "Yes" << endl;
		exit(0);
	}
	if ((n & 1) && (m & 1)) {
		bool flg = 0;
		for (auto &it : v) if (it & 1) {
			it--;
			v = f(v);
			flg = 1;
		}
		if (flg == 0) return;
		for (int u : v) if (u & 1) return;
		for (int times = 0; times < (n + m - 2) / 2; times++) {
			sort(v.begin(), v.end(), [](int u, int v) {
				return u % 4 > v % 4;
			});
			v[0]-=2;
			v = f(v);
		}
		for (int u : v) if (u % 4 != 0) return;
		calc(n - 1, m - 1, v);
		return;
	}
	if (n & 1) {
		for (int times = 0; times < m / 2; times++) {
			sort(v.begin(), v.end(), [](int u, int v) {
				return u % 4 > v % 4;
			});
			v[0]-=2;
			v = f(v);
		}
		for (int u : v) if (u % 4 != 0) return;
		calc(n - 1, m, v);
		return;
	}
	if (m & 1) {
		for (int times = 0; times < n / 2; times++) {
			sort(v.begin(), v.end(), [](int u, int v) {
				return u % 4 > v % 4;
			});
			v[0]-=2;
			v = f(v);
		}
		for (int u : v) if (u % 4 != 0) return;
		calc(n, m - 1, v);
		return;
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> a[i]; 
	for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) cnt[a[i][j]]++;
	vector<int> v;
	for (int i = 0; i < 256; i++) if (cnt[i]) v.emplace_back(cnt[i]);
	calc(n, m, v);
	cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,b,n) for(int i=b;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define all(obj) (obj).begin(),(obj).end()
const int mod = 1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;cin>>a>>b;
    if(a<2*b)cout<<0<<endl;
    else cout<<a-2*b<<endl;
    return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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; }

void func(long long N, long long M, std::vector<std::vector<long long>> A){

    set<lli> s;
    REP(i,0,M)s.insert(i+1);

    lli ans = INF;

    while(s.size()){
        map<lli,lli> cnt;
        REP(i,0,N){
            REP(j,0,M){
                if(s.find(A[i][j]) != s.end()){
                    cnt[A[i][j]]++;
                    break;
                }
            }
        }
        lli maxSize=-1;
        lli maxIndex = -1;
        for(auto e:cnt){
            if(e.second > maxSize){
                maxSize = e.second;
                maxIndex = e.first;
            }
        }
        chmin(ans,maxSize);
        s.erase(maxIndex);
    }
    cout<<ans<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<std::vector<long long>> A(N, std::vector<long long>(M));
    for(int i = 0 ; i < N ; i++){
        for(int j = 0 ; j < M ; j++){
            scanf("%lld",&A[i][j]);
        }
    }
    func(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 4416
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AF solver = new AF();
        solver.solve(1, in, out);
        out.close();
    }

    static class AF {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt();
            if (a * b == 15) {
                out.println("*");
            } else if (a + b == 15) {
                out.println("+");
            } else {
                out.println("x");
            }
        }

    }
}



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

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define fr(i,k,n) for (int i = k; i < n; ++i)
#define fri(i,k,n) for (int i = k; i >= n; --i)
#define INF (int)1e9
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define all(arr) arr.begin(),arr.end()

void boost(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve(){
  ll n,d;
  cin>>n>>d;
  pll arr[n];
  fr(i,0,n){
    cin>>arr[i].first>>arr[i].second;
  }
  int cnt=0;
  fr(i,0,n){
    if((arr[i].first*arr[i].first)+(arr[i].second*arr[i].second) <=(d*d)){
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return;
}

int main()
{
  boost();
  
  int tc=1;
  //cin>>tc;
  while(tc--)
    solve();
  return 0;
}

Measured memory_bytes: 6764
#include <stdio.h>
int main(){
	
	int a,b,c;
	int c5=0,c7=0;
	
	scanf("%d %d %d",&a,&b,&c);
	if(a==5) c5++;
	if(b==5) c5++;
	if(c==5) c5++;
	if(a==7) c7++;
	if(b==7) c7++;
	if(c==7) c7++;
	
	if(c5==2&&c7==1) printf("YES");
	else printf("NO");
	
}

Measured memory_bytes: 128
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <cstring>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>
#define inf  1000000000
#define mod  1073741824
#pragma GCC optimization ("O3")
using namespace std;
const long long int N = 6999999;
#define all(x) begin(x),end(x)
long long int dp[51][2700][51];
long long int ways(int n,long long int s,int c,vector <int> &v,int k)
{
	if(n < 0)
		return 0;
	if(n == 0)
	{
		if (c == 0)
			return 0;
		int rem = s % c;
		if (rem != 0)
			return 0;
		int avg = s/c;
		if (avg == k){
			return 1;
		}
	}
	if(dp[n][s][c] != -1)
		return dp[n][s][c];
	long long int dnpick = ways(n-1,s,c,v,k);
	long long int pick = ways(n-1,s+v[n],c+1,v,k);
	long long int t = pick + dnpick;
	dp[n][s][c] = t;
	return t;
}
long long int way(int n,int k,vector <int>&v1)
{
	vector<int> v;
	v.push_back(-1);
	for (int i = 0; i < n; ++i)
	{
		v.push_back(v1[i]);
	}
	memset(dp,-1,sizeof(dp));
	long long int ans = ways(n,0,0,v,k);
	return ans;
}
int main()
{
   
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    //ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  	int n,k;
  	cin >> n >> k;
  	vector <int> v1(n);
  	for (int i = 0; i < n; ++i)
  	{
  		cin >> v1[i];
  	}
  	cout << way(n,k,v1);
  	// for (int i = 1; i < 4; ++i)
  	// {
  	// 	for (int j = 1; j < 3; ++j)
  	// 	{
  	// 		/* code */
  	// 	}
  	// }	
  	return 0;
}	

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

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

#define INF 100000000

int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  rep(i,N) cin >> X.at(i);
  sort(X.begin(), X.end());
  int start = X.at(0);
  int goal = X.at(N-1);
  int64_t ans = INF;
  for(int i = start; i <= goal; ++i){
    int64_t total_cost = 0;
    for(int j = 0; j < N; ++j){
      total_cost += (int64_t)(i - X.at(j)) * (i - X.at(j));
    }
    ans = min(ans, total_cost);
  }
  cout << ans << endl;
  return 0;
}

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

int N, cnt = 0;

void dfs(ll n,int f){
    if(n>N)
        return;
    if(n <= N && f == 7)
        cnt++;
    dfs(n * 10 + 3, f | 1);
    dfs(n * 10 + 5, f | 2);
    dfs(n * 10 + 7, f | 4);
}

int main() {
    cin >> N;
    dfs(0, 0);
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	int a,b;
	cin>>a>>b;
	if(a>0){
		cout<<"Positive"<<endl;
	}
	if(a<=0){
		if(b>=0){
			cout<<"Zero"<<endl;
		}
		else{
			cout<<(((b-a+1)&1)? "Negative":"Positive")<<endl;
		}
	}
	return 0;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> to(n);
  rep(i, m) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  vector<bool> seem(n, false);
  int block = 0;
  rep(i, n) {
    if(seem[i])
      continue;

    seem[i] = true;
    queue<int> q;
    q.push(i);
    while(!q.empty()) {
      int now = q.front();
      q.pop();
      for(int j : to[now]) {
        if(seem[j] == false) {
          seem[j] = true;
          q.push(j);
        }
      }
    }
    block++;
  }

  cout << block - 1;
}


Measured memory_bytes: 8540
from scipy.sparse.csgraph import floyd_warshall
H,W = map(int, input().split() )

C=[list(map(int,input().split())) for i in range(10)]
A=[list(map(int,input().split())) for i in range(H)]

d = floyd_warshall(C)
cnt = 0
for arr in A:
  for i in arr:
    if i != -1:
      cnt += d[i][1]
      
print(int(cnt))

Measured memory_bytes: 17984
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.text.BreakIterator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	static int[] dx = new int[] { -1, 0, 1, 0, -1, -1, 1, 1 };
	static int[] dy = new int[] { 0, 1, 0, -1, -1, 1, -1, 1 };
	static int A, B, C;

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st = new StringTokenizer(br.readLine());
		n = Integer.parseInt(st.nextToken());
		st = new StringTokenizer(br.readLine());
		a = new int[n];
		ans = new int[n];
		l = new int[n];
		adj = new ArrayList[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(st.nextToken());
			adj[i] = new ArrayList<Integer>();
		}

		for (int i = 0; i < n - 1; i++) {
			st = new StringTokenizer(br.readLine());
			int u = Integer.parseInt(st.nextToken()) - 1;
			int v = Integer.parseInt(st.nextToken()) - 1;
			adj[u].add(v);
			adj[v].add(u);
		}
		dfs(0, -1, 0);
		for (int i = 0; i < ans.length; i++) {
			pw.println(ans[i]);
		}
		pw.flush();
	}

	static int n, m;
	static boolean[][] vis;
	static int[] a, ans, l;
	static ArrayList<Integer>[] adj;
	static ArrayList<Integer> L = new ArrayList<Integer>();

	static void dfs(int u, int p, int lis) {
		int idx = binSh(a[u], lis);
		idx++;
		if (idx == lis) {
			lis++;
		}
		int temp = l[idx];
		l[idx] = a[u];
		ans[u] = lis;
		for (int x : adj[u]) {
			if (x != p)
				dfs(x, u, lis);
		}
		l[idx] = temp;
	}

	static int binSh(int val, int lis) {
		int ans = -1;
		int s = 0;
		int e = lis - 1;
		while (s <= e) {
			int mid = s + e >> 1;
			if (l[mid] < val) {
				ans = mid;
				s = mid + 1;
			} else
				e = mid - 1;
		}
		return ans;
	}

//	5
//	699987654 570044284 602693693 585497124 680075708
//	1 3
//	1 4
//	1 5
//	2 1

//	static int lis(int[] A, int n) // Can be implemented with TreeSet (lower, remove, add)
//	{
//		int[] P = new int[n];
//		int[] L_id = new int[n];
//
//		for (int i = 0; i < n; ++i) {
//			int pos = Collections.binarySearch(L, A[i]);
//			if (pos < 0)
//				pos = -(pos + 1);
//
//			if (pos >= L.size())
//				L.add(A[i]);
//			else
//				L.set(pos, A[i]);
//
//			if (pos + 1 > lis) {
//				lis = pos + 1;
//				lis_end = i;
//			}
//
//			// lis_end and the following part for printing the solution
//			L_id[pos] = i;
//			P[i] = pos > 0 ? L_id[pos - 1] : -1;
//		}
//		return lis;
//	}

}


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

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    for (auto& e : x) cin >> e;
    int ans = INT_MAX;
    for (int i = 1; i <= 100; i++) {
        int can = 0;
        for (auto& e : x) {
            can += pow(e - i, 2);
        }
        ans = min(ans, can);
    }

    cout << ans << endl;
}


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

int n, m;
double g[100][100];
double dp[101][100];

double rec(int a, int b){ //a回目，前に与えた肥料b
	if(dp[a][b]>0) return dp[a][b];
	
	double ret=1.0;

	if(a==m-1) ret=1.0;
	else{
		double t=-1;
		for(int i=0; i<n; ++i){
			double s=g[b][i]*rec(a+1, i);	
			//printf("s=%lf\n", s);
			if(s>t) t=s;
		}
		ret=t;
		//printf("t=%lf\n", t);
	}
	
	return dp[a][b]=ret;
}

int main(){
	while(1){
		scanf(" %d %d", &n, &m);
		if(n==0) break;
		for(int i=0; i<n; ++i)
		for(int j=0; j<n; ++j)
		scanf(" %lf", &g[i][j]);
		
		for(int i=0; i<101; ++i)
		for(int j=0; j<100; ++j)
		dp[i][j]=-1.0;		
		
		double ans=0;
		for(int i=0; i<n; ++i){
			double tmp=rec(0, i);
			if(tmp>ans) ans=tmp;	
		}
		
		/*
		for(int i=0; i<m; ++i){
			for(int j=0; j<n; ++j){
				printf("%.4lf ", dp[i][j]);		
			}
			printf("\n");
		}
		*/
		
		ans*=100;
		ans=round(ans);
		ans/=100;
		printf("%.2lf\n", ans);
	}
}	

Measured memory_bytes: 1416
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    string s;
    cin >> s;
    map<char, int> mp;
    rep(0, i, s.size())
    {
        mp[s.at(i)]++;
    }
    rep(0, i, 26)
    {
        if (mp[(char)('a' + i)] == 0)
        {
            cout << (char)('a' + i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}

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

#define N 1500000
#define L 13
  
char moji[N][L], order[7];
  
int h1(int key){
    return key % N;
    }

int h2(int key){
    return  1 + (key % (N-1));
    }
  
int ctoi(char str){
    if(str == 'A') return 1;
    else if(str == 'C') return 2;
    else if(str == 'G') return 3;
    else if(str == 'T') return 4;
    else return 0;
}
  
int getKey(char str[]){
    int sum = 0, time = 1, i;
    for(i = 0; i < strlen(str); i++){
        sum += time * (ctoi(str[i]));
        time *= 4;
    }
    return sum;
}
  
void insert(char str[]){
    int i, key, h;
    key = getKey(str);
    for(i = 0;; i++){
        h = (h1(key) + i * h2(key)) % N;
        if(strcmp(moji[h], str) == 0) break;
        else if(strlen(moji[h]) == 0){
            strcpy(moji[h], str);
            break;
        }
    }
}
  
int find(char str[]){
    int key, i, h;
    key = getKey(str);
    for(i = 0;; i++){
        h = (h1(key) + i * h2(key)) % N;
        if(strcmp(moji[h], str) == 0) return 1;
        else return 0;
    }
}
  
int main(){
    int i, j, num;
    char str[L];
    scanf("%d", &num);
    for(i = 0; i < N; i++) moji[i][0] = '\0';
    for(i = 0; i < num; i++){
        scanf("%s%s", order, str);
        if(strcmp(order, "insert") == 0) insert(str);
        else{ 
            if(find(str) == 1) printf("yes\n"); 
            else  printf("no\n");
        }
    }
    
    return 0;
}

Measured memory_bytes: 19648
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#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>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#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 <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#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>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll euclidean_gcd(ll a, ll b) {
  if(a < b) euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int input(){
  ll a;
  cin >> a;
  return a;
}

bool sub(string s,string ans,int p,int init){
  if(++p==4){if(init==7){
    cout << ans << "=7" << endl;
    return true;
  }else{
    return false;
  }}
  if(sub(s,ans+"+"+string(1,s[p]),p,init+(s[p]-48)))return true;
  if(sub(s,ans+"-"+string(1,s[p]),p,init-(s[p]-48)))return true;
  return false;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool b=sub(s,string(1,s[0]),0,s[0]-48);
}


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

using namespace std;

const int inf = 1e9;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;

int main() {
	int n, ma, mb;

	cin >> n >> ma >> mb;
	vector<int> a(n), b(n), c(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}

	VVVI dp(n + 1, VVI(401, VI(401, inf)));
	dp[0][0][0] = 0;

	for (int i = 0; i < n; i++) {
	for (int j = 0; j < 401; j++) {
	for (int k = 0; k < 401; k++) {
			if (dp[i][j][k] == inf) {
				continue;
			}

			int j2 = j + a[i];
			int k2 = k + b[i];

			dp[i+1][j2][k2] = min(dp[i+1][j2][k2], dp[i][j][k] + c[i]);
			dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
	}}}

	int min_cost = inf;
	for (int i = 1; i <= n; i++) {
	for (int j = 0; j < 401; j++) {
	for (int k = 0; k < 401; k++) {
		if (dp[i][j][k] == inf || dp[i][j][k] == 0) {
			continue;
		}
		if (j * mb == k * ma) {
			min_cost = min(min_cost, dp[i][j][k]);
		}
	}}}

	if (min_cost == inf) {
		min_cost = -1;
	}

	cout << min_cost << endl;
	return 0;
}


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

#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define ALL(x) (x).begin(), (x).end()
#define OUT(a) cout << (a) << "\n"

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

const ll MOD = 10e9 + 7;

int main() {
    ll n,k,s;
    cin >> n >> k >> s;
    REP(i, n) {
        if (i < k) {
            printf("%lld ", s);
        } else {
            if (s == 1000000000) printf("%lld ", s-1);
            else printf("%lld ", s+1);
        }
    }
    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(int argc, const char * argv[]) {
  int a, b, c;
  cin >> a >> b >> c;
  cout << ((b-a == c-b) ? "YES" :"NO") << endl;
  return 0;
}


Measured memory_bytes: 256
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

#include <bits/stdc++.h>
 
using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair 
 
typedef long long ll;
typedef long double ld;

void solve(){
    string s;
    cin >> s;
    for(int i = 0; i < (int)s.size(); i++){
        if(s[i] == '7'){
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";
    return;
}
 
int main(){
    IOS;
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000000000000ll
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

ll mul(ll a, ll b) {
  ll tmp = (b + MOD) % MOD;
  ll r = (a * tmp) % MOD;
  assert(r >= 0);
  return r;
}

int main() {
  ll n, k, ans = 1;
  cin >> n >> k;
  if (n == k) {
    REP(i, n) {
      ll t;
      cin >> t;
      ans = mul(ans, t);
    }
    cout << ans << "\n";
    return 0;
  }
  vector<ll> b(n);
  priority_queue<ll> p;
  priority_queue<ll, vector<ll>, greater<ll>> m;
  REP(i, n) {
    ll tmp;
    cin >> tmp;
    if (tmp >= 0)
      p.push(tmp);
    else
      m.push(tmp);
    b[i] = tmp;
  }

  sort(ALL(b));
  if (k % 2 == 1 && m.size() == n) {
    //どうやっても負になる
    reverse(ALL(b));
    REP(i, k) { ans = mul(ans, b[i]); }
    cout << ans << "\n";
    return 0;
  } else if (m.size() == n) {
    //全部負
    REP(i, k) { ans = mul(ans, abs(b[i])); }
    cout << ans << "\n";
    return 0;
  } else if (m.size() <= 1) {
    //全部正か一つだけ負
    reverse(ALL(b));
    REP(i, k) { ans = mul(ans, b[i]); }
    cout << ans << "\n";
    return 0;
  } else {
    ll cnt = 0, st_p = 1, st_m = 1, c = 0;
    bool fp = false, fm = false;
    while ((p.size() > 0 || m.size() > 0) && cnt < k) {
      ll f = 0;
      if (m.size() == 0) {
        f = 1;
      } else if (p.size() == 0) {
        f = -1;
      } else if (p.top() > -m.top()) {
        f = 1;
      } else if (p.top() < -m.top()) {
        f = -1;
      } else if (p.top() == -m.top()) {
        f = 1;
      }

      if (f == 1) {
        fp = true;
        ans = mul(ans, st_p);
        st_p = p.top();
        p.pop();
        cnt++;
      }
      if (f == -1) {
        fm = true;
        ans = mul(ans, st_m);
        st_m = m.top();
        m.pop();
        c++;
        cnt++;
      }
      assert(f != 0);
    }


    if (c % 2 == 1 && p.empty()) {
      ans = mul(mul(ans, st_m), m.top());
    } else if (c % 2 == 1 && m.empty()) {
      ans = mul(mul(ans, p.top()), st_p);
    } else if (c % 2 == 1) {
      if(!fm)
        ans = mul(ans, st_p);
      else if (!fp)
        ans = mul(ans, p.top());
      else if (st_m * m.top() > p.top() * st_p)
        ans = mul(mul(ans, st_m), m.top());
      else
        ans = mul(mul(ans, p.top()), st_p);
    } else {
      ans = mul(ans, st_m);
      ans = mul(ans, st_p);
    }

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

  return 0;
}


Measured memory_bytes: 6808
#include<iostream>
using namespace std;
static const int N = 100;

int main() {
    int M[N][N];
    int n, u, k, v;
    
    cin >> n;
    
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            M[i][j] = 0;
        }
    }
    
    for(int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        
        for(int j = 0; j < k; j++) {
            cin >> v;
            v--;
            M[u][v] = 1;
        }
    }
    
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            if(j) cout << " ";
            cout << M[i][j];
        }
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3112
x = int(input())
prime = []
for i in range(2,2*x):
    prime_check = 0
    for j in prime:
        if i % j == 0:
            prime_check = 1
            break
    if prime_check == 0:
        if i >= x:
            ans = i
            break
        else:
            prime.append(i)
print(ans)

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

ans = 0
for a in range(1,N):
    for b in range(1,N):
        c = N - a * b
        if a * b + c == N and c > 0:
            ans += 1
            # print(a,b,c)
        elif a * b > N:
            break

print(ans)


Measured memory_bytes: 73260
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		String str = stdIn.nextLine();
		
		for(int i=str.length()-1;i>=0;i--){
			System.out.print(str.charAt(i));
		}
		
		System.out.println();
	}
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll N, Q, B, C;
ll S = 0;
ll A[100005];
map<ll, ll> mp;

int main(){
	cin>>N;
	for(int i=0; i<N; i++){
		int a; cin>>a;
		S += a;
		mp[a]++;
	}

	cin>>Q;
	while(Q--){
		cin>>B>>C;
		if(mp.find(B) == mp.end()){
			cout<<S<<endl;

		}else{
			ll nb = mp[B];
			mp.erase(B);
			mp[C] += nb;
			S += nb * C - nb * B;

			cout<<S<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 7480
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;

int main() {
	int x;
	cin >> x;
	int a[500];
	int ans,k=0;
	for (int i = 1; i <= 31; i++) {
		for (int j=2; j < 11; j++) {
			ans = pow((double)i,(double)j);
			if (x >= ans) {
				a[k] = ans;
				k++;
			}
		}
	}
	int maxv = -1;
	for (int i = 0; i < k; i++) {
		maxv = max(maxv, a[i]);
	}
	cout << maxv << endl;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n,a,b;
	cin>>n>>a>>b;

	lli now = 0;
	lli kaigai = 0;
	REP(i,0,n){
		char s;
		cin>>s;
		if(s=='a'){
			if(now < a+b){
				now++;
				cout<<"Yes"<<endl;
			}
			else cout<<"No"<<endl;
		}
		else if(s == 'b'){
			if(now<a+b && kaigai < b){
				now++;
				kaigai++;
				cout<<"Yes"<<endl;
			}
			else cout<<"No"<<endl;
		}
		else cout<<"No"<<endl;
	}
	



	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>X(N);
  int tai,taim;
  taim=99999999;
  for(int i=0;i<N;i++){cin>>X[i];}
  sort(X.begin(),X.end());
  for(int i=X[0];i<=X[N-1];i++){
    tai=0;
  for(int j=0;j<N;j++){
    tai=tai+(X[j]-i)*(X[j]-i);
  }
    taim=min(taim,tai);
  }
  cout<<taim<<endl;
  return 0;

}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
pub fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x.abs()
    } else {
        gcd(y, x % y)
    }
}

fn solve() {
    let mo:i64 = 1_000_000_007;
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut left = vec![0; n];
    let mut right = vec![0; n];
    left[0] = a[0];
    right[n-1] = a[n-1];
    for i in 1..n{
        left[i] = gcd(left[i-1], a[i]);
        right[n-i-1] = gcd(right[n-i], a[n-i-1]);
    }
    let mut ans = 0;
    ans = max(left[n-2],right[1]);
    for i in 0..n-2{
        ans = max(ans, gcd(left[i],right[i+2]));
    }
    println!("{}", ans);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 10620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string c;
  cin >> c;
  if (c == "25") {
    cout << "Christmas" << endl;
  }
  else if (c == "24") {
    cout << "Christmas Eve" << endl;
  }
  else if (c == "23") {
    cout << "Christmas Eve Eve" << endl;
    }
   else cout << "Christmas Eve Eve Eve" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int f[1001][1001];
	string s,s1;
	int t,n,m;
	cin>>t; 
	while (t--){
		  memset(f,0,sizeof(f));
		  cin>>s>>s1; 
		  n=s.length(); m=s1.length();
		  s='0'+s; s1='0'+s1;
		  for (int i=1; i<=n; i++)
		      for (int j=1; j<=m; j++){
		      	  if (s[i]==s1[j]){
		      	     f[i][j]=f[i-1][j-1]+1;	
				  }
				  else{
				  	 f[i][j]=max(f[i][j-1],f[i-1][j]);
				  }
			  }
		  cout<<f[n][m]<<endl;
	}
	return 0;
}


Measured memory_bytes: 7116
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=1e5+5;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll x,y;cin>>x>>y;
    if(x==y)return cout<<"0" , 0;
    if(y>x)cout<<min(y-x , abs(y+x)+1);
    else cout<<min(abs(x+y)+1 , 2+abs(x-y));
}



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

using namespace std;
#define DEBUG
#ifdef DEBUG
#define dump(x) cout << "[*] " #x ": " << x << endl
#define debug(x) x
#else
#define dump(x)
#define debug(x)
#endif
#define rep(i,n) for (int i = 0; i < (n); ++i)

#define int long long
typedef long long ll;
//constexpr int INF = 1e9;
//constexpr int MOD = 1000000007;

decltype(1) main() {
    //cin.tie(nullptr);
    //ios_base::sync_with_stdio(false);
    double l;
    cin >> l;
    printf("%.12f\n", l * l * l / 27);
    return 0;
}


Measured memory_bytes: 256
import sys

s = int(input())

a = []
a.append(s)
i = 1

def f(n):
    if n%2 == 0:
        return n//2
    else:
        return 3*n+1


while True:
    val = f(a[i-1])
    if val in a:
        print(i+1)
        sys.exit()
    a.append(val)
    i += 1


Measured memory_bytes: 3060
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] T = new int[N+1];
        int[] X = new int[N+1];
        int[] Y = new int[N+1];
        T[0] = X[0] = Y[0] = 0;
        boolean yes = true;
        for (int i = 1; i <= N; i++) {
            T[i] = sc.nextInt();
            X[i] = sc.nextInt();
            Y[i] = sc.nextInt();
            int d = Math.abs(X[i] - X[i-1]) + Math.abs(Y[i] - Y[i-1]);
            int td = T[i] - T[i-1];
            if (d > td || d%2 != td%2) {
                yes = false;
                break;
            }
        }
        System.out.println(yes ? "Yes" : "No");
    }
}


Measured memory_bytes: 92660
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> a(n+1);
vector<int> b(n);

  for(int i=0; i<=n; i++){
cin>>a[i];
}
for(int i=0; i<n; i++){
cin>>b[i];
}
long long ans = 0;
for(int i=0; i<n; i++){
    int cur = min(a[i], b[i]);
    ans+=cur;
    b[i]-=cur;
    int next = min(a[i+1], b[i]);
    ans+=next;
    a[i+1]-=next;
}
cout<<ans<<endl;
return 0;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  bool a = true, b = false, c = false;  
  char x, y, z;  

  while(cin >> x >> y >> z) {
    if(x > z) swap(x, z);
    if(x == 'A'&& z == 'B') {
      a ^= 1;
      b ^= 1;
    } else if(x == 'A' && z == 'C') {
      a ^= 1;
      c ^= 1;
    } else {
      b ^= 1;
      c ^= 1;
    }
  }
  if(a) cout << 'A' << endl;
  else if(b) cout << 'B' << endl;
  else cout << 'C' << endl;
}

Measured memory_bytes: 1132
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int A,B,C;cin >> A >> B >> C;
    int X,Y;cin >> X >> Y;
    if(A+B < 2*C)cout << A*X + B*Y << endl; // 1 root
    else{                                   // 2 root
        int yen = (max(X,Y) == X ? A : B);              //　多い枚数はAピザかBピザか
        int ans = (yen < 2*C ? yen : 2*C);              //  (1)か(2)か
        cout << min(X,Y)*2*C + abs(X-Y)*ans << endl;    //  いずれも結局 abs(X-Y) * k　枚買うので　ans で一本にまとめた。
    }
}


// ABC095 C-Half and Half
// ・ABピザ二枚の値段　VS　A,B一枚ずつの値段

// 1.AB二枚の方が高い時は全部A,Bを単体で用意。
//
// 2.AB2枚の方が安い時は min(X,Y)*2 枚のABを購入
//  そののち、max(X,Y)の方のピザの値段　VS　AB二枚の値段
//     (1)max(X,Y)の方が安い時
//          abs(X-Y)枚　max(X,Y)ピザを買う。
//     (2)AB二枚の方が安い時
//          abs(X-Y)*2枚の　AB　を買う。


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int mt,ht,h1,m1,h2,m2,s,ans;
	scanf("%d %d %d %d %d", &h1, &m1, &h2, &m2, &s);
	ht=h2-h1;
	mt=m2-m1;
	ht=(ht*60)+mt;
	ans=ht-s;
	if (ans<=0)
	{
		printf("0");
		return 0;
	}
	else
	{
		printf("%d", ans);
	}
	
	
	
	return 0;
}

Measured memory_bytes: 1704
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    vc<vc<int>> al(n*n);
    auto match = [n](int i, int j){ return min(i, j)*n + max(i, j); };
    
    For(i, n){
        Cins(int, n-1, a);
        For(j, n-2){
            al[match(i, a[j]-1)].push_back(match(i, a[j+1]-1));
        }
    }

    vc<int> v(n*n, 0);
    auto dfs = [&](int x, auto self){
        if(v[x] == 1) return false;
        if(v[x] == 2) return true;
        v[x] = 1;
        for(const int &y : al[x]) if(!self(y, self)) return false;
        v[x] = 2;
        return true;
    };
    For(i, n*n) if(!dfs(i, dfs)){
        Cout(-1);
        return 0;
    }
    
    vc<int> v2(n*n, 0);
    auto dfs2 = [&](int x, auto self) -> void {
        if(v2[x] != 0) return;
        for(const int &y : al[x]){
            self(y, self);
            Maxi(v2[x], v2[y]);
        }
        v2[x] ++;
    };
    int ans = 0;
    For(i, n*n){
        dfs2(i, dfs2);
        Maxi(ans, v2[i]);
    }
    Cout(ans);
}




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

using namespace std;

int main()
{
	string str;
	size_t pos;
	
	getline(cin, str);
	
	while ( (pos = str.find("apple")) != string::npos ) str.replace(pos, 5, "-----");
	while ( (pos = str.find("peach")) != string::npos ) str.replace(pos, 5, "apple");
	while ( (pos = str.find("-----")) != string::npos ) str.replace(pos, 5, "peach");
	
	cout << str << endl;
	
	return 0;
}

Measured memory_bytes: 2976
#include <iostream>
#include <vector>
#include <cstring>

using std::cin;
using std::cout;
using std::endl;


/*  From : https://gist.github.com/arukuka/ab48f27d33015a8a99e6da067ac901cd */
long long MOD = 1000000007;
long long pow(long long a, long long r) {
    long sum = 1;
    while (r > 0) {
        if ((r & 1) == 1) {
            sum *= a;
            sum %= MOD;
        }
        a *= a;
        a %= MOD;
        r >>= 1;
    }
    return sum;
  }

long long C(int n, int r) {
    long long sum = 1;
    for (int i = n; 0 < i; --i) {
        sum *= i;
        sum %= MOD;
    }
    long long s = 1;
    for (int i = r; 0 < i; --i) {
        s *= i;
        s %= MOD;
    }
    sum *= pow(s, MOD - 2);
    sum %= MOD;

    long long t = 1;
    for (int i = n - r; 0 < i; --i) {
        t *= i;
        t %= MOD;
    }
    sum *= pow(t, MOD - 2);
    sum %= MOD;

    return sum;
  }

int main()
{
    int x, y, sum;
    cin >> x >> y;
    sum = x + y;

    if(sum % 3 != 0) {
       cout << 0 << endl;
       return 0;
    }

    int n = sum/3;
    if(n < x-n || x-n < 0){
        cout << 0 << endl;
        return 0;
    }
    cout << C(n, x-n) << endl;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    char[][] A = new char[N][N];
    char[][] B = new char[M][M];
    for(int i=0;i<N;i++){
      String n = sc.next();
      for(int j=0;j<N;j++){
        A[i][j]=n.charAt(j);
      }
    }
    for(int i=0;i<M;i++){
      String m = sc.next();
      for(int j=0;j<M;j++){
        B[i][j]=m.charAt(j);
      }
    }
    for(int i=0;i<N;i++){
      for(int j=0;j<N;j++){
        if(i+M>N || j+M>N){
          break;
        }
        boolean match = true;
        for(int k=0;k<M;k++){
          for(int l=0;l<M;l++){
            if(A[i+k][j+l]!=B[k][l]){
              match = false;
              break;
            }
          }
        }
        if(match){
          System.out.println("Yes");
          return;
        }
      }
    }
    System.out.println("No");
  }
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0;i < n;i++)cin >> a[i];
    sort(a,a+n,greater<int>());
    cout << a[0]-a[n-1] << endl;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> 
using namespace std;


bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
    int x;
    int i=0;
    cin>>x;
    while(1){
if(IsPrime(x+i))break;
i++;
    }

cout<<x+i;
return 0;
}

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

#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvc = vector<vector<char>>;
using pii = pair<int , int>;
using pll = pair<long long , long long>;

//プロトタイプ宣言
void faster(void);
template <class T>
T gcd(T , T);
template <class T>
T get_digent(T);
template <class T>
T POW(T , T);



int main(){
  faster();
  int n,m,s,ans=0;
  cin >> n >> m;
  vvi cond(11,vi(11,-1));
  vi p(11),k(11);
  rep(i,m){
    cin >> k[i];
    rep(j,k[i]){
      cin >> cond[i][j];
    }
  }
  rep(i,m) cin >> p[i];

  for(int i=0;i<(1<<n);i++){
    bool flag = true;
    rep(j,m){
      int cnt=0;
      rep(l,k[j]){
        if(i&(1<<cond[j][l]-1)) cnt++;
      }
      if(cnt%2!=p[j]) flag = false;
    }
    if(flag) ans++;
  }

  cout << ans << endl;
}



























//同期解除
void faster(void){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

//ユークリッドの互除法
template <class T>
T gcd(T a, T b) {
  return (b ? gcd(b, a%b) : a);
} 

//桁数取得
template <class T>
T get_digent(auto x){
  string s;
  s = to_string(x);
  ll digent = s.size();
  return digent;
} 

//べき乗計算
template <class T>
T POW(T x, T y){
  if(y==0) return 1;
  if(y%2 == 1){
    ll temp = POW(x,y-1);
    return (temp*x);
  }
  else{
    ll temp = POW(x,y/2);
    return temp*temp;
  }
} 



Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string str;
    long long k;
    cin >> str;
    cin >> k;
    for(long long i = 0; i < k; i ++){
        if(str[i] != '1'){
            cout << str[i] << "\n";
            return 0;
        }
    }
    cout << "1\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <boost/range/adaptors.hpp>
#include <iomanip>
#include <tuple>


int main() {
    int X;
    int Y;
    int Z;
    std::cin >> X >> Y >> Z;

    std::cout << Z << " " << X << " " << Y << std::endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;

int solve(vector<int> a)
{
  int n = a.size();
  vector<int> seq;
  seq.push_back(a[0]);
  for (int i = 1; i < n; ++i) {
    if (a[i] > seq.back()) {
      seq.push_back(a[i]);
    }
    else {
      //int pos = search(0, seq.size() - 1, a[i], seq);
      //seq[pos] = a[i];
      vector<int>::iterator iter = lower_bound(seq.begin(), seq.end(), a[i]);
      *iter = a[i];
    }
  }
  return seq.size();
}

int main()
{
  int n = 0;
  fscanf(stdin, "%d", &n);
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    fscanf(stdin, "%d", &a[i]);
  }
  int ans = solve(a);
  fprintf(stdout, "%d", ans);
  fprintf(stdout, "\n");
  return 0;
}

Measured memory_bytes: 2452