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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
template<class T> inline void sort_uniq(T& c) { sort(ALL(c)); c.erase(unique(ALL(c)), c.end()); }
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class K, class V> void cout_v(map<K, V>& m)
{ for(auto it=m.begin();it!=m.end();it++)cout<<it->first<<":"<<it->second<<endl;}
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
inline int powi(int x,int y) {int p=1; while(y--) p*=x; return p;}
template<class T> inline bool is_overlap(const T& a, const T& b, const T& p, const T& q)
{ return p <=b && a <= q; }
#define MOD = 1000000007;
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

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

    int N; cin >>N;

    bool f = true;
    int t_prev = 0, x_prev = 0, y_prev = 0;
    rep(i, N) {
        int t, x, y;
        cin >> t >> x >> y;
        int d = abs(x - x_prev) + abs(y - y_prev);
        int td = t - t_prev;
        if (d > td || d%2 != td%2) {
            f = false;
            break;
        }          
        x_prev = x;
        y_prev = y;
        t_prev = t;
    }
    
    Yes(f);
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#define INF 1e9
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;
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; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  return s;
}

template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
  s << vv[i] << endl;
  }
  return s;
}

int N,M,Q;
vector<int> L;
vector<int> R;
vector<vector<int>> X(510,vector<int>(510,0));
vector<vector<int>> C(510,vector<int>(510,0));
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N >> M >> Q;
  L.resize(M);
  R.resize(M);
  for(int i = 0 ; i < M ; i++){
    cin >> L[i] >> R[i];
    X[L[i]][R[i]]++;
  }
  for(int i = 1; i <= N ; i++){
    for(int j = 1; j <= N; j++){
      C[i][j] = C[i][j-1] + X[i][j];
    }
  }
  for(int i = 1; i <= Q; i++){
    int p,q;
    cin >> p >> q;
    int s = 0;
    for(int j = p ; j <= q; j++){
      s += C[j][q] - C[j][p-1];
    }

    cout << s << endl;
  }

  return 0;
}


Measured memory_bytes: 4608
K,N = map(int, input().split())
A = list(map(int, input().split()))

max = 0
for i in range(1,N):
    if max < A[i] - A[i-1]:
        max = A[i] - A[i-1]
if max < K - A[N-1] + A[0]:
    max = K - A[N-1] + A[0]
print(K - max)

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(_v) for(auto _x:_v){cout<<_x<<" ";}cout<<endl
#define printVS(_vs) for(auto _x : _vs){cout << _x << endl;}
#define printVV(_vv) for(auto _v:_vv){for(auto _x:_v){cout<<_x<<" ";}cout<<endl;}
#define printP(_p) cout << _p.first << " " << _p.second << endl
#define printVP(_vp) for(auto _p : _vp) printP(_p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
const int inf = 1e9;
const int mod = 1e9 + 7;

// #define double long double

typedef complex<double> P;
typedef vector<P> G;
#define here(g, i) g[i]
#define next(g, i) g[(i + 1) % g.size()]
#define prev(g, i) g[(i - 1 + g.size()) % g.size()]
const double EPS = 1e-6;
const double INF = 1e12;
const double PI = acos(-1);

// N, E, S, W
const int dx[4] = {-1, 0,  1,  0};
const int dy[4] = { 0, 1,  0, -1};

bool inside(int x, int y, int H, int W) {
    return 0 <= x && x < H && 0 <= y && y < W;
}

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

    int H, W, m;
    cin >> H >> W >> m;
    vector<string> s(H);
    rep(i, H) cin >> s[i];
    vvi power(H, vi(W));
    rep(i, H) rep(j, W) cin >> power[i][j];
    vvi on(H, vi(W));
    rep(i, H) rep(j, W) cin >> on[i][j];
    vvi off(H, vi(W));
    rep(i, H) rep(j, W) cin >> off[i][j];
    vector<Pii> task(m);
    rep(i, m) cin >> task[i].first >> task[i].second;

    vvvi time(H, vvi(W));
    time[task[0].first][task[0].second].emplace_back(0);
    std::function<int(int,int,int,int,int,int,int)> dfs = [&](int x, int y, int px, int py, int gx, int gy, int t) {
        if (x == gx && y == gy) {
            return t;
        }

        rep(k, 4) {
            int nx = x + dx[k], ny = y + dy[k];
            if (!inside(nx, ny, H, W)) continue;
            if (s[nx][ny] == '#') continue;
            if (nx == px && ny == py) continue;
            time[nx][ny].emplace_back(t);
            int ret = dfs(nx, ny, x, y, gx, gy, t + 1);
            if (ret < inf) return ret;
            time[nx][ny].pop_back();
        }

        return inf;
    };

    int t = 1;
    rep(i, m - 1) {
        t = dfs(task[i].first, task[i].second, -1, -1, task[i + 1].first, task[i + 1].second, t);
    }

    // rep(i, H) {
    //     rep(j, W) {
    //         cout << i << " " << j << ": ";
    //         printV(time[i][j]);
    //     }
    // }

    int ans = 0;
    rep(i, H) {
        rep(j, W) {
            if (time[i][j].empty()) {
                continue;
            }
            ans += on[i][j];
            rep(k, (int)time[i][j].size() - 1) {
                ans += min(power[i][j] * (time[i][j][k + 1] - time[i][j][k]), off[i][j] + on[i][j]);
            }
            ans += off[i][j];
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 13476
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int A = line[0];
            int P = line[1];
            Console.WriteLine((3 * A + P) / 2);
        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define debug(x) cout << #x << " -> " << x << endl
#define booga cout << "booga" << endl
#define ll long long int
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;


void testcase(){
	int a[5];
	for(int i{0};i < 5;i++){
		cin >> a[i];
	}
	for(int i{0};i < 5;i++){
		if(a[i] == 0){
			cout << i+1 << "\n";
			return;
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	t = 1;
	while(t--){
		testcase();
	}
	return 0;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

class union_find {
    private:
        vector<int> par;
        vector<int> ran;
        vector<ll> size;
    public:
        union_find(int n);
        int find(int x);
        void unite(int x, int y);
        bool same(int x, int y);
        ll show_size(int x);
};

union_find::union_find(int n){
    par.resize(n);
    ran.resize(n);
    size.resize(n);
    rep(i,n) par[i] = i;
    rep(i,n) ran[i] = 0;
    rep(i,n) size[i] = 1;
};

int union_find::find(int x) {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    ll t = show_size(x)+show_size(y);
    size[x] = size[y] = t;
    if(ran[x] < ran[y]){
        par[x] = y;
        //size[y] += size[x];
    }
    else{
        par[y] = x;
        //size[x] += size[y];
        if(ran[x] == ran[y]) ran[x]++;
    }
};

ll union_find::show_size(int x) {
    if(par[x] == x) return size[x];
    return show_size(par[x] = find(par[x]));
}

bool union_find::same(int x, int y) {
    return (find(x) == find(y));
};

class Edge {
public:
	ll source, target, cost;
	Edge(ll source = 0, ll target = 0, ll cost = 0) :
		source(source), target(target), cost(cost) {}
	bool operator<(const Edge &e)const {
		return cost < e.cost;
	}
};
 
ll kruskal(ll N, vector<Edge> &edges) {
	ll totalCost = 0;
	sort(edges.begin(), edges.end());
	union_find uni(N);
	ll source, target;
	for (ll i = 0; i < edges.size(); i++) {
		Edge e = edges[i];
		if (!uni.same(e.source, e.target)) {
			totalCost += e.cost;
			uni.unite(e.source, e.target);
		}
	}
	return totalCost;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<ll, P>> xv, yv;
    rep(i,n){
        ll x, y;
        cin >> x >> y;
        xv.emplace_back(x, P(y, i));
        yv.emplace_back(y, P(x, i));
    }
    sort(xv.begin(), xv.end());
    sort(yv.begin(), yv.end());
    vector<Edge> es;
    rep(i,n-1){
        ll s, t, w;
        s = xv[i].second.second;
        t = xv[i+1].second.second;
        w = min(abs(xv[i].first - xv[i+1].first), abs(xv[i].second.first - xv[i+1].second.first));
        es.push_back(Edge(s, t, w));
    }
    rep(i,n-1){
        ll s, t, w;
        s = yv[i].second.second;
        t = yv[i+1].second.second;
        w = min(abs(yv[i].first - yv[i+1].first), abs(yv[i].second.first - yv[i+1].second.first));
        es.push_back(Edge(s, t, w));
    }
    ll ans = kruskal(n, es);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 13860
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int a,b;
    cin>>a>>b;
    cout<<(0<(a%b))<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<bitset>
#include<vector>
const int MaxN=50010,MaxM=100010,MaxB=450;
int N,M,T,x[MaxM],y[MaxM];
std::bitset<MaxN>reach[MaxN];
bool vis[MaxN];
char ans[MaxM];
void solve1(){
	for(int i=1;i<=N;i++)reach[i][i]=1;
	for(int i=0;i<M;i++)reach[x[i]]=reach[y[i]]|=reach[x[i]];
	for(int i=1;i<=N;i++)if(reach[i].count()==N){
		vis[i]=1;
		for(int j=M;j--;){
			if(vis[x[j]]&&!vis[y[j]])vis[y[j]]=1,ans[j]='^';
			else if(!vis[x[j]]&&vis[y[j]])vis[x[j]]=1,ans[j]='v';
			else ans[j]='^';
		}
		puts(ans);
		return;
	}
	puts("-1");
}
bool pairs[MaxB][MaxB];
std::vector<std::pair<int,int> >flips[MaxM];
void flip(int i,int x,int y){
	if(i>=0)flips[i].push_back(std::make_pair(x,y));
	pairs[x][y]=pairs[y][x]^=1;
}
void solve2(){
	int n=1;while(n<N&&n*(n-1)/2<=M)n++;
	for(int i=1;i<=n;i++)
		for(int j=1;j<i;j++)pairs[i][j]=pairs[j][i]=1;
	for(int i=0;i<M;i++)if(y[i]<=n){
		if(pairs[x[i]][y[i]])flip(i,x[i],y[i]);
		for(int j=1;j<=n;j++)if(j!=x[i]&&j!=y[i]&&pairs[x[i]][j]!=pairs[y[i]][j]){
			pairs[x[i]][j]?flip(i,y[i],j):flip(i,x[i],j);
		}
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<i;j++)if(pairs[i][j]){
			for(int k=M;k--;){
				for(int l=flips[k].size();l--;)flip(-1,flips[k][l].first,flips[k][l].second);
				ans[k]=y[k]==i||y[k]==j?'v':'^';
				if(!pairs[i][j]){
					if(i==x[k])i=y[k];
					else if(i==y[k])i=x[k];
					else if(j==x[k])j=y[k];
					else if(j==y[k])j=x[k];
				}
			}
			puts(ans);
			return;
		}
	puts("-1");
}
int main(){
	scanf("%d%d%d",&N,&M,&T);
	for(int i=0;i<M;i++)scanf("%d%d",x+i,y+i);
	if(T==1)solve1();
	else solve2();
}

Measured memory_bytes: 309248
//Kyokai no Kanata //
#include<bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef pair<int,int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector< VI > VVI;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
  const char* comma=strchr(names+1,',');
  cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...)
#endif
//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
float  inf=std::numeric_limits<double>::infinity();
LL INF=std::numeric_limits<LL>::max();
const int N=105;
int H[N],X[N],Y[N];
int check(int cx,int cy,int n){

  int ret =-1,i;
  for(i=0;i<n && H[i]==0;i++);
  if(i<n)
    ret=abs(X[i]-cx)+abs(Y[i]-cy)+H[i];
  for(int i=0;i<n;i++){
    if(H[i]==0 && (abs(X[i]-cx)+abs(Y[i]-cy)<ret)) return -1;
    if(H[i]!=0 && abs(X[i]-cx)+abs(Y[i]-cy)+H[i]!=ret) return -1;
  }
  return ret;
}
int main(){
  int n; si(n);
  for(int i=0;i<n;i++) si(X[i]),si(Y[i]),si(H[i]);
  int h;
  for(int i=0;i<=100;i++)
    for(int j=0;j<=100;j++)
      if((h=check(i,j,n))!=-1) return 0*printf("%d %d %d\n",i,j,h);
  return 0;
}


Measured memory_bytes: 256
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto rd = readln.split.to!(long[]), n = rd[0], l = rd[1];
  auto s = new string[](n);
  foreach (i; 0..n) s[i] = readln.chomp;
  s.sort();
  foreach (si; s) write(si);
  writeln;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=300005;
int fac[N],inv[N];
int n,a,b,ans;
long long k;
const long long MOD = 998244353;
int C(int x,int y){
    return 1ll*fac[x]*inv[y]%MOD*inv[x-y]%MOD;
}
int main(){
    scanf("%d%d%d%lld",&n,&a,&b,&k);
    fac[0]=inv[0]=inv[1]=1;
    for (int i=2;i<=n;i++)
        inv[i]=1ll*inv[MOD%i]*(MOD-MOD/i)%MOD;
    for (int i=1;i<=n;i++){
        fac[i]=1ll*fac[i-1]*i%MOD;
        inv[i]=1ll*inv[i-1]*inv[i]%MOD;
    }
    for (int red=0;red<=n;red++){
        long long rest=k-1ll*red*a;
        if (rest<0||rest>1ll*b*n||rest%b) continue;
        int blue=rest/b;
        ans=(ans+1ll*C(n,red)*C(n,blue))%MOD;
    }
    printf("%d",ans);
    return 0;
}

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

int n, m, x;
vector<vector<int>> ca;
ll INF = 1000000000000;
ll ans = INF;

void dfs(vector<int> A){
        if (A.size() == n){
                ll sum = 0;
                vector<int> v(m,0);
                rep(i,n){
                        if(A[i]==1){
                                sum += ca[i][0];
                                rep(j,m)v[j] += ca[i][j+1];
                        }
                }

                rep(j,m){
                        if(v[j]<x)return;
                }
                ans = min(sum, ans);
                return;
        }
        A.push_back(0);
        while(A.back()<=1){
                dfs(A);
                A.back()++;
        }
}

int main() {
        cin >> n >> m >> x;
        ca = vector<vector<int>>(n, vector<int>(m));
        rep(i,n)rep(j,m+1)cin >> ca[i][j];
        dfs(vector<int>(1,0));
        dfs(vector<int>(1,1));
        if (ans == INF) ans = -1;
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	long long ans=0;
	long long n,m;
	scanf("%lld %lld",&n,&m);
	if(m-2*n>=0)
	{
		ans+=n;
		m=m-2*n;
		ans+=m/4;
	}
	else
	{
		ans+=m/2;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
// Crt. 2020-01-07  16:43:40
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 200005
using namespace std;
typedef long long ll;

int n, a[N];
ll sum[N], asum[N];

inline int Abs(int x) {
    return x < 0 ? -x : x;
}

int main(){
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n;

    scanf("%d", a + 1);
    for (int i = 2; i <= n; ++i) {
        char pos;
        scanf(" %c %d", &pos, a + i);
        if (pos == '-') a[i] *= -1;
    }

    for (int i = 1; i <= n; ++i)
        sum[i] = sum[i - 1] + a[i];
    for (int i = n; i >= 1; --i)
        asum[i] = asum[i + 1] + Abs(a[i]);

    ll ans = sum[n];
    for (int i = 2, j; i <= n; ++i) {
        if (a[i] > 0) continue;
        for (j = i; j < n && a[j + 1] > 0; ++j);
        ans = max(ans, sum[i] * 2 - sum[j] + asum[j + 1]);
    }

    cout << ans << endl;

	return 0;
}


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

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

  if (S.at(0) == S.at(1) || S.at(1) == S.at(2) || S.at(2) == S.at(3)) {
    cout << "Bad" << endl;
  } else {
    cout << "Good" << endl;
  }
}

Measured memory_bytes: 256
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

s = sr()
k = ir()
dic = {}
for l in range(5):
    for i in range(len(s)-l):
        tmp = s[i:i+l+1]
        dic[tmp] = 1
ans = []
for key in dic.keys():
    ans.append(key)
ans.sort()
print(ans[k-1])

Measured memory_bytes: 80044
#include <iostream>
#include <unordered_set>
#include <cstdint>
#include <vector>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
#include <math.h>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	if (a >= 1 && a <= 9 && b >= 1 && b <= 9)
		cout << a * b;
	else cout << "-1";
}

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;

int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int a, b, c, d, ans;
		cin >> a >> b >> c >> d;
		if (c >= 5 && d >= 2) { ans = 4 * (a*c + b * d) / 5; }
		else { ans = min((max(5, c)*a + max(2, d)*b) * 4 / 5, a*c + b * d); }
		cout << ans << endl;
	}
}


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

int main(){
  string S;
  cin >> S;
  int A,Z;
  for (int i = 0; i < S.size(); i++){
    if (S.at(i) == 'A'){
      A = i;
      break;
    }
  }
  for (int i = S.size() - 1; i >= 0; i--){
    if (S.at(i) == 'Z'){
      Z = i;
      break;
    }
  }
  cout << Z - A + 1 << endl;
}


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

using namespace std;
void Swap(int &x,int &y){
	int tmp;
	tmp=x;
	x=y;
	y=tmp;
}
int main(int argc, char* argv[])
{
	int N;
	cin>>N;
	int i;
	vector<int> p(N+1,0);
	for (i=1;i<=N;i++){
		cin>>p[i];
	}
	int aw=0;
	for (i=1;i<=N;i++){
		if (p[i]==i){
			if (i<N){
				Swap(p[i],p[i+1]);
			}else{
				Swap(p[i-1],p[i]);
			}
			aw++;
		}
	}

	cout<<aw<<endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<numeric>
using namespace std;

int main(void)
{
    int X;
    cin >> X;

    if(X >= 400 && X <= 599){
        cout << 8 << endl;
    }
    else if (X >= 600 && X <= 799){
        cout << 7 << endl;
    }
    else if (X >= 800 && X <= 999){
        cout << 6 << endl;
    }else if (X >= 1000 && X <= 1199){
        cout << 5 << endl;
    }else if (X >= 1200 && X <= 1399){
        cout << 4 << endl;
    }else if (X >= 1400 && X <= 1599){
        cout << 3 << endl;
    }else if (X >= 1600 && X <= 1799){
        cout << 2 << endl;
    }else if (X >= 1800 && X <= 1999){
        cout << 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

std::map<long long, long long> primeFactorization(
    long long n) { /* prime factorization * nを素因数分解する */
  std::map<long long, long long> pf;
  for (long long i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      n /= i;
      ++pf[i];
    }
  }
  if (n > 1) {
    ++pf[n];
  }
  return pf;
}
LL N;
LL dfs(map<LL, LL> &pf, LL Sum) {
  DUMP("dfs", pf, Sum);
  if (pf.size() == 0) {
    LL m = max(Sum - 1, 1LL);
    DUMP("edge ", m, N, N / m, N % m);
    if (N / m == N % m)
      return m;
    else
      return 0;
  }
  LL ans = 0;
  pair<long, long> r = *pf.begin();
  pf.erase(pf.begin());
  REP(i, 0, r.second + 1) {
    LL t = pow(r.first, i);
    DUMP("         ", i, r, pf, t, Sum * t);
    ans += dfs(pf, Sum * t);
  }
  pf.insert(r);
  return ans;
}
int main() {
  cin >> N;
  LL sum = 0;
//   REP(m, 1, N) {
//     if (N / m == N % m) {
//       DUMP(m, sum);
//       sum += m;
//     }
//   }
//   DUMP("simple", sum);

  auto pf = primeFactorization(N);
  LL ans = dfs(pf, 1LL);
  cout << ans << endl;

  return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll P[100005];

struct UnionFind {
    UnionFind(int n) {
        rank.assign(n, 0);
        parent.resize(n);
        for (int i = 0; i < n; ++i) {
            parent[i] = i;
        }
    }

    int find(int x) {
        if (x == parent[x])
            return x;
        return parent[x] = find(parent[x]);
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    void unit(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;

        if (rank[x] < rank[y]) {
            parent[x] = y;
        }
        else {
            parent[y] = x;
            if (rank[x] == rank[y])
                rank[x]++;
        }
    }

    vector<int> rank;
    vector<int> parent;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    REP(i, N) {
        cin >> P[i];
    }
    UnionFind uf(N);
    REP(i, M) {
        ll x, y;
        cin >> x >> y;
        x--;
        y--;
        uf.unit(x, y);
    }

    ll ans = 0;
    REP(i, N) {
        if (uf.same(i, P[i] - 1))
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		if(n+1<a+b || (long)a*b<n){
			System.out.println(-1);
			return;
		}
		StringBuilder sb=new StringBuilder();
		int start=0;
		int end=n;
		int rem=b;
		while(rem>0){
			start=Math.max(end-a+1,rem);
			for(int i=start; i<=end; i++){
				sb.append(i+" ");
			}
			end=start-1;
			rem--;
		}
		System.out.println(sb);
	}

}


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


using namespace std;

typedef long long ll;

#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
#define ALL(x) x.begin(),x.end() 
#define SIZE(x) ll(x.size())

#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange

#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

void solve() {
    ll N;
    cin >> N;
    ll ans;
    if (N <= 1)
    {
        ans = 0;
    }
    else
    {
        ans = modpow(10, N, MOD);
        ans = (ans + modpow(8, N, MOD)) % MOD;
        ans = (ans - modpow(9, N, MOD) + MOD) % MOD;
        ans = (ans - modpow(9, N, MOD) + MOD) % MOD;
    }
    
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}

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

int m,n;
int x[100000];
int ans[60];
int now=0;

int main(){
  int i,j,k=3,l,a,p,count =0;
  cin >> n;
  x[0]=2;
  now=1;
  while(now<100000&&k<55555*4&&count!=n){
    for(i=0;i<now;i++){
      if(k%x[i]==0)break;
      if(i==now-1){
	x[now]=k;
	now++;
	if(k%10==1&&k<55555){
	  ans[count]=k;
	  count++;
	  }
	if(count==n)break;
      }
    }
    k+=2;
  }
  /* for(i=0;i<5;i++)ans[i]=x[i];
     nowx = 5;
     for(a=5;a<n;a++){
     while(1){
     nowa = x[nowx];
     for(
  */
  //cout << "Ok"<<endl;
  /*for(i=0;i<n;i++){
    for(j=0;j<n;j++){
    for(k=0;k<n;k++){
    for(l=0;l<n;l++){
    for(p=0;p<n;p++){
    if(i==j||i==k||i==l||j==k||j==l||k==l||p==i||p==j||p==k||p==l)continue;
    m = x[i]+x[j]+x[k]+x[l]+x[p];
    for(a=0;a<now;a++){
    //if(x[a]!=m)break;
    if(x[a]==m)cout << x[i]<<" "<<x[j]<<" "<<x[k]<<" "<<x[l]<<" "<<x[p]<<" "<<m<<endl;
    }
    }
    }
    }
    }
    }*/
  for(i=0;i<n;i++){
    if(i==0)cout << ans[i];
    else cout << " " <<ans[i];
  }
  //cout << endl;
  //cout << count <<endl;
  //for(i=0;i<now;i++)cout << x[i] <<" ";
  /*cout <<endl << now;*/
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main()
{
    long long int n,d,sumx=0,sum=0,a=0,x=0;

    scanf("%lld",&n);

    while (n > 0)
    {
        d = n % 10;
        sumx+=d;
        n /= 10;
        a++;
        if(d!=9) x=1;
    }
    //   printf("d=%lld a=%lld ",d,a);

    if(x==0) sum=a*9;
    else sum=((a-1)*9)+d-1;

    if(sum>sumx) printf("%lld",sum);
    else printf("%lld",sumx);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <map>

int main() {
    std::map<std::string, int> mp;
    int Q;
    std::cin >> Q;

    for (int q = 0; q < Q; ++q) {
        int t;
        std::cin >> t;
        if (t == 0) {
            std::string k;
            int x;
            std::cin >> k >> x;
            mp[k] = x;
        } else if (t == 1) {
            std::string k;
            std::cin >> k;
            std::cout << (mp.count(k) ? mp[k] : 0) << std::endl;
        } else if (t == 2) {
            std::string k;
            std::cin >> k;
            mp.erase(k);
        } else {
            std::string l, r;
            std::cin >> l >> r;
            auto e = mp.upper_bound(r);
            for (auto itr = mp.lower_bound(l); itr != e; ++itr) {
                std::cout << itr->first << " " << itr->second << std::endl;
            }
        }
    }
}


Measured memory_bytes: 27744
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
static const int MAX = 10000;
static const int INFTY = (1<<20);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n;
vector< pair<int,int> > adj[MAX];

void dijkstra(){
  priority_queue< pair<int,int> > PQ;
  int color[MAX];
  int d[MAX];
  for(int i=0;i<n;i++){
    d[i]=INFTY;
    color[i]=WHITE;
  }

  d[0]=0;
  PQ.push(make_pair(0,0));
  color[0] = GRAY;

  while(!PQ.empty()){
    pair<int,int> f=PQ.top();
    PQ.pop();
    int u=f.second;
    color[u]=BLACK;

    // 最小値を取り出し、最短じゃなきゃ無視
    if(d[u]<f.first*(-1)) continue;

    for(int j=0;j<adj[u].size();j++){
      int v=adj[u][j].first;
      if(color[v]==BLACK) continue;
      if(d[v] > d[u]+adj[u][j].second){
        d[v] = d[u]+adj[u][j].second;
        PQ.push(make_pair(d[v]*(-1),v));
        color[v] = GRAY;
      }
    }
  }
  for(int i=0;i<n;i++){
    cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
  }
}

int main()
{
  int k,u,v,c;

  cin >> n;
  for(int i=0;i<n;i++)
  {
    cin >> u >> k;
    for(int j=0;j<k;j++)
    {
      cin >> v >> c;
      adj[u].push_back(make_pair(v,c));
    }
  }

  dijkstra();
  return 0;
}



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

int main() {
    int N,M,a,b;
    cin >> N >> M;
    vector<int> r(N,0);

    rep(i,M) {
        cin >> a >> b;
        r.at(--a)++;
        r.at(--b)++;
    }

    rep(i,N)
        cout << r.at(i) << endl;
}

Measured memory_bytes: 256
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ll long long
#define ull unsigned long long
#define ii pair<int, int>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls signed
#define give main()
const int mod = 1000000007;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

#pragma endregion

const int N = 100005;
int n, k, sum[N], ans;
vector<int> primes;

int qexp(int A, int B, int M) {
    if (B == 0) return 1; //A^0 = 1 for all A
    long long half = qexp(A, B/2, M); //Note that B/2 is rounded down, this will be compensated later
    half *= half; //Long long is required to ensure this operation does not overflow when M is close to 2^31
    half %= M;
    if (B%2==1) half *= A;  //Compensate the 'round down' of B/2 when B is odd
    return half%M;
}

pls give {
    AC;
    cin >> n >> k;
    for (int i=1; i<=k; i++) {
        sum[i] = qexp(k/i, n, mod);
    }

    for (int i=k; i>=1; i--) {
        for (int j=i+i; j<=k; j+=i) {
            sum[i] = (sum[i] - sum[j] + mod) qmod;
        }
        ans += sum[i]*i;
        ans = ans qmod;
    }
    cout << ans << nl;
}

Measured memory_bytes: 4356
n,m=map(int,input().split())
num=[None]*n
for _ in range(m):
  s,c=map(int,input().split())
  s-=1
  if None!=num[s]!=c:
    print(-1)
    exit()
  else:
    num[s]=c
if n>1 and num[0]==0:
  print(-1)
  exit()
if n>1 and num[0] is None:
  num[0]=1
for x in num:
  if x is None:
    x=0
  print(x ,end='')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define cer(x) cerr << x <<endl
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

struct UnionFind
{
	vector<int> par;
	vector<int> rank;

	UnionFind(int n) : par(n), rank(n)
	{
		for (int i = 0; i < n; i++)
		{
			par[i] = i;
			rank[i] = 0;
		}
	}
	int root(int x)
	{
		if (par[x] == x)
		{
			return x;
		}
		else
		{
			return par[x] = root(par[x]);
		}
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if (rx == ry)return;
		if (rank[rx] < rank[ry])
		{
			par[rx] = ry;
		}
		else
		{
			par[ry] = rx;
			if (rank[rx] == rank[ry])rank[rx]++;
		}
	}
	bool same(int x, int y)
	{
		return root(x) == root(y);
	}
};


int main()
{
	int n, m; cin >> n >> m;
	vector<int>p(n);
	rep(i, n)
	{
		cin >> p[i];
		p[i]--;
	}
	UnionFind uf(n);
	rep(i, m)
	{
		int x, y; cin >> x >> y;
		x--; y--;
		uf.unite(x, y);
	}
	int ans = 0;
	rep(i, n)
	{
		if (uf.same(p[i], i))ans++;
	}
	co(ans);
	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

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

using namespace std;

struct edge
{
	int from;
	int to;
	int cost;

	edge (int from, int to, int cost) : from(from),to(to),cost(cost) {}
};

bool cmp(const edge& e1, const edge& e2)
{
	return e1.cost < e2.cost;
}

int par[101];
int rank[101];

void init(int n)
{
	rep(i,n)
	{
		par[i] = i;
		rank[i] = 0;
	}
}

int find(int x)
{
	if(par[x] == x)
	{
		return x;
	}
	else
	{
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y)
{
	x = find(x);
	y = find(y);

	if(x == y) return;

	if(rank[x] < rank[y])
	{
		par[x] = y;
	}
	else
	{
		par[y] = x;
		
		if(rank[x] == rank[y]) rank[x]++;
	}
}

bool same(int x,int y)
{
	return find(x) == find(y);
}

int main()
{
	int n,m;
	while(cin >> n >> m)
	{
		if(n == 0 && m == 0) break;
			
		
		vector<edge> v;

		rep(i,m)
		{
			int t1,t2,temp;
			cin >> t1 >> t2 >> temp;

			v.push_back(edge(t1,t2,temp));
		}

		sort(v.begin(),v.end(),cmp);

		init(n);
		int res = 0;
		

		rep(i,m)
		{
			edge e = v[i];

			if(!same(e.from,e.to))
			{
				unite(e.from,e.to);
				res += e.cost;
			}
		}

		cout  << res << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, i, A[100001], B[100001]={0}, sumA=0, sum=0;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> A[i];
        sumA += A[i];
    }

    B[1] = 0;

    for(i=1; i<=N-2; i+=2){
        B[i+2] = B[i] + (A[i+1]-A[i])*2;
    }

    B[N-1] = B[1] + (A[N-1]-A[N])*2;

    for(i=N-1; i>=4; i--){
        B[i-2] = B[i] + (A[i-2]-A[i-1])*2;
    }

    for(i=1; i<=N; i++){
        sum += B[i];
    }

    for(i=1; i<=N; i++){
        B[i] += (sumA-sum)/N;
    }

    for(i=1; i<=N; i++){
        cout << B[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2816
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>
#include <stack>
#include <queue>
#include <cstring>
#include <map>
#include <list>
#include <cassert>
 
using namespace std; 

int gcd(int x,int y){
	return y==0?x:gcd(y,x%y);
}

int dp[41][401][401];

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

	int N=n/2,M=n-N;
	int cost1[401][401],cost2[401][401];
	for(int i=0;i<401;i++){
		for(int j=0;j<401;j++) cost1[i][j]=cost2[i][j]=1e8;
	}

	for(int bit=0;bit<(1<<N);bit++){
		int a_sum=0,b_sum=0,c_sum=0;
		for(int i=0;i<N;i++){
			if( bit&(1<<i) ) a_sum+=a[i],b_sum+=b[i],c_sum+=c[i];
		}
		cost1[a_sum][b_sum]=min(cost1[a_sum][b_sum],c_sum);
	}

	for(int bit=0;bit<(1<<M);bit++){
		int a_sum=0,b_sum=0,c_sum=0;
		for(int i=0;i<M;i++){
			if( bit&(1<<i) ) a_sum+=a[N+i],b_sum+=b[N+i],c_sum+=c[N+i];
		}
		cost2[a_sum][b_sum]=min(cost2[a_sum][b_sum],c_sum);
	}

	int res=1e8;
	for(int i=1;i<=400;i++){
		int A=ma*i,B=mb*i;
		if(A>400 || B>400) break;

		for(int LA=0;LA<=400;LA++){
			int RA=A-LA;
			if(RA<0) break;
			for(int LB=0;LB<=400;LB++){
				int RB=B-LB;
				if(RB<0) break;
				res=min(res,cost1[LA][LB]+cost2[RA][RB]);
			}
		}

	}

	if(res==1e8) res=-1;
	cout<<res<<endl;


}

Measured memory_bytes: 1536
#include<stdio.h>
 
int main(){
  int N,a[100],flag=1,i,j,tmp,n=0;
 
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
 
  i =0;
  while(flag){
    flag =0;
    for(j = N-1;j > i;j--){
      if(a[j] < a[j-1]){
    tmp = a[j];
    a[j] = a[j-1];
    a[j-1] = tmp;
    flag = 1;
    n++;
      }
    }
    i++;
  }
  for(i = 0;i<N-1;i++)
    printf("%d ",a[i]);
  printf("%d\n%d\n",a[N-1],n);
 
  return 0;
}

Measured memory_bytes: 600
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H,W = map(int,read().split())

def F(H,W):
    opt = H * W + 100
    for a in range(1,W):
        x = H * a
        y = (W-a) * (H//2)
        z = (W-a) * (H-H//2)
        d = max(x,y,z) - min(x,y,z)
        if opt > d:
            opt = d
    if W >= 3:
        a = W//3
        b = (W-a)//2
        c = W-a-b
        d = (max(a,b,c) - min(a,b,c)) * H
        if opt > d:
            opt = d
    return opt

answer = min(F(H,W),F(W,H))
print(answer)


Measured memory_bytes: 3064
#include<iostream>
#include<cstring>
using namespace std;
#define R 0
#define L 1
int main(){
    string s;
    cin>>s;
    long long H[1000000];
    int color=R;
    int k=0,l=0;
    int n=s.length();
    for(int i=0;i<n-1;i++){
        if(color==R){
            if(s[i+1]=='R'){
                k++;
                H[i]=0;
            }
            else{
                H[i]=1+k/2;
                H[i+1]=1+k-k/2;
                k=0;
                color=L;
            }
        }
        else{
            if(s[i+1]=='L'){
                l++;
                s[i+1]=0;
            }
            else{
                H[i-l]+=l/2;
                H[i-l-1]+=l-l/2;
                l=0;
                color=R;
            }
        }
    }
    H[n-1-l]+=l/2;
    H[n-2-l]+=l-l/2;

    for(int i=0;i<n;i++){
        if(i==0) cout<<H[i];
        else cout<<" "<<H[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e9;
const long long LINF = 1LL << 50;
#define int long long
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	VE a(m), b(m); rep(i, m)cin >> a[i] >> b[i];
	rep(i, m) { a[i]--; b[i]--; }
	VE ans(n,0);
	rep(i, m) {
		ans[a[i]]++; ans[b[i]]++;
	}
	bool ok = true;
	rep(i, n) {
		if (ans[i] % 2 != 0)ok = false;
	}
	YES(ok);
	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>
int a[110];
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	bool flag=false;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			if(n-i-j<0) break;
			if(i*10000+j*5000+(n-i-j)*1000==m)
			{
				printf("%d %d %d\n",i,j,n-i-j);
				flag=true;
				break;
			} 
		}
		if(flag) break;
	}
	if(!flag) printf("-1 -1 -1\n");
	return 0;
}


Measured memory_bytes: 128
import sys
import bisect
input = sys.stdin.readline

def f(x):
    if 0<=x and a-1>= x:
        return True
    return False
def g(x):
    if 0<=x and b-1>= x:
        return True
    return False

a,b,q = map(int,input().split())
s = []
t = []
for i in range(a):
    S = int(input())
    s.append(S)
for i in range(b):
    T = int(input())
    t.append(T)
s.sort()
t.sort()
 
for i in range(q):
    x = int(input())
    p = bisect.bisect_left(s,x)
    m = bisect.bisect_left(t,x)
    
    res = []
    if f(p) and g(m):
        res.append(max(t[m],s[p])-x)
    if f(p) and g(m-1):
        res.append(min(s[p]-x,x-t[m-1])+s[p]-t[m-1])
    if f(p-1) and g(m):
        res.append(t[m]-s[p-1]+min(t[m]-x,x-s[p-1]))
    if f(p-1) and g(m-1):
        res.append(x-min(t[m-1],s[p-1]))
    print(min(res))

Measured memory_bytes: 12188