akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
template<typename T>bool maxup(T& a, const T& b) { if (a < b) { a = b; return true; }; }

int dp[2005][2005][2];
int main() {
	int m, n; cin >> m >> n;
	vector<int> s(m + 1);
	s[m] = 0;
	rep(i, m) {
		char c; cin >> c;
		s[i] = c == 'I';
	}
	vector<int> t(n + 1);
	rep(i, n) {
		char c; cin >> c;
		t[i] = c == 'I';
	}
	t[n] = 0;

	int ans = 0;
	rep(i, m + 1) rep(j, n + 1) {
		maxup(dp[i + 1][j][0], (dp[i][j][1] + 1) * !!dp[i][j][1] * !s[i]);
		maxup(dp[i][j + 1][0], (dp[i][j][1] + 1) * !!dp[i][j][1] * !t[j]);

		maxup(dp[i + 1][j][1], (dp[i][j][0] + 1) * s[i]);
		maxup(dp[i][j + 1][1], (dp[i][j][0] + 1) * t[j]);

		maxup(ans, dp[i + 1][j][1]);
		maxup(ans, dp[i][j + 1][1]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 34468
// بِسمِ اللہِ  الرَّحم?نِ  الرَّ حِیم
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e18
#define N 1001000
typedef pair<ll,ll> pll;
ll power(ll a,ll b)
{
    if(b==1)return a;
    if(b==0)return 1;
    ll temp=power(a,b/2);
    ll ans=temp*temp;
    if(b&1)
        ans*=a;
    return ans;
}
ll power(ll a,ll b,ll p)
{
    a=a%p;
    if(b==1)return a;
    if(b==0)return 1;

    ll temp=power(a,b/2,p);
    ll ans=(temp*temp)%p;
    if(b&1)
        ans=(a*ans)%p;
    return ans%p;
}
ll inv(ll a,ll m)
{
    return power(a,m-2,m);
}
//code begins
bool isPal(string s)
{
    string temp=s;
    reverse(all(s));
    if(s==temp)return true;
    return false;
}
signed main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    cin.sync_with_stdio(false);
    ll t;
    t=1;
//    cin>>t;
    while(t--)
    {
        string s;cin>>s;
        ll n=s.length();
        string s1=s.substr(0,(n-1)/2);
        string s2=s.substr((n+3)/2-1,string::npos);
        if(isPal(s) && isPal(s1) && isPal(s2))
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 #define PI 3.141592653
using namespace std;

vector<int> adj[100001];
int level[100001];

void solve(){
	int n,m; cin>>n>>m;
	memset(level,-1,sizeof(level));
	for(int i=0; i<m; i++){
		int a,b;
		cin>>a>>b;
		adj[a].pb(b);
		adj[b].pb(a);
	}
	level[1] = 0;
	queue<int> q;
	q.push(1);
	while(!q.empty()){
		int s = q.front(); q.pop();
		for(auto v: adj[s]){
			if(level[v] == -1){
				level[v] = 1 + level[s];
				q.push(v);
			}
		}
	}
	for(int i=2; i<=n; i++){
		if(level[i] == -1){
			cout<<"No";
			return;
		}
	}
	cout<<"Yes\n";
	for(int i=2; i<=n; i++){
		int mm = 1e6, w;
		for(auto v: adj[i]){
			if(mm > level[v]){
				mm = level[v];
				w = v;
			}
		}
		cout<<w<<"\n";
	}


}


int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout<<fixed<<setprecision(12);
	int t =1; //cin>>t;
	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}
	return 0;

}

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

/**
 * @brief ユークリッドの互除法による、
 *        最大公約数を求める
 * 
 * @param m 
 * @param n 
 * @return long 
 */
template <typename T>
T Gcd(T m, T n)
{
    T temp;
    while (m % n != 0)
    {
        temp = n;
        n = m % n;
        m = temp;
    }
    return n;
}

/**
 * @brief 最小公倍数を求める
 * 
 * @tparam T 
 * @param m 
 * @param n 
 * @return T 
 */
template <typename T>
T Lcm(T m, T n)
{
    return m * n / Gcd<T>(m, n);
}

/**
 * @brief プログラムのエントリーポイントです
 * 
 * @return int 終了後、0を返却しなければなりません。
 */
int main()
{
    // 入力
    long A, B;
    cin >> A >> B;

    // 出力
    cout << Lcm<long>(A, B) << endl;
    return 0;
}


Measured memory_bytes: 888
//2009情報オリンピック本選問題1「旅人」
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int *List, n, m, s, k, t, f1, np = -1, sum = 0;

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

	List = new int [n];
	for(f1 = 0; f1 < n-1; f1++){
		scanf("%d",&s);
		if(f1 == 0)
			List[f1] = s;
		else
			List[f1] = List[f1-1] + s;
	}

	for(f1 = 1; f1 <= m; f1++){
		scanf("%d",&k);
		t = np + k;
		//スタート地点からか
		if(np == -1)
			sum += List[t];
		else{
			//スタート地点に戻らないか
			if(t >= 0)
				sum += abs(List[t] - List[np]);
			else
				sum += List[np];
		}

		if(sum >= 100000)
			sum %= 100000;

		np = t;
	}

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

	return 0;
}

Measured memory_bytes: 1148
// abc136d.cpp : Gathering Children
#include <bits/stdc++.h>
using namespace std;
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))

void out(int s, int l, int e, int o){
	up(i,s,l-1,1) cout<<0<<" ";
	cout<< (l%2? e:o) <<" "<< (l%2? o:e) <<" ";
}

int main(){
	string S; cin>>S; int n = S.length();
	int s, l, r, e, o;
	s = 0; r = l = -1;
	up(i,0,n,1){
		if(r<0 && S[i]=='R'){
			if(l>=0) out(s,l,e,o);
			s = l + 1;
			r = i; l = -1;
			e = o = 0;
		}
		else if(l<0 && S[i]=='L'){
			l = i; r = -1;
		}
		if(i%2) o++; else e++;
	}
	out(s,l,e,o);
	up(i,l+1,n,1) cout<<0<<" ";
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int a, b;
  cin >> a >> b;
  int ans = b;
  if (a >= 13) ans = b;
  else if (a >= 6) ans = b / 2;
  else ans = 0;
  cout << ans << endl; 
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstring>

using namespace std;

bool isPrime[10001];

void setPrime( bool *p, int size )
{
	memset(p, true, size);
	p[0] = p[1] = false;

	for(int i=2; i < size; ++i) {
		if(!p[i]) continue;
		for(int j=i+i; j < size; j+=i) {
			p[j] = false;
		}
	}
}

int main( void )
{
	setPrime(isPrime, 10001);
	int n;
	while(cin >> n, n) {
		bool hit = true;
		for(int i=n-2; i > 0 && hit; --i) {
			if(isPrime[i]) {
				if(isPrime[i+2]) {
					cout << i << ' ' << i+2 << endl;
					hit = false;
				}
			}
		}
	}
	return 0;
}

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

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

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

  rep(i, n) {
    if (i + 1 == k) {
      s.at(i) = tolower(s.at(i));
    }
  }
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
// using namespace std;
int N;
int i = 2;
int num;
char buf[8], out[20];
char k;
s;
size_t ii;
int main()
{
  s = read(0, buf, 8);
  for (;;)

  {
    k = buf[ii++];
    if (k < '0')
      break;
    N = N * 10 + k - '0';
  }
  // printf("%d\n", N);
  long long ans = (long long)N * (N + 1) - 1;

  for (; i * i <= N; i++)
  {
    num = N / i;
    ans += (long long)(num - i + 1) * i * (i + num) - i * i;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 1604
s = input()

i = 1
badFlag = 0
for c in s:
    if i % 2 == 0:
        if not(c == 'L' or c == 'U' or c == 'D'):
            badFlag = 1
    else:
        if not(c == 'R' or c == 'U' or c == 'D'):
            badFlag = 1
    if badFlag == 1:
        break
    i += 1

if badFlag == 1:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3060
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

    N=int(input())
    A=list(map(int,input().split()))

    AA=Counter(A)

    ans=0
    if N==1:
        print(1)
    elif N==2:
        if abs(A[0]-A[1])<=1:
            print(2)
        else:
            print(1)
    else:
        for i in range(N-2):
            ans=max(AA[i]+AA[i+1]+AA[i+2],ans)
        print(ans)

resolve()

Measured memory_bytes: 14564
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
using namespace std;
typedef long long ll;

int main() {
	string S;
	cin >> S;
	int a = 0;
	for (ll i = 0; i < S.size(); ++i) {
		for (ll j = i + 1; j < S.size(); ++j) {
			if (S[i] == 'C'&&S[j] == 'F')
			{
				++a;
			}
		}
	}
	if (a>0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

#define rep(countName, left, right, up) for (ll countName = left; countName < right; countName += up)
#define rev(countName, right, left, down) for (ll countName = right - 1; countName >= left; countName -= down)

int solve1()
{
    int a, b;
    cin >> a >> b;

    for (int x = 12; x <= 1000; x++)
    {
        //cout << (int)(x * 0.08) << " " << (int)(x * 0.1) << endl;
        if ((int)(x * 0.08) == a && (int)(x * 0.1) == b)
        {
            return x;
        }
    }

    return -1;
}

int main(void)
{
    cout << solve1() << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

x, y, a, b, c = map(int,input().split())
L = []
Pa = list(map(int,input().split()))
Pb = list(map(int,input().split()))
Pc = list(map(int,input().split()))
Pa.sort(reverse = True)
Pb.sort(reverse = True)
Pc.sort(reverse = True)

ca = 0
cb = 0
cc = 0
flg1 = True
flg2 = True
flg3 = True
ans = 0
for i in range(x+y):
    if ca == x:
        flg1 = False
        ca = 0
        Pa[ca] = 0
    if cb == y:
        flg2 = False
        cb = 0
        Pb[cb] = 0
    if cc == c:
        flg3 = False
        cc = 0
        Pc[cc] = 0
    if Pa[ca] == max(Pa[ca], Pb[cb], Pc[cc]) and flg1:
        ans += Pa[ca]
        ca += 1
    elif Pb[cb] == max(Pa[ca], Pb[cb], Pc[cc]) and flg2:
        ans += Pb[cb]
        cb += 1
    elif Pc[cc] == max(Pa[ca], Pb[cb], Pc[cc]) and flg3:
        ans += Pc[cc]
        cc += 1
        #print("###")

print(ans)

Measured memory_bytes: 23328
#include <bits/stdc++.h>
using namespace std; 
int main(){
	long long a;
	char c[10];
	cin>>a;
	scanf("%s",c);
	cout<<(long long)((long double)a*(long double)(c[0]-'0')+((long double)a*(long double)(c[2]-'0')/10)+((long double)a*(long double)(c[3]-'0')/100));
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define forn(i,a,n) for(int i =a;i < n; i++)
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
typedef long long int lli;
typedef pair<int,int> pii;
typedef vector<lli> vi;
#define MAXN 200005
lli dp[MAXN];
vi pref[MAXN],suf[MAXN];
vi adj[MAXN];
lli ans[MAXN];
int m;

lli gpref(int u, int i){
	if(i-1 >= 0)
		return pref[u][i-1]%m;
	return 1ll;
}

lli gsuf(int u, int i){
	if(i+1 < suf[u].size())
		return suf[u][i+1]%m;
	return 1ll;
}

int dfs(int u, int p){
	if(dp[u]  != -1) return dp[u]%m;
	dp[u] = 1;
	pref[u].resize(adj[u].size());
	suf[u].resize(adj[u].size());
	for(int i =0; i < adj[u].size(); i++){
		int v = adj[u][i];
		if(v == p){
			pref[u][i] = 1ll;
			suf[u][i] = 1ll;
			continue;
		}
		lli res = 0;
		res = (dfs(v,u) + 1) % m;
		dp[u] = (dp[u] * res) % m;
		pref[u][i] = res;
		suf[u][i] = res;
	}
	//pref
	for(int i =1; i < pref[u].size(); i++){
		pref[u][i] = (pref[u][i] * pref[u][i-1])%m;
	}
	for(int i = suf[u].size()-2; i >=0; i--){
		suf[u][i] = (suf[u][i] * suf[u][i+1])%m;
	}
	return dp[u] % m;
}

void dfs2(int u, int p){
	//if(u!= 1){
	dp[u]= (dp[u] * (dp[p]+1) % m) %m;
	ans[u] = dp[u]%m;
	//}
	for(int i =0; i < adj[u].size(); i++){
		int v = adj[u][i];
		if(v == p) continue;
		lli og = dp[u];
		lli poner = (gpref(u,i) * gsuf(u,i))%m;
		poner = (poner * (dp[p]+1)%m ) %m;
		dp[u] = poner;
		dfs2(v,u);
		dp[u] = og;
	}
}

int main(){__
	int n;
	cin >> n >> m;
	for(int i =0;i < MAXN; i++) dp[i] = -1;
	dp[0] = 0;
	for(int i =0; i < n-1;i++){
		int u,v;
		cin >> u >> v;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	cout <<  dfs(1,0)%m << endl;
	//dfs(1,1,1);
	dfs2(1,0);
	for(int i =2;i <=n; i++) cout << ans[i]%m << endl;
}


Measured memory_bytes: 34944
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>
#include <utility>


using namespace std;
typedef long long ll;
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 ll INF = 1LL <<60;
const int INF = 10000;

//最小公倍数
ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}

//最大公倍数
ll lcm(ll x,ll y){
  return x/gcd(x,y)*y;
}

//階乗
ll kaijo(ll k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum%=1000000000+7;
    }
    return sum;
}

//for(int i = ; i < ; i++){}

ll lmax(ll s,ll t){
  if(s>t){
    return s;
  }
  else{
    return t;
  }
}

ll lmin(ll s,ll t){
  if(s<t){
    return s;
  }
  else{
    return t;
  }
}
// ここから開始

int main(){
  double N;
  cin>>N;
  for(double h = 1; h <= 3500; h++){
    for(double n = 1; n <= 3500; n++){
      if((N*h*n)/(4*h*n-N*n-N*h)<=3500&&N*h*n/(4*h*n-N*n-N*h)>0&&(ll)(N*h*n)%(ll)(4*h*n-N*n-N*h)==0){
        cout<<h<<" "<<n<<" "<<(N*h*n)/(4*h*n-N*n-N*h)<<endl;
        return 0;
      }
    }
  }
  // double h = 4664;
  // double n = 4664;
  // cout<<((N*h*n)/(4*h*n-N*n-N*h)<=3500)<<" "<<(N*h*n/(4*h*n-N*n-N*h)>0)<<" "<<((int)(N*h*n)%(int)(4*h*n-N*n-N*h)==0)<<endl;
  // cout<<(int)(N*h*n)%(int)(4*h*n-N*n-N*h)<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
const int maxn = 1e5+10;

int main() {    
    int n,x; cin >> n;
    map<int,int> o,e;
    int o1 = -1,o2 = -1;
    int e1 = -1,e2 = -1;
    for(int i = 0; i < n; i++) {
        cin >> x;
        if(i&1) {
            o[x] = o[x] + 1;
            if(o[x] > o[o1]) o2 = o1, o1 = x;
            else if(o[x] > o[o2] && x != o1) o2 = x;
        } else {
            e[x] = e[x] + 1;
            if(e[x] > e[e1]) e2 = e1, e1 = x;
            else if(e[x] > e[e2] && x != e1) e2 = x;
        }
    }
    int ansd = e[e1] + o[o1];
    if(o1 == e1) {
        ansd = max(e[e1]+o[o2],e[e2]+o[o1]);
    }
    cout<<(n-ansd)<<endl;

    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define int long long
/*#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define tr(container, it) \
for(typeof((container).begin()) it = (container).begin(); it != (container).end(); it++)
#define present(container, element) ((container).find(element) != (container).end())
#define cpresent(container, element) (find(all(container),element) != (container).end())
*/

using namespace std;

/*typedef long long ll;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
*/

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

int n,a,b,cnt=LLONG_MAX;
cin>>n>>a>>b;
if(a>b)
	swap(a,b);
cnt=min(n-a,b-1);

if((b-a)%2!=0)
{
	int temp;
	if(a-1<n-b)
	{
		temp=a;
		temp+=(b-temp-1)/2;
	}
	else
	{
		temp=n+1-b;
		temp+=(n-(a+temp))/2;
	}
//	cout<<temp;
	cnt=min(cnt,temp);
}
else
{
	cnt=min(cnt,(b-a)/2);
}


cout<<cnt;
return 0;
}


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

int N, K;
int[2000][2000] WS, BS;
int[2000] WCS, WCSR, BCS, BCSR;

void main()
{
    readf("%d %d", &N, &K);
    int x, y;
    char c;
    auto k2 = K*2;
    foreach (_; 0..N) {
        readf(" %d %d %c", &x, &y, &c);
        if (c == 'W') {
            WS[y%k2][x%k2] += 1;
        } else {
            BS[y%k2][x%k2] += 1;
        }
    }

    foreach (i; 0..K) {
        foreach (j; 0..K) {
            WCS[j] += WS[i][j];
            WCS[K+j] += WS[K+i][K+j];
            WCSR[j] += WS[K+i][j];
            WCSR[K+j] += WS[i][K+j];
            BCS[j] += BS[K+i][j];
            BCS[K+j] += BS[i][K+j];
            BCSR[j] += BS[i][j];
            BCSR[K+j] += BS[K+i][K+j];
        }
    }

    auto cur = 0;
    foreach (n; WCS) cur += n;
    foreach (n; BCS) cur += n;

    auto max = cur;
    for (auto i = 0;; ++i) {
        auto tmp = cur;
        foreach (j; 0..K) {
            cur = cur + WCSR[j] + WCSR[K+j] + BCSR[j] + BCSR[K+j] - WCS[j] - WCS[K+j] - BCS[j] - BCS[K+j];
            max = max > cur ? max : cur;
        }
        cur = tmp;
        foreach_reverse (j; 0..K) {
            cur = cur + WCSR[j] + WCSR[K+j] + BCSR[j] + BCSR[K+j] - WCS[j] - WCS[K+j] - BCS[j] - BCS[K+j];
            max = max > cur ? max : cur;
        }
        if (i == K) break;
        cur = tmp;
        foreach (j; 0..K) {
            cur = cur + WS[K+i][j] + WS[i][K+j] + BS[i][j] + BS[K+i][K+j] - WS[i][j] - WS[K+i][K+j] - BS[i][K+j] - BS[K+i][j];
            WCS[j] = WCS[j] + WS[K+i][j] - WS[i][j];
            WCS[K+j] = WCS[K+j] - WS[K+i][K+j] + WS[i][K+j];
            WCSR[j] = WCSR[j] - WS[K+i][j] + WS[i][j];
            WCSR[K+j] = WCSR[K+j] + WS[K+i][K+j] - WS[i][K+j];
            BCS[j] = BCS[j] - BS[K+i][j] + BS[i][j];
            BCS[K+j] = BCS[K+j] + BS[K+i][K+j] - BS[i][K+j];
            BCSR[j] = BCSR[j] + BS[K+i][j] - BS[i][j];
            BCSR[K+j] = BCSR[K+j] - BS[K+i][K+j] + BS[i][K+j];
        }
    }

    writeln(max);
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
/*vector<Type> v;
vector<Type> v();
vector<Type> v(n);
vector<Type> v(n, d);
vector<vector<Type>> vv;
vector<vector<Type>> vv();
vector<vector<Type>> vv(n);
vector<vector<Type>> vv(n, vector<Type>(m));
vector<vector<Type>> vv(n, vector<Type>(m, d));*/

int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  rep(i,n){
    cin >> a[i];
  }
  vector<long long> da(n,0);
  for(int i=0;i<n-1;i++){
    if(a[i]>a[i+1]){
      da[i] = 1;//上に凸
    }else if(a[i]<a[i+1]){
      da[i] = -1;//下に凸
    }
  }
  da[n-1] = 1;
  long long now_money = 1000;
  long long now_stock = 0;
  long long num_buy;
  rep(i,n){
    if(da[i]==1){
      now_money += now_stock * a[i];
      now_stock = 0;
    }else if(da[i]==-1){
      num_buy = now_money/a[i];
      now_money -= num_buy*a[i];
      now_stock += num_buy;
    }
  }
  if(now_money<1000) now_money = 1000;
  cout << now_money;
 
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<string,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<Pi,int> P2;
const ll INF=1000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


int main() {

	int p,q,r;
	cin>>p>>q>>r;

	int m1=p,m2=min(q,r);
	if(m1>q){
		m1=q;
		m2=min(p,r);
	}
	if(m1>r){
		m1=r;
		m2=min(q,p);
	}
	cout<<m1+m2<<endl;

	return 0;

}


Measured memory_bytes: 256
def par(a):
    if P[a] == a: return a
    t = par(P[a])
    P[a] = t
    return t
def unite(a, b):
    P[par(b)] = par(a)

N, M = map(int, input().split())
X = [[int(a) - 1 for a in input().split()] for _ in range(M)]

ans = 0
for i in range(M):
    P = [i for i in range(N)]
    for j in range(M):
        if i != j:
            unite(X[j][0], X[j][1])
    if sum([1 if par(i) == i else 0 for i in range(N)]) > 1:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define rep(i, a, b) for(ll i=a; i<b; i++)
#define rer(i, a, b) for(ll i=a-1; i>=b; i--)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, m;
#define MAX_M 31
int v[MAX_M];

signed main(){
    cin >> n >> m;
    rep(i, 0, MAX_M) v[i] = 1;
    rep(i, 0, n){
        ll k; cin >> k;
        int w[MAX_M] = {};
        rep(j, 0, k){
            ll a; cin >> a;
            w[a-1] = 1;
        }
        rep(j, 0, m){
            v[j] = min(w[j], v[j]);
        }
    }
    int ret = 0;
    rep(i, 0, m){
        if(v[i] == 1) ret++;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

#include <string>
using namespace std;

int main(){
    string S,T;

    cin >> S;
    cin >> T;

    int s,t;
    s = S.size();
    t = T.size();

    if(t != s+1){

        cout << "No" << endl;

    }else{
        int f = 1;

        f = S.compare(0, s, T, 0 ,s);


        if(f == 0) 
        {
            cout << "Yes" << endl;

        }else{
            cout << "No" << endl;

        }


    }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

int n;
ll a[MAXN], b[MAXN], C, CL[MAXN], CCL[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> C;
    FOR(i,1,n) cin >> a[i] >> b[i];
    ll res = 0, dist = 0, calo = 0;
    FOR(i,1,n) {
        dist = a[i];
        calo += b[i];
        CL[i] = max(CL[i-1], calo - dist);
        res = max(res, calo - dist);
    }
    calo = 0;
    FORE(i,n,1) {
        dist = C - a[i];
        calo += b[i];
        CCL[i] = max(CCL[i+1], calo - dist);
        res = max(res, calo - dist);
    }

    calo = 0;
    FOR(i,1,n-1) {
        dist = a[i] + a[i];
        calo += b[i];
        res = max(res, calo - dist + CCL[i+1]);
    }
    calo = 0;
    FORE(i,n,2) {
        dist = C - a[i] + C - a[i];
        calo += b[i];
        res = max(res, calo - dist + CL[i-1]);
    }

    cout << res;
    return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

template <typename T>
int getFormer(const vector<T> &vec, T x) {
    return upper_bound(vec.begin(), vec.end(), x) - vec.begin() - 1;
}

template <typename T>
int getLatter(const vector<T> &vec, T x) {
    return lower_bound(vec.begin(), vec.end(), x) - vec.begin();
}

void solve(int n, int m, int t, int p) {
    vector<int> d(t), c(t), _x(p), _y(p);
    vector<vector<int>> before(m, vector<int>(n, 1)), after;
    REP(i, t) {
        int d, c;
        cin >> d >> c;
        if (d == 1) {
            int _n = max(n - c, c);
            after = vector<vector<int>> (m, vector<int> (_n));
            REP(y, m) {
                REP(x, n - c) {
                    after[y][x] = before[y][x + c];
                }
            }

            REP(y, m) {
                REP(x, c) {
                    after[y][c - x - 1] += before[y][x];
                }
            }
            n = _n;
        } else {
            int _m = max(m - c, c);
            after = vector<vector<int>> (_m, vector<int> (n));
            REP(x, n) {
                REP(y, m - c) {
                    after[y][x] = before[y + c][x];
                }
            }

            REP(x, n) {
                REP(y, c) {
                    after[c - y - 1][x] += before[y][x];
                }
            }
            m = _m;
        }
        before = after;
    }

    REP(i, p) {
        int x, y;
        cin >> x >> y;
        cout << before[y][x] << endl;
    }
}

int main() {
    int n, m, t, p;
    while(cin >> n>> m >> t >> p && n) {
        solve(n, m, t, p);
    }
}


Measured memory_bytes: 3088
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long x,y,i;
    
    while(x!=0 or y!=0)
    {
        cin>>x>>y;
        
        if(x!=0 or y!=0)
        {
            if(x<y )
            {
                cout<<x<<" "<<y<<endl;

            }
            else
            {
                cout<<y<<" "<<x<<endl;

            }
            
            
            
        }
        
    }
    
    

    
    
    
    
    return 0;
    
}



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

#define pb push_back
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define digits(x) floor(log10(x) + 1)
#define countbits(x) ((int)log2(x)+1)
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define init(arr,value) memset(arr,value,sizeof(arr))
#define deb(x) cout << #x << "=" << x << endl;
#define test unsigned int tet;cin >> tet;while(tet--)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout.precision(10);cout << fixed;
#define int long long

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const ll N   = 500500;

vector<int> a,dp(100005,-1);

bool winner(int k)
{
    if(k == 0) return 1;
    if(dp[k] != -1) return dp[k];
    for(auto x : a)
    {
        if(x <= k)
        {
            dp[k-x] = winner(k-x);
            int win = dp[k-x]^1;
            if(win == 0) return (dp[k] = 0);
        }
    }
    return (dp[k] = 1);
}

signed main(void)
{
    	fastio
        int n,k;
        cin >> n >> k;

        for(int i=0; i<n; i++){
            int t;
            cin >> t;
            a.pb(t);
        }

        if(winner(k)){
            cout << "Second";
        }
        else cout << "First";

    	return 0;
}



Measured memory_bytes: 8700
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

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


using namespace std;



int main() {

	int a, b;
	cin >> a >> b;
	cout << a+1 - b << endl;

	return 0;



}

Measured memory_bytes: 256
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
const int MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint n, t;
    lint ans = 0;
    cin >> n;
    multiset<lint> nums;
    set<lint> num;
    vector<lint> sum(n+1, 0);
    for (int i=0; i<n; ++i){
        cin >> t;
        sum[i+1] = sum[i] + t;
    }
    for (int i=0; i<=n; ++i){
        nums.insert(sum[i]);
        num.insert(sum[i]);
    }
    for (auto itr = num.begin(); itr != num.end(); ++itr){
        lint k = nums.count(*itr);
        ans += (k * (k - 1)) / 2;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 20608
#include <cstdio>
#include <algorithm>

using namespace std;

class inverse {
    public:
    inverse(int n, int mod);
    ~inverse();
    long long get_inv(int x);
    long long get_fact(int x);
    long long get_invfact(int x);
    long long get_comb(int x, int y);
    
    private:
    int mod;
    long long* inv;
    long long* fact;
    long long* invfact;
};

inverse::inverse(int n, int mod) : mod(mod) {
    inv = (long long *)malloc(sizeof(long long) * (n + 1));
    fact = (long long *)malloc(sizeof(long long) * (n + 1));
    invfact = (long long *)malloc(sizeof(long long) * (n + 1));
    inv[1] = 1;
    for (int i = 2; i <= n; i++) inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    fact[0] = invfact[0] = 1;
    for (int i = 1; i <= n; i++) fact[i] = fact[i - 1] * i % mod;
    for (int i = 1; i <= n; i++) invfact[i] = invfact[i - 1] * inv[i] % mod;
}

inverse::~inverse() {
    free(inv);
    free(fact);
    free(invfact);
}

long long inverse::get_inv(int x) {
    return inv[x];
}

long long inverse::get_fact(int x) {
    return fact[x];
}

long long inverse::get_invfact(int x) {
    return invfact[x];
}

long long inverse::get_comb(int x, int y) {
    return fact[x] * invfact[y] % mod * invfact[x - y] % mod;
}

long long mod_inverse(long long a, long long m) {
    long long b = m, x = 1, y = 0;
    while (b) {
        long long t = a / b;
        a -= t * b;
        x -= t * y;
        swap(a, b);
        swap(x, y);
    }
    x %= m;
    if (x < 0) x += m;
    return x;
}

const int mod = 1000000007;

int main() {
    int b, w, i;
    long long pb = 0, pw = 0, x = 1;
    
    scanf("%d %d", &b, &w);
    
    inverse inv(b + w, mod);
    
    for (i = 0; i < b + w; i++) {
        long long nx = x * 2 % mod;
        
        if (i >= b) pb = (pb * 2 + inv.get_comb(i - 1, i - b)) % mod;
        if (i >= w) pw = (pw * 2 + inv.get_comb(i - 1, i - w)) % mod;
        
        printf("%lld\n", (x - pb + pw + mod) % mod * mod_inverse(nx, mod) % mod);
        
        x = nx;
    }
    
    return 0;
}


Measured memory_bytes: 6912
#include <iostream>
#include <fstream>
#include <sstream>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

#define pb push_back
#define pbk pop_back
#define mp make_pair
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define foreach(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define len(a) ((int) (a).size())

#ifdef CUTEBMAING
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

#define rank hurank

using namespace std;

typedef long long int64;
typedef long double ld;
typedef unsigned long long lint;

const int inf = (1 << 30) - 1;
const int64 linf = (1ll << 62) - 1;
const int N = 1e6 + 100;

int n, m, k;
int a[N];

int64 dp[N];

int parent[N], rank[N];
int64 value[N];

inline int findSet(int v) {
    if (parent[v] != v) {
        return parent[v] = findSet(parent[v]);
    }
    return v;
}

inline void unite(int a, int b) {
    a = findSet(a);
    b = findSet(b);
    if (a == b) {
        return ;
    }
    if (rank[a] == rank[b]) {
        rank[a]++;
    }
    if (rank[a] > rank[b]) {
        swap(a, b);
    }
    parent[a] = b;
}

int main() {
#ifdef XCODE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < k; i++) {
        for (int j = n - 1; j >= 0; j--) {
            dp[j + 1] = dp[j];
        }
        dp[0] = i == 0 ? 0 : -linf;
        for (int j = 0; j < n; j++) {
            parent[j] = j;
            rank[j] = 0;
        }
        vector<pair<int64, int>> stack;
        for (int j = 0; j < n; j++) {
            pair<int64, int> curValue(dp[j] + 1ll * (i + 1) * a[j], j);
            while (len(stack) > 0 && stack.back().fs <= curValue.fs) {
                unite(stack.back().sc, curValue.sc);
                stack.pbk();
            }
            value[findSet(curValue.sc)] = curValue.fs;
            stack.pb(curValue);
            dp[j] = value[findSet(max(0, j - m + 1))];
        }
    }
    cout << *max_element(dp, dp + n) << endl;
    return 0;
}


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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}






int ggcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,count4,count2,count1;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  rep(i,n){
    if(a[i]%4==0){
      count4++;
    }else if(a[i]%2==0){
      count2++;
    }else{
      count1++;
    }
  }
  if(count2<=1){
    if(count1+count2<=count4+1){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }else{
    if(count1<=count4){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  
  
}
///////////////////////////



Measured memory_bytes: 640
N = int(input())
ans = "No"
if 3 < N:
    if (N % 4 == 0) or (N % 7 == 0):
        ans = "Yes"
    elif ((N % 4) % 7 == 0) or ((N % 7) % 4 == 0):
        ans = "Yes"
    x = 0
    while x <= N:
        x += 4
        if (N - x) % 7 == 0:
            ans = "Yes"
            break 
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define mod (int)1000000007
#define MOD (int)10000000007
#define X 1001100011100001111ll
#define M 26388279066623ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for0e(i, n) for (int i = 0; i <= n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int> 
#define F first
#define S second
#define pi pair<int, int>
#define ppi pair<pair<int,int> , int >
#define vii vector<pi>
#define endl "\n"
const int MAXN = (int)((1e5) + 100);
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;} 
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int cbrt(int x){ int lo=1,hi=min(2000000ll,x);while(hi-lo>1){int mid=(lo+hi)/2;if(mid*mid*mid<x){lo=mid;}else hi=mid;}if(hi*hi*hi<=x) return hi;else return lo;} 
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const int N =  (int)(1e6+5); 
// ========================================================
signed main(){
  #ifndef ONLINE_JUDGE
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  #endif
  fio;
    int n,x,t;
    cin>>n>>x>>t;
    ll ans;
    if(n%x == 0){
        ans = (n/x)*t;
    }
    else{
        ans = ((n/x) + 1)*t;
    }
    cout<<ans<<endl;
  rr;
}



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

int n;

int main() {
	scanf("%d", &n);
	
	int it = 1;
	for(int i=1;i<=n;i++) {
		int x;
		scanf("%d", &x);
		if(x==it) it++;
	}
	
	if(it==1) puts("-1");
	else printf("%d\n", n-(it-1));
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

int main() {
	vector<pii> v, vv;
	vector<pii> in;
	int N, Ma, Mb;
	cin >> N >> Ma >> Mb;
	rep(i,N) {
		int a, b, c;
		cin >> a >> b >> c;
		in.push_back(pii(Mb*a-Ma*b,c));
	}
	rep(k,2) {
		int off = 0;
		int mx  = N/2;
		if(k) {off = N/2; mx = N;}
		rep(i,1 << (mx-off)) {
			int ab, c;
			ab = 0;
			c = 0;
			rep(j,mx-off) {
				if(i & (1 << j)) {
					ab += in[off+j].fi;
					c += in[off+j].se;
				}
			}
			pii p(ab,c);
			if(k)
				vv.push_back(p);
			else
				v.push_back(p);
		}
	}
	sort(all(vv));
	sort(all(v));
	const int INF = 1e9;
	int res = INF;
	rep(i,v.size()) {
		int indx;
		indx = upper_bound(all(vv), pii(-v[i].fi, -1)) - vv.begin();
		if(indx < vv.size() && vv[indx].se == 0 && v[i].se == 0) indx++;
		if(indx >= vv.size() || v[i].fi+vv[indx].fi) continue;
		res = min(res, vv[indx].se + v[i].se);
	}

	if(res == INF)
		cout << -1 << endl;
	else
		cout << res << endl;
	return 0;
}


Measured memory_bytes: 22120
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner s = new Scanner(System.in);
        double a =s.nextDouble(),b= s.nextDouble();
        System.out.println((int)(Math.ceil(a/b)));
    }
}



class Scanner
{
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

    public String next() throws IOException
    {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {return Integer.parseInt(next());}

    public long nextLong() throws IOException {return Long.parseLong(next());}

    public String nextLine() throws IOException {return br.readLine();}

    public double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }

    public boolean ready() throws IOException {return br.ready();}


}

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

int dp[40][1<<14];
int v[40];

int pnt(int c){
    return c>0?50+c*10:0;
}

int toBit(int c[7],int p){
    int bit=0;
    for(int i=1;i<7;i++){
        bit=(bit<<2)|c[i];
    }
    bit=(bit<<2)|(~v[p+7]?v[p+7]:0);
    return bit;
}

void solve(){
    memset(v,-1,sizeof(v));
    for(int i=0;i<25;i++)cin>>v[i],v[i]--;
    memset(dp,-1,sizeof(dp));
    int start=0;
    for(int i=0;i<7;i++)start=(start<<2)|(~v[i]?v[i]:0);
    dp[0][start]=0;
    for(int i=0;i<25;i++){

        for(int S=0;S<(1<<14);S++){
            if(dp[i][S]==-1)continue;
            int c[7];
            for(int j=0;j<7;j++)c[6-j]=S>>(j*2)&3;

            if(i%5==4||i>=20){
                dp[i+1][toBit(c,i)]=max(dp[i+1][toBit(c,i)],dp[i][S]+pnt(c[0]));
                continue;
            }
            for(int j=0;j<4;j++){
                dp[i+1][toBit(c,i)]=max(dp[i+1][toBit(c,i)],dp[i][S]+pnt(c[0]));

                for(int k=0;k<7;k++)if(k<2||k>=5){
                    if(~v[i+k])c[k]=(c[k]+1)%4;
                }
            }

        }
    }

    int ans=0;
    for(int i=0;i<(1<<14);i++)ans=max(ans,dp[25][i]);

    cout<<ans<<endl;

}

int main(){
    int n;cin>>n;
    while(n--)solve();
    return 0;
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)


void aryan_p() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	return;
}
const int N = 50000;

void player_1() {
	cout << "Ashishgup" << endl;
}

void player_2() {
	cout << "FastestFinger" << endl;
}

bool check_prime(int n) {
	if (n == 2) {
		return true;
	}
	for (int i = 2; i < min(N, n); i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return true;
}

int32_t main() {
	

	int n,b;
	cin>>n>>b;


	int val = n-2*b;
	if(val>0){
		cout<<val;
	}
	else{
		cout<<0;
	}


	return 0 ;
}



Measured memory_bytes: 3648
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
 
sys.setrecursionlimit(10**7)
inf = 10**20
gosa = 1.0 / 10**10
mod = 10**9 + 7
 
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
 
 
def main():
    x,a,b = LI()
    if abs(x-a) > abs(x-b):
        return 'B'
 
    return 'A'
 
print(main())

Measured memory_bytes: 6096
A, B, C = [int(v) for v in input().strip().split(" ")]
K = int(input().strip())

while K > 0:
    if B <= A:
        B *= 2
        K -= 1
    elif C <= B:
        C *= 2
        K -= 1
    else:
        break

if C > B > A:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9180
package main

// Next lexicographical permutation algorithm
// https://www.nayuki.io/page/next-lexicographical-permutation-algorithm

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

func stringifyArray(arr []int) string {
	s := fmt.Sprintf("%+v", arr)
	return s[1:(len(s) - 1)]
}

func swap(a []int, i, j int) {
	t := a[i]
	a[i] = a[j]
	a[j] = t
}

func sortNonDecreasing(a []int, iHead int) {
	n := len(a)
	for i := iHead + 1; i < n; i++ {
		v := a[i]
		j := i - 1
		for j >= iHead && a[j] > v {
			a[j+1] = a[j]
			j--
		}
		a[j+1] = v
	}
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = i + 1
	}

	fmt.Println(stringifyArray(a))

	iHeadDecreasingSuffix := n - 1
	nCachedLine := 0
	cachedLines := ""
	for {
		for iHeadDecreasingSuffix > 0 && a[iHeadDecreasingSuffix-1] >= a[iHeadDecreasingSuffix] {
			iHeadDecreasingSuffix--
		}
		if iHeadDecreasingSuffix == 0 {
			break
		}

		iLargestInSuffix := n - 1
		for a[iHeadDecreasingSuffix-1] >= a[iLargestInSuffix] {
			iLargestInSuffix--
		}

		// fmt.Println(iHeadDecreasingSuffix-1, iLargestInSuffix, a)
		swap(a, iHeadDecreasingSuffix-1, iLargestInSuffix)
		sortNonDecreasing(a, iHeadDecreasingSuffix)

		// fmt.Println(iHeadDecreasingSuffix-1, iLargestInSuffix, a)
		iHeadDecreasingSuffix = n - 1

		// fmt.Println(stringifyArray(a))

		aStr := make([]string, n)
		for i := 0; i < n; i++ {
			aStr[i] = strconv.Itoa(a[i])
		}
		cachedLines += strings.Join(aStr, " ") + "\n"

		if nCachedLine < 10 {
			nCachedLine++
		} else {
			fmt.Print(cachedLines)
			nCachedLine = 0
			cachedLines = ""
		}
	}
	fmt.Print(cachedLines)
}



Measured memory_bytes: 6192
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

using namespace std;

const long long mod = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  for (int i = 2; i * i <= m; i++) {
    while (m % i == 0) {
      mp[i]++;
      m /= i;
    }
  }
  if (m != 1) mp[m]++;
  long long ans = 1;
  for (auto kv : mp) {
    vector<long long> dp(kv.second + 1);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
      for (int j = 1; j <= kv.second; j++) {
        dp[j] += dp[j - 1];
        dp[j] %= mod;
      }
    }
    ans *= dp[kv.second];
    ans %= mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

n = int(input())

res = 1
for i in range(n):
    a = int(input())
    g = gcd(res, a)
    res = (res // g) * a

print(res)


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>

int main (int argc, char const *argv[])
{
    int64_t H, W, h, w;

    scanf("%"PRId64"%"PRId64, &H, &W);
    scanf("%"PRId64"%"PRId64, &h, &w);

    

    printf("%"PRId64"\n", (H - h) * (W - w));

    return 0;
}


Measured memory_bytes: 128
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_3_D
#include <iostream>
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  int counter = 0; //?????°?????°??????
  for(int i = a; i<=b; i++){
    if(c % i ==0){
      counter++;
    }
  }
  cout << counter << endl;
}

Measured memory_bytes: 1164