akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int H,W,hp,HP;
char t[1005][1005];
int T,S,P;
map<char,int> mp;
vector<int> u;
int dp[1005][(1<<12)];
int v[12];

int main(){

  while(1){
    u.clear();
    cin>>hp>>HP;
    if(hp==0&&HP==0)break;
    cin>>H>>W;
    for(int i=0;i<H;i++)
      for(int j=0;j<W;j++)
        cin>>t[i][j];
    cin>>T;
    for(int i=0;i<T;i++){
      char ch;
      int num;
      cin>>ch>>num;
      mp[ch]=num;
    }
    int y=0,x=0;
    cin>>S;
    for(int i=0;i<S;i++){
      char ch;
      int num;
      cin>>ch>>num;
      while(num--){
        if(ch=='U')y--;
        if(ch=='R')x++;
        if(ch=='D')y++;
        if(ch=='L')x--;
        u.push_back(mp[ t[y][x] ]);
      }
    }
    cin>>P;
    for(int i=0;i<P;i++)cin>>v[i];
    memset(dp,0,sizeof(dp));
    dp[0][0]=hp;
    int N=u.size();
    for(int i=0;i<N;i++){
      for(int S=0;S<(1<<P);S++){
        if(dp[i][S]==0)continue;        
        for(int k=0;k<P;k++){
          if(S>>k&1)continue;
          int nS=S|(1<<k);
          dp[i][nS]=max(dp[i][nS],min(HP,dp[i][S]+v[k]));
        }
        dp[i+1][S]=max(dp[i+1][S],dp[i][S]-u[i]);
      }
    }
    string ans="NO";
    for(int i=0;i<(1<<P);i++)
      if(dp[N][i]>0)ans="YES";
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 17620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
const ll INF=1e9+7;
const ll N = 100002;

ll a,b,c,aa,bb,cc,k;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>a>>b>>c>>k;
	if(k%2==0){
		if(abs(a-b)<1e18)pri(a-b);
		else pri("Unfair");
	}
	else{
		if(abs(b-a)<1e18)pri(b-a);
		else pri("Unfair");
	}


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define show(x) for(auto i: x){cout << i << " ";}
#define showm(m) for(auto i: m){cout << m.x << " ";}
typedef long long ll;
typedef pair<int, ll> P;

#define N_OVERSIZE 100050
vector<P> root[N_OVERSIZE];
int color[N_OVERSIZE] = {0}; //white 0, black 1

void dfs(int v, int p){
    if (root[v].size() == 1 && p != -1) return;
    for (auto next: root[v]){
        if (next.first == p) continue;
        if (next.second % 2 == 0) color[next.first]=color[v];
        else color[next.first]=color[v]^1;
        dfs(next.first, v);
    }
    return;
}

int main()
{
    int n;
    cin >> n;
    rep(i, n-1){ 
        int tmpu, tmpv, tmpw; 
        cin >> tmpu >> tmpv >> tmpw;
        tmpu--; tmpv--; 
        root[tmpu].push_back(P(tmpv, tmpw));
        root[tmpv].push_back(P(tmpu, tmpw));
    }

    color[0] = 0; //white_start
    dfs(0, -1); 

    rep(i, n){
        cout << (color[i] == 1 ? 1: 0) << endl;
    }

}

Measured memory_bytes: 10240
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010

int main(){
	IOS;
	ll a,b;char c;
	cin>>a>>c>>b;
	if(c=='+')cout<<a+b;
	else cout<<a-b;
	
	
	
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#define N 100

int a[N];

void PrintMatrix(int n){
	int i;
	for(i=0;i<n-1;i++) printf("%d ",a[i]);
	printf("%d\n",a[n-1]);
}

void Bubble(int n){
	int i,j,f,temp,c=0;
	f=1;
	i=0;
	while(f){
		f=0;
		for(j=n-1;j>i;j--){
			if(a[j]<a[j-1]){
				temp=a[j];
				a[j]=a[j-1];
				a[j-1]=temp;
				f=1;
				c++;
			}
		}
		i++;
	}
	PrintMatrix(n);
	printf("%d\n",c);
}


int main(void){
	int i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&a[i]);
	Bubble(n);
	return 0;
}

Measured memory_bytes: 1812
import sys
from itertools import groupby

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = map(int, readline().split())
    S = readline().strip()

    ans = groups = 0
    for k, g in groupby(S):
        ans += len(list(g)) - 1
        groups += 1

    ans += 2 * K
    if ans > N - 1:
        ans = N - 1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9824
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll x, y, z;
  x = y = z = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ll cnt = 0;
    while (a[i]%2 == 0) {
      a[i] /= 2;
      cnt++;
    }
    if (cnt == 0) x++;
    else if (cnt == 1) z++;
    else if (cnt > 1) y++;
  }
  if (z > 0) x++;
  x <= y+1 ? dump("Yes") : dump("No");
  return 0;
}


Measured memory_bytes: 1024
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc165/tasks/abc165_c

//ポイント
//単調増加な数列の全探索の、計算量の見積もりに
//仕切りを用いた考え方を使う

//参考：
//https://img.atcoder.jp/abc165/editorial.pdf

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,M,Q;
LL a[50],b[50],c[50],d[50];

LL ans = 0;

void permutation(vector<int> array,int added){
	if(array.size()==N){
		LL ret = 0;
		for(int i=0;i<Q;i++){
			if(array[b[i]-1]-array[a[i]-1]==c[i]) ret += d[i];
		}
		ans = max(ans,ret);
		return;
	}else{
		for(int i=added;i<=M;i++){
			vector<int> arr(array);
			arr.push_back(i);
			permutation(arr,i);
		}
	}
}

void solve(){
	permutation(vector<int>(0),1);
}
 
int main(){
    cin >> N >> M >> Q;
    for(int i=0;i<Q;i++) cin >> a[i] >> b[i] >> c[i] >> d[i];

    solve();

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

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

using namespace std;

const int maxn = 100010;
int N, k, cs, P[maxn], lca[maxn][17], L[maxn], Q;
vector<int> A[maxn];


void dfs( int v, int lvl ){

	L[v] = lvl;
	vector<int>::iterator x = A[v].begin();
	for( ; x != A[v].end(); ++x )
		dfs( *x, lvl + 1 );
}


void preLCA(){

	for( int i = 0; i < N; ++i )
		for( int j = 0; ( 1 << j ) < N; ++j )
			lca[i][j] = -1;

			
	for( int i = 0; i < N; ++i )
		lca[i][0] = P[i];


	for( int i = 1; ( 1 << i ) < N; ++i )
		for( int j = 0; j < N; ++j )
			if(lca[j][i-1] != - 1)
				lca[j][i] = lca[lca[j][i - 1]][i - 1];
}

int findlca( int nx, int ny ){

	if( L[nx] < L[ny] )
		swap(nx, ny);

	int lg = 1;

	for( ; (1 << lg) <= L[nx]; ++lg );
	--lg;

	for( int i = lg; i >= 0; --i )
		if( L[nx] - ( 1 << i ) >= L[ny] )
			nx = lca[nx][i];

	if( nx == ny )
		return nx;
	
	for( int i = lg; i >= 0; --i )
		if( lca[nx][i] != -1 && lca[nx][i] != lca[ny][i] )
			nx = lca[nx][i], ny = lca[ny][i];
	                     
	return P[nx];
}               

int main( void ){

	//freopen("input.in", "r", stdin);
    scanf("%d", &N);

    for( int i = 0; i < N; ++i ){
    	scanf("%d", &k);
    	for( int j = 0; j < k; ++j )
    		scanf("%d", &cs), 
    		A[i].push_back(cs), 
    		P[cs] = i; 
    }
	
	dfs( 0, 0 );
	preLCA();
	scanf("%d", &Q);
	int a, b;
	for( ; Q > 0; --Q ){
		scanf("%d%d", &a, &b);
		printf("%d\n", findlca(a, b));	
	}

	return 0;
}

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

total = []
for i in range(1,n+1):
  
  if sum(total)>=n:
    break
  total.append(i)
  
if sum(total)-n<total[-1]:
  if sum(total)-n in total:
    del total[sum(total)-n-1]
      
for i in total:
  print(i)
  

Measured memory_bytes: 68648
#include <bits/stdc++.h>
#define inp(X) cin >> X
#define out(X) cout << X << endl
#define out16(X) cout << setprecision(16) << X << endl
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define MAX(A) *max_element(A.begin(),A.end())
#define MIN(A) *min_element(A.begin(),A.end())
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vd = std::vector<double>;
using vvd = std::vector<std::vector<double>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using namespace std;
#define MOD 1000000007
#define INF 1000000001
#define LL_INF 1001001001001001001

int main(void) {
	int n,k; cin >> n >> k;
	vll h(n); rep(i,n) cin >> h[i];
	SORT(h); REV(h);
	ll ans = 0;
	for(int i=k; i<n; i++) ans += h[i];
	out(ans);
}




Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <utility>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;

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

typedef long long lint;
typedef pair<int,int> P;


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

    vector<lint> a(N);
    REP(i,N) cin >> a[i];

    vector<lint> s(N+1,0);
    REP(i,N) s[i+1]=s[i]+a[i];

    map<lint,lint> nums;
    REP(i,N+1) nums[s[i]]++;

    lint ans=0;

    for(auto i:nums){
    	lint tmp=i.second;
    	ans+=tmp*(tmp-1)/2;
    }
    cout << ans << endl;

	return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<string> a {"Sunny", "Cloudy", "Rainy"};
  string s;
  cin >> s;
  for (int i = 0; i < a.size(); ++i) {
    if (s == a[i]) {
      cout << a[(i + 1) % a.size()] << '\n';
    }
  }
  return 0;
}


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

int main() {
 int K;
 cin >> K;
  int sum = 0;
  for(int a = 1; a < K+1; a++){
    for(int b = 1; b < K+1; b++){
      for(int c = 1; c < K+1; c++){
        int A = gcd(a,b);
        sum += gcd(A,c);
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

long long modpow(long long a, long long b){ 
  long long r = 1LL;

  while(b){
    if(b & 1LL)r *= a;
    if(r >= MOD)r %= MOD;
    a *= a;
    if(a >= MOD)a %= MOD;
    b >>= 1LL;
  }
  return r;
}

int main() {
	ll n;
	cin>>n;
	vector<ll> v;
	rep(i,0,n){
		ll a;
		cin>>a;
		v.pb(a);
	}
	sort(all(v));
	if(v.sz%2==0){
		int flag = 1;
		rep(i,0,v.sz/2){
			if(v[i*2]!=i*2+1||v[i*2+1]!=i*2+1){
				flag = 0;
			}
		}
		if(flag == 0){
			cout << 0 << endl;
			return 0;
		}
	}
	else{
		int flag = 1;
		if(v[0]!=0){
			cout << 0 << endl;
			return 0;
		}
		rep(i,0,v.sz/2){
			if(v[i*2+1]!=i*2+2||v[i*2+2]!=i*2+2){
				flag = 0;
			}
		}
		if(flag == 0){
			cout << 0 << endl;
			return 0;
		}		
	}
	ll nn = v.sz/2;
	ll ans = modpow(2,nn);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1400
/*
g++ -std=c++11 -o2 -Wall AGC024B.cpp -o ./out/AGC024B.out
./out/AGC024B.out
*/

#include <bits/stdc++.h>
using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define tr(c, i) for (iter(c) != (c).begin(); i != (c).end(); ++i)
#define pb push_back
#define mp make_pair

typedef long long ll;

using namespace std;

int ans;
string s[300];
main()
{
	int n;cin>>n;
	for(int i=0;i<n;i++)cin>>s[i];
	for(int a=0;a<n;a++)
	{
		bool f=1;
		for(int i=0;i<n;i++)for(int j=0;j<n;j++)f&=s[(i+a)%n][j]==s[(j+a)%n][i];
		if(f)ans+=n;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 384
N=int(input())
L=list(map(int,input().split()))

if N<=2:
    print(0)
else:
    answer=0
    for l in range(N-2):
        for m in range(l+1,N-1):
            for n in range(m+1,N):
                a=sorted([L[l],L[m],L[n]])
                if a[2]<a[0]+a[1]:
                    if a[0]!=a[1] and a[1]!=a[2] and a[2]!=a[0]:
                        answer+=1
    print(answer)

Measured memory_bytes: 74056
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  

}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){
  while(u != NIL && k != u->key){
    if(k < u->key)
      u = u->left;

    else
      u = u->right;
  }

  return u;
}

Node treeSuccessor(Node x){


}

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



}

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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;

    if(z->key < x->key)
      x = x->left;

    else
      x = x->right;
  }

  z->parent = y;

  if(y==NIL)
    root = z;

  else if(z->key < y->key)
    y->left = z;

  else
    y->right = z;
}

void inorder(Node u){
  if(u == NIL)
    return;

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


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

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

    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }

    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
      
    }

    else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20460
#include<iostream>
using namespace std;
int main()
{
    int x, y, z;
    cin >> x >> y >> z;
    for(int i = 1; ; i++){
        if((y * i) + (z * (i+1)) > x){
            cout << i - 1 << endl;
            return 0;
        }
    }
}

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

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

#define pb push_back
#define in ,
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int n;
  int a[200];
  cin >> n;
  rep(i, 0, n * 2) cin >> a[i];

  sort(a, a + n * 2);
  int ans = 0;
  for(int i = n * 2 - 2; i >= 0; i -= 2) {
    ans += a[i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
int N, i;
cin >> N;
vector<int> a(3*N);
for(i = 0;i < N;++ i) cin >> a[i];
sort(a.begin(), a.begin()+N);
for(i = 0;i < (N+2)/3;++ i) a[N] ^= a[i] ^ a[i + N/3] ^ a[i + N/3*2];
cout << (a[N] ? "No" : "Yes");
return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

ll N, K, ans;

int main()
{
    cin >> N >> K;
    vector<int> a(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i];
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (i < j && a[i] > a[j])
            {
                ans += K * (K + 1) / 2;
            }
            else if (i > j && a[i] > a[j])
            {
                ans += K * (K - 1) / 2;
            }
            ans %= mod;
        }
    }
    cout << ans % mod << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;

bool check(int a, int b) {
	return a > b;
}

int solve(int cnt, int x, int y, vint c, vint s, vint f) {
	if (cnt > cnt / f[x]*f[x]) {
		cnt = cnt / f[x] * f[x] + f[x];
	}
	else {
		cnt = cnt / f[x]*f[x];
	}
	if (cnt < s[x]) {
		cnt = s[x];
	}
	cnt += c[x];
	if (x + 1 == y) {
		return cnt;
	}
	else {
		return solve(cnt, x + 1, y, c, s, f);
	}
}

int main() {
	int a, b;
	cin >> a >> b;
	rep(i, a + 1) {
		rep(j, a - i + 1) {
			if (10000 * i + 5000 * j + 1000 * (a - i - j) == b) {
				cout << i << " " << j << " " << a - i - j << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Foldable
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import qualified Data.Set as S
import System.IO.Unsafe
import Debug.Trace

unew :: VU.Unbox a => Int -> VUM.IOVector a
unew !n = accursedUnutterablePerformIO $ VUM.unsafeNew n

uread :: VU.Unbox a => Int -> VUM.IOVector a -> a
uread !i !v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VU.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite !i !a !v =
  accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

umodify :: VU.Unbox a => Int -> (a -> a) -> VUM.IOVector a -> VUM.IOVector a
umodify !i !f !v =
  accursedUnutterablePerformIO $ VUM.unsafeModify v f i >> return v

uthaw :: VU.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw !v = accursedUnutterablePerformIO $ VU.unsafeThaw v

ufreeze :: VU.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze !v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

solve :: Int -> Int -> VU.Vector (Int, Int) -> Int
solve !n !w !wvs = uread (toIndex n w) dp
 where
  toIndex i k = i * (w + 1) + k

  dp = VU.ifoldl'
    ( \(!dp) !i (!wi, !vi) -> foldl'
      ( \(!dp) !k ->
        let z = max
              (uread (toIndex i k) dp)
              (if k - wi < 0 then 0 else uread (toIndex i (k - wi)) dp + vi)
        in  z `seq` uwrite (toIndex (i + 1) k) z dp
      )
      dp
      [0 .. w]
    )
    ( foldl' (\(!dp) !k -> uwrite (toIndex 0 k) 0 dp)
             (unew (succ n * succ w))
             [0 .. w]
    )
    wvs

main = do
  let readInt = fmap (second B.tail) . B.readInt

  (n, w) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  wvs <-
    VU.replicateM n
    $   (\vec -> (vec VU.! 0, vec VU.! 1))
    .   VU.unfoldrN 2 readInt
    <$> B.getLine
  print $ solve n w wvs


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

int main()
{
    rep(i, 3)
    {
        string s;
        cin >> s;
        cout << s[0];
    }
    cout << endl;
}


Measured memory_bytes: 256
import sys, io, os, re
import bisect
from pprint import pprint
from math import sin, cos, pi, radians, sqrt, floor
from copy import copy, deepcopy
from collections import deque
from fractions import gcd
from functools import reduce

def array1(n): return [0] * n
def array2(n, m): return [[0] * m for x in range(n)]
def array3(n, m, l): return [[[0] * l for y in xrange(m)] for x in xrange(n)]

n = int(sys.stdin.readline().strip())
a = array1(n)
b = array1(n)

for i in range(n):
    (a[i], b[i]) = list(map(int, sys.stdin.readline().strip().split()))

a = sorted(a)
b = sorted(b)

if n % 2 == 1:
    print(int(b[n//2] - a[n//2] + 1))
else:
    print(int(((b[n//2-1]+b[n//2])/2 - (a[n//2-1]+a[n//2])/2)*2 + 1))



Measured memory_bytes: 82532
shared void main(){
  assert(exists u=process.readLine());
  assert(exists n=parseInteger(u));
  value c=Array.ofSize(n,0);
  value s=Array.ofSize(n,0);
  value f=Array.ofSize(n,0);
  for(i in 1:n-1){
    assert(exists v=process.readLine());
    value w=v.split().iterator();
    assert(exists x=parseInteger(w.next().string));
    assert(exists y=parseInteger(w.next().string));
    assert(exists z=parseInteger(w.next().string));
    c.set(i,x);
    s.set(i,y);
    f.set(i,z);
  }
  for(i in 1..n){
    variable Integer t=0;
    for(j in i:n){
      value st=s.get(j);
      value ct=c.get(j);
      value ft=f.get(j);
      if(is Integer st){
        if(is Integer ct){
          if(is Integer ft){
            if(t<st){
              t=st;
            }
            else if(t%ft!=0){
              t+=ft-t%ft;
            }
            t+=ct;
          }
        }
      }
    }
    print(t);
  }
}

Measured memory_bytes: 191128
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort(key=lambda x: x[0])

res = 0
rem = M
for ab in AB:
    a, b = ab
    if rem >= b:
        rem -= b
        res += (a * b)
    else:
        res += (a * rem)
        break
        
print(res)

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

#define FO(i,a,b) for (int i = (a); i < (b); i++)
#define sz(v) int(v.size())

using namespace std;

typedef long long ll;

int n; ll l;
ll a[100005];

int main() {
    scanf("%d %lld", &n, &l);
    FO(i,0,n) scanf("%lld", a+i);
    FO(i,0,n-1) if (a[i]+a[i+1] >= l) {
        printf("Possible\n");
        FO(j,0,i) printf("%d\n", j+1);
        for (int j = n-2; j >= i+1; j--) {
            printf("%d\n", j+1);
        }
        printf("%d\n", i+1);
        return 0;
    }
    printf("Impossible\n");
}



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

typedef long long ll;

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

    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i=0;i<n-2;i++){
        if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	unsigned long long n,a,i;
	scanf("%lld", &n);
	for(i=1; i<n; i++)
	{
		if(i*i>n)
		break;
		if(n%i==0)
		a=i;
	}
	if(n/a==1)
	i=1;
	else
	i=2;
	printf("%lld\n", n/a+a-i);
	
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main(void){
  string s;
  cin >> s;
  if(s=="abc"||s=="acb"||s=="bac"||s=="bca"||s=="cab"||s=="cba")cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by wintermaples on 2017/04/29.
 */
public class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String read;
    while (scanner.hasNext()) {
      read = scanner.nextLine();
      //1????????????????????§int?????????
      int[] variables = Arrays.stream(read.split(" "))
          .mapToInt(s -> Integer.parseInt(s))
          .toArray();

      //????????????????????????????????????????????°???????´?
      int a = variables[0];
      int b = variables[1];
      int c = variables[2];
      int d = variables[3];
      int e = variables[4];
      int f = variables[5];

      //?§£????????????????????¬?????§??????
      double x = (double) (c * e - b * f) / (a * e - b * d);
      double y = (double) (a * f - c * d) / (a * e - b * d);
      BigDecimal xBD = new BigDecimal(x);
      BigDecimal yBD = new BigDecimal(y);
      xBD = xBD.setScale(3, BigDecimal.ROUND_HALF_UP);
      yBD = yBD.setScale(3, BigDecimal.ROUND_HALF_UP);

      //3???????????¨????????????
      System.out.println(
          String.format("%.3f", xBD) + " " + String.format("%.3f", yBD)
      );

    }
  }

}

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

using namespace std;

#define fore(i, s, e) for(int i = s; i < e; i++)

const int N = 1e5;

int n;
int a[N];
int dp[N];

int calc(int i) {
    if(i == n - 1) return 0;
    int r = 0;
    if(dp[i] != - 1) return dp[i];

    r = abs(a[i] - a[i+1]) + calc(i + 1);
    if(i < n - 2) r = min(r, abs(a[i] - a[i + 2]) + calc(i + 2));
    return dp[i] = r;
}


int main() {
    cin >> n;
    fore(i, 0, n) cin >> a[i];
    memset(dp, -1, sizeof dp);
    cout << calc(0) << endl;
}

Measured memory_bytes: 4096
for e in iter(input,'0'):
 a=sorted([list(map(int,input().split()))for _ in[0]*int(e)],key=lambda x:x[0])
 b=sorted([tuple(map(int,input().split()))for _ in[0]*int(input())],key=lambda x:x[0])
 for s,t in b:
  x,y=s-a[0][0],t-a[0][1]
  if not set((u+x,v+y)for u,v in a)-set(b):print(x,y);break


Measured memory_bytes: 5920
#include <stdio.h>
int n, q;
char s[200005];
char t[200005];
char d[200005];
int lx, rx, ly, ry, e;
int check(int a) {
	for (int i = 0; i < q; i++) {
		if (s[a] == t[i]) {
			if (d[i] == 'L')a--;
			if (d[i] == 'R')a++;
		}
		if (a == -1)return -1;
		if (a == n)return n;
	}
	return a;
}
int main() {
	scanf("%d%d", &n, &q);
	scanf("%s", s);
	for (int i = 0; i < q; i++) {
		scanf(" %c %c", &t[i], &d[i]);
	}
	if (check(n - 1) == -1) {
		printf("0\n");
		return 0;
	}
	if (check(0) == n) {
		printf("0\n");
		return 0;
	}
	lx = -1;
	rx = n - 1;
	while (rx - lx > 1) {
		e = (rx + lx) / 2;
		if (check(e) == -1) {
			lx = e;
		}
		else {
			rx = e;
		}
	}
	ly = 0;
	ry = n;
	while (ry - ly > 1) {
		e = (ry + ly) / 2;
		if (check(e) == n) {
			ry = e;
		}
		else {
			ly = e;
		}
	}
	printf("%d\n", ly - rx + 1);
}


Measured memory_bytes: 768
#include <iostream>
using namespace std;
int main(){
	int r, g, b;
	cin >> r >> g >> b;
	
	int num = (r * 100) + (g * 10) + b;
	
	if(num % 4 == 0){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
}

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

#define INF INT_MAX

using namespace std;

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

int main(void){
 	cin.tie(0);
    ios::sync_with_stdio(false);
	int N;
	cin >> N;

	int ans = 0;
	int ac = 0;
	int bc = 0;
	int ab = 0;
	vector<string> vs;
	for(int i = 0;i < N;i++){
		string s;
		cin >> s;
		vs.push_back(s);
	}
	for(int i = 0;i < N;i++){
		string s = vs[vs.size()-i-1];
		for(int j = 0;j < s.size()-1;j++){
			if(s[j] == 'A' && s[j+1] == 'B')ans++;
		}
		bool f = true;
		if(s[0] == 'B'){
			bc++;
			f = false;
		}
		if(s[s.size()-1] == 'A'){
			if(!f){
				bc--;
				ab++;
			}else{
				ac++;
			}
		}
	}
	if(ab>0){
		ans += ab-1;
		ab=1;
		if(ac > 0){
			ans++;
			ac--;
		}
		if(bc > 0){
			ans++;
			bc--;
		}
	}

	if(ac > 0 || bc > 0){
		ans += min(ac,bc);
		ac += min(ac,bc);
		bc += min(ac,bc);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int n;
	cin>>n;
	
	vector<int> h(n);
	for(auto &it: h) cin>>it;
	
	vector<int> dp(n);
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);
	
	for(int i=2; i<n; i++) {
		dp[i] = min(dp[i-2] + abs(h[i]-h[i-2]), dp[i-1] + abs(h[i] - h[i-1]));
	}
	cout<<dp[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int main(){
    int A, B, C;
    int cnt = 0;
    cin >> A >> B >> C;
    int S[3] = {A, B, C};
    int minv = min(A, min(B, C));
    int maxv = max(A, max(B, C));
    int midl;
    int m = 0, M = 0;
    REP(i, 3){
        if(S[i] == minv && m == 0){
            S[i] = 0;
            m++;
        }
        else if(S[i] == maxv && M == 0){
            S[i] = 0;
            M++;
        }
    }
    REP(i, 3){
        if(S[i] != 0)
            midl = S[i];
    }
    if(maxv - midl == 1 && maxv - minv == 1 && minv == midl){
        cnt++;
        cout << cnt << endl;
        return 0;
    }
    while(!(maxv - minv == 0 || maxv - minv == 1)){
        minv += 2;
        cnt++;
    }
    while(!(maxv - midl == 0 || maxv - midl == 1)){
        midl += 2;
        cnt++;
    }
    if(maxv - minv == 1 && maxv - midl == 1){
        cnt++;
    }
    else if(minv == midl && maxv - minv == 1){
        cnt += 2;
    }
    else if(maxv == minv && maxv - midl == 1){
        cnt += 2;
    }
    else if(maxv == midl && maxv - minv == 1){
        cnt += 2;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

class Main{

    public static void main(String[] args){

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i=0; i<m; i++){
            list.add(scanner.nextInt());
        }
        scanner.close();
        int sum = 0;
        for (int val : list) {
            sum += val;
        }
        if(n<sum){
            System.out.println("-1");
            return;
        }
        System.out.println(n - sum);
    }

}

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

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

    auto blocks = 0;
    auto active = char(0);
    for (const auto c : s) if (c != active)
    {
        active = c;
        blocks++;
    }

    cout << blocks-1 << endl;
}


Measured memory_bytes: 1020
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

const int MAX_N = 200000;
int n, k;
int a[MAX_N];
int b[MAX_N + 1];

int main(){
  cin >> n >> k;
  REP(i, n) cin >> a[i];
  REP(i, MAX_N + 1) b[i] = 0;
  REP(i, n) b[a[i]]++;
  sort(b, b + MAX_N + 1);

  ll ans = 0;
  REP(i, MAX_N + 1 - k) {
    ans += b[i];
  }

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


Measured memory_bytes: 1920
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
int n;
cin>>n;
int a[200001];
for(int i=1;i<=n;i++)
  cin>>a[i];
if(a[1]>0)
  {cout<<"-1";
   system("pause");
   return 0;}
for(int i=2;i<=n;i++)
  if(a[i]>a[i-1]+1)
   {cout<<"-1";
    system("pause");
    return 0;}
long long ans=0;
for(int i=2;i<=n;i++){
  if(a[i]>a[i-1])
    ans+=1;
  else
    ans+=a[i];}
cout<<ans;
system("pause");
return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int main(){
  int A,B;
  cin>>A>>B;

  if(B==1){
    cout<<0<<endl;
    return 0;
  }

  int now=1;
  for(int i=1;i<=B;i++){
    now--;
    now+=A;
    if(now>=B){
      cout<<i<<endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
)

const turtle = 4
const crane = 2

func main() {

	var x, y int

	fmt.Scan(&x, &y)

	if y%2 == 1 {
		fmt.Println("No")
		os.Exit(0)
	}

	min := crane * x
	max := turtle * x

	if y >= min && y <= max {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")

	}

}


Measured memory_bytes: 1824
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring> 
using namespace std;

int map[55][55]={0};
int main()
{
	int row,col,i,j,k;
	cin>>row>>col;
	getchar();
	for (i=1;i<=row;i++)
	{
		for (j=1;j<=col;j++)
		 {
		 	char ch=getchar();
		 	if (ch=='#')
		 	{
		 		map[i][j]=1;
			 }
		 }
		 	getchar();
	}
	for (i=1;i<=row;i++)
	 for (j=1;j<=col;j++)
	  if (map[i][j] && !(map[i-1][j]||map[i+1][j]||map[i][j-1]||map[i][j+1])) 
	   {
	   	 cout<<"No"<<endl;
	   	 return 0;
	   }
	cout<<"Yes"<<endl;
}
 

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    long long int l,r,da,db,lx,rx,v,lcm,dadb;
    scanf("%lld %lld %lld %lld",&l,&r,&da,&db);
    lx=(l-1)/da+(l-1)/db;
    rx=r/da+r/db;

    dadb=da*db;
    if(da<db){
        v=da;
        da=db;
        db=v;
    }
    v=da%db;
    while(v!=0){
        da=db;
        db=v;
        v=da%db;
    }
    lcm=dadb/db;

    lx-=(l-1)/lcm;
    rx-=r/lcm;
    printf("%lld\n",(r-l+1)-(rx-lx));
    return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int L = sc.nextInt();
		int R = sc.nextInt();
		int d = sc.nextInt();
		int ans = 0;
		for(int i = L;i < R+1;i++){
			if(i % d == 0){
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 26980
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
int main(){
    int n,m;
    ll sum=0;
    cin>>n>>m;
    int a[n];
  	for(int i=0;i<n;i++){cin>>a[i];sum+=a[i];}
  	int ct=0;
  	for(int i=0;i<n;i++)
      if(4LL*m*a[i]>=sum)ct++;
  	if(ct>=m)cout<<"Yes";else cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
#include <cmath>
#include <map>
#include <iomanip>
#include <tuple>
#define INF 1000000009
#define LINF 1000000000000000009
#define double long double
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
//ll mod = 1000000007;
//ll mod = 998244353;

vector<ll> cnt(500010);

void add(ll i, ll x) {
	i += 131071;
	cnt[i] += x;
	while (i > 0) {
		i = (i - 1) / 2;
		cnt[i] = cnt[i * 2 + 1] + cnt[i * 2 + 2];
	}
}

ll query(ll a, ll b, ll k, ll l, ll r) {
	if (r <= a || b <= l) return 0;
	if (a <= l && r <= b) return cnt[k];
	else {
		ll c1 = query(a, b, 2 * k + 1, l, (l + r) / 2);
		ll c2 = query(a, b, 2 * k + 2, (l + r) / 2, r);
		return c1 + c2;
	}
}

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vector<ll> s(n + 1);
	s[0] = 0;
	for (int i = 0; i < n; i++) s[i + 1] = s[i] + a[i] - k;
	map<ll, ll> mp;
	for (int i = 0; i <= n; i++) {
		s[i] += k * n;
		mp[s[i]]++;
	}
	vector<ll> t(n + 1);
	for (int i = 0; i <= n; i++) t[i] = s[i];
	sort(all(t));
	for (int i = 1; i <= n; i++) {
		if (t[i] != t[i - 1]) mp[t[i]] += mp[t[i - 1]];
	}
	ll ans = 0;
	for (int i = 0; i <= n; i++) {
		s[i] = mp[s[i]];
		ll res = query(130171, 131072 + s[i], 0, 131071, 262143);
		ans += res;
		add(s[i], 1);
	}
	cout << ans << endl;
}


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

int main(){
  int n, x;
  cin >> n >> x;
  int now=0;
  int cnt=1;
  int L;
  for(int k=0;k<n;k++){
    cin >> L;
    now += L;
    if(now <= x){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 256
/* Filename: ABC043B.java
 * Author: Mushiyo
 */

import java.util.Scanner;

public class Main{

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

		while (input.hasNext()) {
			String s = input.next();
			StringBuilder result = new StringBuilder();

			for (int i = 0; i < s.length(); ++i) {
				switch (s.charAt(i)) {
				case '0':
					result.append('0');
					break;
				case '1':
					result.append('1');
					break;
				case 'B':
					if (result.length() > 0){
						result.deleteCharAt(result.length() - 1);
					}
					break;
				}
			}
			
			System.out.println(result);
		}
	}
}


Measured memory_bytes: 8660
package main

import "fmt"

func main() {
	var A, B, C, X, Y, ans int
	fmt.Scan(&A, &B, &C, &X, &Y)
	ans = int(1e10)
	// ABピザをi枚からmax(X,Y)まで買った場合を全探索し、それぞれのiについてコストを計算し最小値を求める
	for i := 0; i <= max(X, Y); i++ {
		// ABピザからi枚からできるA,Bピザの枚数 をZとすると、Z = i/2となる
		// ABピザからできるだけAピザとBピザを作って、残りを単品のAピザあるいはBピザで補う
		ans = min(ans, i*2*C+max(X-i, 0)*A+max(Y-i, 0)*B)
	}
	fmt.Println(ans)
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  int x,y;
  while(1){
    cin >> x >> y;
    if(x == 0 && y == 0) break;
    if(x > y){
      cout << y << " " << x << endl;
    }else{
      cout << x << " " << y << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
#define PII pair<ll,int>
const int M = 2e5+5;
vector<int> vec[M];
int k[M],val[M];
ll L[M],R[M];
bool dn[M];
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int test;
	cin>>test;
	while(test--)
	{
		int n;
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			vec[i].clear();
			val[i]=-1;
			dn[i]=0;
		}
		for(int i=1;i<=n;i++)
		{
			cin>>k[i]>>L[i]>>R[i];
			vec[k[i]].pb(i);
		}
		priority_queue<PII> pq;
		vector<int> v;
		for(int i=n;i>=1;i--)
		{
			for(auto u:vec[i])
			{
				if(L[u]>R[u])
				{
					pq.push({L[u]-R[u],u});
				}
			}
			if(!pq.empty())
			{
				auto P = pq.top();
				pq.pop();
				v.pb(P.ss);
				dn[P.ss] = 1;
			}
		}
		reverse(all(v));
		for(int c=0;c<sz(v);c++)
		{
			val[c+1] = v[c];
		}
		priority_queue<PII> rpq;
		for(int i=1;i<=sz(v);i++)
		{
			for(auto u:vec[i])
			{
				if(!dn[u])
					rpq.push({R[u]-L[u],u});
			}
		}
		for(int i=sz(v)+1;i<=n;i++)
		{
			if(!rpq.empty())
			{
				auto P = rpq.top();
				rpq.pop();
				val[i] = P.ss;
			}
			for(auto u:vec[i])
			{
				if(!dn[u])
					rpq.push({R[u]-L[u],u});
			}
		}
		for(int i=1;i<=n;i++)
		{
			if(val[i]==-1)
			{
				val[i] = rpq.top().ss;
				rpq.pop();
			}
		}
		ll ans=0;
		for(int i=1;i<=n;i++)
		{
			int x = val[i];
			if(i>k[x])
				ans += R[x];
			else
				ans += L[x];
		}
		cout<<ans<<"\n";
	}
	return 0;
}

Measured memory_bytes: 18800
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

ll N;
ll x[110], y[110], h[110];

int main() {
    cin>>N;
    REP(i,0,N){
        cin>>x[i]>>y[i]>>h[i];
    }

    REP(cx,0,101) {
        REP(cy, 0, 101) {

            ll mxh = inf;
            vector<ll> chv;

            REP(i, 0, N) {
                if (h[i] == 0) {
                    mxh = min(mxh, abs(x[i] - cx) + abs(y[i] - cy));
                } else {
                    ll ch = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
                    chv.push_back(ch);
                }
            }

            bool f = true;

            ll th = 1;
            if (chv.size() > 0) {
                th = chv[0];
                REP(i, 0, chv.size()) {
                    if (th != chv[i]) {
                        f = false;
                    }
                }
            }

            if(th > mxh){
                f = false;
            }

            if(f){
                cout<<cx<<" "<<cy<<" "<<th<<endl;
                return 0;
            }

        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll mod = 1000000007;

const ll LINF = 1e13;
const ll LLINF = 1e18;
const ll ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


int main() {
  ll n, x;
  cin >> n >> x;

  vector<ll> lvp(51, 0);
  vector<ll> lv(51, 0);
  lv[0] = 1;
  lvp[0] = 1;
  for (int i = 1; i < 51; ++i) {
    lv[i] = lv[i - 1] * 2 + 3 ;
    lvp[i] = lvp[i - 1] * 2 + 1;
  }


  ll ans = 0;

  ll tmplv = n;
  ll pos = 0;
  // for (int i = n; i >= 0 ; --i) {
  //   tmplv = i;
  //   if (x >= pos + lv[i])break;
  //   pos++;
  // }


  // x -= pos + lv[tmplv];
  // ans += lvp[tmplv];

  // if (x > 0) {
  //   x--;
  //   ans++;
  // }

  for (int i = n; i >= 0 ; --i) {
    if (x >= lv[i] + pos) {
      x -= pos +lv[i];
      ans += lvp[i];
      if (x > 0) {
        x--;
        ans++;
      }
      i++;
      pos = 0;
      continue;
    }

    pos++;

  }







  cout << ans ;

}




















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

using namespace std;

#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
#define repinv(i, st, n) for (int i = ((n)-1); i >= (st); --i)
#define MEM(a, b) memset(a, b, sizeof(a));

#define debug(x) std::cout << #x << ": " << x << endl
#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileIO(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)

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

//mt19937 mrand(random_device{}());
const ll mod=1e9+7;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
pii operator+(const pii&x, const pii&y) { return mp(x.X+y.X, x.Y+y.Y);}
pii operator-(const pii&x, const pii&y) { return mp(x.X-y.X, x.Y-y.Y);}
//INT_MAX, ULLONG_MAX, LLONG_MAX or numeric_limits<int>::min()

inline ll read(){
	char ch=getchar();ll x=0,f=0;
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}

//------------------------------------------------------------------------//
int T;
const int maxn = 2e5+7;
int n;
double a, b;

//check T
void solve()
{
	cin >> a >> b;//100
	//cout << 100*100/8 << endl;
	rep(i, 0, 100000)
	{
		if(floor(i*0.08) == a && floor(i*0.1) == b) {cout << i << endl;return;}
	}
	cout << -1 << endl;
  return;
}


signed main()
{
  fastIO();
  T = 1;
  //cin >> T; //this
  while(T--) solve();
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
using namespace std;

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

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

long long getkey(char str[]){
  long long sum = 0,p = 1,i;
  for(i = 0;i< strlen(str);i++){
    sum += p * (getchar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){return key % M;}
int h2(int key){return 1 + (key % (M -1));}
int find(char str[]){
  long long key,i,h;
  key = getkey(str);
  for(i = 0; ; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key = getkey(str);
  for(i = 0; ; i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0) return 1;
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i,n,h;
  char str[L],com[9];
  for(i = 0; i < n;i++) H[i][0] = '\0';
  scanf("%d",&n);
  for(i = 0; i < n ; i++){
    scanf("%s %s",com,str);
    if(com[0] == 'i'){
      insert(str);
    }else {
      if(find(str)){
        printf("yes\n");
      }else {
        printf("no\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 16900
import java.util.*;
import java.math.*;
import java.awt.geom.*;
import java.io.*;
    
    
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int ans = selectionSort(a,n);
		System.out.print(a[0]);
		for(int i = 1; i < n; i++) {
			System.out.print(" " + a[i]);
		}
		System.out.println();
		System.out.println(ans);
		
	}
	static int selectionSort(int[] A, int N) {
		int ret = 0;
		for(int i = 0; i < N; i++) {
			int minj = i;
			for(int j = i; j < N; j++) {
				if(A[j] < A[minj]) {
					minj = j;
				}
			}
			if(i != minj) {
				ret++;
				int tmp = A[i];
				A[i] = A[minj];
				A[minj] = tmp;
			}
		}
		return ret;
	}
}

Measured memory_bytes: 26424
n = int(input())
s = list(input())
r, g, b = 0, 0, 0
for i in s:
    if i == "R":
        r += 1
    elif i == "G":
        g += 1
    else:
        b += 1
ans = r * g * b
for i in range(n - 2):
    k = i + 2
    while True:
        if k >= n:
            break
        j = i + (k - i) // 2
        if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            ans -= 1
        k += 2
print(ans)

Measured memory_bytes: 70492