akhauriyash/Code-Regression huggingface dataset:
use proconio::input;

fn calc(start: usize, end: usize, v: &Vec<(i64, i64)>) -> Vec<(i64, i64)> {
    let mut res = Vec::new();
    let mut val = Vec::new();
    let mut idx = start;
    while idx > end {
        val.push(v[idx-1]);
        idx /= 2;
    }
    for i in 0..1<<val.len() {
        let mut sv = 0;
        let mut sw = 0;
        for j in 0..val.len() {
            if i&(1<<j) != 0 {
                sv += val[j].0;
                sw += val[j].1;
            }
        }
        res.push((sw, sv));
    }
    res.sort();
    for i in 1..res.len() {
        res[i].1 = std::cmp::max(res[i].1, res[i-1].1);
    }
    res
}

fn main() {
    input! {
        n : usize,
        v : [(i64, i64); n],
        q : usize,
        query : [(usize, i64); q]
    };
    let thr = 1024;
    let mut first = Vec::new();
    for i in 0..std::cmp::min(thr, n) {
        first.push(calc(i+1, 0, &v));
    }
    for &t in &query {
        let mut res = 0;
        if t.0 <= thr {
            for &r in &first[t.0-1] {
                if r.0 > t.1 { continue }
                res = std::cmp::max(res, r.1);
            }
        } else {
            let second = calc(t.0, thr, &v);
            let mut par = t.0;
            while par > thr { par /= 2; }
            par -= 1;
            let mut idx0 = 0;
            let mut idx1 = second.len() - 1;
            while idx0 < first[par].len() && idx1 < second.len() {
                if first[par][idx0].0 + second[idx1].0 <= t.1 {
                    res = std::cmp::max(res, first[par][idx0].1 + second[idx1].1);
                    idx0 += 1;
                } else {
                    idx1 = idx1.wrapping_add(!0);
                }
            }
        }
        println!("{}", res);
    }
}


Measured memory_bytes: 23008
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    long long n,sum=0,he=0;
    cin>>n;
    long long a[n];
    for(int i=0;i<n;i++){ 
        cin>>a[i];
        he+=abs(a[i]);
        if(a[i]<0) sum++;
        a[i]=abs(a[i]);
    }
    sort(a,a+n);
    if(sum%2==0) cout<<he<<endl;
    else cout<<he-a[0]*2<<endl;
    return 0;
}

Measured memory_bytes: 4464
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define REP(i,n) for(ll i = 0; i<(ll)(n); i++)
#define REPS(i,n) for (ll i = 1; i<=(ll)(n); i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define pb push_back
#define MOD 1000000007
#define MOD2 998244353
#define PI 3.141592653
#define INF 100000000000000 //14
#define N 1000000
#define L 100100

ll M = 512;
vector<vector<ll>> dp(M,vector<ll>(L,0));
vector<ll> val(N);
vector<ll> wei(N);

int main(){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll n, v, l, q; cin >> n;
    REP(i,n) cin >> val[i+1] >> wei[i+1];
    cin >> q;
    FOR(i,1,min(M-1,n)){
        REP(j,L){
            if (j-wei[i]>=0) dp[i][j]=max(dp[i/2][j],dp[i/2][j-wei[i]]+val[i]);
            else dp[i][j]=dp[i/2][j];
        }
        FOR(j,1,L-1){
            dp[i][j]=max(dp[i][j-1],dp[i][j]);
        }
    }
    REP(i,q){
        cin >> v >> l;
        if (v<M){
            cout << dp[v][l] << endl;
        }
        else{
            ll ans = 0;
            vector<ll> jelv;
            vector<ll> jelw;
            while(v>=M){
                jelv.pb(val[v]);
                jelw.pb(wei[v]);
                v/=2;
            }
            ll len = jelv.size();
            REP(j,(1ll<<len)){
                ll twei = 0; ll tval = 0;
                REP(p,len){
                    if ((j>>p)%2){
                        tval+=jelv[p];
                        twei+=jelw[p];
                        if (twei>l){
                            break;
                        }
                    }
                }
                if (twei<=l) ans = max(ans,dp[v][l-twei]+tval);
            }
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 211528
/* AtCoder Beginner Contest abc128
 * Problem B
 * Au: SJoshua
 */
#include <cstdio>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;

struct node {
	string city;
	int score, id;
	bool operator < (node &r) {
		return city == r.city ? score > r.score : city < r.city;
	}
};

int main(void) {
	int n;
	cin >> n;
	vector <node> res;
	for (int i = 1; i <= n; i++) {
		string c;
		int s;
		cin >> c >> s;
		res.push_back({c, s, i});
	}
	sort(res.begin(), res.end());
	for (auto e: res) {
		cout << e.id << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod

int main(){
    ll N; cin>>N;
    string S; cin>>S;
    if(S.size()<=N) cout<<S<<endl;
    else{
        string ans;
        rep(i,N) ans.pb(S[i]);
        rep(i,3) ans.pb('.');
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int x, y, z;
int ans;

int main(){
  ios_base::sync_with_stdio(false);

  scanf(" %d %d %d",&x ,&y ,&z);

  x -= z;
  y += z;
  ans = x / y;

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

  return 0;
}

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

int main(){
	char ch;
	while(1){
		scanf("%c",&ch);
		if(islower(ch)){
			ch=toupper(ch);
		}
		else if(isupper(ch)){
			ch=tolower(ch);
		}
		printf("%c",ch);
		if(ch=='\n') break;
	}
	return 0;
}

Measured memory_bytes: 940
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
struct H {
	int x, y;
};
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad＝座標上の2点間の距離
 //---------------------------------------------------
 //+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int n, m, k;
	cin >> n >> m >> k;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= m; j++) {
			if (i*m + j*n - 2 * i*j == k) {
				cout << "Yes\n";
				return 0;
			}
		}
	}
	cout << "No\n";
	getchar(); getchar();
}

Measured memory_bytes: 384
from itertools import permutations

N = int(input())
Ps = tuple(map(int,input().split()))
Qs = tuple(map(int,input().split()))

patterns = list(permutations([i for i in range(1,N+1)]))

a = 0
b = 0
for i in range(len(patterns)):
    if Ps == patterns[i]:
        a = i
    if Qs == patterns[i]:
        b = i

print(abs(a-b))

Measured memory_bytes: 8052
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;

typedef tree <pii, null_type, less <pii>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 2e5 + 123;
int n, m, used[N], dist[N], ans[N];
vi adj[N], vec[N];

queue <int> q;

void bfs(int s) {
	q.push(s);
	used[s] = 1;
	while (!q.empty()) {
		int v = q.front();
		q.pop();
		for (int to : adj[v]) {
			if (!used[to]) {
				used[to] = 1;
				dist[to] = dist[v] + 1;
				q.push(to);
			}
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		int x, y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	bfs(1);
	for (int i = 2; i <= n; i++) {
		vec[dist[i]].pb(i);
	}
	for (int i = 1; i <= n; i++) {
		if (vec[i].empty()) {
			break;
		}
		for (int j : vec[i]) {
			for (int to : adj[j]) {
				if (dist[to] == i - 1) {
					ans[j] = to;
					break;
				}
			}
		}
	}
	cout << "Yes\n";
	for (int i = 2; i <= n; i++) {
		cout << ans[i] << '\n';
	}
}


Measured memory_bytes: 20440
#include<bits/stdc++.h>
#define ll long long int
#define ss second
#define ff first
#define Mem(x,val) memset(x,val,sizeof x)
#define pb push_back
#define all(v) v.begin(),v.end()
#define unik(v)  v.erase(unique(v.begin(),v.end()),v.end())
#define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\n"
#define debug(a,b) cerr << #a<<" = "<<a<<"   |   "<<#b<<" = "<<b<<'\n'
#define endl '\n'
#define SZ(a) ((int)a.size())
using namespace std;
typedef pair<int, int> pi32;
typedef pair<ll, ll> pi64;
typedef vector<int> vi32;
typedef vector<ll> vi64;
typedef vector<pi32> vp32;
typedef vector<pi64> vp64;
const ll mod = 1e9 + 7;
const int MX = 2e5+7;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	char ch;cin>>ch;
	if(isupper(ch))cout<<"A\n";
	else cout<<"a\n";
	
	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll n; cin >> n;
    ll k; cin >> k;
    vector <ll> as;
    REP(i, n){
        ll a; cin >> a;
        as.push_back(a);
    }
    vector <bool> dp(k+1, false);
    REP(i, k+1){
        for(auto a: as){
             if (i-a < 0){
                 continue;
             }
             dp[i] = dp[i] or !dp[i-a];
        }
    }
    string winner;
    if (dp[k]){
        winner = "First";
    } else {
        winner = "Second";
    }
    cout << winner << endl;
    return 0;
}

Measured memory_bytes: 256
"""
author : halo2halo
date : 22, Jan, 2020
"""

import sys

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

A, B = map(int, readline().split())
print(A + B // 2)


Measured memory_bytes: 2940
# そのまま入力文字列の入力
n = int(input())
an = list(map(int, input().split()))
bn = list(map(int, input().split()))
cn = list(map(int, input().split()))

sum = 0
prev = -1
for i in an:
    sum += bn[i-1]
    if prev + 1 == i:
        sum += cn[i-1-1]
    prev = i


print(sum)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
#define tvple pair<int,pair<long long,long long> >
#define make_tvple(x,y,z) make_pair((x),make_pair((y),(z)))
#define mo 1000000007
map<tvple,int> mp;
int p3[70],aans;
long long l,r;
int solve(int d,long long l,long long r){
	tvple tmp=make_tvple(d,l,r);
	if(mp.count(tmp)) return mp[tmp];
	long long s=(1ll<<d);
	long long t=(1ll<<(d+1))-1;
	if((r<s)||(l>t)) return mp[tmp]=0;
	if(l<=s&&t<=r) return mp[tmp]=p3[d];
	r=min(r,t);
	l=max(l,s);
	long long mid=(s+(1ll<<(d-1)));
	long long dif=(1ll<<(d-1));
	if(r<mid) return mp[tmp]=solve(d-1,l-dif,r-dif);
	if(l>=mid) return mp[tmp]=solve(d-1,l-s,r-s);
	int re=(solve(d-1,l-dif,r)+solve(d-1,dif,r-s))%mo;
	if(l-dif<=r-s) re=(re+solve(d-1,l-dif,r-s))%mo;
	return mp[tmp]=re;
}
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	p3[0]=1;
	for(int i=1;i<=69;i++){
		p3[i]=((p3[i-1]+p3[i-1])%mo+p3[i-1])%mo;
	}
	cin>>l>>r;
	for(int i=0;i<=60;i++){
		aans=(aans+solve(i,l,r))%mo;
	}
	cout<<aans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)
#define pb push_back

const int W = 400;

int height[W][W];
int board[W][W];

int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};

class Die{
	public:
	int num[6];
	int x,y;
	
	int getNum1(int t,int f){
		if(t==1 && f==2)return 3;
		if(t==1 && f==3)return 5;
		if(t==1 && f==4)return 2;
		if(t==1 && f==5)return 4;
		
		if(t==2 && f==1)return 4;
		if(t==2 && f==3)return 1;
		if(t==2 && f==4)return 6;
		if(t==2 && f==6)return 3;
		
		
		if(t==3 && f==1)return 2;
		if(t==3 && f==2)return 6;
		if(t==3 && f==5)return 1;
		if(t==3 && f==6)return 5;
		
		
		if(t==4 && f==1)return 5;
		if(t==4 && f==2)return 1;
		if(t==4 && f==5)return 6;
		if(t==4 && f==6)return 2;
		
		if(t==5 && f==1)return 3;
		if(t==5 && f==3)return 6;
		if(t==5 && f==4)return 1;
		if(t==5 && f==6)return 4;
		
		if(t==6 && f==2)return 4;
		if(t==6 && f==3)return 2;
		if(t==6 && f==4)return 5;
		if(t==6 && f==5)return 3;
		return 0;
	}
	
	int setNum(int t,int f){
		num[4] = t;
		num[2] = f;
		
		num[1] = getNum1(t,f);
		
		num[0] = 7-num[2];
		num[3] = 7-num[1];
		num[5] = 7-num[4];
	}
	
	Die(int top, int front){
		x = 200;
		y = 200;
		setNum(top, front);
	}
	
	int getRollDir(){
		
		int nowh = height[y][x];
		int dir = -1;
		int maxp = 3;
		rep(i,4){
			int nx = x+dx[i];
			int ny = y+dy[i];
			
			if(nowh > height[ny][nx]){
				if(maxp < num[i]){
					maxp = num[i];
					dir = i;
				}
			}
		}
		
		return dir;
	}
	
	void stamp(){
		board[y][x] = num[4];
		height[y][x]++;
		
		//printf("stamp (y=%d x=%d) b=%d  h=%d\n",y,x,board[y][x], height[y][x]);
	}
	
	void doRoll(int dir){
		int tmp = 0;
		if(dir==0){
			tmp = num[0];
			num[0] = num[4];
			num[4] = num[2];
			num[2] = num[5];
			num[5]=tmp;
			
			y--;
		}
		if(dir==1){
			tmp = num[1];
			num[1] = num[4];
			num[4] = num[3];
			num[3] = num[5];
			num[5] = tmp;
			
			x++;
		}
		if(dir==2){
			tmp = num[2];
			num[2] = num[4];
			num[4] = num[0];
			num[0] = num[5];
			num[5] = tmp;
			
			y++;
		}
		if(dir==3){
			tmp = num[3];
			num[3] = num[4];
			num[4] = num[1];
			num[1] = num[5];
			num[5] = tmp;
			
			x--;
		}
	}
};

int n;
vector<Die> dice;
bool input(){
	cin>>n;
	if(n==0)return false;
	dice.clear();
	
	rep(i,n){
		int a,b;
		cin>>a>>b;
		dice.pb(Die(a,b));
	}
	
	rep(i,W){
		rep(j,W){
			board[i][j] = height[i][j] = 0;
		}
	}
	return true;
}

void solve(){
	
	rep(i,n){
		while(1){
			int dir = dice[i].getRollDir();
			
			if(dir==-1){
				dice[i].stamp();
				break;
			}
			
			dice[i].doRoll(dir);
		}
	}
	
	int cnt[7] = {0};;
	rep(i,W){
		rep(j,W){
			cnt[board[i][j]]++;
		}
	}
	
	
	reps(i,1,7){
		if(i!=1)cout<<" ";
		cout<<cnt[i];
	}cout<<endl;
}

int main(){
	while(input())solve();
}

Measured memory_bytes: 2456
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/
#define rep(i,l,r) for(ll i=l;i<=r;i++)

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

int main(){
    string s;cin>>s;
    int w;cin>>w;
    int len=s.size();
    rep(i,0,len-1){
        if(i%w==0)cout<<s[i];
    }
    cout<<endl;
    return 0;
}


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

t = [0] * (10 ** 4 + 1)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            n = x * x + y * y + z * z + x * y + y * z + z * x
            if n <= 10 ** 4:
                t[n] += 1

print(*[t[i] for i in range(1, N + 1)], sep='\n')


Measured memory_bytes: 9536
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    bool chmax<T>(ref T a, T b) where T : IComparable<T> { if (a.CompareTo(b) < 0) { a = b; return true; } return false; }
    bool chmin<T>(ref T a, T b) where T : IComparable<T> { if (b.CompareTo(a) < 0) { a = b; return true; } return false; }

    void Calc()
    {
        cin = new Scanner();

        long W = cin.nextLong();
        long H = cin.nextLong();
        long X = cin.nextLong();
        long Y = cin.nextLong();

        double ans = W * H / 2.0;

        bool flag = (W / 2.0 == X && H / 2.0 == Y);

        WriteLine("{0} {1}", ans, flag?"1": "0");
    }
}

public static class StringExtension
{
    public static char GetChar1(this string str, int indexOneBase)
    {
        return str[indexOneBase - 1];
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
	ll K;cin >> K;
	ll x = K / 50;
	ll y = K % 50;
	vector<ll> ans;
	cout << 50 << endl;
	for (int i = 0;i < 51;i++) {
		if (i + y != 50)
			ans.push_back(i);
	}
	for (int i = 0;i < 50;i++) {
		cout << ans[i] + x << " ";
	}
}

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

int main(){
  
  string str;  
  getline(cin, str);
  for(char c: str){
    cout <<  (isupper(c)? (char)tolower(c): (char)toupper(c));
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3160
#include <cstdio>
#include <vector>
#include <algorithm>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<int> s(N);
  int sum=0;
  for (size_t i=0; i<N; ++i) {
    scanf("%d", &s[i]);
    sum += s[i];
  }

  if (sum % 10 > 0)
    return !printf("%d\n", sum);

  std::sort(s.begin(), s.end());

  for (size_t i=0; i<N; ++i) {
    if (s[i] % 10 > 0) {
      sum -= s[i];
      break;
    }
  }

  if (sum % 10 == 0)
    return !printf("0\n");

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define lp(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using l = long;
using vi = vector<int>;
using vl = vector<l>;
using vll = vector<ll>;
using vvl = vector<vector<l>>;
using vvll = vector<vector<ll>>;
using pll = pair<ll, ll>;
using un = unsigned;

int n, res = 0, ccc = 0;
string s;

int main()
{
	string s;
	cin >> s;
	s == "ABC" ? cout << "ARC" : cout << "ABC";
}



Measured memory_bytes: 3584
k = int(input())
L = [49]*50
t = k//50
for i in range(50):
    L[i] += t
m = k%50
for i in range(m):
    for j in range(50):
        if i == j:
            L[j] += 50
        else:
            L[j] -= 1
print(50)
print(' '.join(map(str, L)))


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

int main(){
    int n, m;
    while(cin >> n >> m, n || m){
        bool p[1000];
        fill(p, p+1000, true);
        int count = 0;
        int l = 0;
        for(int i=0;; i++){
            if(p[i%n]) l++;
            if(p[i%n] && l == m && count == n-1){
                cout << i%n+1 << endl;
                break;
            }
            else if(p[i%n] && l == m){
                p[i%n] = false;
                count++;
                l = 0;
            }
        }
    }
}

Measured memory_bytes: 1156
import Data.List
import Text.Printf

ans i =
  let g1 = take 2 $ sortBy (\ (a,b) (c,d) -> compare b d) $ take 8 i
      g2 = take 2 $ sortBy (\ (a,b) (c,d) -> compare b d) $ drop 8 $ take 16 i
      g3 = take 2 $ sortBy (\ (a,b) (c,d) -> compare b d) $ drop 16 i
      r1 = i \\ g1
      r2 = r1 \\ g2
      r3 = r2 \\ g3
      rr = take 2 $ sortBy (\ (a,b) (c,d) -> compare b d) $ r3
  in
    g1 ++ g2 ++ g3 ++ rr
    
main = do 
  c <- getContents
  let i = map (\ [a,b] -> (read a, read b) ) $ map words $ lines c :: [(Int,Float)]
      o = ans i
  mapM_ (\(a,b) -> printf "%d %.02f\n" a b) o

Measured memory_bytes: 4452
def solve():
    N, L = map(int, input().split())
    ans = 0
    biting_apple = 200

    for i in range(N):
        ans += L+i
        if abs(L+i) < abs(biting_apple):
            biting_apple = L+i
    
    ans -= biting_apple

    print(ans)

solve()

Measured memory_bytes: 38384
#include<stdio.h>
int cpll(int  p0[2],int p1[2],int p2[2],int p3[2],double *x,double *y){
  int a=p1[0]-p0[0],c=p2[0]-p0[0],e=p3[0]-p2[0];
  int b=p1[1]-p0[1],d=p2[1]-p0[1],f=p3[1]-p2[1];
  if(b*e-a*f==0)return 0;
  *x=p2[0]+1.0*e*(a*d-b*c)/(b*e-a*f);
  *y=p2[1]+1.0*f*(a*d-b*c)/(b*e-a*f);
  return 1;
}
int main(){
  int p[4][2],n,i;
  double x,y;
  scanf("%d",&n);
  while(n--){
    for(i=0;i<8;i++)scanf("%d",&p[i/2][i%2]);
    if(cpll(p[0],p[1],p[2],p[3],&x,&y))printf("%.9f %0.9f\n",x,y);
  }
  return 0;
}

Measured memory_bytes: 640
x,y=map(int,input().split())
if 0<x<=y:
  print(y-x)
if 0<y<x:
  print(x-y+2)
if x>0 and y<=0:
  if(x<=-y):
    print(-y-x+1)
  else:
    print(y+x+1)
if x<=0 and y>0:
  if(x==0):
    print(y)
  elif(-x<=y):
    print(y+x+1)
  else:
    print(-y-x+1)
if x<=0 and y<=0:
  if(x==0):
    print(1-y)
  elif(x<=y):
    print(y-x)
  else:
    print(x-y+2)

Measured memory_bytes: 3064
#include <iostream>

#define int long long

using namespace std;

const int N = 2e5 + 10;

int32_t main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);    
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int z = min(a, k);
    k -= z;
    k -= min(k, b);
    z -= min(k, c);
    cout << z;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
 
#define infi            5e9
#define infl            5e18
#define MX              100005
#define pi              2*acos(0.0)
#define ll              long long int
#define rr              read()
#define ff              first
#define ss              second
#define pb              push_back
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define ms(a,b)         memset(a, b, sizeof(a))
#define loop(i,n)       for(register int i=0;i<n;i++)
#define pool(i,n)       for(register int i=n-1;i>=0;i--)
#define loop1(i,n)      for(register int i=1;i<=n;i++)
#define pool1(i,n)      for(register int i=n;i>0;i--)
 
using namespace std;
 
inline ll read(){char c=getchar();ll num,sign=1;for(;c<'0'||c>'9';c=getchar())if(c=='-')sign=-1;for(num=0;c>='0'&&c<='9';){c-='0';num=num*10+c;c=getchar();}return num*sign;}
// inline ll pw(ll b, ll p){ll ans=1;while(p>0){if(p&1)ans*=b;p>>=1;b*=b;}return ans;}
inline bool isPrime(ll n){if(n==1)return false;if(n==2)return true;if(!(n%2))return false;for(ll i=3;i<=sqrt(n);i+=2)if(!(n%i))return false;return true;}
// inline ll gcd(ll a, ll b){if(a==0)return b;return gcd(b%a,a);}
 
// //*************************************  Bitmask Opereations  **********************************//
// int Set(int N,int pos){return N=N | (1<<pos);}
// int reset(int N,int pos){return N= N & ~(1<<pos);}
// bool check(int N,int pos){return (bool)(N & (1<<pos));}
// //********************************************************************************************//

#define mod 1000000007

bool prime[1100]; 
void sieve(){
    prime[0]=1;

    for(register int i=2; i<1005;){

        for(register int j=i+i; j<1005; j+=i)prime[j]=1;

        for(++i;; i++)
            if(!prime[i])break;
    }
}

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //#ifdef rid.dle//freopen("in.txt", "r", stdin);//#endif

    int n=rr;
    sieve();
    ll ans=1,x;
    for(register int i=2;i<=n;i++){
      if(prime[i])continue;

      x=1;
      for(register int j=i;j<=n;j*=i)x += n/j;
      
      ans = (ans*x)%mod;
    }
    cout << ans << endl;
    
    return 0;
}


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

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	int N = (int)s.length();
	int P = 0;
	rep (i, N){
		P += (int)(s[i] == 'p');
	} // end rep

	int res = N / 2 - P;
	cout << res << endl;

	return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
ll const INF = 1LL<<60;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct interval {
    int l,r,v;
    bool operator<(const interval& a) const {
        return r < a.r;
    }
};

struct LazySegmentTree {
private:
    int n;
    vector<ll> node,lazy;
public:
    LazySegmentTree(vector<ll> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1,0);
        for (int i = 0;i < sz;++i) node[i+n-1] = v[i];
        for (int i = n-2;i >= 0;--i) node[i] = min(node[i*2+1],node[i*2+2]);
    }

    void eval(int k,int l,int r) {
        if (lazy[k] != 0) {
            node[k] += lazy[k]/(r-l);
            if (r-l > 1) {
                lazy[2*k+1] += lazy[k]/2;
                lazy[2*k+2] += lazy[k]/2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a,int b,ll x,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        eval(k,l,r);
        if (b <= l || r <= a) return;
        if (a <= l && r <= b) {
            lazy[k] += (r-l)*x;
            eval(k,l,r);
        } else {
            add(a,b,x,2*k+1,l,(l+r)/2);
            add(a,b,x,2*k+2,(l+r)/2,r);
            node[k] = max(node[2*k+1],node[2*k+2]);
        }
    }

    ll getmax(int a,int b,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        if (b <= l || r <= a) return -INF;
        eval(k,l,r);
        if (a <= l && r <= b) return node[k];
        ll vl = getmax(a,b,k*2+1,l,(l+r)/2);
        ll vr = getmax(a,b,2*k+2,(l+r)/2,r);
        return max(vl,vr);
    }
};

int main() {
    int n,m;
    cin >> n >> m;
    LazySegmentTree seg(vector<ll>(n+10,0));
    vector<interval> a(m);
    for (int i = 0;i < m;++i) cin >> a[i].l >> a[i].r >> a[i].v;
    sort(a.begin(),a.end());
    int j = 0;
    for (int i = 1;i <= n;++i) {
        seg.add(i,i+1,seg.getmax(0,i+1));
        while (j < m && a[j].r == i) {
            seg.add(a[j].l,a[j].r+1,a[j].v);
            j++;
        }
    }
    cout << seg.getmax(0,n+10) << endl;
    return 0;
}

Measured memory_bytes: 10852
# coding: utf-8
from operator import itemgetter
n = int(input())
data = []
for i in range(n):
    s, p = map(str, input().split())
    data.append([i+1, s, int(p)])
data = sorted(data, key=itemgetter(2), reverse=True)
data = sorted(data, key=itemgetter(1))
for j in range(n):
    print(data[j][0])


Measured memory_bytes: 3060
# ARC 064 B

def resolve():
  n = int(input())
  a = list(map(int, input().split()))
  a.sort()
  ans = 0
  prev = a[0]
  for v in a:
    ans += (v - prev)
    prev = v

  print(ans)
  return

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define int long long int
const int N=2e3+5,mod=1e9+7;
int fact[N],ifact[N];
int pw(int x,int y){
    int res=1;
    while(y){
        if(y%2){
            res*=x;
            res%=mod;
        }
        y/=2;
        x=x*x;
        x%=mod;
    }
    return res;
}
int ncr(int n,int r){
    if(n<0||r>n)return 0ll;
    int res=fact[n];
    res*=ifact[n-r];
    res%=mod;
    res*=ifact[r];
    res%=mod;
    return res;
}
int32_t main() {
	int i,n,s,ans=0;
	cin>>s;
	fact[0]=ifact[0]=1;
	for(i=1;i<=2000;i++){
	    fact[i]=fact[i-1]*i;
	    fact[i]%=mod;
	    ifact[i]=pw(fact[i],mod-2);
	}
	for(i=1;i<=s;i++){
	    ans+=ncr(s-3*i+i-1,i-1);
	    ans%=mod;
	}cout<<ans;
	return 0;
}


Measured memory_bytes: 3656
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Console.WriteLine((((A+B) % 3 == 0) || (A % 3 == 0) || (B % 3 == 0)) ? "Possible" : "Impossible");
		
		
	}
	int A,B;
	public Sol(){
		var d = ria();
		A = d[0]; B = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>

std::string s;
int n, xg, yg;
std::vector<int> dx, dy;

int main(){
   std::cin >> s >> xg >> yg;
   n = s.size();

   int move = 0;
   bool toX = true;
   bool first = true;
   for(int i=0; i<n; ++i){
      if(s[i]=='F'){
	 ++move;
	 if(i==n-1){
	    if(first){
	       if(xg==move) std::cout << "Yes" << std::endl;
	       else std::cout << "No" << std::endl;
	       return 0;
	    }else{
	       if(toX) dx.push_back(move);
	       else dy.push_back(move);
	    }
	 }
      }else{
	 if(first){
	    xg -= move;
	    toX = !toX;
	    first = false;
	    move = 0;
	    continue;
	 }
	 if(toX){
	    dx.push_back(move);
	    toX = false;
	    move = 0;
	 }else{
	    dy.push_back(move);
	    toX = true;
	    move = 0;
	 }
      }
   }

   std::sort(dx.begin(),dx.end(),std::greater<int>());
   std::sort(dy.begin(),dy.end(),std::greater<int>());

   for(int i=0; i<dx.size(); ++i){
      if(xg>=0) xg -= dx[i];
      else xg += dx[i];
   }
   for(int i=0; i<dy.size(); ++i){
      if(yg>=0) yg -= dy[i];
      else yg += dy[i];
   }
   if(xg==0 && yg==0) std::cout << "Yes" << std::endl;
   else std::cout << "No" << std::endl;

   return 0;
}


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

typedef struct _vec{
    int *data;
    int cnt;
}VEC;

int main(){
    int i;
    int n,q;
    scanf("%d %d\n",&n,&q);
    
    VEC v[n];
    for(i=0;i<n;i++){
        v[i].cnt=0;
    }
    
    int com,t,x;
    while(q--){
        scanf("%d %d \n",&com,&t);
        switch(com){
            case 0:
                //pushback
                scanf("%d\n",&x);
                if(v[t].cnt==0){
                    v[t].data=(int*)malloc(sizeof(int));
                }else{
                    v[t].data=(int*)realloc(v[t].data,sizeof(int)*(v[t].cnt+1));
                }
                v[t].data[v[t].cnt++]=x;
                break;
            case 1:
                //dump
                for(i=0;i<v[t].cnt;i++){
                    if(i==0)printf("%d",v[t].data[i]);
                    else printf(" %d",v[t].data[i]);
                }
                printf("\n");
                break;
            case 2:
                //clear
                if(v[t].cnt!=0){
                    free(v[t].data);
                    v[t].cnt=0;
                }
                break;
        }
    }
    
    for(i=0;i<n;i++){
        if(v[t].cnt!=0){
            free(v[t].data);
            v[t].cnt=0;
        }
    }
    
    return 0;
}


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

long long mod = 998244353;

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

    vector<pair<long long, long long>> a(n + 1);
    for (int i = 0; i < n; i++){
        cin >> a[i].first >> a[i].second;
        a[i].second += a[i].first;
    }

    a[n].first = a[n].second = 1e18;

    sort(a.begin(), a.end());

    vector<long long> dp(n + 1);
    dp[n] = 1;
    stack<int> st;
    st.push(n);
    for (int i = n - 1; i >= 0; i--){
        while (a[i].second > a[st.top()].first)
            st.pop();

        int j = st.top();
        st.push(i);
        dp[i] = (dp[i + 1] + dp[j]) % mod;

    }

    cout << dp[0] << '\n';

    return 0;
}


Measured memory_bytes: 5376
# include<stdio.h>

int main(){
  int N;
  scanf("%d",&N);
  char S[N+1];
  scanf("%s",S);

  int w=0;
  int e=0;
  int sum;
  for (int i=1;i<N;i++){
    if(S[i]=='E'){
      e++;
    }
  }
  sum=e;
  for(int i=1;i<N;i++){
    if(S[i]=='E'){
      e--;
    }
    if(S[i-1]=='W'){
      w++;
    }
    if (w+e<sum){
      sum=w+e;
    }
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef double db; 
typedef string str;
 
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
 
typedef vector<int> vi; 
typedef vector<bool> vb; 
typedef vector<ll> vl; 
typedef vector<db> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
 
#define sz(x) (int)(x).size()
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define sor(x) sort(all(x))
#define ins insert 
#define ft front() 
#define bk back()
#define pf push_front 
#define pb push_back
#define endl '\n'
 
const ll MOD = 1e9+7; // 998244353;
const ll INF = 1e18;
 
int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int n; cin >> n;
   bool ans = false;
   int cur = 0;
   while (n--) {
      int d1, d2; cin >> d1 >> d2;
      if (d1 == d2) cur++;
      if (d1 != d2) cur = 0;
      if (cur == 3) ans = true;
   }
   cout << (ans ? "Yes" : "No");
   return 0;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    int m,k;
    cin>>m>>k;
    int p = pow(2,m);
    if(k>=p)
    {
        cout<<-1<<endl;
    }
    else if(m == 0)
    {
        cout<<"0 0"<<endl;
    }
    else if (m==1)
    {
        if(k==0) cout<<"0 0 1 1"<<endl;
        else cout<<-1<<endl;
    }
    else
    {    
        cout<<k;
        for (int i = 0; i < p; i++)
        {
            if(i==k) continue;
            cout<<" "<<i;
        }
        cout<<" "<<k;
        for (int i = p - 1; i >= 0; i--)
        {
            if(i==k) continue;
            cout<<" "<<i;
        }
        cout<<endl;
    }    

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int MAX = 510000;
const int MOD = 1000000007;

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

//a^nを計算する
long long modpow(long int a, long int n, long int mod) {
    long int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = (a * a) % mod;
        n >>= 1;
    }
    return res;
}

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long 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] % MOD) % MOD;
}

int main(){
    COMinit();
    ll N, M, K; cin >> N >> M >> K;
    ll ans = 0;
    ll MOD_ = COM(N*M-2,K-2);

    for(int i = 1; i < N; i++){
        ll temp = (N-i)*M*M*i;
        ans += temp;
        ans %= MOD;
    }

    for(int i = 1; i < M; i++){
        ll temp = (M-i)*N*N*i;
        ans += temp;
        ans %= MOD;
    }
    cout << (ans*MOD_)%MOD << endl;

}

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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

string s;


int main(){
    cin >> s;
    if(s=="AAA"||s=="BBB")
    {
        cout << "No" << endl;
    }
    else
    {
        cout << "Yes" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a,b,c,x,y;
  cin>>a>>b>>c>>x>>y;
  int ans=0;
  if(a+b>c*2){
    while(x!=0 && y!=0){
      ans+=c*2;
      x--; y--;
    }
    if(x!=0){
      if(a>c*2){
        ans+=c*2*x;
      }
      else{
        ans+=a*x;
      }
    }
    else{
      if(b>c*2){
        ans+=c*2*y;
      }
      else{
        ans+=b*y;
      }
    }
  }
  else{
    if(a>c*2){
      ans+=c*2*x;
    }
    else{
      ans+=a*x;
    }
    if(b>c*2){
      ans+=c*2*y;
    }
    else{
      ans+=b*y;
    }
  }
  cout<<ans<<'\n';
  return(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
 
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  auto calc=[](Int x){
    if(x <= 9) return x + 1;
    Int res=10;
    Int t = 10;
    Int k = 2;
    while( t * 10 <= x){
      res += k * (t * 9);
      k++;
      t *= 10;
    }
    return res + (x - t + 1) * k;
  };
 
  //cout<<calc(101)<<endl;
  //cout<<calc(13)<<endl;
   
  auto sub=[](string s,Int k){
    return s.substr(s.size()-k);
  };
 
  auto inc=[](string s){
    for(Int i=s.size()-1;i>=0;i--){
      if(s[i]=='9'){
    s[i]='0';
    continue;
      }
      s[i]++;
      break;
    }
    return s;
  };
   
  string s;
   
  while(cin>>s,s!="#"){
    Int ans=1e18;
    for(Int i=1;i<min(Int(17),Int(s.size()));i++){
      string t=s.substr(0,i),u=s.substr(i);
      if(u.front()=='0'||u.size()>16) continue; 
      //cout<<t<<"::"<<u<<endl;
      for(Int j=max((Int)t.size(),(Int)u.size());j<17;j++){
    string x=inc(t),y=u;
    //cout<<i<<" "<<j<<":"<<x<<":"<<y<<endl;
    x=string(j-t.size(),'$')+x;
    y=y+string(j-u.size(),'$');
    bool f=0;
    for(Int k=0;k<j;k++){
      if(k+1!=j){
        f|=(isdigit(x[k])&&isdigit(y[k])&&x[k]!=y[k]);
      }
      f|=(x[k]=='$'&&y[k]=='$');
    }
    if(f) continue;
    if(y.back()!='$'){
      if(x.back()-'0'!=y.back()-'0') continue;
    }
     
    for(Int k=0;k<j;k++){
      if(y[k]!='$') continue;
      y[k]=isdigit(x[k])?x[k]:'0';
    }
    if(y=="1") continue;
    Int tmp=calc(stoll(y)-1)-i;
    //cout<<i<<" "<<j<<":"<<x<<":"<<y<<":"<<tmp<<endl;
    ans=min(ans,tmp);
     
      }
    }
    //cout<<"SPL"<<endl;
    for(Int i=1;i<17;i++){
      for(Int j=0;j<i;j++){
    if(j+i>(Int)s.size()) continue;
    string t=s.substr(j,i);
    if(t.front()=='0') continue;
    Int x=stoll(t);
    //cout<<t<<" "<<x<<endl;
    if(j){
      if(x==1) continue;
      string u=to_string((long long)(x-1));
      //cout<<s.substr(0,j)<<":"<<u<<" "<<sub(u,j)<<endl;
      if(s.substr(0,j)!=sub(u,j)) continue;
    }
    Int p=j+i;
    bool f=1;
    while(p<(Int)s.size()){
      string u=to_string((long long)++x);
      string v=s.substr(p,min((Int)u.size(),(Int)s.size()-p));
      //cout<<u<<":"<<v<<endl;
      u=u.substr(0,v.size());
      f&=(u==v);
      p+=u.size();
    }
    if(!f) continue;
    Int tmp=calc(stoll(t)-1)-j;
    //cout<<i<<" "<<j<<" "<<":"<<t<<" "<<tmp<<endl;
    ans=min(ans,tmp);
      }
    }
    if(ans==1e18){
      ans=calc(stoll("1"+s)-1)+1;
    }
    cout<<(long long)ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3240
import itertools

n, m = map(int, input().split())
a = [1]
for i in range(1, n):
    a.append(a[i-1]+2)
b = [2]
for i in range(1, m):
    b.append(b[i-1]+2)

cnt = 0
for v in itertools.combinations(a+b, 2):
    #print(v[0], v[1])
    if (v[0]+v[1]) % 2 == 0:
        cnt += 1
print(cnt)


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

typedef long long int ll;


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

	int n;
	cin>>n;

	int A[n];
	int B[n];
	int C[n];

	for(int i=0;i<n;++i)	cin>>A[i];
	for(int i=0;i<n;++i)	cin>>B[i];
	for(int i=0;i<n-1;++i)	cin>>C[i];

	ll sum = 0;

	for(int i=0;i<n;++i)
	{
		sum += B[A[i]-1];
		if(i>0 && A[i] == A[i-1] + 1)	sum += C[A[i-1]-1];
	}

	cout<<sum<<"\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
ll n,m,l,r,an,ab,ans,a[100005],b[200005],c[200005];
int main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<n;i++){
		l=a[i],r=a[i+1];
		if(r<l)r+=m;
		an+=r-l;
		if(l+1<r){
			b[l+2]++,c[l+2]-=l+1;
			b[r+1]--,c[r+1]+=l+1;
		}
	}
	for(int i=1;i<=m+m;i++){
		b[i]+=b[i-1];
		c[i]+=c[i-1];
	}
	for(int i=1;i<=m;i++){
		ab=b[i]*i+c[i]+b[i+m]*(i+m)+c[i+m];
		if(ab>ans)ans=ab;
	}
	printf("%lld",an-ans);
	return 0;
}

Measured memory_bytes: 7604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N;

struct Block {
  int w, s, v;
};

vector<Block> B;

int main() {
  cin >> N;
  B.resize(N);
  int S = 0;
  rep(i, N) {
    cin >> B[i].w >> B[i].s >> B[i].v;
    S = max(S, B[i].s + B[i].w);
  }

  sort(B.rbegin(), B.rend(),
       [&](const Block& a, const Block& b) { return a.s + a.w < b.s + b.w; });

  vector<ll> dp(S + 1, 0);

  rep(i, N) rep(j, S + 1) {
    if (j + B[i].w <= S && B[i].s >= j)
      dp[j] = max(dp[j], dp[j + B[i].w] + B[i].v);
  }

  cout << dp[0] << endl;

  return 0;
}


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

using namespace std;

unsigned long long clp(unsigned long long x)
{
    x -= 1;
    x = x | (x >>  1);
    x = x | (x >>  2);
    x = x | (x >>  4);
    x = x | (x >>  8);
    x = x | (x >> 16);
    x = x | (x >> 32);
    return x + 1;
}

// a[0], a[1], ... , a[n - 1] is a given array of length n.
// T is the type of elements of array a.
// ZERO is a element such that for any element x, f(x, ZERO) == x.
// e.g. f(x, y) = sum(x, y), ZERO = 0.
// e.g. f(x, y) = min(x, y), ZERO = INFINITY.
template <class T>
class segment_tree
{
    private:
        const size_t n;
        const T ZERO;
        function<T(T, T)> f;
        T *a;
    public:
        segment_tree(size_t size, T ZERO, function<T(T, T)> f) : n(clp(size)), ZERO(ZERO), f(f)
        {
            //printf("n is initialized: %d\n", n);
            a = new T[2 * n - 1];
            fill(a, a + 2 * n - 1, ZERO);
        }
        template <class Iterator>
        segment_tree(Iterator first, Iterator last, int ZERO, function<T(T, T)> f) : n(clp(distance(first, last))), ZERO(ZERO), f(f)
        {
            size_t size = distance(first, last);
            a = new T[2 * n - 1];
            fill(a, a + 2 * n - 1, ZERO);
            /*
            for (int i = 0; i < size; ++i) {
                a[i] = {kk*/
        }
        ~segment_tree() {
            delete [] a;
        }
        void update(size_t i, T x)
        {
            i += n - 1;
            a[i] = x;
            while (i) {
                i = (i - 1) / 2;
                a[i] = f(a[2 * i + 1], a[2 * i + 2]);
            }
            /*printf("updated:\n");
            for (int i = 0; i < 2 * n - 1; i++) {
                printf("a[%d] = %d\n", i, a[i]);
            }*/
        }
        T query(size_t query_first, size_t query_last, size_t k = 0, size_t node_first = 0, size_t node_last = 0)
        {
            if (k == 0) {
                node_last = n;
            }
            if (node_last <= query_first || query_last <= node_first) {
                return ZERO;
            }
            if (query_first <= node_first && node_last <= query_last) {
                return a[k];
            } else {
                size_t node_mid = (node_first + node_last) / 2;
                T vl = query(query_first, query_last, k * 2 + 1, node_first, node_mid);
                T vr = query(query_first, query_last, k * 2 + 2, node_mid, node_last);
                return f(vl, vr);
            }
        }
};

int main(void)
{
    int n, q;
    cin >> n >> q;
    segment_tree<int> t(n, INT_MAX, [](int x, int y) {return min(x, y);});
    while (q--) {
        int com, x, y;
        cin >> com >> x >> y;
        if (com == 0) {
            t.update(x, y);
        } else if (com == 1) {
            cout << t.query(x, y + 1) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3856