akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<queue>
#include<stack>
#include<list>
#include<unordered_map>
#include<unordered_set>
#include<cctype>
#include<iomanip>
#include<limits>
#include<bitset>

using namespace std;
typedef long long int ll; typedef pair<int, int> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define REP(i,n) for(int i=1;i<=(int)n;i++)
#define all(a) (a).begin(),(a).end()
#define allg(a) (a).begin(),(a).end(),greater<>()
#define SUM(a) accumulate((a).begin(),(a).end(),0)
#define d10 std::setprecision(10)
#define d20 std::setprecision(20)
const double PI = 3.14159265359;
ll gcd(ll a, ll b) { ll t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
int gcd(int a, int b) { int t; while (b != 0) { t = a % b; a = b; b = t; }return a; }
ll recfact(ll start, ll n) {
	ll i;
	if (n <= 16) {
		ll r = start;
		for (i = start + 1; i < start + n; i++) r = r * i % mod;
		return r % mod;
	}
	i = n / 2;
	return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}
ll fct(ll n) { return recfact(1, n); }
ll ncm(ll n, ll m) {
	if (n < m)return 0;
	ll x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
	return x;
}
bool isincluded(char x, string str) {
	bool f = 0;
	for (size_t i = 0; i < str.size(); i++) {
		if (str.at(i) == x)f = 1;
	}
	return f;
}
int ctoi(char c) {
	if ('0' <= c && c <= '9') {
		return c - '0';
	}
	return 0;
}





int main(void) {
	int n; cin >> n;
	int ans = 0, a, b; cin >> a >> b;
	REP(i, n) {
		int tmp = 0;
		for (int j = i; j > 0; j /= 10) {
			tmp += j % 10;
		}
		if (a <= tmp && tmp <= b) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}

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


int main() {
    int a;
    long long std = 1000000000000000000;
    cin >> a;
    long long ans = 1;
    for(int i = 0;i < a;i++){
        long long next;
        cin >> next;
        if(next == 0){
            cout << 0;
            return 0;
        }
        if(next != -1){
            if(next > std / ans){
                ans = -1;
            }else{
                ans *= next;
            }
        }

    }
    cout << ans;

    return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int go_all = abs(a[0]) + abs(a[n-1]);
  for (int i = 1; i < n; ++i) go_all += abs(a[i] - a[i-1]);
  vector<int> pass(n);
  rep(i, n) {
    if (i == 0) pass[0] = go_all - abs(a[0] - 0) - abs(a[1] - a[0]) + abs(a[1] - 0);
    else if (i == n-1) pass[n-1] = go_all - abs(a[n-1] - a[n-2]) - abs(0 - a[n-1]) + abs(0 - a[n-2]);
    else pass[i] = go_all - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i-1]);
  }
  rep(i, n) cout << pass[i] << endl;
  return 0;
}

Measured memory_bytes: 4020
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=0;i<N;i++)

signed main(){
  int N,M;
  cin>>N>>M;
  vector<int> A(M,0);
  int a,k;
  rep(i,N){
    cin>>k;
    rep(i,k){
      cin>>a;
      A[a-1]++;
    }
  }
  int ans=0;
  rep(i,M){
    if(A[i]==N)ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

const string YES = "";
const string NO  = "";

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

    int a[5], k;
    bool flg = false;

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

    for (int i = 0; i < 4; ++i) {
        for (int j = i + 1; j < 5; ++j) {
            if (abs(a[i] - a[j]) > k) {
                flg = true;
                break;
            }
        }
    }

    cout << (flg ? ":(" : "Yay!") << endl;

    return 0;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{
// }}}

struct FastIO {
    FastIO() { cin.tie(nullptr); ios::sync_with_stdio(false); }
} fastIO_ydk ;

signed main()
{
    i64 N, K;
    cin >> N >> K;

    i64 hori = (N-1) * (N-2) / 2;

    if (hori < K) {
        cout << -1 << endl;
        return 0;
    }

    vector<pii> log;
    for (int i = 2; i <= N; ++i) {
        log.emplace_back(1, i);
    }

    for (int i = 2; i <= N; ++i) {
        for (int j = i+1; j <= N; ++j) {
            if (hori == K) goto QUIT;
            log.emplace_back(i, j);
            --hori;
        }
    }

QUIT:
    cout << log.size() << endl;
    for (auto e: log) {
        cout << e.first << ' ' << e.second << endl;
    }

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define ldb long double
#define lint long long
#define N 200010
#define gc getchar()
#define rep(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
int a[N];lint s[N];
inline lint S(int a,int b) { return s[b]-s[max(a-1,0)]; }
int main()
{
	int n=inn(),X=inn();rep(i,1,n) s[i]=s[i-1]+inn();
	a[1]=5;rep(i,2,n) a[i]=2*i+1;ldb ans=1e100;
	rep(k,1,n)
	{
		ldb s=0ll;
		for(int i=n,j=1;i>0;i-=k,j++)
			s+=a[j]*S(i-k+1,i);
		ans=min(ans,s+(lint)X*(n+k));
	}
	return !printf("%lld\n",(lint)ans);
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

#define all(x) begin(x),end(x)

using namespace std;
using ll = long long;

int main()
{
	ll N, K;
	cin >> N >> K;
	ll ans = 0;
	ll t = N / K;
	ans = t * t * t;
	if (K % 2 == 0) {
		t = (N + (K/2)) / K;
		ans += (t * t * t);
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

int main() {
  int n;
  int a[100000];
  int x = 0;
  std::cin >> n;
  for (int ni = 0; ni < n; ++ni) {
    std::cin >> a[ni];
  }
  for (int ni = 0; ni < n; ++ni) {
    if (a[a[ni] - 1] == ni + 1) {
      ++x;
    }
  }
  std::cout << x / 2 << std::endl;
  return 0;
}


Measured memory_bytes: 640
def solve():
    N, K = map(int, input().split())
    A = [0]+list(map(int, input().split()))
    visited = [-1]*(N+1)
    visited[1] = 0
    now = 1
    for i in range(1,K+1):
        now = A[now]
        if visited[now]>=0:
            break
        visited[now] = i
    if i==K:
        ans = now
    else:
        num = (K-visited[now])%(i-visited[now])+visited[now]
        ans = visited.index(num)
    return ans
print(solve())


Measured memory_bytes: 93012
import sys
from collections import defaultdict as dd
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N, M = map(int, input().split())
e = dd(list)
inc = [0] * (N + 1)
for _ in range(M):
  u, v = map(int, input().split())
  e[u].append(v)
  e[v].append(u)
  inc[u] += 1
  inc[v] += 1
s = 0
inc[0] = float("inf")
for i in range(N):
  if inc[i] < inc[s]:
    s = i
vis = set()
vis.add(s)
res = []
def dfs(x):
  global vis
  global res
  vis.add(x)
  res.append(x)
  c = 0
  for y in e[x]:
    if y in vis: continue
    c += 1
    dfs(y)
  if c == 0:
    for y in e[s]:
      if not (y in vis):
        c += 1
    if c == 0:
      print(len(res))
      print(*res)
      exit(0)
  res.pop()
  vis.discard(x)

dfs(s)

Measured memory_bytes: 154844
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

A,B,C=map(int,input().split())
K=int(input())
while A>=B:
    B*=2
    K-=1
while B>=C:
    C*=2
    K-=1
YesNo(K>=0)

Measured memory_bytes: 61816
#include <iostream>
#include <stdio.h>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <iomanip>
#include <algorithm>

using namespace std;

#define ull unsigned long long
#define ll long long
#define ff first
#define ss second
#define mod 1e9+7
ll gcd(ll a, ll b){ if ( a == 0 ) return b; return gcd(b%a, a); }
void tf(int b){ b == 1 ? cout<<"NO"<<endl : cout<<"YES"<<endl; }

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

    int x,y;
    cin>>x>>y;

    if ( n < k ){
        cout<<x*n<<endl;
    }else{
        cout<<x*k+(n-k)*y<<endl;
    }
    return 0;
}


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

int main()
{
    int d, n;
    
    cin >> d >> n;
    
    if(n == 100)
        cout << 101 * int(pow(100, d)) << endl;
    else
        cout << n * int(pow(100, d)) << endl;
    
    return 0;
}


Measured memory_bytes: 256
def find(n):
    if root[n] == n:
        return n
    else:
        parent = root[n]
        root[n] = find(parent)
        return root[n]

def unite(x,y):
    rx = find(x)
    ry = find(y)
    if rx == ry:
        return
    else:
        root[rx] = ry

def same(x,y):
    if find(x) == find(y):
        return True
    else:
        return False

def member(x):
    root = find(x)
    return [i for i in range(n) if find(i) == root]

def member_count(x):
    return len(member(x))

n , m = map(int,input().split())
route = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(m)]
ans = 0
for i in range(m):
    root = [k for k in range(n)]
    for j in range(m):
        if i == j:
            continue
        a,b = route[j]
        unite(a,b)
    if member_count(0) != n:
        ans += 1
        
print(ans)

Measured memory_bytes: 9192
/*************************************************************************
    > File Name: f.cpp
    > Author: Amano Sei
    > Mail: amano_sei@outlook.com 
    > Created Time: 2019年12月22日 星期日 22时47分59秒
 ************************************************************************/

#include <cstdio>
#include <cstring>
#include <vector>

using namespace std;

const int maxn = 100005;

vector<int> edge[maxn];
int n;

int sp[maxn];
int ans;

void dfs(int u, int cf, int cr, int dep){
    if(cr == 1){
        ans = max(sp[u], ans);
        if(dep >= sp[u])
            return;
    }else
        sp[u] = dep;
    for(size_t i = 0; i < edge[u].size(); i++){
        register int cv = edge[u][i];
        if(cv != cf)
            dfs(cv, u, cr, dep+1);
    }
}

int main(){
    int cu, cv, u, v;
    scanf("%d%d%d", &n, &u, &v);
    for(int i = 0; i < n-1; i++){
        scanf("%d%d", &cu, &cv);
        edge[cu].push_back(cv);
        edge[cv].push_back(cu);
    }
    dfs(v, 0, 0, 0);
    dfs(u, 0, 1, 0);
    printf("%d\n", ans-1);
    return 0;
}



Measured memory_bytes: 12544
#include<stdio.h>
int main()
{
  int j,k;
      for(j=1;j<=9;j++)
	{
	  for(k=1;k<=9;k++)
	    {
	      printf("%dx%d=%d\n",j,k,j*k);
	    }
	}
  return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++)cin >> A.at(i);
    int flag = 0;
    for(int i = 0; i < N; i++){
        if(A.at(i)%2==0){
            if(A.at(i)%3!=0&&A.at(i)%5!=0) flag = 1;
        }
    }
    if(flag) cout << "DENIED" << endl;
    else cout << "APPROVED" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
int A;
int B;
scanf("%d %d",&A,&B);
if((A+B)<=(A-B) && (A*B)<=(A-B)) {
    printf("%d\n",A-B);
}else if((A-B)<=(A+B) && (A*B)<= (A+B)){
    printf("%d\n",A+B);
}else if((A-B)<=(A*B) && (A+B)<=(A*B)){
    printf("%d\n",A*B);

} else{
    printf("\n");
}
return 0;
}

Measured memory_bytes: 128
package main

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

func main() {
	n := readInt()

	fmt.Println(float64(n-n/2) / float64(n))
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 640
N = int(input())

min_P = 1
ans = 0
for _ in range(N):
    A = int(input())
    if A == min_P:
        min_P += 1
    else:
        ans += (A - 1) // min_P
        if min_P == 1:
            min_P += 1

print(ans)


Measured memory_bytes: 3060
// スマホコーディング
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(int I = int((B)-1); I >= int(A); --I)
const ll INF = 1e18;
int main(){

int n;
cin >> n;
ll a[n+1]={},dp[n+1][n+1]={},sum[n+1]={};
FOR(i,1,n+1)cin>>a[i];

FOR(i,1,n+1)sum[i]=sum[i-1]+a[i];
FOR(i,1,n+1)
FOR(j,1,n+1){
if(i==j)continue;
dp[i][j]=INF;
}

FOR(i,1,n+1)
FOR(j,1,n+1-i){
FOR(k,0,i){
dp[j][i+j]=min(dp[j][i+j],dp[j][j+k]+dp[j+k+1][j+i]);
}
dp[j][j+i]+=sum[j+i]-sum[j-1];
}
cout << dp[1][n] << endl;

}

Measured memory_bytes: 1536
x,y = map(str,input().split())
tmp = {"1":1,"3":1,"5":1,"7":1,"8":1,"10":1,"12":1,"4":2,"6":2,"9":2,"11":2,"2":3}
ans = []
ans.append(tmp[x])
ans.append(tmp[y])
if ans[0] == ans[1]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<bitset>
#include<functional>
#include<iterator>
#include<complex>
#include<fstream>
#include<random>
#include<ctype.h>
#include<stdio.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using PII = pair<ll, ll>;
using piii = pair<pii, pii>;
using Pi = pair<int, pii>;
using Graph = vector<vector<int>>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
bool check(int x, int y) {
	if (0 <= x && x<55 && 0 <= y && y<55)return true;
	else return false;
}
const ll INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
using Graph = vector<vector<int>>;

//iの逆元mod inf
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
const double PI = 3.14159265358979323846;
const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
//テーブルをつくる前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;//mod pにおける1,2,,,nの逆元
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}

ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
double Euclidean_distance(double x1, double y1, double x2, double y2) {
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

//素因数分解
map<int, int>prime_factor(int n) {
	map<int, int>res;
	for (int i = 2; i*i <= n; ++i) {
		while (n%i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1)res[n] = 1;
	return res;
}


ll powmod(ll a, ll k, ll mod) {
	ll ap = a, ans = 1;
	while (k) {
		if (k & 1) {
			ans *= ap;
			ans %= mod;
		}
		ap = ap * ap;
		ap %= mod;
		k >>= 1;
	}
	return ans;
}
ll invi(ll a, ll mod) {
	return powmod(a, mod - 2, mod);
}
#define PI 3.14159265358979323846  // 円周率
//逆元Aを足したときのmodで割った余りは
//+=invi(A)
//Yで割ることはY^(10^9+7)-2を掛けることは同値
///////////////////////////////////////
bool is_prime(int n) {
	for (int i = 2; i*i <= n; ++i) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


int main() {
	string s, t; cin >> s >> t;
	int cnt = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] != t[i])cnt++;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 3816
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>

using namespace std;
long long n,a,b,sum;
int main()
{
    scanf("%lld",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld%lld",&a,&b);
        sum+=(b-a+1);
    }
	cout<<sum<<endl;
    return 0;
}

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

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

  int count = 0;
  for (int i = 0; i < s.size(); i++ ) {
    if (s[i] == '9') count += 1;
  }

  if (count == 0) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
 
using namespace std;
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;
 
ll f(ll b, ll n){
  if(n<b) return n;
  return f(b,n/b)+(n%b);
}
 
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,s;
  cin >> n >> s;
  if(s == n){
    cout << n+1 << endl;
    return 0;
  }
 
  for(ll b=2;b*b <= n;b++){
    if(f(b,n) == s){
      cout << b << endl;
      return 0;
    }
  }
  ll ans = -1;
  for(ll i=1;i*i <= n;i++){
    if(i > s) break;
    ll b = (n-s)/i +1;
    if(b >= 2 && f(b,n) == s){
      ans = b;
    }
  }
  cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
N, M = [int(i) for i in input().split()]

S, G = set(), set()
for _ in range(M):
    a, b = [int(i) for i in input().split()]
    if a == 1:
        S.add(b)
    if b == N:
        G.add(a)

if len(S & G) >= 1:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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

int main(){
    long long n, c = 0, ans, t;
    cin >> n;
    n++;
    t = n;
    while(t > 10){
        t /= 10;
        c++;
    }
    ans = t - 1 + 9 * c;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    int n, m;
    int ans = 0;
    cin >> n >> m;
    for (int i = 1; i < n; i++) {
        ans += i;
    }
    for (int i = 1; i < m; i++) {
        ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3580
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <climits>
#include <functional>

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

using namespace std;
typedef long long ll;
const int INF = INT_MAX / 4;

const int max_n = 1e3;

int solve(void) {
  string x, y;
  cin >> x >> y;

  int xl = x.length(), yl = y.length();
  int dp[xl][yl];

  dp[0][0] = (int)(x[0] == y[0]);
  for (int j = 1;j < yl;j++)
    dp[0][j] = max(dp[0][j-1], (int)(x[0] == y[j]));
  for (int i = 1;i < xl;i++) {
    dp[i][0] = max(dp[i-1][0], (int)(x[i] == y[0]));
    for (int j = 1;j < yl;j++) {
      dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
      if (x[i] == y[j]) {
	dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
      }
    }
  }

  return dp[xl-1][yl-1];
}


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

  int cases;
  cin >> cases;
  REP(i, cases) {
    cout << solve() << "\n";
  }
  return 0;
}

Measured memory_bytes: 7080
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    long long X; cin >> X;

    for(long long  A=-200; A<200; A++){
        for(long long B=-200; B<200; B++){
            if(A*A*A*A*A-B*B*B*B*B == X){
                cout << A << ' ' << B << endl;
                return 0;
            }
        }
    }

}

Measured memory_bytes: 3632
n, x, y = map(int, input().split())
 
ans = [0]*(n+1)
for i in range(1,n+1):
  for j in range(i+1, n+1):
    d = min(abs(i-j), abs(y-j)+abs(x-i)+1, abs(y-i)+abs(x-j)+1)
    ans[d] += 1
 
for a in ans[1:-1]:
  print(a)

Measured memory_bytes: 3444
while True:
    n=int(raw_input())
    if n==0: break
    m=[]
    for _ in xrange(n):
        m.append(map(int,raw_input().split()[1:]))
    k=map(int,raw_input().split()[1:])
    d=[]
    for i in xrange(n):
        isValid=True
        for x in k:
            if x not in m[i]:
                isValid=False
        if isValid: d.append(i+1)
    if len(d)==1: print d[0]
    else: print -1

Measured memory_bytes: 6368
module Main where

main = interact $ printer . solver . parser
int = read :: String -> Int

parser = map int . words

printer = unlines .(:[]).show

solver [n,a,b] = if ans < 0 then 0 else ans
  where
    minv = a + b + a * (n-2)
    maxv = a + b + b * (n-2)
    ans  = maxv - minv + 1



Measured memory_bytes: 508
class PriorityQueue
  def initialize
    @heapArr = []
  end

  def empty?
    @heapArr.empty?
  end

  def push(n)
    i = @heapArr.size

    while i>0
      p = (i-1)/2
      break if @heapArr[p] <= n
      @heapArr[i] = @heapArr[p]
      i=p
    end

    @heapArr[i] = n
  end

  def top(n = 1)
    @heapArr[0]
  end

  def pop
    min = @heapArr[0]
    n   = @heapArr.pop
    unless @heapArr.empty?
      i   = 0
      while (i*2+1) < @heapArr.size
        if @heapArr[i*2+2].nil?
          buf=i*2+1
        else
          buf=(@heapArr[i*2+1]<@heapArr[i*2+2])?i*2+1:i*2+2
        end
        break if @heapArr[buf] >= n
        @heapArr[i] = @heapArr[buf]
        i=buf
      end
      @heapArr[i]=n
    end
    return min
  end

  def show
    level=0
    p=0
    while p<@heapArr.size
      (2**level).times do
        if @heapArr[p].nil?
          print "x "
        else
          print "#{@heapArr[p]} "
        end
        p+=1
      end
      puts ""
      level+=1
    end
    puts ""
  end
end

n = gets.to_i
arr = []

n.times do
  arr << gets.to_i
end

queue = PriorityQueue.new

arr.each do |e|
  queue.push(-e)
end

n.times do |i|
  t = queue.top
  
  if -t == arr[i]
    e = queue.pop
    t = queue.top
    queue.push(e)
  end
  
  puts -t
end

Measured memory_bytes: 6780
n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for _ in range(n)]

INF = 10**9 + 100
MAX_V = 10**5 + 100
dp = [INF] * (MAX_V + 1)
dp[0] = 0
for wi, vi in wv:
    for sum_v in reversed(range(vi, MAX_V+1)):
        dp[sum_v] = min(dp[sum_v - vi] + wi, dp[sum_v])
#print(dp)
ans = 0
for i in range(MAX_V, -1, -1):
    if dp[i] <= w:
        print(i)
        exit()
#print(ans)


Measured memory_bytes: 43332
n, t = map(int, input().split())
A = list(map(int, input().split()))
B = [-1]*n
B[-1] = A[-1]
for i in range(n-2, 0, -1):
  B[i] = max(A[i], B[i+1])
L = [B[i+1]-A[i] for i in range(n-1)]
ans = L.count(max(L))
print(ans)

Measured memory_bytes: 14228
S = input()
l = ['maerd','remaerd', 'esare', 'resare']

def test(S,l):
    while len(S) > 0:
        if S[::-1] in l:
            print('YES')
            return
        elif S[-1:-6:-1] in l:
            S = S[:-5]
        elif S[-1:-7:-1] in l:
            S = S[:-6]
        elif S[-1:-8:-1] in l:
            S = S[:-7]
        else:
      	    print('NO')
      	    return
  
test(S,l)

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

int main(){
    long int n;
    cin>>n;
    vector<char> name(0);
    while (1)
    {
        if (n%26==0)
        {
           name.insert(name.begin(),char(122));
           n=n/26-1; 
        }else{
            name.insert(name.begin(),char(n%26+96));
            n=n/26;
        }
        
        
        if (n==0)
        {
            break;
        }
        
    }
    for (int i = 0; i < name.size(); i++)
    {
        cout<<name[i];
    }
    cout<<endl;
return 0;
}

Measured memory_bytes: 3104
s = int(input())
ans = [s]
for i in range(1000000):
    if ans[i]%2 == 0:
        dum = ans[i]//2
    else:
        dum = ans[i]*3+1
    if ans.count(dum) == 1:
        print(i+2)
        break
    ans.append(dum)

Measured memory_bytes: 61988
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair <int, int>;
const double PI = acos(-1);
const ll MOD = 1000000007;

int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> baito(100001, vector<int>(1,0));
  rep(i, N){
    int A, B;
    cin >> A >> B;
    baito[A].push_back(B);
  }

  ll ans = 0;

  priority_queue<int> choice;

  rep(i, M) {
    rep(j, baito[i+1].size()) choice.push(baito[i+1][j]);
    ans += choice.top();
    choice.pop();
  }

  cout << ans << endl;

}


Measured memory_bytes: 7808
#include<bits/stdc++.h>
#define FOR0(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}

int main(){
	string s;
	cin >> s;
	if (s[3]==s[2] && s[5]==s[4]) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
ch = [0]*2
i = 0
j = 2
ans = 1
a.sort()
a = a[::-1]
while True:
    if a[i] == a[i+1]:
        ch[0] = a[i]
        break
    else:
        i += 1
    if i == n-1:
        ans = 0
        break

while True:
    if ans == 0:
        break
    if a[i+j] == a[i+j+1]:
        ch[1] = a[i+j]
        break
    else:
        j += 1
    if i+j == n-1:
        ans = 0

if ans == 0:
    print(0)
else:
    print(ch[0]*ch[1])

Measured memory_bytes: 19984
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

pair<int, pair<int, int>>p1, p2;

int main(void)
{
	cin >> p1.first >> p1.second.first >> p1.second.second;
	cin >> p2.first >> p2.second.first >> p2.second.second;
	if (p1 > p2)swap(p1, p2);
	if (p1.second < p2.second) {
		cout << p2.first - p1.first + 1 << endl;
	}
	else {
		cout << p2.first - p1.first << endl;
	}
	return 0;
}



Measured memory_bytes: 3120
#include<stdio.h>

#define N 100000

typedef struct
{
  int parent;
  int left;
  int right;
} node;


int finddepth(int);

node T[N];

int main()
{
  int pa, pr, x, i, j, n, k;

  scanf("%d", &n);
  for(i=0; i<n; i++)
    {
      T[i].parent = -1;
      T[i].left = -1;
      T[i].right = -1;
    }

  for(i=0; i<n; i++)
    {
      scanf("%d%d", &pa, &k);
      if(k!=0)
	{
	  scanf("%d", &x);
	  T[pa].left = x;
	  T[x].parent = pa;
	  pr = x;
	}
      for(j=1; j<k; j++)
	{
	  scanf("%d", &x);
	  T[x].parent = pa;
	  T[pr].right = x;
	  pr = x;
	}
    }
  for(i=0; i<n; i++)
    {
      printf("node %d: parent = %d, depth = %d, ", i, T[i].parent, finddepth(i));
      if(T[i].parent == -1)
	{
	  printf("root, ");
	}
      else if(T[i].left != -1)
	{
	  printf("internal node, ");
	}
      else
	{
	  printf("leaf, ");
	}
      printf("[");
      if(T[i].left != -1)
	{
	  printf("%d", pr=T[i].left);
	}
      while(T[pr].right != -1)
	{
	  printf(", %d", T[pr].right);
	  pr = T[pr].right;
	}
      printf("]\n");
    }
      
  return 0;
}

int finddepth(int x)
{
  int c=0;
  while(T[x].parent >= 0)
    {
      c++;
      x = T[x].parent;
    }
  return c;
}

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#define _USE_MATH_DEFINENS
#include <cmath>

using namespace std;

#define p(x) cout << x << endl;
#define el cout << endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

    int n;
    cin >> n;

    int i = n / 111;
    if(n % 111 != 0) {
        i++;
    }

    p(i * 111);
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int W,H,x,y,r;
    
    cin >> W >> H >> x >>  y >> r; 
    
    if ( x>=r && y>=r && W-r>=x && H-r>=y){
        cout << "Yes" << endl;
    }
    
    else {
        cout << "No" << endl;
    }
    
    return 0 ;

}



Measured memory_bytes: 3104
N = int(input())
A = list(map(int, input().split()))

X = dict()
ans = 0
for i in range(N):
    L = i + A[i]
    R = i - A[i]
    if L not in X:
        X[L] = 1
    else:
        X[L] += 1
    if R in X:
        ans += X[R]
        
print(ans)

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

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int M[3][3];
    while(cin >> M[0][0] >> M[0][1] >> M[0][2])
    {
        for(int i = 1; i < 3; i++)
            for(int j = 0; j < 3; j++)
                cin >> M[i][j];

        int found = 0;
        for(int a1 = -100; a1 <= 100 && !found; a1++)
            for(int a2 = -100; a2 <= 100 && !found; a2++)
                for(int a3 = -100; a3 <= 100 && !found; a3++)
                    if(M[0][0] - a1 == M[1][0] - a2 && M[0][0] - a1 == M[2][0] - a3 &&
                       M[0][1] - a1 == M[1][1] - a2 && M[0][1] - a1 == M[2][1] - a3 &&
                       M[0][2] - a1 == M[1][2] - a2 && M[0][2] - a1 == M[2][2] - a3)
                        found = 1;
        cout << (found? "Yes" : "No") << '\n';
    }
    return 0;
} 

Measured memory_bytes: 256
import java.util.Scanner;

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

        int A1 = scanner.nextInt();
        int A2 = scanner.nextInt();
        int A3 = scanner.nextInt();

        if (A1 + A2 + A3 >= 22) {
            System.out.println("bust");
        } else {
            System.out.println("win");
        }
    }
}


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


void solve(long long N, long long M, std::vector<long long> A){
    multiset<long long> ms;
    for(long long a:A)ms.insert(a);
    for(int i=0;i<M;++i){
        auto itr = ms.end();
        itr--;
        long long tmp = *itr;
        ms.erase(itr);
        ms.insert(tmp>>1);
    }
    long long res=0;
    for(long long tmp:ms)res+=tmp;
    cout<<res<<endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, M, std::move(A));
    return 0;
}


Measured memory_bytes: 7184
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


class BinaryIndexedTree:
    # http://hos.ac/slides/20140319_bit.pdf
    def __init__(self, size):
        """
        :param int size:
        """
        self._bit = [0] * size
        self._size = size

    def add(self, i, w):
        """
        i 番目に w を加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= self._size:
            self._bit[x - 1] += w
            x += x & -x

    def sum(self, i):
        """
        0 番目から i 番目までの合計
        :param int i:
        :return:
        """
        ret = 0
        x = i + 1
        while x > 0:
            ret += self._bit[x - 1]
            x -= x & -x
        return ret

    def __len__(self):
        return self._size


def compress(li, origin=0):
    """
    座圧
    :param li:
    :param int origin:
    :rtype: list of int
    """
    *ret, = map({v: i + origin for i, v in enumerate(sorted(set(li)))}.__getitem__, li)
    return ret


def bisect_left_callable(fn, x, lo, hi):
    """
    :param callable fn:
    :param x:
    :param int lo: 最小値
    :param int hi: 最大値 + 1
    :return: lo <= ret <= hi
    """
    while lo < hi:
        mid = (lo + hi) // 2
        if fn(mid) < x:
            lo = mid + 1
        else:
            hi = mid
    return lo


N = int(sys.stdin.readline())
S = list(map(int, sys.stdin.readline().split()))


def solve(S):
    S = compress(S, origin=1)
    S.sort(reverse=True)

    # bit[i]: サイズが i 以下のスライムの数
    bit = BinaryIndexedTree(size=max(S) + 1)
    for s in S:
        bit.add(s, 1)

    slimes = [S[0]]
    bit.add(S[0], -1)

    for _ in range(N):
        cnt = len(slimes)
        for i in range(cnt):
            # slimes[i] より小さい、一番大きいスライムを作る
            smallers = bit.sum(slimes[i] - 1)
            if smallers == 0:
                return False
            # 作れたら1減らす
            s = bisect_left_callable(bit.sum, smallers, lo=0, hi=slimes[i])
            slimes.append(s)
            bit.add(s, -1)
    return True


if solve(S):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 119864
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        String[] params = in.nextLine().split(" ");
        int a = Integer.parseInt( params[0] );
        int b = Integer.parseInt( params[1] );

        int ans = 0;
        for( int i = 0 ; i < ( a < b ? b : a ) ; i++ ){
            ans *= 10;
            ans += a < b ? a : b;
        }
        System.out.println( ans );

    }

}


Measured memory_bytes: 23124
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <list>
#include <iomanip>
#include <queue>
#include <cmath>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const long long mod = 1e9 + 7;
ll dx[] = { 1,0 };
ll dy[] = { 0,1 };

int main() {

    ll a, b, x;
    cin >> a >> b >> x;

    ll cnt1, cnt2;
    if (a == 0) {
        cnt1 = -1;
    }
    else    
    {
        cnt1 = (a - 1) / x;
    }

    cnt2 = b / x;

    cout << cnt2 - cnt1;

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int a, b, c;
  cin >> a >> b >> c;
  
  if(a==b && b==c){
    cout << "No" << endl;
  }
  
  else if(a!=b && b!=c && c!=a){
    cout << "No" << endl;
  }
  
  else{
    cout << "Yes" << endl;
  }
  
}

Measured memory_bytes: 256
def dijkstra(n,s):
    inf=float("inf")
    color=["white" for i in range(n)]
    D=[inf for i in range(n)]
    P=[0 for i in range(n)]
    M=[[inf for i in range(n)] for j in range(n)]

    for i in range(n):
        weight=list(map(int,input().split()))[2:]
        for j in range(len(weight)//2):
            M[i][weight[2*j]]=weight[2*j+1]

    D[s]=0
    P[s]=-1

    while 1:
        cost,u=inf,0
        for i in range(n):
            if color[i]!="black" and D[i]<cost:
                cost=D[i]
                u=i

        if cost==inf:break

        color[u]="black"

        for i in range(n):
            if color[i]!="black" and M[u][i]!=inf:
                if D[u]+M[u][i]<D[i]:
                    D[i]=D[u]+M[u][i]
                    color[i]="gray"
                    P[i]=u

    return D


n=int(input())
distant=dijkstra(n,0)
for i in range(n):
    print(i,distant[i])


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

ll n,q;

ll par(ll x){
  return (x+n-2)/n;
}

int main(){
	cin>>n>>q;
  if(n==1){
    while(q--){
      ll u,v;
      cin>>u>>v;
      cout<<min(u,v)<<endl;
    }
    return 0;
  }
  while(q--){
    ll u,v;
    cin>>u>>v;
    while(u!=v){
      if(u>v)u=par(u);
      else v=par(v);
    }
    cout<<u<<endl;
  }
	return 0;
}


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

int main() {
  int a, b; std::cin >> a >> b;

  if (a > b) std::cout << "a > b" << std::endl;
  else if (a == b) std::cout << "a == b" << std::endl;
  else std::cout << "a < b" << std::endl;

  return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <vector>
#include <cstring>
#include <queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uld = unsigned long long;
using P = pair<int,int>;
ll MAX(ll a,ll b,ll c){return max(a,max(b,c));}
ll MIN(ll a,ll b,ll c){return min(a,min(b,c));}
const ll mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
template<class T> inline bool chmax(T &a,T& b){if(a < b){a = b; return true;} else return false;}
template<class T> inline bool chmin(T &a,T& b){if(a > b){a = b; return true;} else return false;}
int main(){
    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll ans;
    if(a+b > 2*c){
        if(x > y){
            ans = 2*y*c + (x-y)*a;
        }
        else{
            ans = 2*x*c + (y-x)*b;
        }
    }
    else ans = 1e10;
    ans = min<ll>({ans,a*x+b*y,2*c*max<ll>(x,y)});
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



// a/b/cに使うかどれにも使わない 4択
int n, a, b, c, x[10], res = 1<<30;

void rec(int m, int aa, int bb, int cc, int g) {
	if (m==n) {
		if (aa && bb && cc) chmin(res, abs(a-aa) + abs(b-bb) + abs(c-cc) + g*10);
		return;
	}
	rec(m+1, aa+x[m], bb, cc, g+(aa!=0));
	rec(m+1, aa, bb+x[m], cc, g+(bb!=0));
	rec(m+1, aa, bb, cc+x[m], g+(cc!=0));
	rec(m+1, aa, bb, cc, g);
}

signed main() {
	cin >> n >> a >> b >> c;
	rep(i,n) cin >> x[i];
	rec(0,0,0,0,0);
	cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll lINF = 0x3f3f3f3f3f3f3f3fLL;
const int nINF = 1<<31;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

const int N = 100+10, V = 1e5+10;
int n, c, v[N], w[N];
ll dp[N][V]; //dp[i][j] is minimum capacity knapsack needed for first i items that total a value of j

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    memset(dp, INF, sizeof(dp));
    cin >> n >> c;
    FOR(i, 1, n) cin >> w[i] >> v[i];
    int s = 0;
    FOR(i, 1, n) s += v[i];
    dp[0][0] = 0;
    FOR(i, 1, n) {
    	FOR(j, 0, s) {
	    	if(dp[i-1][j] != lINF) {
	    		dp[i][j] = min(dp[i][j], dp[i-1][j]);
	    		dp[i][j+v[i]] = min(dp[i][j+v[i]], dp[i-1][j]+w[i]);
	    	}
    	}
    }
    FORD(i, V-1, 0) {
    	if(dp[n][i] <= c) {
    		cout << i << endl;
    		exit(0);
    	}
    }

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting min to 0 instead of -INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)


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

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

typedef struct node * Node;
Node root;

void insert(int a){

  Node y = NULL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = a;
  z->left = NULL;
  z->right = NULL;

  while(x != NULL){
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NULL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

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

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

int main(){
  int n, i, x;
  char num[20];
  scanf("%d", &n);
  root = NULL;

  for(i=0;i<n;i++){
    scanf("%s", num);
    if (num[0] == 'i'){
      scanf("%d", &x);
      insert(x);
    }
     else if(num[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 24040