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 < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
double distance(double x1, double y1, double x2, double y2){
  return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

int main() {
  int n;cin>>n;
  string s;cin>>s;
  REP(i,s.size()){
    s[i]=(s[i]-'A'+n)%26+'A';
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
# coding:UTF-8
import sys
from math import factorial

MOD = 10 ** 9 + 7
INF = float('inf')

N = int(input())    # 数字
A = list(map(int, input().split()))     # スペース区切り連続数字

mny = 1000
m = A[0]
for i in range(1, N):
    if A[i] < m:
        m = A[i]
    if A[i] > m:
        if i == N-1:
            num = mny // m
            mny += num * (A[i] - m)
        elif A[i+1] <= A[i]:
            num = mny // m
            mny += num * (A[i] - m)
            m = A[i+1]

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


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

using namespace std;
const double inf = 1e100;

int n, m;
vector<int> G[600];
double P[600];
double E[600];
int main() {
  scanf("%d %d", &n, &m);
  for (int j = 0; j < m; ++j) {
    int a, b;
    scanf("%d %d", &a, &b);
    --a; --b;
    G[a].push_back(b);
  }
  
  P[0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j : G[i]) {
      P[j] += P[i] / G[i].size();
    }
  }
  
  for (int i = n - 2; i >= 0; --i) {
    double sum = 0;
    for (int j : G[i]) {
      sum += E[j];
    }
    E[i] = sum / G[i].size() + 1;
  }
  
  double mn = 0;
  for (int i = 0; i < n; ++i) {
    int d = G[i].size();
    if (d <= 1) continue;
    for (int j : G[i]) {
      double ans = P[i] / d * (
        (d * E[i] - E[j] - 1) / (d - 1) - E[j] - 1
      );
      mn = min(mn, ans);
    }
  }
  cout << fixed << setprecision(16) << E[0] + mn << endl;
}

Measured memory_bytes: 1408
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

//#define int ll

using namespace std;



signed main(void)
{
	//変数の宣言
	int n,m;
	int h,w;
	char s[110];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int temp3=0;
	static int vec[100010];
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;
	static char stemp[100010];
	
	//データの読み込み


//	scanf("%d %d",&n,&m);
//	scanf_s("%d %d",&n,&m);


	scanf("%s",&s);
//	scanf_s("%s",&s,110);




/*	//scanf("%c",&dummy);
	scanf_s("%c",&dummy);
	for(i=0;i<n;i++){
//		scanf("%c",&s[i]);
		scanf_s("%c",&s[i]);
	}*/


/*	for(i=0;i<3;i++){
//		scanf("%s",&s);
		scanf_s("%s",&s[i],100010);
	}*/


	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

//	clock_t start=clock();

	n=strlen(s);
	m=(n-1)/2;
	for(i=0;i<m;i++){
		if(s[i]!=s[m-1-i]||s[i]!=s[m+1+i]||s[i]!=s[n-1-i]){
			printf("No");
			return 0;
		}
	}

	printf("Yes");


//	clock_t end=clock();

	//	printf("計算部分終了\n");

	//出力
	
	//printf("%d",(d[i-1][j-1]+1)/2);

//	printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC);
	//	printf("結果の出力終了\n");

	return 0;
}



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

int main() {
  int n;
  cin >> n;
  long long f = 1;
  while (n > 0) {
    f *= n--;
  }
  cout << f << endl;
}

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int INF = 0x3f3f3f3f;
const ll  LINF = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 1e5+10;
const int mod = 1e9+7;

using namespace std;

int p[maxn],sz[maxn],ans;

void start(){
    for(int i=0;i<maxn;++i){
        p[i] = i;
        sz[i] = 1;
    }
}

int find_set(int x){
    return p[x] = (p[x] == x ? x:find_set(p[x]));
}

void union_set(int x,int y){
    x = find_set(x);
    y = find_set(y);
    if(x==y) return;
    if(sz[x] > sz[y]) swap(x,y);
    p[x]=y;
    sz[y]+=sz[x];
    --ans;
}

void solve(){
	int n,m;
    cin >> n >> m;
    ans=n;
    for(int i=0;i<m;++i){ 
        int x,y,z;
        cin >> x >> y >> z;
        union_set(x,y);
    }
    cout << ans << endl;
}

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

    int t = 1;

    // cin >> t;

    start();

    while(t--){
    	solve();
    }

    return 0;
}

Measured memory_bytes: 4408
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define f first
#define s second
#define pb push_back
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<pair<int,int>> vii;
typedef vector<pair<ll,ll>> vll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;

ll ppow(ll x,ll y,ll mod) {
    ll res=1;
    while(y) {
        if(y&1) res=res*x%mod;
        y>>=1;
        x=x*x%mod;
    }
    return res;
}



int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,m; cin >> n >> m;
    cout << m*(m-1)/2+n*(n-1)/2;
}


Measured memory_bytes: 256
//config = {input: 'tmp', newline: '\r\n'}; // win
config = {input: '/dev/stdin', newline: '\n'}; //linux

line = require('fs').readFileSync(config.input, 'ascii')
  .trim()
  .split(config.newline)
  .slice(1)
  .map(Number);

const NUM_MAX = Math.pow(10, 9);
minRi = line.shift();
max = -NUM_MAX;

for (i in line) {
  max = Math.max(max, line[i] - minRi);
  minRi = Math.min(minRi, line[i]);
}

console.log(max);

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

using namespace std;

int main(void)
{
        int n;
        int k;
        cin >> n >> k;

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

        cout << ans << endl;

        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N, W; cin >> N >> W;
	vl w(N + 1), v(N + 1);
	FOR(i, 1, N + 1) cin >> w[i] >> v[i];
	vvl dp(N + 1, vl(W + 1, 0));
	FOR(i,1,N + 1) {
		FOR(j,0,W + 1) {
			dp[i][j] = dp[i - 1][j];
			if (j - w[i] >= 0) {
				dp[i][j] = max(
					dp[i][j],
					dp[i - 1][j - w[i]] + v[i]
				);
			}
		}
	}
	cout << dp[N][W] << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 80256
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    string s;
    int q;
    string command;
    int a, b;
    string p;

    cin >> s >> q;
    for (int i=0; i<q; ++i) {
        cin >> command >> a >> b;
        if (command[2] == 'i') {
            // print
            cout << s.substr(a, b-a+1) << endl;
        } else if (command[2] == 'v') {
            // reverse
            string sub = s.substr(a, b-a+1);
            std::reverse(sub.begin(), sub.end());

            s = s.substr(0, a) + sub + s.substr(b+1);
        } else if (command[2] == 'p') {
            // replace
            cin>>p;
            s = s.substr(0, a) + p + s.substr(b+1);
        }
    }

    return 0;
}



Measured memory_bytes: 3204
import math
ans = 0
N = int(input())
if N <= 5:
  for i in range(N):
    for j in range(N):
        for k in range(N):
            ans += math.gcd(math.gcd(i+1,j+1),math.gcd(j+1,k+1))
else:
    for i in range(N):
        ans += i+1
    for i in range(N-1):
        for j in range(i+1,N):
            ans += 6*math.gcd(i+1,j+1)
    for i in range(N-2):
        for j in range(i+1,N-1):
            for k in range(j+1,N):
                ans += 6*math.gcd(math.gcd(i+1,j+1),math.gcd(j+1,k+1))
print(ans)

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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        vi64 a(n);
        forn(i, n) cin >> a[i];
        string s;
        cin >> s;
        reverse(all(a));
        reverse(all(s));
        vi64 b;
        bool ok = false;
        forn(i, n) {
            if (s[i] == '1') {
                i64 x = a[i];
                for (i64 y: b) uin(x, x ^ y);
                if (x) ok = true;
            } else {
                i64 x = a[i];
                for (i64 &y: b) {
                    if (!x) break;
                    int a = 63 - __builtin_clzll(x);
                    int b = 63 - __builtin_clzll(y);
                    if (a == b) x ^= y;
                    else if (a > b) swap(x, y);
                }
                if (x) b.pb(x);
            }
        }
        cout << (ok ? 1 : 0) << '\n';
    }

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


Measured memory_bytes: 3612
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

#define MAX(a,b) ((a)>(b)?(a):(b))

typedef struct point{
  int x,y,r;
} point;

double distance(point a,point b){
  double dx=a.x-b.x;
  double dy=a.y-b.y;
  double l=sqrt(dx*dx+dy*dy);
  return MAX(0,l-a.r-b.r);
}

void run(void){
  point s,t;
  scanf("%d%d%d%d",&s.x,&s.y,&t.x,&t.y);
  s.r=t.r=0;
  int n;
  scanf("%d",&n);
  const int m=n+2;
  point *p=(point *)calloc(m,sizeof(point));
  p[0]=s;
  p[m-1]=t;
  int i;
  for(i=1;i<=n;i++){
    int x,y,r;
    scanf("%d%d%d",&x,&y,&r);
    p[i]=(point){x,y,r};
  }
  double *dp=(double *)calloc(m,sizeof(double));
  for(i=1;i<m;i++) dp[i]=2000000000*sqrt(2)*2;
  int *used=(int *)calloc(m,sizeof(int));
  for(i=0;i<m;i++){
    int j;
    for(j=0;used[j];j++);
    int min=j;
    for(j=min+1;j<m;j++) if(used[j]==0 && dp[j]<dp[min]) min=j;
    used[min]=1;
    for(j=0;j<m;j++){
      if(used[j]) continue;
      double d=distance(p[min],p[j]);
      if(dp[j]>dp[min]+d){
	dp[j]=dp[min]+d;
      }
    }
  }
  printf("%.10f\n",dp[m-1]);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_D
{
    class D118
    {


        static void Main(string[] args)
        {
            int[] p = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int N = p[0], M = p[1];
            int[] A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).OrderBy(x=>x).ToArray();
            
            int[] m = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

            string[] z = new string[N+1];

            for(int i = 0; i < M; i++)
            {
                int k = A[i];
                int nm = m[k];

                for (int j = nm; j <= N; j++)
                {
                    if (j > nm && z[j - nm] == null) continue;
                    string scand = k.ToString() + z[j - nm];
                    //サイズ（＝桁数）が同じなら最大桁が大きいから必ず元より大きい
                    if (z[j] == null || scand.Length >= z[j].Length) z[j] = scand;
                }

            }
            Console.WriteLine(z[N]);
        }
    }
}


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

int N, W;
long long f[100003];

inline int Rd() {
	int x = 0; char ch = getchar();
	while(ch < '0' || ch > '9') ch = getchar();
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	return x;
}
inline void ChkMax(long long &aa, long long bb) {
	if(aa < bb) aa = bb;
	return;
}

int main()  {
	int w, v;
	N = Rd(), W = Rd();
	for(register int i = 1; i <= N; ++i) {
		w = Rd(), v = Rd();
		for(register int j = W; j >= w; --j)
			ChkMax(f[j], v + f[j - w]);
	}
	cout << f[W] << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
string b[8]={"SUN", "MON","TUE","WED","THU","FRI","SAT"};
int main()
{
	string a;
	cin>>a;
	for(int i=0;i<7;i++)
	{
		if(b[i]==a)cout<<7-i<<'\n';
	}
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
#define gap ' '
#define L(i) ((i) - (&i))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DFOR(i,a,b) for(int i=a;i>=b;i--)

const int MAXN = 1000111;
const int mxn = 1e5+10;
const int MAX = 1e6 + 1;
const int MOD = 1e9;
const int INF = 1e9;

int main(){
	int n; cin >> n;
	if(n % 2 == 0)
		cout << n << "\n";
	else
		cout << (ll)2*n << "\n";
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define LLI long long int
#define FOR(v, a, b) for(LLI v = (a); v < (b); ++v)
#define FORE(v, a, b) for(LLI v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(LLI v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define popcount __builtin_popcount
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m/gcd(m,n)*n;}

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void puts_all(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void puts_all(const T &value, const Args&... args){std::cout << value << " ";puts_all(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;


const int MAX = 10000;

int main(){
  int h, n;

  while(cin >> h >> n){
    vector<LLI> A(n), B(n);
    REP(i,n) cin >> A[i] >> B[i];

    vector<int> M(MAX + 1, INT_MAX);

    M[0] = 0;

    REP(i,n){
      FORE(j,0,MAX){
        if(j + A[i] <= MAX) chmin(M[j + A[i]], M[j] + B[i]);
      }
    }

    REV(i,MAX-1,0){
      chmin(M[i], M[i+1]);
    }

    cout << M[h] << endl;
    
  }

  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char a[55][55],b[55][55];
int main()
{
    int n,m,flag1=0,flag2=0;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;i++)
        scanf("%s",a[i]);
    for(int i=0;i<m;i++)
    scanf("%s",b[i]);
    for(int i=0;i<=n-m;i++)
        for(int j=0;j<=n-m;j++)
    {
        flag1=0;
        for(int k=0;k<m;k++)
                for(int l=0;l<m;l++)
            {
                if(a[i+k][j+l]!=b[k][l]) {flag1=1;break;}
            }

        if(flag1==0)
        {
            flag2=1;
            break;
        }
    }
    if(flag2) puts("Yes");
    else puts("No");
    return 0;
}


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

#define FOR(i,a,b) for (int i = a; i < b; i++)
#define C1(x) cout << x 

using namespace std;

int main(){
  	int n;
  	cin >> n;
  	while(n%111!=0) ++n;
  	C1(n);
  	return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
template<class T>bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
const int INF = 1e9;
const ll LINF = 1e18;
#define ANS(ans) cout<<ans<<endl;
// clang-format on

void solve(long long A, long long P) { ANS((A * 3 + P) / 2); }

int main() {
  long long A;
  scanf("%lld", &A);
  long long P;
  scanf("%lld", &P);
  solve(A, P);
  return 0;
}


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

int main() {
	int n; cin >> n;
	vector<int> v;
	vector<int> c;
	int z;
	for (int i = 0; i < n; i++) {
		cin >> z;
		v.push_back(z);
	}
	for (int i = 0; i < n; i++) {
		cin >> z;
		c.push_back(z);
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (v[i] > c[i]) ans += v[i] - c[i];
	}

	cout << ans << endl;

	return 0;
}

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

int main(){
  int N; cin >> N;
  vector<int> kaz(N+1, 0);
  int ans = 0;
  for(int i = 0; i < N; i++){
    int a; cin >> a;
    if(a <= N) kaz[a]++;
    else ans++;
  }
  for(int i = 0; i <= N; i++){
    if(kaz[i] == 0 || kaz[i] == i) continue;
    if(kaz[i] < i) ans += kaz[i];
    else ans += (kaz[i] - i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

const int MAX = 3000000;
const int P = 1000000007; //shuoud be prime

long long fac[MAX], finv[MAX], inv[MAX];

void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % P;
        inv[i] = P - inv[P%i] * (P / i) % P;
        finv[i] = finv[i - 1] * inv[i] % P;
    }
}

// 二項係数計算
long long COMB(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % P) % P;
}

long long X, Y;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	COMBinit();

	cin >> X >> Y;
	long long K = X + Y;
	if((K % 3) != 0){
		printf("0\n");
		return 0;
	}
	int k = K / 3;
	if(2*Y < X || Y > 2*X){
		printf("0\n");
		return 0;
	}

	long long ans = COMB(k, ((2 * K) / 3) - X);
	ans %= P;
	if(ans < 0) ans += P;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 74068
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;

template <typename T>
struct Edge { int src, dst; T cost;
    Edge(int dst, T cost) : src(-1), dst(dst), cost(cost) { }
    Edge(int src, int dst, T cost) : src(src), dst(dst), cost(cost) { }
};
template <typename T> using Edges = vector<Edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
template <typename T> using Matrix = vector<vector<T>>;

template <typename T>
void warshall_floyd(Matrix<T> &g) {
    const T INF = numeric_limits<T>::max();
    for (int k = 0; k < g.size(); k++) {
        for (int i = 0; i < g.size(); i++) if (g[i][k] != INF) {
            for (int j = 0; j < g.size(); j++) if (g[k][j] != INF) {
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
}

int main() {
    int n, m;
    const auto INF = numeric_limits<int>::max();
    while (cin >> n >> m, n) {
        Matrix<int> cost(m, vector<int>(m, INF));
        Matrix<int> time(m, vector<int>(m, INF));
        for (int i = 0; i < m; i++) cost[i][i] = 0, time[i][i] = 0;
        while (n--) {
            int a, b, c, t; cin >> a >> b >> c >> t; a--, b--;
            cost[a][b] = cost[b][a] = c;
            time[a][b] = time[b][a] = t;
        }
        warshall_floyd(cost);
        warshall_floyd(time);
        int k; cin >> k;
        while (k--) {
            int p, q, r; cin >> p >> q >> r; p--, q--;
            cout << (r == 0 ? cost[p][q] : time[p][q]) << endl;
        }
    }
    return 0;
}


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

signed main() {
    string s; cin >> s;
    sort(s.begin(), s.end());
    bool ok = s[0] == s[1] && s[2] == s[3] && s[0] != s[2];
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
vector<int>g[123456];
int dp[123456];
vector<int>a;
int ans;
int dfs(int u){
    if(dp[u] != -1) return dp[u];
    int res = 0;
    for(int x:g[u]){
        res = max(res, 1 + dfs(x));
    }
    return dp[u] = res;
}
int main(){
    int n,m;
    cin >> n  >> m;
    rep(i,n)dp[i] = -1;
    while(m--){
        int A,b;
        cin >>A >> b;
        A--,b--;
        g[A].push_back(b);
    }
    rep(i,n){
        ans = max(dfs(i),ans);
    }
    cout << ans << endl;
}

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

using namespace std;

int main()
{
 int a,b,c;
  cin>>a>>b>>c;
  if((c>a && c<b)||(c<a&&c>b))
  {
   cout<<"Yes"<<endl;
    return 0;
  }
  else
  {
    cout<<"No"<<endl;
    return 0;
  }
}

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

int main() {
	int n, k;
	string s;
	cin >> n >> k >> s;
	vector<int> v;
	if (s[0] == '0') v.push_back(0);
	for (int i = 0; i < n; ) {
		int a = 0;
		while (i < n-1 && s[i] == s[i+1]) {
			i++;
			a++;
		}
		i++;
		a++;
		v.push_back(a);
	}
	if (v.size() % 2 == 0) v.push_back(0);
	k = min(k, (int)v.size() / 2);
	for (int i = 0; i < v.size()-1; i++) {
		v[i+1] += v[i];
	}
	v.insert(v.begin(), 0);
	int ans = 0;
	for (int i = 0; i+k*2+1 < v.size(); i += 2) {
		ans = max(ans, v[i+k*2+1] - v[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4064
#A

#B
"""
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = sum(l) - 2*l[-1]
if ans > 0:
    print("Yes")
else:
    print("No")
"""

#C
"""
import bisect
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
xb = [abs(x[i] - x[i + 1]) for i in range(m-1)]
xb.sort(reverse=True)
ans = sum(xb[n - 1::])
print(ans)
"""

#D
n, m = map(int, input().split())
x = list(map(int, input().split()))
a = 0
b = 0
ans = 0
ansb = 0
mae = 0
b = [0 for i in range(40)]
for i in range(40):
    for k in x:
        b[i] += (k & (1 << i)) >> i

for i in range(39, -1, -1):
    if m & (1 << i) > 0:
        ansb = mae
        ansb += b[i] << i
        for k in range(i):
            ansb += max(b[k], n-b[k]) << k
        ans = max(ans, ansb)
        mae += (n-b[i]) << i
    else:
        mae += b[i] << i
ans = max(ans, mae)
print(ans)



        





Measured memory_bytes: 69008
#include <iostream>
#include <string>
#include <queue>
#define llint long long

using namespace std;

llint n;
llint a[100005];

void GaussianElimination(llint a[], int n)
{
	llint r = 0;
	for(int i = 59; i >= 0 && r < n; i--){
		if((a[r]&(1LL<<i)) == 0){
			int p = -1;
			for(int j = r+1; j < n; j++){
				if(a[j] & (1LL<<i)){
					p = j;
					break;
				}
			}
			if(p == -1) goto end;
			swap(a[r], a[p]);
		}
		for(int j = 0; j < n; j++){
			if(j == r) continue;
			if(a[j]&(1LL<<i)) a[j] ^= a[r];
		}
		r++;
		end:;
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	
	llint ans = 0;
	for(int i = 0; i < 60; i++){
		llint cnt = 0;
		for(int j = 0; j < n; j++) if(a[j] & (1LL<<i)) cnt++;
		if(cnt % 2){
			ans += (1LL<<i);
			for(int j = 0; j < n; j++) a[j] &= ~(1LL<<i);
		}
	}
	
	/*for(int i = 0; i < n; i++){
		for(int j = 20; j >= 0; j--){
			cout << ((a[i]>>j)&1);
		}
		cout << endl;
	}
	cout << endl;*/
	
	GaussianElimination(a, n);
	
	/*for(int i = 0; i < n; i++){
		for(int j = 20; j >= 0; j--){
			cout << ((a[i]>>j)&1);
		}
		cout << endl;
	}*/
	
	llint tmp = 0, pre = 0;
	for(int i = 59; i >= 0; i--){
		if(tmp & (1LL<<i)) continue;
		for(int j = pre; j < n; j++){
			for(int k = 59; k >= i+1; k--){
				if(a[j] & (1LL<<k)) goto pass;
			}
			if(a[j] & (1LL<<i)) tmp ^= a[j], pre = j;
			break;
			pass:;
		}
	}
	//cout << tmp << endl;
	ans += tmp * 2;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
;; #!/usr/bin/env sbcl --script

(declaim (optimize (speed 3) (safety 0) (debug 0)))

(deftype int32 () '(signed-byte 32))

(defun main ()
  (let* ((n (read))
         (k (read))
         (a (make-array n :element-type 'int32))
         (dp (make-array n :element-type 'int32 :initial-element (+ (expt 10 9) 100))))
    (let ((stream (make-string-input-stream (read-line))))
      (loop for i from 0
         for j = (read stream nil) until (null j)
         do (setf (aref a i) (the int32 j))))
    (setf (aref dp 0) 0)
    (loop for i of-type int32 from 0 below n do
      (loop with from-val of-type int32 = (aref dp i)
         for j of-type int32 from (1+ i) to (+ i k)
         while (< j n)
         do
           (let ((nval (+ from-val (abs (- (aref a i) (aref a j))))))
             (setf (aref dp j) (min (aref dp j) nval)))))
    (format t "~a~%" (aref dp (- n 1)))))

(main)


Measured memory_bytes: 57704
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef vector <int> VI;

int main() {
    int n;
    while ( cin >> n && n ) {
        VI A( n );
        for ( int i = 0; i < n; ++ i ) cin >> A[i];
        sort( A.begin(), A.end() );
        int n = A.size();
        long long answer = 0;
        long long w = 0;
        for ( int i = 0; i < n; ++ i ) {
            answer += w;
            w += A[i];
        }
        cout << answer << endl;
    }
    return 0;
}

Measured memory_bytes: 0
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

constexpr long double pi = acos(-1L);
const long double EPS = 1e-8;

void expr(int X) {
    long double rad = X * pi / 180;

    long double x = 0, y = 0, vx = 0, vy = 1;

    int itr = 0;
    while(true) {
        x += vx, y += vy; itr++;
        fprintf(stderr, "vx = %.12Lf, vy = %.12Lf\n", vx, vy);
        if(itr >= 10000) break;
        if(abs(x) < EPS and abs(y) < EPS) break;
        long double n_vx = vx * cos(rad) - vy * sin(rad);
        long double n_vy = vx * sin(rad) + vy * cos(rad);
        swap(vx, n_vx);
        swap(vy, n_vy);
    }
    printf("%d\n", itr);
}

int main() {
    int X; cin >> X;
    expr(X);
    return 0;
}


Measured memory_bytes: 4072
n,k = map(int, input().split())

ab = [list(map(int, input().split())) for _ in range(n)]
s_ab = sorted(ab, key=lambda x: x[0])
cnt = 0
ans = -1
for i in s_ab:
    cnt += i[1]
    if cnt >= k:
        ans = i[0]
        break
print(ans)

Measured memory_bytes: 29912
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin>>x;
  if(x==3||x==5||x==7)
  {
    cout<<"YES"<<endl;
  }
  else
  {
    cout<<"NO"<<endl;
  }

  return 0;

}


Measured memory_bytes: 256
import sys

n = sys.stdin.readline()
S = [1]*13
H = [1]*13
C = [1]*13
D = [1]*13

for e in sys.stdin:
    inp = list(e.split())
    suit = inp[0]
    num = int(inp[1])
    if suit == "S":
        S[num-1] = 0
    elif suit == "H":
        H[num-1] = 0
    elif suit == "C":
        C[num-1] = 0
    elif suit == "D":
        D[num-1] = 0
        
for i in range(13):
    if S[i] == 1:
        print("S " + str(i+1))

for i in range(13):
    if H[i] == 1:
        print("H " + str(i+1))

for i in range(13):
    if C[i] == 1:
        print("C " + str(i+1))

for i in range(13):
    if D[i] == 1:
        print("D " + str(i+1))



Measured memory_bytes: 5608
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int[] a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = scanner.nextInt();
    }
    
    int negative_count_parity;
    if(a[0] < 0){
      negative_count_parity = 1;
    }else{
      negative_count_parity = 0;
    }
    //boolean zero_existence = false;
    int zero_closer = abs(a[0]);
    long sum = 0;
    for(int i = 1; i < n; i++){
      int ai = a[i];
      if(ai > 0){
        if(ai < zero_closer){
          sum += (long)zero_closer;
          zero_closer = ai;
        }else{
          sum += (long)ai;
        }
      }else if(ai == 0){
        sum += (long)zero_closer;
        zero_closer = 0;
      }else{
        if(ai > -zero_closer){
          sum += (long)zero_closer;
          zero_closer = -ai;
        }else{
          sum += (long)(-ai);
        }
        negative_count_parity ^= 1;
      }
    }
    
    if(negative_count_parity == 0){
      sum += (long)zero_closer;
    }else{
      sum -= (long)zero_closer;
    }
    
    System.out.println(sum);
  }
  
  public static int abs(int m){
    if(m < 0) m = -m;
    return m;
  }
}


Measured memory_bytes: 50512
#include <stdio.h>

int main(void)
{
    int i, j;
    int n;
    int num;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++){
        scanf("%d", &num);
        printf("Case %d:\n", i + 1);
        for (j = 0; j < 10; j++){
            num *= num;
            num /= 100;
            num %= 10000;
            printf("%d\n", num);
        }
    }
    
    return (0);
}

Measured memory_bytes: 0
#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll N;
map<ll, ll> A;
ll need[35];
vector<ll> vt;
ll ans;
int main() {
    cin>>N;
    ll n=1;
    while(n<=2e9){
        vt.push_back(n);
        n*=2;
    }
    REP(i,0,N){
        ll a;
        cin>>a;
        A[a]++;
    }
    map<ll,ll>::reverse_iterator m = A.rbegin();
    for(;m!=A.rend();++m){
        RREP(j,1,31){
            if(vt[j]<= m->first || m->second == 0) break;

            if(A.find(vt[j]-m->first)!=A.end()){
                ll cnt=min(m->second, A[vt[j]-m->first]);

                ll ans_cnt=cnt;
                if(vt[j]==2*(m->first)) {
                    if(A[vt[j]-m->first] == 1) continue;
                    if(cnt%2) cnt--;
                    ans_cnt=cnt/2;

                }
                m->second-=cnt;
                A[vt[j]-m->first]-=cnt;
                ans+=ans_cnt;
            }
        }
    }
    p(ans);
    return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 61)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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

i64 ceil(i64 a, i64 b) { return (a+b-1)/b; }
mt19937 rnd(time(NULL));

int d, c[30], s[404][30];
int ans[400];
clock_t start;

int score(int a[400], int l, int r){
	int cnt = 0;
	int last[26] = {};
	fill(last,last+26,l-1);
	
	for(int i = l; i < r; i++){
		cnt += s[i][a[i]];
		last[a[i]] = i;
		for(int j = 0; j < 26; j++){
			cnt -= c[j]*(i-last[j]);
		}
	}
	return cnt;
}

void solve(){
	start = clock();
	
	cin >> d;
	for(int i = 0; i < 26; i++) cin >> c[i];
	for(int i = 0; i < d; i++){
		for(int j = 0; j < 26; j++) cin >> s[i][j];
	}
	
	int ma = 0;
	set<int> st[30];
	for(int i = 0; i < 26; i++){
		st[i].insert(-1);
		st[i].insert(d);
	}
	for(int i = 0; i < d; i++){
		int v = rnd()%26;
		ans[i] = v;
		st[v].insert(i);
	}
	ma = score(ans,0,d);
	
	int cc[30] = {};
	for(int i = 0; i < 26; i++){
		cc[i+1] = c[i] + cc[i];
	}
	
	int lp = 0;
	while(clock()-start < 1.9*CLOCKS_PER_SEC){
		int p = rnd()%d;
		int pp = p+rnd()%(int)(d * (1.9-(clock()-start)/CLOCKS_PER_SEC)/1.9 + 1);
		if(pp >= d) continue;
		int q = ans[pp];
		int was = ans[p];
		
		if(q == was) continue;
		
		ans[p] = q;
		ans[pp] = was;
		
		int cnt = ma;
		
		cnt -= s[p][was];
		cnt += s[p][q];
		auto D = st[was].find(p);
		auto D1 = D; D1++;
		auto D0 = D; D0--;
		int l = *D1 - *D, r = *D - *D0;
		int lr = l+r;
		cnt += c[was] * (l*(l+1)/2 + r*(r+1)/2);
		cnt -= c[was] * lr*(lr+1)/2;
		st[was].erase(p);
		
		st[q].insert(p);
		D = st[q].find(p);
		D1 = D; D1++;
		D0 = D; D0--;
		l = *D1 - *D; r = *D - *D0;
		lr = l+r;
		cnt -= c[q] * (l*(l+1)/2 + r*(r+1)/2);
		cnt += c[q] * lr*(lr+1)/2;
		
		
		cnt -= s[pp][q];
		cnt += s[pp][was];
		D = st[q].find(pp);
		D1 = D; D1++;
		D0 = D; D0--;
		l = *D1 - *D, r = *D - *D0;
		lr = l+r;
		cnt += c[q] * (l*(l+1)/2 + r*(r+1)/2);
		cnt -= c[q] * lr*(lr+1)/2;
		st[q].erase(pp);
		
		st[was].insert(pp);
		D = st[was].find(pp);
		D1 = D; D1++;
		D0 = D; D0--;
		l = *D1 - *D; r = *D - *D0;
		lr = l+r;
		cnt -= c[was] * (l*(l+1)/2 + r*(r+1)/2);
		cnt += c[was] * lr*(lr+1)/2;
		
		if(!chmax(ma,cnt)){
			ans[p] = was;
			ans[pp] = q;
			st[was].insert(p);
			st[q].erase(p);
			st[was].erase(pp);
			st[q].insert(pp);
		}
		
		
		//if(lp%1000 == 0) cout << ma << endl;
		lp++;
	}
	// cout << lp << endl;
	// cout << ma << endl;
	// cout << score(ans,0,d) << endl;
	
	for(int i = 0; i < d; i++){
		cout << ans[i]+1 << endl;
	}
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3744
n,m = map(int,input().split())
c = list(map(int,input().split()))

dp = [None]*50001
for i in c:
    dp[i] = 1

for i in range(1,n+1):
    if dp[i]:
        continue
    min_count = float('inf')
    for j in c:
        if i-j>0:
            min_count = min(min_count,1+dp[i-j])
            
    dp[i] = min_count
    
print(dp[n])


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

int main(){
	string str;
	cin >> str;
	int work[26] = { 0 };
	for (int i = 0; i < str.size(); i++){
		int a = str[i] - 'a';
		work[a]++;
	}
	bool flag = false;
	for (int i = 0; i < 26; i++){
		if (work[i] % 2 != 0){
			flag = true;
			break;
		}
	}

	if (flag)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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; }

const int mod=1e9+7;
const int INF=1001001001;
int dp[50][500][500];
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];
  }
  for(int i=0;i<=N;i++){
    for(int j=0;j<=500;j++){
      for(int k=0;k<=500;k++){
        dp[i][j][k]=INF;
      }
    }
  }
  dp[0][0][0]=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<=500;j++){
      for(int k=0;k<=500;k++){
        chmin(dp[i+1][j+a[i]][k+b[i]],dp[i][j][k]+c[i]);
        chmin(dp[i+1][j][k],dp[i][j][k]);
      }
    }
  }
  int MIN=INF;
  for(int j=1;j<=500;j++){
    for(int k=1;k<=500;k++){
      if(j*Mb==k*Ma){
        chmin(MIN,dp[N][j][k]);
      }
    }
  }
  if(MIN==INF){cout<<-1<<endl;}
  else{cout<<MIN<<endl;}
  return 0;  
}

Measured memory_bytes: 43624
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
#include <stack>
  
using namespace std;

#define pi 3.141592653589793

int ans(int w, int d, int hw[], int hd[])
{
	int wcnt = 0, dcnt = 0, ans = 0;
	for(int i = 0; i < w; i++){
		ans += hw[i];
	}
	while(wcnt < w && dcnt < d){
		if(hw[wcnt] == hd[dcnt]){
			wcnt++;
			dcnt++;
		} else if(hw[wcnt] > hd[dcnt]){
			ans += hd[dcnt];
			dcnt++;
		} else {
			wcnt++;
		}
	}
	while(dcnt < d){
		ans += hd[dcnt];
		dcnt++;
	}
	return ans;
}

int main()
{
	int w, d;
	while(1){
		cin >> w >> d;
		if(w == 0 && d == 0) break;
		int hw[11], hd[11];
		for(int i = 0; i < w; i++){
			cin >> hw[i];
		}
		for(int i = 0; i < d; i++){
			cin >> hd[i];
		}
		sort(hw, hw + w);
		sort(hd, hd + d);
		cout << ans(w, d, hw, hd) << endl;
	}
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){
    if(u==NIL){
        return NIL;
    }
    if(k==u->key){
    return u;
    }
    else{
        if(u->key>k){
            return treeSearch(u->left, k);
        }
        else{
            return treeSearch(u->right, k);
        }
    }
}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL){
      y=x;
      if(z->key < x->key){
          x=x->left;
      }
      else{
          x=x->right;
          
      }
  }
  z->parent=y;
  if(y==NIL){
      root=z;
      
  }
  else if(z->key<y->key){
      y->left=z;
      
  }  
  else{
      y->right=z;
      
  }
}

void inorder(Node u){
    if (u==NIL){
        return;
    }
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}
void preorder(Node u){
    if (u==NIL){
        return;
    }
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}


Measured memory_bytes: 20444
#pragma region Header
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

// {waapu, h, w}
using p = tuple<int, int, int>;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int h_size, w_size;
    cin >> h_size >> w_size;
    int h_from, w_from;
    cin >> h_from >> w_from;
    --h_from;
    --w_from;
    int h_to, w_to;
    cin >> h_to >> w_to;
    --h_to;
    --w_to;
    vector can_go(h_size, vector<bool>(w_size));
    rep(h, h_size)
    {
        rep(w, w_size)
        {
            char c;
            cin >> c;
            can_go[h][w] = (c == '.');
        }
    }

    // dijkstra
    int ans = -1;
    vector dist(h_size, vector<int>(w_size, 1000'000));
    priority_queue<p, vector<p>, greater<p>> pq;
    vector used(h_size, vector<bool>(w_size, false));
  int num_used = 0;
    pq.emplace(0, h_from, w_from);
    while (not pq.empty() and num_used < h_size * w_size)
    {
        auto [cost, h, w] = pq.top();
        pq.pop();
        if (h == h_to and w == w_to)
        {
            ans = cost;
            break;
        }
        if (used[h][w])
        {
            continue;
        }
        used[h][w] = true;
      ++num_used;
        FOR(dh, -2, 2)
        {
            FOR(dw, -2, 2)
            {
                auto h_new = h + dh, w_new = w + dw;
                if (h_new < 0 or h_new >= h_size or w_new < 0 or w_new >= w_size)
                {
                    continue;
                }
                if (not can_go[h_new][w_new] or used[h_new][w_new])
                {
                    continue;
                }
                int dcost = (abs(dh) + abs(dw) > 1);
                if (not chmin(dist[h_new][w_new], cost + dcost))
                {
                    continue;
                }
                pq.emplace(cost + dcost, h_new, w_new);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7924
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef priority_queue<ll, vl> decendingQueue;              //降順
typedef priority_queue<ll, vl, greater<ll>> ascendingQueue; //昇順
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 9 * 1e18;
const ll MOD = 1e9 + 7;

void solve(long long H, long long W, std::vector<std::string> S) {
  vector<vl> cntsH(H + 1, vl(W + 1));
  vector<vl> cntsW(H + 1, vl(W + 1));
  rep(h, 1, H + 1) {
    rep(w, 1, W + 1) {
      if (S[h - 1][w - 1] == '.') {
        cntsW[h][w] += cntsW[h][w - 1] + 1;
      }
    }
  }

  rep(w, 1, W + 1) {
    rep(h, 1, H + 1) {
      if (S[h - 1][w - 1] == '.') {
        cntsH[h][w] += cntsH[h - 1][w] + 1;
      }
    }
  }

  rrep(h, 1, H + 1) {
    rrep(w, 1, W + 1) {
      if (cntsW[h][w] > 0 && cntsW[h][w - 1] > 0) {
        cntsW[h][w - 1] = cntsW[h][w];
      }
    }
  }

  rrep(w, 1, W + 1) {
    rrep(h, 1, H + 1) {
      if (cntsH[h][w] > 0 && cntsH[h - 1][w] > 0) {
        cntsH[h - 1][w] = cntsH[h][w];
      }
    }
  }

  ll ans = 0;
  rep(h, 1, H + 1) {
    rep(w, 1, W + 1) {
      if (cntsH[h][w] > 0) {
        ans = max(cntsH[h][w] + cntsW[h][w] - 1, ans);
      }
    }
  }

  print(ans);
}

int main() {
  long long H;
  scanf("%lld", &H);
  long long W;
  scanf("%lld", &W);
  std::vector<std::string> S(H);
  for (int i = 0; i < H; i++) {
    std::cin >> S[i];
  }
  solve(H, W, std::move(S));
  return 0;
}


Measured memory_bytes: 67072