akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<list>
#include<cmath>
using namespace std;
using ll = long long;
const int INF = 1e8;
ll D, G;
int main() {
	cin >> D >> G;
	vector<ll>P(D), C(D);
	for (int i = 0; i < D; ++i) {
		cin >> P[i] >> C[i];
	}
	ll res = 1 << 29;
	for (int bit = 0;bit<(1<<D);++bit) {
		ll sum = 0;
		ll num = 0;
		for (int i = 0; i < D; ++i) {
			if (bit &(1 << i)) {
				sum += C[i] + P[i] * 100 * (i + 1), num += P[i];
			}
		}
		if (sum >= G)res = min(res, num);
		else {
			for (int i= D - 1; i >= 0; --i) {
				if (bit&(1 << i))continue;
				for (int j = 0; j < P[i]; ++j) {
					if (sum >= G)break;
					sum += 100 * (i + 1);
					++num;
				}
			}
			res = min(res, num);
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
s = gets.chomp

s1 = s[0, 2].to_i
s2 = s[2, 2].to_i

def checkMM(n)
  true if 1 <= n && n <= 12
end

if checkMM(s1) && checkMM(s2) then
  puts "AMBIGUOUS"
elsif checkMM(s1) then
  puts "MMYY"
elsif checkMM(s2) then
  puts "YYMM"
else
  puts "NA"
end

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

ll fact(int i)
{
	int j = 1;
	ll ans = 1;
	while (++j <= i) {
		ans = (ans * j) % MOD;
	}
	return ans;
}

int main()
{
	int n;
	cin >> n;
	cout << fact(n) << endl;
	return 0;
}



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

int main(){
    double r;
    cin >> r;
    
    cout << fixed << setprecision(6)<< M_PI*r*r << " " << fixed << setprecision(6) << 2*M_PI*r << endl;
    return 0;
    
}

Measured memory_bytes: 3212
using System;
using System.Linq;

class D
{
	static void Main()
	{
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
		for (var i = a[1] / a[0]; ; i--) if (a[1] % i == 0) { Console.WriteLine(i); return; }
	}
}


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

const long long mod = 1e9+7;

int main()
{
        int N, M;
        cin >> N >> M;

        vector<int> a(N+1, true);
        for(int i = 0; i < M; i++)
        {
                int aa = 0;
                cin >> aa;
                a[aa] = false;
        }

        vector<long long int> dp(N+1);
        dp[0] = 1;
        for(int i = 0; i < N; i++)
        {
                for(int j = i+1; j <= min(N, i+2); j++)
                {
                        if(a[j] >= 1)
                        {
                                dp[j] += dp[i];
                                dp[j] %= mod;
                        }
                }
        }

        cout << dp[N] << endl;

        return 0;
}

Measured memory_bytes: 1408
//52
#include<iostream>
#include<algorithm>

using namespace std;

int g[9][9];
bool u[9][9];
int n,c;

int ff(int y,int x,int cc){
  if(y<0||x<0||y>=n||x>y){
    return 0;
  }else if(g[y][x]==0){
    return -100;
  }else if(g[y][x]!=cc||u[y][x]){
    return 0;
  }else{
    u[y][x]=true;
    int cp=1;
    for(int i=0;i<6;i++){
      int dy[]={-1,-1,0,1,1,0};
      int dx[]={-1,0,1,1,0,-1};
      cp+=ff(y+dy[i],x+dx[i],cc);
    }
    return cp;
  }
}

int main(){
  while(cin>>n>>c,n|c){
    for(int i=0;i<n;i++){
      for(int j=0;j<=i;j++){
	cin>>g[i][j];
      }
    }
    int mp=1<<31;
    for(int i=0;i<n;i++){
      for(int j=0;j<=i;j++){
	if(g[i][j])continue;
	g[i][j]=c;
	int cp=0;
	fill(u[0],u[9],false);
	for(int k=0;k<n;k++){
	  for(int l=0;l<=k;l++){
	    int r=ff(k,l,g[k][l]);
	    if(r>0){
	      cp+=(g[k][l]==c)?-r:r;
	    }
	  }
	}
	mp=max(mp,cp);
	g[i][j]=0;
      }
    }
    cout<<mp<<endl;
  }
  return 0;
}
	  

Measured memory_bytes: 1160
# frozen_string_literal: true

require 'matrix'

n, m = readline.split(' ').map(&:to_i)
a = Matrix.rows(n.times.map { gets.split(' ').map(&:to_i) })
b = Matrix.rows(m.times.map { gets.split(' ').map(&:to_i) })
c = a * b
puts c.to_a.map { |row| row.join(' ') } .join("\n")



Measured memory_bytes: 7776
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007

ll modpow(ll x, ll y) {
	ll ans = 1;
	while (y) {
		if (y & 1)ans *= x;
		ans %= MOD;
		x *= x;
		x %= MOD;
		y /= 2;
	}
	return ans;
}

ll fact[200010];
ll inv[200010];

ll nCk(ll n, ll k) {
	return fact[n] * inv[k] % MOD * inv[n - k] % MOD;
}

int main() {
	ll N, K;
	cin >> N >> K;

	fact[0] = 1;
	inv[0] = 1;
	for (ll i = 1;i < 200010;i++) {
		fact[i] = fact[i - 1] * i % MOD;
		inv[i] = modpow(fact[i], MOD - 2);
	}

	ll ans = 0;
	for (ll i = 0;i < N;i++) {
		if (i > K)break;
		ans += nCk(N, i) * nCk(N - 1, N - i - 1);
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328
import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline
mod=10**9+7
n=int(input())
es=[[] for i in range(n)]
for i in range(n-1):
   a,b=map(int,input().split())
   es[a-1].append(b-1)
   es[b-1].append(a-1)
dp=[[0,0] for i in range(n)]
def dfs(v,c,p):
    if dp[v][c]:
        return dp[v][c]
    ans=1
    if c:
        for i in es[v]:
            if i-p:
                ans*=dfs(i,0,v)+dfs(i,1,v)
                ans%=mod
    else:
        for i in es[v]:
            if i-p:
                ans*=dfs(i,1,v)
                ans%=mod
    # print(ans,c,v)
    dp[v][c]=ans
    return ans
print((dfs(0,0,-1)+dfs(0,1,-1))%mod)

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

#define p pair<int,int>
#define mp(a,b) make_pair(a,b)
using namespace std;

int main() {
	int n,m; cin>>n>>m;
	vector<vector<p>> city(n);
	for(int i=0;i<m;i++) {
		int a,b; cin>>a>>b;
		a--; city[a].push_back(mp(b,i));
	}
	vector<p> ret(m);
	for(int i=0;i<n;i++){
		sort(city[i].begin(),city[i].end());
		for(int j=0;j<city[i].size();j++){
			ret[city[i][j].second]=mp(i+1,j+1);
		}
	}
	for(int i=0;i<m;i++){
		p x=ret[i];
		string s1=to_string(x.first); string s2=to_string(x.second);
		cout<<string(max(0,6-(int)s1.size()),'0')<<s1<<
			  string(max(0,6-(int)s2.size()),'0')<<s2<<endl;
	}
	return 0;
}

Measured memory_bytes: 7808
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int abcde[]=new int[5];
		for(int i=0;i<abcde.length;i++) {
			abcde[i]=scan.nextInt();
		}
		scan.close();
		int x=0;
		int suffix=0;
		for(int i=0;i<5;i++) {
			if(10-abcde[i]%10>x && abcde[i]%10!=0) {
				suffix=i;
				x=10-abcde[i]%10;
			}
		}
		int sum=0;
		for(int i=0;i<5;i++) {
			if(suffix!=i) {
				sum+=(abcde[i]%10==0)? abcde[i]:abcde[i]-abcde[i]%10+10;
			}
		}
		sum+=abcde[suffix];
		System.out.println(sum);
	}

}

Measured memory_bytes: 21844
#include <stdio.h>
int main() {
char s[4];
int a = 0;
scanf("%s", s);
for (int i = 0;i < 4;i++) {
if (s[i] == '+') {
a = a + 1;
} else if (s[i] == '-') {
a = a - 1;
} }
printf("%d\n", a);
return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) {
	Scanner scanner = new Scanner(System.in);
    String text = scanner.nextLine();
    
    StringBuilder result = new StringBuilder();
    for (int ix = 0; ix < text.length(); ix++) {
      if (text.charAt(ix) == '9') {
        result.append(1);
      } else {
        result.append(9);
      }
    }
    
    System.out.println(result);
  }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define endl '\n'
#define pii pair<int,int>
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define fill(a,b) memset(a,b,sizeof(a))
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int x,y,p,q,r; cin>>x>>y>>p>>q>>r;
    vector<int> a(p),b(q),c(r); 
    for(int i=0;i<p;i++) cin>>a[i];
    for(int i=0;i<q;i++) cin>>b[i];
    for(int i=0;i<r;i++) cin>>c[i];
    sort(all(a),greater<int>());
    sort(all(b),greater<int>());
    for(int i=0;i<x;i++) c.pb(a[i]);
    for(int i=0;i<y;i++) c.pb(b[i]);
    sort(all(c),greater<int>());
    int sum=0;
    for(int i=0;i<x+y;i++) sum+=c[i];
    cout<<sum<<endl;
}

Measured memory_bytes: 6000
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const ll MAX_N = 1e5 + 10;
ll cnt[2 * MAX_N];
ll arr[MAX_N];
ll n;

ll solve(ll x) {
    ll curr = 0, nowans = 1;
    fill_n(cnt, 2 * MAX_N, 0);
    cnt[MAX_N] ++;
    ll ret = 0;
    for(ll i = 0; i < n; i ++) {
        if(arr[i] >= x) {
            curr ++;
            nowans += cnt[curr + MAX_N];
        } else {
            nowans -= cnt[curr + MAX_N];
            curr --;
        }
        cnt[curr + MAX_N] ++;
        ret += nowans;
        nowans ++;
    }
    return ret;
}

signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for(ll i = 0; i < n; i ++) {
        cin >> arr[i];
    }
    ll need = ((n * n + n) / 2ll + 1) / 2ll;
    ll l = 0, r = mod;
    while(l < r - 1) {
        ll m = (l + r) / 2;
        //cout << solve(m) << " " << m << endl;
        if(need > solve(m)) {
            r = m;
        } else {
            l = m;
        }
    }
    cout << l << endl;
    return 0;
}




Measured memory_bytes: 2560
n = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

if len(prime_factorize(n)) == 1:
  print(n - 1)
  exit()

ret = None
min_r = n
for x in range(2, int( n / 2)):
  q, mod = divmod(n, x)
  _min_r = (2 * x - 2) + (q - x)
  if mod == 0 and min_r > _min_r:
    min_r = _min_r
    ret = (x, q)
  
  if x > q:
    break

print(min_r)

Measured memory_bytes: 3064
#include <stdio.h>

int main(){
	int A, B;
	scanf("%d %d", &A, &B); getchar();
	int sum = A+B;
	int kurang = A-B;
	int kali = A*B;
	if(sum >= kurang && sum >= kali) printf("%d\n", sum);
	else if(kurang >= sum && kurang >= kali) printf("%d\n", kurang);
	else if(kali >= sum && kali >= kurang) printf("%d\n", kali);
		
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    ll n, T;
    cin >> n >> T;
    vint t(n);
    rep(i, n) cin >> t[i];

    ll ans = 0;
    ll now, end, prev;
    end = 0;
    prev = 0;
    rep(i, n) {
        prev = end;
        now = t[i];
        end = now+T;
        ans += min(end - prev, T);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
C = [list(map(int,input().split())) for i in range(3)]
if C[0][0]-C[0][1] == C[1][0]-C[1][1] == C[2][0]-C[2][1] \
   and C[0][2]-C[0][1] == C[1][2]-C[1][1] == C[2][2]-C[2][1] \
   and C[0][0]-C[1][0] == C[0][1]-C[1][1] == C[0][2]-C[1][2] \
   and C[2][0]-C[1][0] == C[2][1]-C[1][1] == C[2][2]-C[1][2]:
    print('Yes')
else:
    print('No')

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

using ll = long long;

const int N = 100005;

int n, a[3 * N];
ll b[2 * N], c[2 * N], ans = ll(-1e18);

void f(ll d[], int p){
	ll s = 0;
	priority_queue<ll> pq;
	for(int i = 0; i <= 2 * n; i++){
		pq.push(p * a[i]);
		s += p * a[i];
		while(pq.size() > n){
			s -= pq.top();
			pq.pop();
		}
		d[i] = p * s;
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	for(int i = 0; i < 3 * n; i++) cin >> a[i];
	f(b, -1);
	reverse(a, a + 3 * n);
	f(c, 1);
	for(int i = 0; i <= n; i++) ans = max(ans, b[n - 1 + i] - c[2 * n - 1 - i]);
	cout << ans << endl;
}

Measured memory_bytes: 6384
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << "[" << pa.first << ", " << pa.second << "]";
}

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  os << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  os << "}";
  return os;
}

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

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

  ll n;
  std::cin>>n;

  std::vector<P> a(n);
  rep(i,0,n){
    ll temp;
    std::cin>>temp;
    a[i]={temp,i+1};
  }

  std::sort(all(a));
  rep(i,0,n){
    std::cout<<a[i].second<<" ";
  }

  return 0;
}

Measured memory_bytes: 2432
//created by pyoxiao on 2020/05/10
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod){LL ans = 1; a %= p; while(b) {if(b & 1) ans = ans * a % p; b >>= 1; a = a * a % p;} return ans;}
LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a % b);}
int a, b, c, k;
void solve() {
    cin >> a >> b >> c >> k;
    if(k <= a) {
        cout << k << '\n';
        return;
    }
    k -= a;
    if(k <= b) {
        cout << a << '\n';
        return;
    }
    k -= b;
    cout << a - k << '\n';
}
int main() {
    int T = 1;
    // scanf("%d", &T);
    while(T --) 
        solve();
    return 0;
}

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

using namespace std;

const int maxn = 2e3 + 5;

int a[maxn];

int main() {
	int n;
	ios::sync_with_stdio(0);
	cin >> n;
	for(int i = 0 ; i < n ; i++) {
		cin >> a[i];
	}
	sort(a , a + n);
	int ans = 0;
	for(int i = 0 ; i < n -2; i++) {
		for(int j = i + 1 ; j < n - 1; j++) {
			int t = a[i] + a[j];
			int left = j + 1, right = n - 1;
			if(a[j + 1] >= t) {
				continue;
			}
			while(left < right) {
				int mid = (left + right + 1) / 2;
				if(a[mid] < t)left = mid;
				else right = mid - 1;
			}
			if(left > j) 
			ans += left - j;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(void){
  char a;
  cin >>a;
  if(a=='A') cout<<"T"<<endl;
  else if(a=='T') cout<<"A"<<endl;
  else if(a=='C') cout<<"G"<<endl;
  else  cout<<"C"<<endl;
  return 0;
}


Measured memory_bytes: 256
//
// Created by 今村秀明 on 2017/01/20.
//

#include <stdio.h>
#include <vector>

using namespace std;

int main(){
    unsigned long long n,a,b,ans,tmp;
    vector<unsigned long long> x;

    scanf("%lld %lld %lld", &n, &a, &b);
    for(int i = 0; i < n; i++){
        scanf("%lld", &tmp);
        x.push_back(tmp);
    }

    ans = 0;
    for(int i = 0; i < x.size() - 1; i++){
        ans += min((x[i + 1] - x[i]) * a, b);
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 1400
#include <iostream>

using namespace std;

int main(void){

    long long n, cnt = 1;
    string s;
    char tmp;

    cin >> n >> s;

    tmp = s[0];

    for(long long int i = 1; i < n; i++){
        if(tmp != s[i]){
            tmp = s[i];
            cnt++;
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

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

   vector<pair<int,int>> v;
   rep(i,n){
       int a,b;
       cin>>a>>b;
       v.push_back({b,a});
   }

   sort(all(v));
   int s=0;
   rep(i,n){
       if(s+v[i].second>v[i].first){
           //cout<<i<<" "<<s<<endl;
           cout<<"No"<<endl;
           return 0;
       }
       s+=v[i].second;
   }

   cout<<"Yes"<<endl;
}

Measured memory_bytes: 5356
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <functional>
#include <numeric>
#include <vector>
using namespace std;

const double PI=acos(-1);

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

    vector<int> p(n), q(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    for(int i = 0; i < n; i++){
        cin >> q[i];
    }
    int pp = 0, qq = 0;
    for(int i = 0; i < n; i++){
        if(i!=0){
            for(int j = i; j < n; j++){
                if(p[j] > p[i-1]) p[j]--;
                if(q[j] > q[i-1]) q[j]--;
            }
        }
        if(n-1 == i) break;
        int a = 1;
        for(int j = 1, k = 1; j <= n-i-1; j++, k++){
            a *= k;
        }
        pp += (p[i] - 1)*a;
        qq += (q[i] - 1)*a;
    }
    cout << abs(pp - qq) << endl;
    return 0;
}

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

#define llong long long

class Hash {
  char V[1200000][13];
  int max;

  int charToInt(char c) {
    if (c == 'A') return 1;
    else if (c == 'C') return 2;
    else if (c == 'G') return 3;
    else if (c == 'T') return 4;
    else return 0;
  }

  llong getKey(char w[]) {
    llong key = 0, coefficient = 1;
    for(int i = 0; i < strlen(w); i++ ) {
      int t = charToInt(w[i]);
      key += coefficient * t;
      coefficient *= 5;
    }
    return key;
  }

  llong h1(llong v) { return v % max; }
  llong h2(llong v) { return (v % max) + 1; }
  llong h(llong v, int t) { return (h1(v) + t * h2(v)) % max; }
  public:
    Hash() {
      max = 1200000;
    }
    void insert(char w[]) {
      llong key = getKey(w);
      for ( int i = 0; i < max; i++ ) {
        llong hv = h(key, i);
        if ( strlen(V[hv]) == 0) {
          strcpy(V[hv], w);
          return;
        } else if( strcmp(V[hv], w) == 0) return;
      }
    }
    bool find(char w[]) {
      llong key = getKey(w);
      for ( int i = 0; i < max; i++ ) {
        llong hv = h(key, i);
        if( strcmp(V[hv], w) == 0) return 1;
        else if ( strlen(V[hv]) == 0) return 0;
      }
      return 0;
    }
};

int main() {
  int n;
  char o[7], w[13];
  Hash hash = Hash();

  scanf("%d", &n);
  while( scanf("%s %s", o, w) != EOF ) {
    if(o[0] == 'i') hash.insert(w);
    else if(o[0] == 'f') {
      if(hash.find(w)) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}


Measured memory_bytes: 17684
#include<iostream>

using namespace std;
using P=pair<int,int>;

int main(){
    long long a;
    double b;
    cin>>a>>b;
    long long ib=b*100+0.5;//
    long long ans=a*ib;
    ans/=100;
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[200005];
int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if (n == 0) {
        cout << endl;
        return 0;
    }
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    cout << a[n - 1];
    int i;
    for (i = n - 3; i >= 0; i -= 2) {
        cout << " " << a[i];
    }
    if (i == -2) {
        i = 1;
    } else {
        i = 0;
    }
    for (; i < n; i+= 2) {
        cout << " " << a[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(j, m) for (int j = 0; j <= (int)(m); j++)

void chmin(int &a, int b){
    if(a>b){
        a=b;
    }
}

int n, aa, bb, cc;
vector<int> l;


int dfs(int i, int a, int b, int c)
{if(i==n){
    if(a*b*c==0){return 100000000;}
    return abs(a-aa)+abs(b-bb)+abs(c-cc);
}
int res=dfs(i+1,a,b,c);
chmin(res,dfs(i+1,a+l[i],b,c)+(a?10:0));
chmin(res,dfs(i+1,a,b+l[i],c)+(b?10:0));
chmin(res,dfs(i+1,a,b,c+l[i])+(c?10:0));
return res;
}
int main()
{

    cin >> n >> aa >> bb >> cc;
    l.resize(n);  
    rep(i, n)
    {
        cin >> l[i];
    }

    cout << dfs(0,0,0,0) << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <cassert>
#include <complex>
#include <iomanip>
#include <random>

using namespace std;

typedef long long ll;
#define int long long

int M = 998244353;
#define msum(a, b) ((a) + (b) >= M ? (a) + (b) - M : (a) + (b))
#define msub(a, b) ((a) - (b) < 0 ? (a) - (b) + M : (a) - (b))
#define mmult(a, b) (((a) * (b)) % M)

typedef long double ld;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vlll;
typedef vector<double> vd;
typedef vector<vd> vdd;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpi;
#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define SZ(a) ((int)(a).size())
#define watch(x) cout << (#x) << " = " << (x) << endl;

const double PI = 2 * acos(0.0);
const int oo = 1e18 + 100;
const string DIGITS = "0123456789", alph = "abcdefghijklmnopqrstuvwxyz", ALPH = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

//THE END OF TEMPLATE////////////////////////////////////////////////////////////////////////////////

#define N 100100

int dp[N][3], a[N][3];


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

	int n;
	cin >> n;


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

	for (int i = 1; i <= n; i++)
	{
		dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0];
		dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1];
		dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + a[i][2];
	}


	cout << max(max(dp[n][0], dp[n][1]), dp[n][2]);
	
}

//m1.codeforces.com, m2.codeforces.com или m3.codeforces.com

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        long A = sc.nextLong();
        long B = sc.nextLong();

        System.out.println(lcm(A, B));
    }

    private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    private static long gcd(long a, long b) {
        if (b == 0) return a;
        return gcd(b, a % b);
    }
}


Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
using namespace std;
using ll = long long;
int main(){
    char c[100][100];
    int h,w;
    cin >> h >> w;
    REP(i,h){
        REP(j,w){
            cin >> c[i][j];
        }
    }
    char answer[200][100];
    REP(i,h){
        REP(j,w){
            answer[2*i][j] = c[i][j];
            answer[2*i+1][j]=c[i][j];
        }
    }
    REP(i,h*2){
        REP(j,w){
            cout << answer[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    // 入力処理
    ll n, ans = INFLL; string s; cin >> n >> s;

    // 左右両方から累積和を計算
    vi rw(n, 0), le(n, 0);
    rep(i, n){
        // 右方向に西向きの人数の累積和を取る
        if(s[i] == 'W') (i == 0) ? rw[i] = 1 : rw[i] = rw[i-1] + 1; 
        else (i == 0) ? rw[i] = 0 : rw[i] = rw[i-1]; 
        // 左方向に東向きの人数の累積和を取る
        if(s[n-1-i] == 'E') (i == 0) ? le[n-1-i] = 1 : le[n-1-i] = le[n-1-i+1] + 1;
        else (i == 0) ? le[n-1-i] = 0 : le[n-1-i] = le[n-1-i+1];
    }

    // i番目にリーダを配置した時に向きを変更する人数を算出
    rep(i, n){
        ll tmp = 0;
        // 左端の場合
        if(i == 0) tmp = le[i+1];
        // 右端の場合
        else if(i == n-1) tmp = rw[i-2];
        // 両端以外の場合
        else tmp = rw[i-1] + le[i+1];
        // 最小値の更新
        chmin(ans, tmp);
    }

    // 結果の出力
    cout << ans << endl;
}

Measured memory_bytes: 5396
//lcs
#include<bits/stdc++.h>
using namespace std;
void lcs(string s,string t)
{
	int m=s.size();
	int n=t.size();
	int dp[m+1][n+1];
	for(int i=0;i<=m;i++){
		for(int j=0;j<=n;j++){
			if(i==0 || j==0)dp[i][j]=0;
			else if(s[i-1]==t[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else 
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	//cout<<dp[m][n]<<endl;
	//finding the lcs
	string ans;
	int i=m,j=n;
	while(i>0 && j>0){
			if(s[i-1]==t[j-1]){
				ans.push_back(s[i-1]);
				i--;j--;
			}
			else if(dp[i-1][j]>dp[i][j-1])
				i--;
			else j--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
}
int main(){
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	string s,t;
	cin>>s>>t;
	lcs(s,t);
	return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;
struct edge{ int to,cost; };

const int N=5000, INF=123456789;
vector<int> G[N];

int dist[N][N];
int d[N];
void bfs(int start)
{
    fill(d,d+N,INF);
    d[start]=0;
    queue<int> que;
    que.push(start);
    while(!que.empty())
    {
        int v=que.front();
        que.pop();
        rep(i,G[v].size())
        {
            int nx=G[v][i];
            if(d[nx]>d[v]+1)
            {
                d[nx]=d[v]+1;
                que.push(nx);
            }
        }
    }
}

vector<edge> g[N];
int fare[N];
void dijkstra(int start)
{
    fill(fare,fare+N,INF);

    priority_queue<pi,vector<pi>,greater<pi>> que;
    fare[start]=0;
    que.push(pi(0,start));
    while(!que.empty()){
        pi p=que.top();
        que.pop();
        int v=p.se;
        if(fare[v]<p.fi) continue;
        rep(i,g[v].size())
        {
            edge e=g[v][i];
            if(fare[e.to]>fare[v]+e.cost)
            {
                fare[e.to]=fare[v]+e.cost;
                que.push(pi(fare[e.to],e.to));
            }
        }
    }
}

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

    vector<int> c(n),r(n);
    rep(i,n) scanf(" %d %d", &c[i], &r[i]);

    rep(i,k)
    {
        int a,b;
        scanf(" %d %d", &a, &b);
        --a;
        --b;
        G[a].pb(b);
        G[b].pb(a);
    }

    rep(i,n)
    {
        bfs(i);
        rep(j,n)
        {
            if(d[j]<=r[i]) g[i].pb(edge{j,c[i]});
        }
    }

    dijkstra(0);
    printf("%d\n", fare[n-1]);
    return 0;
}

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

bool test(int x){
    if (x % 2 == 0) return false;
    int d = 3;
    while (d * d <= x){
        if (x % d == 0) return false;
        d += 2;
    }
    return true;
}
int main(){
    int X; cin >> X;
    if (X == 2){
        cout << X << endl;
    } else {
        if (X % 2 == 0) X++;
        while(true){
            if (test(X)){
                cout << X << endl;
                break;
            } else X += 2;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007
 

int main() {
	string s;
	cin >> s;
	if (s.length() < 4)print("No");
	else if (s[0] == 'Y'&&s[1] == 'A'&&s[2] == 'K'&&s[3] == 'I')print("Yes");
	else print("No");



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI acos(-1)
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cerr<<x<<endl;
#define endl "\n"
#define pb push_back
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const int nmax=1e5+10;
const int eps=1e-8;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
    //cout.tie(NULL);
    int n;
    cin>>n;
    vector<double>v(n);
    for(int i=0;i<n;i++)
        cin>>v[i];

    double sumi,mi;

    for(int i=0;i<n;i++){
        sumi+= (1.0/v[i]);
    }

    mi=1.0/sumi;

    cout<<mi<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define REP(i, l, r) for (__typeof(l) i = (l); i != (r); (l)<(r)?++i:--i)
#define popcount __builtin_popcountll
 
const int INF = 1LL<<60;
const int MOD = 998244353;
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> t) {
    return "(" + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ")";
}
 
template <typename A>
string to_string(vector<A> v) {
    bool first = true;
    string result = "[";
    for (A i : v) {
        if (!first) result += ", ";
        first = false;
        result += to_string(i); 
    }
    return result + "]";
}
 
template <typename A>
string to_string(A x[], signed n) {
    string result = "{";
    for (signed i=0; i<n; ++i) {
        if (i!=0) result += ", ";
        result += to_string(x[i]); 
    }
    return result + "}";
}
 
string bin_string(int x) {
    const int d = 64;
    string result(d, ' ');
    for (signed i=d-1; i>=0; --i) result[d-1-i] = '0'+((x&1LL<<i)!=0);
    return result;
}
 
int powa(int base, int exp) {
    if (exp<=0) return 1;
    if (base<=0) return 0;
    int val = powa(base, exp>>1);
    val = val*val % MOD;
    if (exp&1) {
        val = val*base % MOD;
    }
    return val;
}
 
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int res = 0, n; string s;
    cin >> n >> s;
    REP(i, 0, 10) {
        REP(j, 0, 10) {
            REP(k, 0, 10) {
                int state = 0;
                for (char c : s) {
                    if (c-'0' == i && state == 0) state = 1;
                    else if (c-'0' == j && state == 1) state = 2;
                    else if (c-'0' == k && state == 2) state = 3;
                }
                if (state == 3) ++res;
            }
        }
    }
    cout << res;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		String st = s + t;
		int count = 0;
		if (s.length() != t.length() - 1) {
			count++;

		}
		char[] s1 = s.toCharArray();
		char[] t1 = t.toCharArray();
		for (int i = 0; i < s1.length; i++) {
			if (s1[i] != t1[i]) {
				count++;
			}
		}

		if (count == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 26924
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main(){
    int a,b,c;
    cin >>a >> b >> c;
    int sum = a+b+c;
    int ma = max({a,b,c});
    if(ma*3%2!=sum%2)ma++;
    cout << (3*ma-sum)/2 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,b,h[200005],n,m;
bool p=true;
int main()
{
	scanf("%d %d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d %d",&a,&b),h[a]++,h[b]++;
	for(int i=1;i<=n;i++)if(h[i]%2!=0)p=false;
	if(p)printf("YES");
	else printf("NO");
}


Measured memory_bytes: 640
#include <stdio.h>

int xstack[20000];
int xtop;
int lefts[20000];
int vols[20000];
int pooltop;

int main(){
    int c;
    for(int x = 0; (c = getchar()) != '\n'; x++){
        if(c == '\\'){
            xstack[xtop++] = x;
        } else if (c == '/'){
            if(xtop == 0) continue;
            int last_x = xstack[--xtop];
            int new_vol = x - last_x;
            while(pooltop > 0 && last_x < lefts[pooltop-1]){
                new_vol += vols[--pooltop];
            }
            lefts[pooltop] = x;
            vols[pooltop] = new_vol;
            pooltop++;
        }
    }
    int sum = 0;
    for(int i=0; i<pooltop; i++){
        sum += vols[i];
    }
    printf("%d\n%d", sum, pooltop);
    for(int i=0; i<pooltop; i++){
        printf(" %d", vols[i]);
    }
    puts("");
}

Measured memory_bytes: 1868
#include <iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include<map>
#include<type_traits>
using namespace std;
long long int A[10000000];

int main() {	
	long long int N, K;
	cin >> N >> K;
	long long int mini = 1000000000000;
	for (long long int i = 0; i < N; i++) {
		cin >> A[i];
		mini = min(A[i], mini);
	}
	long long int minini = 0;;
	for (long long int i = 0; i < N; i++) {
		if (A[i] == mini)minini++;
	}
	long long int Y = 0;
	Y = (N-minini+(K-2)) / (K - 1);

	cout << Y << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define MAXN 200005
#define mo 994711
//#define ivorysi
using namespace std;
typedef unsigned long long int64;
typedef long double db;
typedef unsigned int u32;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 + c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {putchar('-');x = -x;}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
int64 x[MAXN],XV,sum[MAXN],ans;
pii que[MAXN];
int N; 
void Init() {
    read(N);read(XV);
        
    for(int i = 1 ; i <= N ; ++i) read(x[i]);
    ans = XV * (N + 1) + x[N] * 5;
    for(int i = 1 ; i < N ; ++i) {
    	ans += 1LL * (2 * i + 3) * x[N - i];
    }  
    for(int i = 1 ; i <= N ; ++i) {
    	sum[i] = sum[i - 1] + x[i];
    }
}
void Solve() {
    for(int K = 2 ; K <= N ; ++K) {
    	int64 tmp = (K + N) * XV,t = 1;
    	tmp += 5 * (sum[N] - sum[N - K]);
    	for(int r = N - K; r >= 1 ; r -= K) {
    	    int l = max(1,r - K + 1);
    	    tmp += (2 * t + 3) * (sum[r] - sum[l - 1]);
    	    ++t;
    	}
    	
    	ans = min(ans,tmp);
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
    return 0;
}


Measured memory_bytes: 3328
N, M, X = map(int, input().split())
C=[]
A=[]
for _ in range(N):
    c, *a = map(int, input().split())
    C.append(c)
    A.append(a)

ans=10**18
for maskN in range(1<<N):
  cost=0
  level=[0]*M
  for n in range(N):
    if (maskN>>n&1):
      cost+=C[n]
      for m in range(M):
        level[m] += A[n][m]
  for l in level:
    if l < X:
      break
  else:
    ans=min(ans, cost)
print(f'{ans if ans!=10**18 else "-1"}')


Measured memory_bytes: 9212
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  ll n,ma,mb;
  cin>>n>>ma>>mb;

  int cnst=4000;

  int dp[45][8005];
  rep(i,45)rep(j,8005)
    dp[i][j]=INF;

  rep(i,n){
    int a,b,c;
    cin>>a>>b>>c;
    int diff=a*mb-b*ma;
    dp[i+1][diff+cnst]=min(dp[i+1][diff+cnst],c);
    rep(j,8005){
      dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
      if(j+diff<8005 && j+diff>=0)
         dp[i+1][j+diff]=min(dp[i+1][j+diff],dp[i][j]+c);
    }
  }
  if(dp[n][cnst]<INF)
    cout<<dp[n][cnst]<<endl;
  else
    cout<<-1<<endl;
}


Measured memory_bytes: 1664
class WeightedUnionFind
  attr_reader :parent, :rank, :diff_weight

  def initialize
    @parent = Hash.new { |hash, key| hash[key] = key }
    @rank = Hash.new { |hash, key| hash[key] = 0 }
    @diff_weight = Hash.new { |hash, key| hash[key] = 0 }
  end

  def root(x)
    if parent[x] == x
      x
    else
      r = root(parent[x])
      diff_weight[x] += diff_weight[parent[x]]
      parent[x] = r
    end
  end

  def same?(x, y)
    root(x) == root(y)
  end

  def unite(x, y, w)
    w += weight(x) - weight(y)
    x, y = root(x), root(y)
    return if x == y
    x, y, w = y, x, -w if rank[x] < rank[y]
    rank[x] += 1 if rank[x] == rank[y]
    parent[y] = x
    diff_weight[y] = w
  end

  def weight(x)
    root(x)
    diff_weight[x]
  end

  def diff(x, y)
    weight(y) - weight(x)
  end
end

uf = WeightedUnionFind.new
n, m = gets.split.map(&:to_i)
m.times do
  l, r, d = gets.split.map(&:to_i)
  if uf.same?(l, r)
    unless d == uf.diff(l, r)
      puts "No"
      exit
    end
  else
    uf.unite(l, r, d)
  end
end
puts "Yes"

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

int N;
vector<int> A(110), B(110), C(110), D(110); 

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) A.at(i)=i+1;

    int res = 0;
    
    D = A;
  
    for (int i = 0; i < N; i++){

      while (true) {

        if (A.at(i) % 2 == 0) {
          A.at(i) /= 2;
          res++;
        }
      
        else {
          B.at(i) = res;
          res = 0;
          break;
        }
      }
    }

C = B;    

sort(B.begin(), B.end());
reverse(B.begin(), B.end());

int saidai = -1;

for (int i = 0; i < N; i++) {
  if ( C.at(i) == B.at(0)) {
    saidai = i;
    break;
  }
}

cout << D.at(saidai) << endl;

}

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

int main() {
  
  int n,k,a;
  cin >> n >> k;
  
  vector<int> A(n+1);
  
  for ( int i = 0; i < k; i++){
    int d;
    cin >> d;
    for ( int j = 0; j < d; j++){
      cin >> a;
      A[a]++;
    }
  }
  
  int count = 0;
  
  for ( int i = 1; i <= n; i++){
    if ( A[i] == 0 ){
      count++;
    }
  }
  
  cout << count << endl;
  
}

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

v = [-1] * (N + 1)
n = 1
f = 0

for i in range(N):
    v[n] = i
    n = A[n]
    if v[n] != -1:
        f = 1
        s = n #ループのスタート
        t = i
        l = t - v[s] + 1
        break

if t >= K:
    print(v.index(K))
else:
    K = (K - v[s]) % l
    print(v.index(K + v[s]))

Measured memory_bytes: 32296
n = int(input())
b = [int(i) for i in input().split()]
a = 0

if n == 1:
        print(b[0] * 2)

else:
        a += b[0]
        bb = b[0]
        for i in range(1,n-1):
                if b[i] > bb:
                        a += b[i-1]
                else:
                        a += b[i]
                bb = b[i]
        a += b[n - 2]
        print(a)


Measured memory_bytes: 3060
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    /*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int a,b;
    cin>>a>>b;
    int h,m;
    cin>>h>>m;

    ld thetamin = (m / (ld)60) * 360;
    m+=(h*60); // hour into minutes 

    ld thetahour = (m / (ld)720) * 360;

   // show(thetahour);

    ld theta = (thetahour - thetamin);

    if(theta<0)
        theta+=360;



    ld ans = sqrt(sq(a)  + sq(b) - (2*a*b*cos((theta * PI)/ 180)) );
    cout<<ans;



    printclock;
    return 0;
}


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

#define all( V ) ( V ).begin(), ( V ).end()
#define ff first
#define ss second


int main()
{
int i;
int N;
int M;
long long iSum;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;
	cin >> M;

vector<pair<long long, long long>> A( N );

	for( auto &a: A )
	{
		cin >> a.ff;
		cin >> a.ss;
	}

	sort( all( A ) );

	iSum = 0;
	for( auto a: A )
	{
		if( M <= a.ss )
		{
			iSum += M * a.ff;
			cout << iSum << endl;
			return 0;
		}

		iSum += a.ss * a.ff;
		M -= a.ss;
	}

	return 0;
}


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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int n;
int t[100001], x[100001], y[100001];

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> t[i] >> x[i] >> y[i];
    for (int i = 1; i <= n; i++) {
        if (t[i]-t[i-1] < abs(x[i]-x[i-1])+abs(y[i]-y[i-1]) || (t[i]-t[i-1])%2 != (abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))%2) {
            puts("No");
            return 0;
        }
    }
    puts("Yes");
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
using ull=unsigned long long;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define setbits(x)  __builtin_popcount(x)
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;

//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll ans=1LL;
     while(b>0)
     {
          if(b&1)ans=(ans*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return ans;
}
 
 
 
 
 
 
 


vector<pair<int,int>> adj[100005];
int dist[100005];
int visited[100005];
void dfs(int node){
     visited[node]=1;
     for(auto child:adj[node]){
          if(!visited[child.fi]){
               dist[child.fi]=dist[node]+child.se;
               dfs(child.fi);
          }
     }
     
}
int main()
{
     int n,m;
     cin>>n>>m;
     int l[m],r[m],d[m];
     for(int i=0;i<m;i++){
          cin>>l[i]>>r[i]>>d[i];
          adj[l[i]].push_back({r[i],d[i]});
          adj[r[i]].pb({l[i],-d[i]});
     }
     if(m!=0){
          for(int i=0;i<m;i++){
               if(!visited[l[i]]){
                    dfs(l[i]);
               }
          }          
     }
     for(int i=0;i<m;i++){
          int t=abs(dist[l[i]]-dist[r[i]]);
          if(t!=d[i]){cout<<"No";return 0;}
     }
     cout<<"Yes";


}























Measured memory_bytes: 17940