akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(void)
{
    int n, a;
    vector<int> v;
    scanf("%d", &n);
    for(int i=0; i<n; i++)
    {
        scanf("%d", &a);
        v.push_back(a);
    }
    auto r12 = minmax_element(v.begin(), v.end());
    auto r3 = accumulate(v.begin(), v.end(), 0LL);
    printf("%d %d %ld\n", *r12.first, *r12.second, r3);

    return 0;
}


Measured memory_bytes: 2880
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int NUM = 3;

int main()
{
	vector<int> inputs(NUM);
	for (int i = 0; i < NUM; ++i)
	{
		cin >> inputs[i];
	}
	sort(inputs.begin(), inputs.end());
	cout << inputs[0] + inputs[1] << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = [0] * M
B = [0] * M
C = [0]*M
for m in range(M):
    A[m], B[m] = map(int, input().split())
    C[m] = [int(cm) for cm in input().split()]

INF = 100000000
dp = [[INF] * 2**N for _ in range(M + 1)]
dp[0][0] = 0


def Set2Bit(st):
    bt = ["0"]*N
    for i in st:
        bt[i-1] = "1"
    return bt


for m in range(0, M):
    key = Set2Bit(C[m])
    key_bit = int("".join(key), 2)
    for bit in range(2**N):
        pre_bit = next_bit = bit
        dp[m+1][next_bit] = dp[m][pre_bit]
    for bit in range(2**N):
        pre_bit = bit
        next_bit = pre_bit | key_bit
        dp[m+1][next_bit] = min(dp[m+1][next_bit], dp[m][next_bit], dp[m][pre_bit] + A[m])

if dp[-1][-1] == INF:
    print(-1)
else:
    print(dp[-1][-1])


Measured memory_bytes: 77656
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    deque<char> q;
    for(auto& c : s) {
        if(c == '0' || c == '1') q.push_back(c);
        else if(q.size()) q.pop_back();
    }
    for(auto& c : q) cout << c;
    cout << endl;
}

Measured memory_bytes: 256
n=int(input())
ans=0
def make_divisors(n):
      divisors=[]
      for i in range(1,int(n**0.5)+1):
          if n%i == 0:
              divisors.append(i)
              if i != n//i:
                  divisors.append(n//i)
      return len(divisors)
for i in range(1,n+1,2):
    if make_divisors(i)== 8:
        ans+=1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<endl;}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}
 
const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

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

int H,W;

bool fn(int i,int j,char A[10][10]){
	A[i][j]='.';
	if(i==H&&j==W){
		FOR(i,1,H+1)
			FOR(j,1,W+1)
				if(A[i][j]=='#') 
					return false;

		return true;
	}else{
		bool flug=true;
		if(A[i+1][j]=='#'){
			flug=false;
			return fn(i+1,j,A);
		}
		if(A[i][j+1]=='#'){
			flug=false;
			return fn(i,j+1,A);
		}
		if(flug) return false;
	}
	A[i][j]='#';
}

int main(void){
	char A[10][10];
	cin>>H>>W;
	FOR(i,1,H+1)
		FOR(j,1,W+1)
			cin>>A[i][j];

	if(A[1][1]=='#'&&fn(1,1,A)) print("Possible");
	else print("Impossible");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"---------------"#x"---------------"<<endl
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
						For(_x,L,R)cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
LL read(){
	LL x=0,f=0;
	char ch=getchar();
	while (!isdigit(ch))
		f|=ch=='-',ch=getchar();
	while (isdigit(ch))
		x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int N=18,mod=998244353;
int Pow(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=(LL)x*x%mod)
		if (y&1)
			ans=(LL)ans*x%mod;
	return ans;
}
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
void Del(int &x,int y){
	if ((x-=y)<0)
		x+=mod;
}
int Add(int x){
	return x>=mod?x-mod:x;
}
int Del(int x){
	return x<0?x+mod:x;
}
int inv2=(mod+1)>>1;
int n;
int a[1<<N];
void FWT(int *a,int n,int flag){
	for (int d=1;d<n;d<<=1)
		for (int i=0;i<n;i+=d<<1)
			for (int j=0;j<d;j++){
				int x=a[i+j],y=a[i+j+d];
				a[i+j]=Add(x+y);
				a[i+j+d]=Del(x-y);
				if (flag<0){
					a[i+j]=(LL)a[i+j]*inv2%mod;
					a[i+j+d]=(LL)a[i+j+d]*inv2%mod;
				}
			}
}
int main(){
	n=read(),n=1<<n;
	int s=0;
	For(i,0,n-1)
		a[i]=read(),s+=a[i];
	s=Pow(s,mod-2);
	For(i,0,n-1)
		a[i]=(LL)a[i]*s%mod;	
	FWT(a,n,1);
	Fod(i,n-1,0){
		if (a[i]==1){
			a[i]=0;
			continue;
		}
		a[i]=Pow((a[i]-1+mod)%mod,mod-2);
	}
	FWT(a,n,1);
	For(i,0,n-1)
		printf("%d\n",Del(a[i]-a[0]));
	return 0;
}

Measured memory_bytes: 3840
# coding: utf-8
# Here your code !

def calculate_minkowski_distances():
    _ = input()
    data = []
    for i in range(2):
        data.append([float(value) for value in input().rstrip().split()])

    for exponent in (1, 2, 3, float("inf")):
        print(minkowski_distance(data[0],data[1], exponent))
#        print("{0:.8f}".format(minkowski_distance(*data, exponent)))

def minkowski_distance(vector_x, vector_y, exponent):
#    abs_xy = [ abs(pair[0] - pair[1]) for pair in zip(vector_x, vector_y) ]
    abs_xy = [abs(vector_x[i] - vector_y[i]) for i in range(len(vector_x))]
    
    m_dis = 0
    if exponent == float("inf") :
        m_dis = max(abs_xy)
    elif exponent == 0 :
        m_dis = nan
    else :
        m_dis = sum([ elem**exponent for elem in abs_xy ])**(1/exponent)
    
    return m_dis

if __name__ == "__main__" :
    calculate_minkowski_distances()
    
    

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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 C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define N_ALPHABET 26

int main() {
    i64 N; cin >> N;

    string ans = "";
    while (N > 0) {
        i64 parent = (N - 1) / N_ALPHABET;
        i64 ci = N - (parent * 26 + 1);
        ans += ('a' + ci);
        N = parent;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
int main(void){
    int N, tmp, previous = 0, same = 0;
    scanf("%d", &N);

    vector<long> H(N);

    for(int i = 0; i < N; i++){
        scanf("%d", &tmp);
        H[i] = tmp;

        if(previous > tmp){

            for(int j = 0; j <= same; j++){
                H[i - ((j + 1))] --;
            }
        }
        if(previous == tmp) same ++;
        else    same = 0;
        
        previous = tmp;
    }

    if(is_sorted(H.begin(), H.end()))   cout << "Yes\n";
    else    cout << "No\n";
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int h = sc.nextInt();
      int w = sc.nextInt();
      String[][] grid = new String[h][w];
      int[] ph = new int[h];
      int[] pw = new int[w];
      for(int i = 0;i < h;i++){
        String str = sc.next();
      	for(int j = 0;j < w;j++){
          grid[i][j] = str.substring(j,j+1);
          if(grid[i][j].equals("#")){
          	ph[i]++;
            pw[j]++;
          }
          
        }
      }
      for(int i = 0;i < h;i++){
      	for(int j = 0;j < w;j++){
        	if(ph[i] > 0 && pw[j] > 0){
            	System.out.print(grid[i][j]);
            }
        }
        if(ph[i] > 0){
        	System.out.println("");
        }
      }
    }
}


Measured memory_bytes: 25020
import math
A,B,H,M = map(int,input().split())
tyousindeg = M*360/60
tannsinndeg = H*360/12+30*M/60
lst = sorted([tyousindeg,tannsinndeg])
C = lst[1]-lst[0]
if C > 180:
  C = 360 - C
kyori = math.sqrt(A**2+B**2-2*A*B*math.cos(math.radians(C)))
print(kyori)

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

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

  int n, k; cin >> n >> k;
  vector<int> x(n);
  rep(i, n) cin >> x[i];

  int ans = 1e9;
  rep(i, n-k+1) {
    int near = min(abs(x[i+k-1]), abs(x[i]));
    ans = min(ans, near+x[i+k-1]-x[i]);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void){
    int X[3];
    scanf("%d %d %d", &X[0], &X[1], &X[2]);
    if((X[0]==X[1]) && (X[1]==X[2])){
        if(X[0] % 2 ==0){
            printf("-1\n");
            return 0;
        }
    }
    int d, i=0;
    d = X[0] % 2 + X[1] % 2 + X[2] % 2;
    while(d==0){
        int Y[3];
        Y[0] = (X[1] + X[2]) / 2;
        Y[1] = (X[2] + X[0]) / 2;
        Y[2] = (X[0] + X[1]) / 2;
        for(int j=0; j<3; j++){
            X[j] = Y[j]; 
        }
    d = X[0] % 2 + X[1] % 2 + X[2] % 2;
    i++;
    }

    printf("%d\n", i);

    return 0;
}

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

using namespace std;

int dp[2000000][3];

string s;

int bla(char c){
    if(c-'0' == 9)
        return 1;
    else
        return (c-'0')+1;
}

int solve(int i,bool flag){
    if(i == s.size())
        return 0;
    if(dp[i][flag] != -1)
        return dp[i][flag];

    int ret1 = solve(i+1,0)+(s[i]-'0');
    int ret2 = 1e9;
    if(flag)
        ret2 = solve(i+1,1)+( '9' - s[i]);
    else
        ret2 = solve(i+1,1)+( 11 - (s[i]-'0') );

    return dp[i][flag] = min(ret1,ret2);

}

int main()
{

    cin >> s;
    //reverse(s.begin(),s.end());

    memset(dp,-1,sizeof dp);

    cout << solve(0,0) << endl;


}
// APPROVED
// DENIED


Measured memory_bytes: 71684
N,K=map(int,input().split())
A=list(map(int,input().split()))
l,r=1,10**9+1
while r-l>1:
    t=(l+r)//2
    k=sum([(a+t-2)//(t-1)-1 for a in A])
    if K<k:
        l=t
    else:
        r=t
print(l)

Measured memory_bytes: 31088
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>

#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()

using namespace std;

int main() {
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)  {
        cin >> a[i];
        --a[i];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (a[a[i]] == i)
            ++ans;
    }

    cout << ans / 2 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;



int main() {
    int n;
    cin >> n;
    vector<map<int, int>> v(3);
    vector<vector<int>> u(n);
    for (int i = 0; i < n; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        v[0][a]++; v[1][b]++; v[2][c]++;
        u[i].emplace_back(a);
        u[i].emplace_back(b);
        u[i].emplace_back(c);
    }
    for (int i = 0; i < n; ++i) {
        int ans = 0;
        for (int j = 0; j < 3; ++j) {
            if(v[j][u[i][j]] == 1) ans += u[i][j];
        }
        cout << ans << "\n";
    }
    return 0;
}



Measured memory_bytes: 3128
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();
      n-=sc.nextInt();
      m-=sc.nextInt();
        System.out.println(n*m);
    }
}


Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int y = 1000000000;
  for (int i=0; i < N; i++){
    int x = 0;
    int A;
    cin >> A;
    int a = A / 2;
    while (A == 2*a){
      A = a;
      a = a / 2;
      x++;  
    }
    if (y > x){
    y = x;
    }
  }
 cout << y << endl;
}

Measured memory_bytes: 3648
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
public:
  ll *fac,*finv,*inv;
//public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  ll x;
  cin >> x;
  for(ll a=0;a<100;a++){
    for(ll b=0;b<100;b++){
      if(pow(a,5)+pow(b,5) == x){
        cout << a << " " << -1*b << endl;
        return 0;
      }
    }
  }
  for(ll a=0;a<1000;a++){
    for(ll b=0;b<1000;b++){
      if(pow(a,5)-pow(b,5) == x){
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 4048
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a[3];
  int num_c = 0, num_e = 0, num_d = 0;
  for(;;){
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if(a[0] + a[1] <= a[2]){
      cout << num_c + num_e + num_d << " " << num_c << " " << num_e << " " << num_d << endl;
      break;
    }else{
      if(a[0] * a[0] + a[1] * a[1] == a[2] * a[2]) num_c++;
      else if(a[0] * a[0] + a[1] * a[1] > a[2] * a[2]) num_e++;
      else num_d++;
    }
  }
  return 0;
}

Measured memory_bytes: 3144
main(a,b,c){
    scanf ("%d%d%d",&a,&b,&c);
    if(a>b)a = a^b, b = a^b, a = a^b;
    if(a>c)a = a^c, c = a^c, a = a^c;
    if(b>c)b = b^c, c = b^c, b = b^c;
    printf("%d %d %d\n", a, b, c);
}

Measured memory_bytes: 1732
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;




struct Edge{
	int dest,weight;
	Edge(int a,int b):dest(a),weight(b){}
};
pair<int,int> farthest(vector<Edge> edge[],int u,int par=-1){
	pair<int,int> res(u,0),tmp;
	for(int i=0;i<(int)edge[u].size();i++){
		Edge &e=edge[u][i];
		if(par==e.dest)continue;
		tmp=farthest(edge,e.dest,u);
		if(res.second<e.weight+tmp.second){
			res=tmp;
			res.second+=e.weight;
		}
	}
	return res;
}
int tree_diameter(vector<Edge> edge[],int u){
	return farthest(edge,farthest(edge,u).first).second;
}




int wleaf=0;

int delete_leaf(vector<Edge> edge[],int u=0,int par=-1){
	int size=1,tmp,cnt=0;
	for(int i=edge[u].size()-1;i>=0;i--){
		Edge &e=edge[u][i];
		if(0==e.dest&&edge[0].size()==1){
			wleaf+=e.weight;
			swap(e,edge[u][edge[u].size()-1-cnt]);
			cnt++;
			continue;
		}
		if(par==e.dest)continue;
		tmp=delete_leaf(edge,e.dest,u);
		size+=tmp;
		if(tmp==1){
			wleaf+=e.weight;
			swap(e,edge[u][edge[u].size()-1-cnt]);
			cnt++;
		}
	}
	edge[u].erase(edge[u].end()-cnt,edge[u].end());
	return size;
}

int n;
vector<Edge> edge[800];


int main(){
	int p[800],d[800];
	int sum;
	while(cin>>n&&n){
		sum=0;
		rep(i,800){edge[i].clear();}
		rep(i,n-1)cin>>p[i];
		rep(i,n-1)cin>>d[i],sum+=d[i];
		rep(i,n-1){
			edge[i+1].push_back(Edge(p[i]-1,d[i]));
			edge[p[i]-1].push_back(Edge(i+1,d[i]));
		}
		wleaf=0;
		delete_leaf(edge,0);
		int td=tree_diameter(edge,edge[0].size()==1?edge[0][0].dest:0);
		int ans=wleaf+3*(sum-wleaf)-td;
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1376
#ifndef KHOKHO
//#pragma GCC optimize("O3")
#endif
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
//#define CHKR
#define ll long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define ARRS int(1e6+500)
#define MAX ((long long)(1e18+1))
#define EP ((double)(1e-12))
#define HS1 ((ll)(1000001329))
#define HS2 ((ll)(1000001531))
#define MOD ((long long)1000000007ll)
#define AT9 ((long long)1000000000ll)
#define PI 3.14159265358979323846264338327950288419716939937510
#define LG 20

vector<ll> v[ARRS];
ll dp[ARRS];

void go(ll x,ll p){

	set<ll> st;
	ll xr=0;
	for(auto y:v[x]){
		if(y==p)continue;
        go(y,x);
        xr^=(dp[y]+1);
	}
	dp[x]=xr;
	//cout<<x<<" "<<dp[x]<<endl;
}

int main(){
	#ifdef KHOKHO
		freopen("in.in","r",stdin);
		freopen("out.out","w+",stdout);
	#endif //KHOKHO
	ll n,a,k,p,b,c,d;
	cin>>n;
	for(int i=0; i<n-1; i++){
		cin>>k>>p;
		v[k].pb(p);
		v[p].pb(k);
	}
	go(1,-1);
	if(dp[1]){
		cout<<"Alice";
	}
	else cout<<"Bob";
	return 0;
}


Measured memory_bytes: 40192
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

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

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	ll ans = 0;
	if ((A + B ) < 2 * C) {
		ans += (A*X + B*Y);
	}
	else {
		int same_num = min(X, Y);
		ans += same_num * 2 * C;
		X -= same_num;
		Y -= same_num;

		if (X > 0) {
			if (A > 2*C) {
				ans += X*C*2;
			}
			else {
				ans += X*A;
			}
		}
		else if (Y > 0) {
			if (B > 2*C) {
				ans += Y*C*2;
			}
			else {
				ans += Y*B;
			}
		}

	}
	cout << ans;
	system("pause");
	return 0;
}

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

#define rep(a, b, i) for(int i = a; i < b; i++)

char ch(int a, int b, int c) {
	return (a * (c - 'a') + b) % 26 + 'a';
}

int main() {
	int n, a, b, c;
	cin >> n;
	cin.ignore();

	string str, res = "";
	for (; n > 0; n--) {
		getline(cin, str);

		rep(1, 40, a) {
			if (a == 2 || a == 13) continue;
			rep(1, 40, b) {
				res = str;
				c = 0;
				rep(0, str.size(), c) {
					if (res[c] == ' ') continue;

					res[c] = ch(a, b, res[c]);
				}
				if (res.find("this") != -1 || res.find("that") != -1) {
					cout << res << endl;
					a = 114514;
					b = 114514;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3156
//#define NDEBUG

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

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) (((a) + (b) - 1) / (b))
#define tomax(a, b) ((a) = max((a), (b)))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

int main(){
    StarBurstStream

    string s, t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3816
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,maxm=0, x=0;
    cin>>N;
 char S[N];
 
 
for(int i=0;i<N;i++){
cin>>S[i];
 
if(S[i]=='I')
   {
      x++;}
    else
    if(S[i]=='D')
    { x--;}
if( x>=maxm)
      {
 
        maxm= x;}
}
 
 
cout<<maxm;
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define INF 100000000

int n, p[101], m[101][101];

void martixCM(){
  int i,j,k,l;
  for(i=0; i<n; i++){
    m[i][i] = 0;
  }
  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j=i+l-1;
      m[i][j] = INF;
    
    for(k=i; k<=j-1; k++){
      if(m[i][j] > m[i][k]+m[k+1][j]+(p[i-1]*p[k]*p[j])){
	m[i][j] = m[i][k]+m[k+1][j]+(p[i-1]*p[k]*p[j]);
      }
      else{
	m[i][j] = m[i][j];
      }
    }
    }
  }
}

int main(){
  int i;
  scanf("%d",&n);

  for(i=1; i<=n; i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }

  martixCM();

  printf("%d\n",m[1][n]);

  return 0;
}

Measured memory_bytes: 632
object Main {
    def solve(d: Double, ra: Double, rb: Double) = {
        if (ra + rb < d) "0"
        else if (ra > d + rb) "2"
        else if (rb > d + ra) "-2"
        else "1"
    }
    def main(args: Array[String]) = {
        val in = io.Source.stdin.getLines.map(_.split(" ").map(_.toDouble)).toSeq.tail.map{p =>
            (math.sqrt(math.pow(p(0) - p(3), 2) + math.pow(p(1) - p(4), 2)), p(2), p(5))
        }
        in.foreach(p => println(solve(p._1, p._2, p._3)))
    }
}

Measured memory_bytes: 44136
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n*3];
    for(int i=0;i<n*3;i++){
    	cin>>a[i];
    }
    ll sum=0;
    multiset<ll> ms;
    for(int i=0;i<n;i++){
    	ms.insert(a[i]);
    	sum+=a[i];
    }
    ll b[n*3+1],c[n*3+1];
    memset(c,0,sizeof(c));
    b[n-1]=sum;
    for(int i=n;i<n*2;i++){
    	ms.insert(a[i]);
    	sum+=a[i];
    	sum-=*(ms.begin());
    	ms.erase(ms.begin());
    	b[i]=sum;
    }

    ms.clear();
    sum=0;
    for(int i=n*2;i<n*3;i++){
    	ms.insert(a[i]);
    	sum+=a[i];
    }
    //cout << sum<<endl;
    c[n*2]=sum;
    for(int i=n*2-1;i>=n;i--){
    	ms.insert(a[i]);
    	sum+=a[i];
    	sum-=*(--ms.end());
    	ms.erase(--ms.end());
    	c[i]=sum;
    }
    ll ans=-1e18;
    for(int i=n-1;i<n*2;i++){
    	ans=max(ans,b[i]-c[i+1]);
    }
    cout <<ans <<endl;

    return 0;
}


Measured memory_bytes: 13952
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    /*char x='a';
    x+=n;
    x--;
    if(n<=26){cout<<x<<endl;}
    else{
    ll m=1;
    V<ll> d;
    while(true){
        m*=26LL;
        ll x;
        if(d.size()>0)x=d[d.size()-1];
        else x=0;
        x+=m;
        d.push_back(x);
        if(x>=n) break;
    }
    sort(all(d));
    ll x=lb(all(d),n)-d.begin();
    x--;
    string ans;
    ll y=n-d[x]-1;
    ll z=26;
    while(y>0){
        char now='a';
        now+=y%26;
        ans+=now;
        y/=26;
    }
    while(ans.size()!=x+2) ans+='a';
    reverse(all(ans));
    cout<<ans<<endl;
    }*/
    string ans="";
    while(n>0){
        n--;
        ans+=n%26+'a';
        n/=26;
    }
    reverse(all(ans));
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 3580
def penalty(day, last, c):
    val = 0
    for i in range(26):
        val += c[i] * (day - last[i])
    return val

d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]

last = [-1]*26
ans = [0]*(d+1)

for day in range(d):
    ans[day+1] = ans[day] + s[day][t[day]-1]
    last[t[day]-1] = day
    ans[day+1] -= penalty(day, last, c)

for v in ans[1:]:
    print(v)

Measured memory_bytes: 9420
#include<iostream>
using namespace std;
int main(){
  int n[101];
  int i;
  int num;
  cin >> num;
  for(i=0;i<num;i++) cin >> n[i];
  cout << n[num-1];
  for(i=1;i<num;i++) cout <<" "<< n[num-i-1];
  cout << endl;
  return 0;
}




Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[85];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	ll money=1000,stock=0;
	for(int i=1;i<=n-1;i++){
		stock=0;
		if(a[i]<a[i+1]) stock=money/a[i];
		money+=(a[i+1]-a[i])*stock;
	}
	printf("%lld",money);
	return 0;
}

Measured memory_bytes: 3800
/*{{{*/
#include "bits/stdc++.h"
using namespace std;

#define MT make_tuple
#define all(x) begin(x), end(x)
#define putchar(x) cout << (x)
static int fastio = [](){ ios_base::sync_with_stdio(false); cin.tie(0); cout.precision(17); return 0; }();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<typename ...T> string format(const string& fmt, T&&... args) {
    size_t sz = snprintf(nullptr, 0, fmt.c_str(), args...) + 1;
    unique_ptr<char[]> buf(new char[sz]);
    snprintf(buf.get(), sz, fmt.c_str(), args...);
    return string(buf.get(), buf.get() + sz - 1);
}

template<class T> struct rge { T b, e; auto begin() const { return b; } auto end() const { return e; } };
template<class T> rge<T> range(T i, T j) { return rge<T>{i, j}; }
template<class T> auto dud(T* x) -> decltype(cerr << *x, 0);
template<class T> char dud(...);

struct debug {
#ifdef LOCAL
    debug(int line) {
        if(line) cerr << "LINE(" << line << ") -> ";
    }
    template<class T> typename enable_if<sizeof dud<T>(0) != 1, debug&>::type operator<<(T i) {
        cerr << boolalpha << i; return * this;
    }
    template<class T> typename enable_if<sizeof dud<T>(0) == 1, debug&>::type operator<<(T i) {
        return *this << range(begin(i), end(i));
    }
    template<class T, class U> debug& operator<<(pair<T, U> d) {
        return *this << "(" << d.first << ", " << d.second << ")";
    }
    debug& operator<<(tuple<>&) { return *this << "()"; };
    template<class ...T> debug& operator<<(tuple<T...> d) {
        *this << "("; debug_tuple<sizeof...(T), 0>(d);
        return *this << ")";
    }
    template<size_t L, size_t I, class T> void debug_tuple(const T& t) {
        *this << (I == 0 ? "" : ", ") << get<I>(t);
        if(I + 1 < L) debug_tuple<L, (I + 1) % L>(t);
    }
    template<class T> debug & operator <<(rge<T> d) {
        *this << "[";
        for(auto it = d.b; it != d.e; ++it)
            *this << (it != d.b ?  ", " : "") << *it;
        return *this << "]";
    }
    debug& operator<<(ostream&(*pf)(std::ostream&)) {
        cerr << pf; return *this;
    }
#else
    debug(int) {}
    template<class T> debug& operator<<(T&&) { return *this; }
    debug& operator<<(ostream&(*)(std::ostream&)) { return *this; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ << ": " << (__VA_ARGS__) << "] "

#define debug0()  debug(__LINE__)
#define debug1(x) debug(0)
#define GET_MACRO(_0, _1, NAME, ...) NAME
#define debug(...) GET_MACRO(_0, ##__VA_ARGS__, debug1, debug0)(__VA_ARGS__)
/*}}}*/
using LL = long long;

const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL LLINF = 0x3f3f3f3f3f3f3f3f;
const int MAX_N = 200005;

void solve(int) {
    string s;
    cin >> s;
    for(auto& c : s) {
        if(c == '?') {
            c = 'D';
        }
    }
    cout << s << endl;
}

int main() {
    int T = 1;
    //cin >> T;
    for(int i = 1; i <= T; ++i) {
        solve(i);
    }
    return 0;
}


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

int main(){
 while(1){
 int H, W;
 cin >> H >> W;
 if(H == 0 && W == 0) break;

 for ( int i = 0; i < H; i++ ){
    for ( int j = 0; j < W; j++ ){
        if( (i+j) % 2 == 0){
            cout << "#";
        } else {
            cout << ".";
        }
    }
   
    cout << endl;
  }
 cout << endl;
 }
return 0;
} 


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,x;cin>>n>>x;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    vector<ll> b(n,1e+18);
    ll res=1e+18;
    rep(i,n){
        ll tmp=0;
        rep(j,n){
            chmin(b[j],a[(j-i+n)%n]);
            tmp+=b[j];
        }
        tmp+=i*x;
        chmin(res,tmp);
    }
    cout<<res<<endl;
}


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

int main(){
	long long n;	cin>>n;
	int i=0;
	string ans="";

	if(n==0) ans="0";
	else{

		while(n!=0){
			if(n%2==0){
				ans="0"+ans;
			}else{
				ans="1"+ans;
				n--;
			}
			n/=(-2);
		}
	}

	cout<<ans<<endl;

	return 0;
}


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

struct node {
	int k;
	node *p, *l, *r;
};
node *r, *NIL;

void insert(node *u) {
	node *p = NIL, *c = r;
	while (c != NIL) {
		p = c;
		if (u->k < c->k)
			c = c->l;
		else
			c = c->r;
	}
	u->p = p;
	if (p == NIL)
		r = u;
	else if (u->k < p->k)
		p->l = u;
	else
		p->r = u;
}

void inparse(node *u) {
	if (u == NIL)
		return;
	inparse(u->l);
	cout << " " << u->k;
	inparse(u->r);
}

void preparse(node *u) {
	if (u == NIL)
		return;
	cout << " " << u->k;
	preparse(u->l);
	preparse(u->r);
}

void print() {
	inparse(r);
	cout << endl;
	preparse(r);
	cout << endl;
}

int main() {
	int m;
	cin >> m;
	for (int i = 0; i < m; i++) {
		string cmd;
		cin >> cmd;
		if (cmd[0] == 'i') {
			node *u = (node*) malloc(sizeof(node));
			int k;
			cin >> k;
			u->k = k;
			u->l = NIL;
			u->r = NIL;
			insert(u);
		} else {
			print();
		}
	}
	return 0;
}



Measured memory_bytes: 26656
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

using ll = long long;
#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()
int main(){
    int N;
    long long ans = 0;
    cin >> N;
    int a[N];
    map<int, int> mp;
    set<int> num;
    rep(i, N){
        cin >> a[i];
        mp[a[i]] = 0;
        num.insert(a[i]);
    }
    rep(i, N){
        if(num.count(a[i]) == 1){
            mp[a[i]]++;
        }
    }
    for(auto x: mp){
        int p = x.first;
        int q = x.second;
        if(q >= p) ans += q - p;
        else ans += q;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    vector<pair<long long int,long long int>> arr(n);
    for(int i=0;i<n;i++)
    {
        long long int a,b;
        cin>>a>>b;
        arr[i].first=a;
        arr[i].second=b;
    }
    long long int a,b,c,d;
    vector<long long int> sum(n);
    for(int i=0;i<n;i++)
    {
        sum[i]=arr[i].first+arr[i].second;
        arr[i].second=arr[i].second*(-1);
    }
    a=*max_element(sum.begin(),sum.end())-*min_element(sum.begin(),sum.end());
    b=-1*a;
    for(int i=0;i<n;i++)
    {
        sum[i]=arr[i].first+arr[i].second;
    }
    c=*max_element(sum.begin(),sum.end())-*min_element(sum.begin(),sum.end());
    d=-1*c;
    long long int maxi=max(a,b);
    maxi=max(maxi,c);
    maxi=max(maxi,d);
    cout<<maxi<<endl;
}


Measured memory_bytes: 7940
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

#define dicemin 1
#define dicemax 6
#define eps 10e-9
#define max 105

int main(void){
	while(1){
		int N, T, L, B;
		bool lose[max];
		bool back[max];
		double prob[max][max];
		cin >> N >> T >> L >> B;
		if( N == 0 && T == 0 && L == 0 && B == 0 ) break;
		for(int i = 0; i < max; i++) {
			lose[i] = false;
			back[i] = false;
			for(int j = 0; j < max; j++)
				prob[j][i] = 0.0;
		}
		prob[0][0] = 1.0;

		for(int i = 0; i < L; i++){
			int tmp;
			cin >> tmp;
			lose[tmp] = true;
		}
		for(int i = 0; i < B; i++){
			int tmp;
			cin >> tmp;
			back[tmp] = true;
		}
		//シュミレート
		for(int i = 0; i < T; i++) {
			for(int j = 0; j < N; j++) {
				for(int k = dicemin; k <= dicemax; k++) {
					int next = j + k;
					if( next > N ) next = N - ( next - N );
					if( back[next] )
						prob[i + 1][0] += (double)( 1.0 * prob[i][j] ) / 6.0;
					else if( lose[next] )
						prob[i + 2][next] += (double)( 1.0 * prob[i][j] ) / 6.0;
					else
						prob[i + 1][next] += (double)( 1.0 * prob[i][j] ) / 6.0;
				}
			}
		}
		double ans = 0.0;
		for(int i = 0; i <= T; i++)
			ans += prob[i][N];
		printf("%lf\n", ans);
	}
	return 0;
}

Measured memory_bytes: 1268
// D - Knight
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD 1000000007

ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while(b){
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if(u < 0) u += m;
	return u;
}

int main(){
	int X,Y; cin>>X>>Y;
	int n = (2*Y-X)/3, r = (2*X-Y)/3;
	if((X+Y)%3 || n<0 || r<0){puts("0"); return 0;}
	n += r;
	ll nPr = 1;
	for(int i=n; i>=n-r+1; --i) nPr = nPr * i % MOD;
	ll fact_r = 1;
	for(int i=r; i>=2; --i) fact_r = fact_r * i % MOD;
	cout<< nPr * modinv(fact_r, MOD) % MOD << endl;
}

Measured memory_bytes: 256
S = int(input())
def ans(L):
    if len(list(str(L))) == 1:
        return(int(L))
    elif len(list(str(L))) == 2:
        LI = list(str(L))
        return(int(LI[0])+int(LI[1])+int(L))
    else:
        LI = list(str(L))
        SUM = 0
        for i in range(len(list(str(L)))):
            if i != len(list(str(L)))-1:
                LISTA = LI[0:i+1]
                LISTB = LI[i+1:len(list(str(L)))] 
                SUM += (2**(len(LISTB)-1))*int("".join(LISTA)) + ans(int("".join(LISTB)))
            else:
                SUM += L
        return(SUM)
    
print(ans(S))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;

int n, Ma, Mb;
int a[50], b[50], c[50];
int dp[50][500][500];

int main(void){
	cin >> n >> Ma >> Mb;
	rep(i, n) cin >> a[i] >> b[i] >> c[i];
	rep(i, 50)rep(j, 500)rep(k, 500)dp[i][j][k] = INF;
	dp[0][0][0] = 0;
	rep(i, n){
		rep(j, 500)rep(k, 500){
			if(dp[i][j][k] == INF) continue;
			//tukau
			chmin(dp[i + 1][j + a[i]][k + b[i]], dp[i][j][k] + c[i]);
			// printf("1 dp[%d][%d][%d] = %d\n", i, j, k, dp[i][j][k]);
			// printf("2 dp[%d][%d][%d] = %d\n", i + 1, j + a[i], k + b[i], dp[i + 1][j + a[i]][k + b[i]]);
			chmin(dp[i + 1][j][k], dp[i][j][k]);
		}
	}

	int ans = INF;
	reps(i, 1, 50){
		int A = Ma * i, B = Mb * i;
		if(A > 490 || B > 490) break;
		chmin(ans, dp[n][A][B]);
	}
	if(ans == INF) printf("-1\n");
	else printf("%d\n", ans);
	return 0;
}


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

using namespace std;

int main() {

	int n;
	cin >> n;

	vector<int> a(n, 0);

	for (int i =0; i < n; i++) {
		cin >> a[i];
	}

	int x = a[n - 1];
	int i = 0;
	for (int j = i;j < n - 1; j++) {
		if (a[j] <= x) {
			swap(a[i], a[j]);
			i++;
		}
	}
	swap(a[i], a[n - 1]);
	int xx = i;

	for (int i = 0; i < n; i++) {
		if (i!= xx) {
			cout << a[i] << (i == n - 1 ? "\n" : " ");
		}
		else {
			cout << "[" << a[i] << "]" << (i == n - 1 ? "\n" : " ");

		}
	}
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
const int nax = 1e+5;
int dp[nax];
int main(){
    int n; cin >> n;
    
	dp[0] = 0, dp[1] = 1;
    
    for(int i=1;i<=n;i++){
    	
    	dp[i] = i;
    	
    	for(int j=6;j<=i;j*=6){
    		dp[i] = min(dp[i], 1 + dp[i-j]);
		}
		for(int j=9;j<=i;j*=9){
    		dp[i] = min(dp[i], 1 + dp[i-j]);
		}
	}
	
	cout << dp[n];
	
	return 0;
}


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

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int cnt = 0;
    for (int i = 0; i <= A; i++) {
        for (int j = 0; j <= B; j++) {
            for (int k = 0; k <= C; k++) {
                if (500 * i + 100 * j + 50 * k == X) {
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
using namespace std;
typedef pair<int,int>pii;
int a[60];
LL dp[60][3010];
int n,m,sum;
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>a[i],sum+=a[i];
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int k=50;k>=0;k--){
			for(int y=0;y<=sum;y++){
				if(!dp[k][y])continue;
				dp[k+1][y+a[i]]+=dp[k][y];
			}
		}
	}
	LL ans=0;
	for(int k=1;k<=50;k++)
		for(int y=0;y<=sum;y++)
			if(k*m==y)ans+=dp[k][y];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
import static java.lang.System.*;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(in);
		
		int n = sc.nextInt();
		int[] num = new int[n];
		int[] num_org = new int[n];
		
		for(int i=0; i<n; i++) num[i] = num_org[i] = sc.nextInt();
		Arrays.sort(num);
		
		int mid_s = num[n/2-1];
		int mid_l = num[n/2];
		for(int i: num_org) {
			if(i <= mid_s) out.println(mid_l);
			else out.println(mid_s);
		}
		
		return;
	}

}


Measured memory_bytes: 91276
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    string s;
    cin>>a>>b>>s;
    if(s.size()==a+b+1)
    {
        int f=1;
        for(int i=0;i<s.size();i++)
        {
            if(i==a) continue;
            if(!isdigit(s[i]))
            {
                f=0;break;
            }
        }
        if(s[a]=='-'&&f==1) {cout<<"Yes";return 0;}
    }
     cout<<"No";
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int n, m, x;

int main(void)
{
	int left = 0, right = 0;
	cin >> n >> m >> x;
	
	int a;
	for(int i = 0; i < m; i++){
		cin >> a;
		if(a < x) left++;
		else right++;
	}
	cout << min(left, right) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const *argv[]) {
  int x;
  int count = 1;
  while (1) {
    std::cin >> x;
    if (x == 0){
      break;
    }
    std::cout << "Case " << count << ": " << x << '\n';
    count++;
  }
  return 0;
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define _for(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FOR(...)    _for (__VA_ARGS__)
#define rep(i,n)    FOR(i, size_t{}, n)
using namespace std;
using ll = int64_t;
constexpr int64_t inf = 2e18;
constexpr size_t dy [] = {-1ull, 0, 1, 0};
constexpr size_t dx [] = {0, -1ull, 0, 1};

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

  size_t H, W;
  cin >> H >> W;
  vector <vector <char>> s (H, vector <char> (W));
  rep (i, H) rep (j, W) cin >> s[i][j];

  auto is_path = [&] (size_t y, size_t x)
  {
    return y < H && x < W && s[y][x] == '.';
  };

  ll ans = 0;
  rep (i, H) rep (j, W)
  {
    if (is_path (i, j))
    {
      vector <vector <bool>> visited (H, vector <bool> (W, false));
      queue <tuple <size_t, size_t, ll>> q;
      auto update = [&] (auto y, auto x, auto cost)
      {
        visited [y][x] = true;
        q.emplace (y, x, cost);
      };
      update (i, j, 0);
      while (not q.empty ())
      {
        auto now = q.front (); q.pop ();
        ll cost;
        size_t y, x;
        tie (y, x, cost) = now;

        ans = max (ans, cost);

        rep (direction, 4)
        {
          size_t ny = y + dy [direction];
          size_t nx = x + dx [direction];
          if (is_path (ny, nx) && not visited [ny][nx])
          {
            update (ny, nx, cost + 1);
          }
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int k = scan.nextInt();
        int sum = 0;
        for(int a = 1; a <= k; a++){
            for(int b = 1; b <= k; b++){
                for(int c = 1; c <= k; c++){
                    sum += gcd(gcd(a, b),c);
                }
            }
        }
        System.out.println(sum);
    }
    public static int gcd(int m, int n) {
        int r;
        while (n > 0) {
            r = m % n;
            m = n;
            n = r;
        }
        return m;
    }
}

Measured memory_bytes: 27260
#include <fstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
using ll = long long;
using vl = vector<ll>;

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

int main() {
#ifdef CIN_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cout << setprecision(15) << fixed;

	ll n, m; cin >> n >> m;
	vl k(n);
	vector<vector<pair<ll,ll>>> sh(n);
	REP(i, n){
		cin >> k[i];
		sh[i] = vector<pair<ll,ll>>(k[i]);
		REP(j, k[i]){
			ll s, h;
			cin >> s >> h;
			sh[i][j].first = s;
			sh[i][j].second = h;
		}
	}

	auto calc = [&](ll tubo, ll mizu) -> double{
		double l = 0;
		REP(i, k[tubo]){
			if (mizu <= sh[tubo][i].first * sh[tubo][i].second){
				return l + mizu / (double)sh[tubo][i].first;
			}
			mizu -= sh[tubo][i].first * sh[tubo][i].second;
			l += sh[tubo][i].second;
		}
		return l;
	};

	vector<vector<double>> dp(n, vector<double>(m+1, 0));
	REP(i, n) REP(j, m+1){
		double ma = 0;
		REP(k, m - j + 1) ma = max(ma, (i!=0 ? dp[i - 1][j + k] : 0) + calc(i, k));
		dp[i][j] = ma;
	}

	cout << dp[n - 1][0] << endl;

	return 0;
}

Measured memory_bytes: 3392
/*
    Problem 70
    https://onlinejudge.u-aizu.ac.jp/problems/NTL_1_B
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
ll p(ll m, ll n) {
    if (n == 0) return 1;
    ll ret = p(m, n/2) % mod;
    ret = (ret * ret) % mod;
    if (n % 2) ret = (ret * m) % mod;
    return ret;
}
/* main */
int main(){
    ll m, n;
    cin >> m >> n;
    cout << p(m, n) << '\n';
}


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

int main(){
int N;
  cin >> N;
  int a[110];
  int x,y;
  
  for(int i=0;i<N;i++) cin >> a[i];
    x=a[0];
    y=a[0];
  for(int i=0;i<N-1;i++){
    if(x>a[i+1])x=a[i+1];
    if(y<a[i+1])y=a[i+1];
  }
  cout << y-x << endl;

}

Measured memory_bytes: 3592
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    double r;
    cin >> r;
    printf("%.3f\n", (double)r*2.0*3.141);

    return 0;
}

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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;


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

    int ans = 0;
    REP(i, n)REP(j, n + 1) {
        string sub_s = s.substr(i, j);
        string acgt = "ACGT";
        bool is_valid = true;
        for(auto c : sub_s)if(acgt.find(c) == string::npos) is_valid = false;
        if(!is_valid) continue;
        ans = max(ans, (int)sub_s.size());
    }
    cout << ans << ln;
    return 0;
}


Measured memory_bytes: 256