akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using vint=vector<int>;
using pint=pair<int,int>;
using vpint=vector<pint>;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

template<class A,class B>
ostream& operator<<(ostream& ost,const pair<A,B>&p){
    ost<<"{"<<p.first<<","<<p.second<<"}";
    return ost;
}

template<class T>
ostream& operator<<(ostream& ost,const vector<T>&v){
    ost<<"{";
    for(int i=0;i<v.size();i++){
        if(i)ost<<",";
        ost<<v[i];
    }
    ost<<"}";
    return ost;
}

int N;
int A[222222];

signed main(){
    scanf("%lld",&N);
    rep(i,N)scanf("%lld",&A[i]);

    multiset<int>s;
    rep(i,N)s.insert(A[i]);
    int ans=0;
    while(s.size()>1){
        int x=*s.rbegin();
        s.erase(--s.end());
        int y=(1ll<<__lg(x)+1)-x;
        if(s.find(y)!=s.end()){
            s.erase(s.find(y));
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11136
#include <iostream>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <sstream>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <complex>
#include <vector>
#include <cstdio>
#include <cmath>
#include <utility>
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ll long long
#define pb(a) push_back(a)
#define fi first
#define se second
using namespace std;
const int inf=(int)1e9;
const double PI=acos(-1.0);
 
 
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
    int n,m;
    while(cin>>n>>m,n){
        int ldp[201][201];
        int sdp[201][201];
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                ldp[i][j]=inf;
                sdp[i][j]=inf;
            }
        }
        for(int i=0;i<n;i++){
            ldp[i][i]=0;
            sdp[i][i]=0;
        }
        for(int i=0;i<m;i++){
            int a,b,c;
            char d;
            cin>>a>>b>>c>>d;
            a--;b--;
            if(d=='L'){
                ldp[a][b]=c;
                ldp[b][a]=c;
            }else{
                sdp[a][b]=c;
                sdp[b][a]=c;
            }
        }
        for(int k=0;k<n;k++){
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    ldp[i][j]=min(ldp[i][k]+ldp[k][j],ldp[i][j]);
                    sdp[i][j]=min(sdp[i][k]+sdp[k][j],sdp[i][j]);
                }
            }
        }
        int r;cin>>r;
        int a[1001];
        for(int i=0;i<r;i++){
            cin>>a[i];
            a[i]--;
        }
        int dp[1001][201];
        for(int i=0;i<1001;i++)for(int j=0;j<201;j++)dp[i][j]=inf;
        dp[0][a[0]]=0;
        for(int i=0;i<r-1;i++){
            for(int j=0;j<n;j++){
                if(dp[i][j]==inf)continue;
                for(int k=0;k<n;k++){
                    dp[i+1][k]=min(dp[i+1][k],dp[i][j]+ldp[a[i]][j]+sdp[j][k]+ldp[k][a[i+1]]);
                    if(j==k)dp[i+1][k]=min(dp[i+1][k],dp[i][j]+ldp[a[i]][a[i+1]]);
                }
            }
        }
        /*for(int i=0;i<r;i++){
            for(int j=0;j<n;j++){
                cerr<<dp[i][j]<<" ";
            }
            cerr<<"\n";
        }*/
        int ans=inf;
        for(int i=0;i<n;i++){
            ans=min(ans,dp[r-1][i]);
        }
        cout<<ans<<endl;
    }
    return 0;
}



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

const int INF = 1 << 29;

int main(){
	int n, x;
	int mx = -INF, mn = INF;
	long sum = 0;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &x);
		sum += x;
		mx = max(mx, x);
		mn = min(mn, x);
	}
	printf("%d %d %ld\n", mn, mx, sum);
}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n, m;
    cin >> n >> m;
    vector<long long> vec(m);
    ll sum = 0;
    for(long long i = 0; i < m; i ++){
        cin >> vec[i];
        sum += vec[i];
    }

    if(sum > n){
        cout << -1 << endl;
    }else{
        cout << n - sum << endl;
    }


}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

string s;

void input(){
    cin >> s;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    input();
    vector<int> cnt;
    // cnt.push_back(1);
    for(int i=0;i<s.size();i++){
        if(s[i] != 'A' && s[i] != 'C' && s[i] != 'G' && s[i] != 'T'){
            cnt.push_back(i+1);
        }
    }
    if(cnt.empty()){
        cout << s.size() << endl;
        return 0;
    }
    sort(cnt.begin(), cnt.end());
    int ans = cnt[0]-1;
    for(int i=0;i<cnt.size()-1;i++){
        ans = max(ans, cnt[i+1]-cnt[i]-1);
    }
    ans = max(ans, int(s.size()-cnt[cnt.size()-1]));
    // cout << int(s.size()-cnt[cnt.size()-1]) << endl;
    // for(int i=0;i<cnt.size();i++) cout << cnt[i] << endl;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}



signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int n;
  cin>>n;
  vector<Int> A(n);
  cin>>A;
  sort(A.begin(), A.end());

  Int p = 0;
  {
    vector<Int> B;
    vector<Int> used(n, 0);
    for(Int i=0;i<n;i++){
      Int a = i, b = n - 1 - i;
      if(used[a] == 0) B.push_back(A[a]), used[a] = 1;
      if(used[b] == 0) B.push_back(A[b]), used[b] = 1;
      used[a] = used[b] = 1;
    }
    Int mn = INF;
    for(Int i=0;i<n;i++) p = p + abs(B[(i+1)%n] - B[i]), Min(mn, abs(B[(i+1)%n] - B[i]));
    p = p - mn;
  }

  Int q = 0;
  {
    vector<Int> B;
    vector<Int> used(n, 0);
    for(Int i=0;i<n;i++){
      Int a = i, b = n - 1 - i;
      if(used[b] == 0) B.push_back(A[b]), used[b] = 1;
      if(used[a] == 0) B.push_back(A[a]), used[a] = 1;
    }
    Int mn = INF;
    for(Int i=0;i<n;i++) q = q + abs(B[(i+1)%n] - B[i]), Min(mn, abs(B[(i+1)%n] - B[i]));
    q = q - mn;
  }

  Int ans = max(p, q);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
#define MN 100005
long long sum,n,a[MN];
int main(){
	n=read();register int i;
	for(i=1;i<=n;i++) a[i]=read(),sum+=a[i];
	if(sum%((n+n*n)/2)!=0){printf("NO\n");return 0;}
	long long nn=sum/((n+n*n)/2),mm=nn;
	a[n+1]=a[1];
	for(i=1;i<=n;i++){
		if((nn-a[i+1]+a[i])%n!=0||(nn-a[i+1]+a[i])/n<0) {
			printf("NO\n");
			return 0;	
		}
		mm-=(nn-a[i+1]+a[i])/n;
	}
	if(mm!=0) {printf("NO\n");return 0;}
	printf("YES\n");
	return 0;
}


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

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long N = Long.parseLong(sc.next());
		long M = Long.parseLong(sc.next());
		long K = Long.parseLong(sc.next());
		List<Long> countA = new ArrayList();
		List<Long> countB = new ArrayList();
		countA.add(0l);
		countB.add(0l);

		for(int i=1;i<=N;i++) {
			long a =Long.parseLong(sc.next());
			countA.add(countA.get(i-1)+a);
		}
		for(int i=1;i<=M;i++) {
			long b = Long.parseLong(sc.next());
			countB.add(countB.get(i-1)+b);
		}

		long maxCount = 0;
		for(int i=0;i<=N;i++) {
			int max = countB.size()-1;
			int min = 0;
			long a = countA.get(i);
			int aa = max;
			while(true) {
				if(aa == 0){
					if(a <= K) {
						maxCount = Math.max(maxCount, i);
					}
					break;
				} else if(aa == min) {
					maxCount = Math.max(maxCount, aa+i);
					break;
				}
				if(a+countB.get(aa) <= K) {
					min = aa;
				} else {
					max = aa;
				}
				aa = (max+min)/2;
			}
		}
		System.out.println(maxCount);

	}
}

Measured memory_bytes: 62040
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
    FAST
    int h,w,n;
    cin>>h>>w>>n;
    int x = max(h,w);
    cout<<(n+x-1)/x;
}

Measured memory_bytes: 256
n = list(map(int, input().split()))
n.sort()
cnt = 0
if (n[1]-n[0])%2 != 0:
  if (n[0]%2==0 and n[2]%2==0) or (n[0]%2!=0 and n[2]%2!=0):
    cnt += 1
    n[0] += 1
    n[2] += 1
  elif (n[1]%2==0 and n[2]%2==0) or (n[1]%2!=0 and n[2]%2!=0):
    cnt += 1
    n[1] += 1
    n[2] += 1
n.sort()
if (n[1]-n[0])%2 ==0:
  cnt += (n[1]-n[0])//2
  n[0] = n[1]
  print(cnt+n[2]-n[1])

Measured memory_bytes: 3064
// C - HonestOrUnkind2
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	int A[N], X[N][N], Y[N][N];//証言が"確実"か、"不確定"か。
	rp(i, 0, N){
		cin>>A[i];
		rp(j, 0, A[i]){ cin>>X[i][j]>>Y[i][j]; X[i][j]--; }
	}

	int ans = 0;
	rp(bits, 1, 1<<N){//bits: 仮定のbit列: 0|1=不確実|確実
		bool ok = true;//true|false=仮定に矛盾なし|あり
		rp(i, 0, N){
			int assume_i = (bits>>i)&1;//i番目の仮定: 0|1
			if(!assume_i) continue;//不確実: 確認のしようがない
			rp(j, 0, A[i]){//以降、i番目の証言は全て確実と仮定して処理
				int assume_x = (bits>>X[i][j])&1;//x番目の仮定: 0|1
				if(assume_x != Y[i][j]) ok = false;//x番目の仮定と証言が矛盾
			}
		}
		if(ok) ans = max(ans, (int)bitset<16>(bits).count());//矛盾なし: 仮定から最大数を得る
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <tuple>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=(n); ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int n;cin>>n;
    int ans = 0;
    rep(i,n){
        int r,l; cin>>l>>r;
        ans += r-l+1;
    }
    cout<<ans<<endl; return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
 const int INF = 2147483647;
 const ll MOD = 1000000007;
 // const ll INF = 1000000000000000000LL;
 
 int main(){
	 int n;
	 cin >> n;
	 vector<ll> a(n);
	 rep(i,n) cin >> a[i];
	 sort(a.begin(),a.end());
	 vector<ll> sum(n+1);
	 for(int i=1;i<=n;i++){
		 sum[i] = sum[i-1]+a[i-1];
	 }
	 int k;
	 bool flag = true;
	 for(int i=1;i<n;i++){
		//  cout << sum[i] << ',' << a[i] << endl;
		 if(sum[i]*2>=a[i]&&flag) {
			 k = i-1;
			 flag = false;
		 }
		 else if(sum[i]*2<a[i]){
			 flag = true;
		 }
	 }
	 cout << n - k << endl;
	//  cout << n - k << endl;
   return 0;	
 }

Measured memory_bytes: 4772
/*---> 10 February 2020 <--- > 19:32:35 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename   enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;

int32_t main(){__
	string u,t;
	cin>>u>>t;
	int a,b;
	cin>>a>>b;
	string s;
	cin>>s;
	if(s==u)
		a--;
	else
		b--;
	cout<<a<<" "<<b<<"\n";
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N+1);
    for (int i = 1; i <= N; ++i) {
        cin >> A[i]; 
    }
    size_t port = 0;
    size_t value = 1000;
    for (int i = 1; i <= N-1; ++i) {
        if (A[i+1] - A[i] >= 0) {
            port = value / A[i];
        }
        else {
            port = 0;
        }
        value += port * (A[i+1] - A[i]);
    }
    cout << value << endl;
    return 0;
}

Measured memory_bytes: 3552
# -*- coding: utf-8 -*-
from bisect import bisect_left, bisect_right

N, K = map(int, input().split())
A = sorted(list(map(int, input().split()))) # ソートしておく

minus_right = bisect_left(A, 0)
plus_left = bisect_right(A, 0)

# Aにおける正、負、zeroの要素数
plus_cnt = N - plus_left
minus_cnt = minus_right
zero_cnt = N - (plus_cnt + minus_cnt)

# ペアの積が負の組み合わせ
minus_pairs_cnt = plus_cnt * minus_cnt
# 正*zero、負*zero、zero*zero(0を2つ選択する組合せ)
zero_pairs_cnt = plus_cnt * zero_cnt + minus_cnt * zero_cnt + zero_cnt * (zero_cnt - 1) // (2 * 1)

if K <= minus_pairs_cnt:
  # 積のK番目が負の場合
  
  # 二分探索
  low = -10 ** 18 # 積の最小(-10**9 * 10**9)
  high = 0 # 積の最大
  ans = 0
  while abs(high - low) > 1:
    mid = (low + high) // 2
    cnt = 0
    
    r = plus_left # 正の要素を小さい順に検索
    for l in range(minus_right):
      # 負の要素を小さい順に検索する
      # lを固定してrを増やしていき、A[l]*A[r]がmidよりも小さくなれば
      # rよりも右は全てA[l]*A[r]がmidよりも小さくなるので、その数をカウントする
      
      while r < N and A[l]*A[r] > mid:
        r += 1
      cnt += plus_cnt - (r - plus_left)
    if cnt >= K:
      high = mid # cnt==Kを満たしても2分探索が完了していない場合は継続
    else:
      low = mid
    
  print(high) # cnt==Kの場合highに値が入るので最後にcnt==Kを満たしたhighを出力
elif K <= minus_pairs_cnt + zero_pairs_cnt:
  # 積のK番目が0の場合
  # minus_pairs_cnt < K <= minus_pairs_cnt + zero_pairs_cnt の場合
  print(0)
else:
  # 積のK番目が正の場合
  # minus_pairs_cnt + zero_pairs_cnt < K の場合
  
  # 二分探索
  low = 0 # 積の最小
  high = 10 ** 18 # 積の最大(10**9 * 10**9)
  ans = 0
  
  while abs(high - low) > 1:
    mid = (low + high) // 2
    cnt = 0
    
    # 正*正の場合
    r = N-1
    for l in range(plus_left, N):
      # 小さい方(l)を固定し、大きい方(r)を減らしていき、
      # A[l]*A[r]がmidよりも小さくなれば
      # lとrの間は全てA[l]*A[r]がmidよりも小さくなるので、その数をカウントする
      
      while r < N and A[l]*A[r] > mid and l < r:
        r -= 1
      cnt += max(0, r - l)
      
    # 負*負の場合
    l = 0
    for r in range(minus_right - 1, -1, -1):
      # 大きい方(r)を固定し、小さい方(l)を増やしていき、
      # A[l]*A[r]がmidよりも小さくなれば
      # lとrの間は全てA[l]*A[r]がmidよりも小さくなるので、その数をカウントする
      
      while l < N and A [l]*A[r] > mid and l < r:
        l += 1
      cnt += max(0, r - l)
    if minus_pairs_cnt + zero_pairs_cnt + cnt >= K:
      high = mid
    else:
      low = mid
      
  print(high) # cnt==Kの場合highに値が入るので最後にcnt==Kを満たしたhighを出力

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

#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

void bye()
{
   cout << "No";
   exit(0);
}

void solve()
{
   int n;
    cin >> n;
    
    string s;
    
    vector<pii> go;
    
    while(n--)
    {
        cin >> s;
        
        int neg = 0;
        int cnt = 0;
        
        for(auto x : s)
        {
            if(x == '(') cnt++;
            else if(cnt == 0) neg++;
            else cnt--;
        }
        
        go.pb({neg,cnt});
    }
    
    vector<pii> inc,dec;
    
    for(auto x : go) if(x.F <= x.S) inc.pb(x);
                     else dec.pb(x);
    
    sort(inc.begin(),inc.end());
    
    for(auto & x : dec) swap(x.F,x.S);
    sort(dec.begin(),dec.end());
    reverse(dec.begin(),dec.end());
    for(auto & x : dec) swap(x.F,x.S);
    
   int sum = 0;
    
   for(auto x : inc)
   {
      if(x.F > sum) bye();
      sum+=x.S-x.F;
   }
    
   for(auto x : dec)
   {
       if(x.F > sum) bye();
       sum+=x.S-x.F;
   }
    
    if(dec.size() > 0)
    {
    if(dec.back().S > 0) bye();
    }
    
    if(sum == 0) cout <<"Yes";
    else cout <<"No";       
}

signed main()
{
    fast;
    solve();
}

Measured memory_bytes: 24856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
int n;

int main() {
	scanf("%d", &n);
	ll sum = 0;
	for(int i = 1; i <= n - 1; i++) sum += (ll)i;
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Arrays;
import java.util.Collections;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Integer[] x = new Integer[n];
        Integer[] y = new Integer[n];
        Integer[] xy = new Integer[n];
        
        for(int i = 0; i < n; i++){
            x[i] = sc.nextInt();
        }
         for(int i = 0; i < n; i++){
            y[i] = sc.nextInt();
        }
         for(int i = 0; i < n; i++){
            xy[i] = x[i] - y[i];
        }
        Arrays.sort(xy, Collections.reverseOrder());
        int counter = 0;
        
        for(int i = 0; i < n; i++){
            if(xy[i] > 0){
                counter++;
            }else{
                
            }
        }
        int kekka = 0;
        for(int i = 0; i < counter; i++){
            kekka += xy[i];
        }
        
        System.out.println(kekka);
    }
}


Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll n,a,b;
	cin>>n>>a>>b;
	ll cnt=0;
	for(ll i=1;i<=n;i++)
	{
		ll dig = 0;
		ll temp =i;
		while(temp>0)
		{
			dig += temp%10;
			temp/=10;
		}
		//cout<<dig<<"\n";
		if(dig>=a && dig<=b)
		{
			cnt+=i;
			//cout<<cnt<<"\n";
		}
	}
	cout<<cnt<<"\n";
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		char a = 'a';
		for(int i = 0; i < 26; i++) {
			if(s.indexOf(String.valueOf(a)) == -1) break;
			a++;
		}
		System.out.println((a <= 'z')? a : "None");
	}
}


Measured memory_bytes: 26296
#include <vector>
#include <algorithm>
#include <cstdio>
#define LIMIT 10000
using namespace std;
bool ck(vector<int>&v){
	for(int i=0;i<v.size();i++)if(v[i]!=i+1)return false;
	return true;
}
main(){
	int n,i,j,s,x,l;
	vector<int>tri;
	for(i=1;i<9999;i++)tri.push_back(i*(i+1)/2);
	for(;scanf("%d",&n),n;){
		vector<int>v;
		for(s=i=0;i<n;i++){
			scanf("%d",&x);
			s+=x;
			v.push_back(x);
		}
		vector<int>::iterator idx=find(tri.begin(),tri.end(),s);
		i=LIMIT+1;
		if(idx!=tri.end()){
			for(i=0;i<=LIMIT&&!ck(v);i++){
				l=v.size();
				for(j=0;j<l;j++)v[j]--;
				v.erase(remove(v.begin(),v.end(),0),v.end());
				v.push_back(l);
			}
		}
		printf("%d\n",i>LIMIT?-1:i);
	}
}

Measured memory_bytes: 1160
import java.util.*;
import java.io.*;

public class Main {	
	public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		int X = fs.nextInt();

		int a =X/500;
		int b = X-500*a;
		int c = b/5;

		System.out.println(a*1000+5*c);
		
 
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");

		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

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

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

		public int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) {
				a[i]=nextInt();
			}
			return a;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

	}
	
}


Measured memory_bytes: 22740
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;


const long long int mod = 998244353;
const long long int INF = 1e18;
const long double PI=3.14159265358979323; 



long long int dp[200200]={};


long long int N,A,B,S[200200],sum=0,mymax=0,mymin=INF;;
int main(){
    cout << fixed << setprecision(18);
    cin>>N;
    cout<<(N-2)*180<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main() {
	int c[3][3];
	rep(i,3){
		rep(j,3){
			cin >> c[i][j];
		}
	}
	int a[3]={};
	int b[3]={};
	a[0]=c[0][0];
	rep(i,3){
		b[i] = c[0][i]-a[0];
	}
	rep(i,2){
		a[i+1] = c[i+1][0]-b[0];
	}
	rep(i,3){
		rep(j,3){
			if(c[i][j]!=a[i]+b[j]){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int N,a,sum,ans;
  cin>>N;
  sum=0;
  vector<long long int> num;
  map<long long int,long long int> A;
  for(int i=0;i<N;i++){
    cin>>a;
    A[a]++;
    num.push_back(a);
  }
  for(int i=0;i<N+1;i++){
    sum+=A[i]*(A[i]-1)/2;
  }
  for(int i=0;i<N;i++){
    ans=sum-A[num[i]]+1;
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 16752
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1e9+7
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;


int main() {
    int n,m; cin >> n >> m;
    if (n==m) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3600
#長さN
#各値はM以下
n,m,q=map(int,input().split())

abcd=[list(map(int, input().split())) for i in range(q)]

ai=set([])

def zentan(ss,x,i):
    #x以上
    global n,m,ai
    if i==n-1:
        for j in range(x,m):
            ai.add(ss+str(j))
    else:
        for j in range(x,m):
            zentan(ss+str(j),j,i+1)

result=0
zentan("",0,0)


for item in ai:
    point=0
    checked=[0]*n
    for item2 in abcd:
        
        a,b,c,d=item2[0]-1,item2[1]-1,item2[2],item2[3]
        if int(item[a])+c==int(item[b]):
            point+=d
    result=max(result,point)

print(result)


        






        








    





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

const ll inf = 1e18 + 1;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

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

		ll n;
		cin>>n;
		ll ans=0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				for(int k=1;k<=n;k++){
					ans+=__gcd(i ,__gcd(j, k));
				}
			}
		}
cout<<ans;
	return 0;
}


Measured memory_bytes: 3652
// 参考: https://atcoder.jp/contests/abc133/submissions/6278434
// matsuu さんありがとうございました。

package main

import (
	"fmt"
)

func minimumRemainder(minNum int, maxNum int, modNumInit int) int {
	// 各余り値の最小値
	// (最初なので考えられる余り値の最大値)
	var modNum int = modNumInit

	// minNum(i)がmaxNumに徐々に接近！
	for i := minNum; i < maxNum; i++ {
		// i+1(j)がmaxNumに徐々に接近してくっつく！
		for j := i + 1; j <= maxNum; j++ {
			// 現在のminNum(i)×(i+1...maxNum) ÷ 2019 の余り値
			remainder := (i * j) % modNumInit
			// 現在の最小値より小さかったら
			if remainder < modNum {
				// 最小値更新
				modNum = remainder
				// 余りが0になった時点で最小値が決定したので処理終了
				if modNum == 0 {
					return modNum
				}
			}
		}
	}
	return modNum
}

func main() {
	var minNum, maxNum int
	fmt.Scan(&minNum, &maxNum)
	fmt.Println(minimumRemainder(minNum, maxNum, 2019))
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main() {
  int N; cin>>N;
  int D1,D2,cnt=0;
  string ans="No";
  for (int i=0; i<N; i++) {
    cin>>D1>>D2;
    if (D1==D2) cnt++;
    else cnt=0;
    if (cnt==3) {
      ans="Yes";
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
fun main(args: Array<String>) {
    val n = readInt()

    val ans = MutableList(10001) { 0 }
    for (x in 1..100) {
        for (y in 1..100) {
            for (z in 1..100) {
                val v = x * x + y * y + z * z + x * y + y * z + z * x
                if (v <= 10000) {
                    ans[v]++
                }
            }
        }
    }
    for (i in 0 until n) {
        println(ans[i + 1])
    }
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()

Measured memory_bytes: 37372
#include <iostream>
using namespace std;
long long a[100005][3],d[100009][4],i,n;
long long dp(int i,int x){
    if(i==n) return 0;
    if(d[i][x]) return d[i][x];
    for(int j=0;j<3;j++)
        if(j!=x)
            d[i][x]=max(d[i][x],a[i][j]+dp(i+1,j));
    return d[i][x];
}
int main()
{
    cin>>n;
    for(i=0;i<n;i++) cin>>a[i][0]>>a[i][1]>>a[i][2];
    cout<<dp(0,3);
    return 0;
}


Measured memory_bytes: 13568
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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; }

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

	//std::ifstream in("../../test.txt");
	//std::cin.rdbuf(in.rdbuf());

	ll N, K;
	cin >> N >> K;

	if (K == 1) {
		cout << 0 << endl;
	}
	else {
		cout << (N - K) << endl;
	}



	return 0;
}



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

using namespace std;
typedef long long ll;

#define MOD 1000000007
#define INF 1000000000
#define PI 3.14159265359
#define MAX_N 100
#define MAX_M 100

int main(void)
{
  int n, t[MAX_N], temp[MAX_N], m, p[MAX_M], x[MAX_M];
  cin >> n;
  for(int i=0; i<n; i++) cin >> t[i];
  cin >> m;
  for(int i=0; i<m; i++) cin >> p[i] >> x[i];

  for(int i=0; i<m; i++) {
    int sum = 0;
    for(int i=0; i<n; i++) temp[i] = t[i];
    temp[p[i]-1] = x[i];
    for(int i=0; i<n; i++) sum += temp[i];
    cout << sum << endl;
  }

  return 0;
}


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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 1e6;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int h, w;
    cin >> h >> w;
    string s[h];
    for (int i = 0; i < h; i++) {
      cin >> s[i];
    }
    int dp[h + 1][w + 1], x, y;
    dp[h][w] = (s[h - 1][w - 1] == '#' ? 1 : 0);
    for (int i = h; i >= 1; i--) {
      for (int j = w; j >= 1; j--) {
        if (i == h && j == w) continue;
				if (i == h) {
					if (s[i - 1][j - 1] == s[i - 1][j]) dp[i][j] = dp[i][j + 1];
					else if (s[i - 1][j - 1] == '.') dp[i][j] = dp[i][j + 1];
					else dp[i][j] = dp[i][j + 1] + 1;
				}
				else if (j == w) {
					if (s[i - 1][j - 1] == s[i][j - 1]) dp[i][j] = dp[i + 1][j];
					else if (s[i - 1][j - 1] == '.') dp[i][j] = dp[i + 1][j];
					else dp[i][j] = dp[i + 1][j] + 1;
				}
				else {
					if (s[i - 1][j - 1] == s[i - 1][j]) x = dp[i][j + 1];
					else if (s[i - 1][j - 1] == '.') x = dp[i][j + 1];
					else x = dp[i][j + 1] + 1;
					if (s[i - 1][j - 1] == s[i][j - 1]) y = dp[i + 1][j];
					else if (s[i - 1][j - 1] == '.') y = dp[i + 1][j];
					else y = dp[i + 1][j] + 1;
					dp[i][j] = min(x, y);
				}
      }
    }
    cout << dp[1][1] << "\n";
 	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int m, n, i;
	int number[100000] = {0};

	m = 0;
	while (scanf("%d", &n) != EOF)
	{
		for (i = 1; i <= 39; i++)
		{
			n--;
			if (n == 0)
				break;
			if (i == 39)
				i = 0;
		}
		number[m] = i;
		m++;
	}

	for (i = 0; i < m; i++)
		printf("3C%02d\n", number[i]);

	return 0;
}

Measured memory_bytes: 1004
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s1;
    string s2;
    cin>>s1>>s2;
    int count=0;
    for(int i=0;i<s1.size();i++)
    {
    	if(s1[i]==s2[i])
    	{
    		count++;
    		continue;
		}
		else{
			break;
		}
	}
	if(count==s1.size())
	{
		cout<<"Yes"<<"\n";
	}
	else{
		cout<<"No"<<"\n";
	}
}

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

#define		fuckshitup  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) // don't use for small inputs
#define		endl		"\n"
#define		ll			long long int
#define		mod			1000000007
#define		f(i,a,b)	for(ll i = (ll)(a); i < (ll)(b); i++)
#define		rf(i,a,b)   for(ll i = (ll)(a); i > (ll)(b); i--)
#define		ull			unsigned long long
#define		ld			long double

struct custom_hash{
    static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
}

size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = std::chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
}
};

int main()
{
    fuckshitup;
    string s;
    cin >> s;
    ll q;
    cin >> q;
    ll rev = 0;
    string beg, en;
    beg = en = "";
    while (q--)
    {
        ll c;
        cin >> c;
        
        if (c == 1)
        {
            rev++;
        }
        else
        {
            ll pos;
            char ch;
            cin >> pos >> ch;
            if (rev % 2 == 0)
            {
                if (pos == 1)
                {
                    beg = ch + beg;
                }
                else
                {
                    en = en + ch;
                }
            }
            else
            {
                if (pos == 1)
                {
                    en = en + ch;
                }
                else
                {
                    beg = ch + beg;
                }
            }
        }
    }
    if (rev % 2 == 0)
    {
        s = beg + s;
        s = s + en;
    }
    else
    {
        reverse(beg.begin(), beg.end());
        reverse(en.begin(), en.end());
        reverse(s.begin(), s.end());
        s = en + s;
        s = s + beg;

    }
    cout << s << endl;
}


Measured memory_bytes: 1320
/*
    Problem 5
    https://atcoder.jp/contests/abc095/tasks/arc096_a
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const ll MAX = 100000000000;
/* global variables */
/* function */
/* main */
int main(){
    ll A, B, C, X, Y;
    cin >>  A >> B >> C >> X >> Y;
    ll ans = MAX;

    for (ll i = 0; i <= X + Y; i++) {
        ll money = i * 2 * C + max(0LL, X - i) * A + max(0LL, Y - i) * B;
        ans = min(ans, money);
    }

    cout << ans << '\n';
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;

int main() {
  int n;
  scanf("%d", &n);
  vector<ii> a(n);
  int minv = INF, maxv = -INF;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a[i].first, &a[i].second);
    if (a[i].first > a[i].second) swap(a[i].first, a[i].second);
    minv = min(minv, a[i].first);
    maxv = max(maxv, a[i].second);
  }
  int L = -INF, R = INF;
  for (int i = 0; i < n; ++i) {
    L = max(L, a[i].first);
    R = min(R, a[i].second);
  }
  int64 ret = (int64)(L - minv) * (maxv - R);
  sort(a.begin(), a.end(), [](const ii& a, const ii& b) {
      return a.first < b.first;
    });
  int u = a[0].second, v = a[0].second;
  for (int i = 0; i < n; ++i) {
    u = min(u, a[i].second);
    v = max(v, a[i].second);
    if (i < n - 1) {
      L = min(u, a[i + 1].first);
      R = max(v, a[n - 1].first);
      ret = min(ret, (int64)(maxv - minv) * (R - L));
    } else {
      ret = min(ret, (int64)(maxv - minv) * (v - u));
    }
  }
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
int p[N],q[N],a[N];
int main (){
	int n;scanf ("%d",&n);
	for (int i=1;i<=n;i++) scanf ("%d",&p[i]);
	for (int i=1;i<=n;i++) scanf ("%d",&q[i]);
	for (int i=1;i<=n;i++) a[i]=i;
	int A,B,now=0;bool flag;
	do{
		++now;flag=true;
		for (int i=1;i<=n;i++)
			if (a[i]!=p[i]) flag=false;
		if (flag) A=now;
		flag=true;
		for (int i=1;i<=n;i++)
			if (a[i]!=q[i]) flag=false;
		if (flag) B=now;
	}while (next_permutation(a+1,a+n+1));
	printf ("%d",abs(A-B));
	return 0;
}

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

int main(){
  int N,min=0,ans=0;
  cin >> N;
  vector<int> P(N);
  rep(i,N) {
    cin >> P[i];
    if(i==0) {min=P[i]; ans=1;}
    else if(min>=P[i]) {
      ans++;
      min=P[i];
    }
  }
  
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    ll n; cin >> n;
    if (n==1) {
        cout << 0 << endl;
        return 0;
    }

    ll kake1 = 1, kake2 = 1;
    ll zen = 1;
    rep(i,n) {
        kake1 *= 9;
        kake1 %= mod;
    }
    rep(i,n) {
        kake2 *= 8;
        kake2 %= mod;
    }
    rep(i,n) {
        zen *= 10;
        zen %= mod;
    }

    ll ans = zen;
    ll hiku = (kake1*2)%mod-kake2;
    hiku %= mod;
    ans -= hiku;
    // ll ans = zen-kake1*2+kake2;
    ans %= mod;
    if (ans<0) ans += mod;
    cout << ans << endl;
    
    // ll ans = n*(n-1);
    // ans %= mod;

    // ll kake = 1;
    // rep(i,n-2) {
    //     kake *= 10;
    //     kake %= mod;
    // }

    // ans *= kake;
    // ans %= mod;

    // cout << ans << endl;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
    const double Pi = acos(-1);
    int a, b, h, m;
    cin >> a >> b >> h >> m;
    double rad1 = double(h*60+m)/720*2*Pi;
    double rad2 = double(m)/60*2*Pi;
    double xh = a*cos(rad1), yh = a*sin(rad1);
    double xm = b*cos(rad2), ym = b*sin(rad2);
    double dx = xh - xm, dy = yh - ym;
    double ans = sqrt(dx*dx+dy*dy);
    printf("%.10f\n", ans);
    system("pause");
}


Measured memory_bytes: 4048
#include<cstdio>
#define ll long long
#define max(a,b) (a>b?a:b)
#define maxn 100050
using namespace std;
ll dp[maxn];
int main(){
	int n,W;
	scanf("%d%d",&n,&W);
	for (int i=1;i<=n;i++){
		int a,b;
		scanf("%d%d",&a,&b); 
		for (int j=W;j>=a;j--)
		dp[j]=max(dp[j-a]+b,dp[j]);
	}
	ll ans=0;
	for (int j=0;j<=W;j++)
	if (dp[j]>ans) ans=dp[j];
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 896
if __name__ == '__main__':
    A, B = map(int, input().split())
    
    digit_max = len(bin(B)[2:])
    answer = []
    for digit in range(1, digit_max+1):
        mod = (2**digit)
        A_mod = A%mod
        B_mod = B%mod
        
        if digit == 1:
            length = B-A + 1
            if length%2 == 0:
                if (length//2)%2 == 1:
                    ret = 1
                else:
                    ret = 0
                
            else:
                if A%2 == 0:
                    if ((length - 1)//2)%2 == 1:
                        ret = 1
                    else:
                        ret = 0      
                else: #1start
                    if ((length - 1)//2)%2 == 0:
                        ret = 1
                    else:
                        ret = 0
            
        else:
            if A_mod >= mod//2:
                if A%2 == 1:
                    start = 1
                else:
                    start = 0
            else:
                start = 0

            if B_mod >= mod//2:
                if B%2 == 0:
                    end = 1
                else:
                    end = 0
            else:
                end = 0
            
            if start == end:
                ret = 0
            else:
                ret = 1
        
        answer.append(str(ret))
    
    
    print(int(''.join(answer[::-1]), 2))
    
    

Measured memory_bytes: 3188
#include <stdio.h>
int main()
{
  int a,b,c;

  scanf("%d%d%d",&a,&b,&c);
  if(a<b&&b<c)printf("%d %d %d\n",a,b,c);
  if(a<c&&c<b)printf("%d %d %d\n",a,c,b);
  if(b<a&&a<c)printf("%d %d %d\n",b,a,c);
  if(b<c&&c<a)printf("%d %d %d\n",b,c,a);
  if(c<a&&a<b)printf("%d %d %d\n",c,a,b);
  if(c<b&&b<a)printf("%d %d %d\n",c,b,a);
  if(a==b&&b==c)printf("%d %d %d\n",a,b,c);
  if(a==b&&a>c)printf("%d %d %d\n",c,a,b);
  if(a==b&&a<c)printf("%d %d %d\n",a,b,c);
  if(b>a&&b==c)printf("%d %d %d\n",a,b,c);
  if(b<a&&b==c)printf("%d %d %d\n",b,c,a);
  if(a==c&&a>b)printf("%d %d %d\n",b,a,c);
  if(a==c&&a<b)printf("%d %d %d\n",a,c,b);

  return 0;

}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
int n = 0;
cin >> n;
string s;
cin >> s;
string halfs;

for (int i = 0; i < s.size()/2; i++)
{
    halfs += s.at(i);
}

string kotae;
kotae = halfs + halfs;
int ans;
if(n%2 != 0){
    ans = 0;
}
else if(s == kotae){
    ans = 1;
}else{
    ans = 0;
}

if(ans == 1){
    cout << "Yes" << endl;
}else{
    cout << "No" << endl;
}
return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
xyz=[list(map(int,input().split())) for i in range(n)]
ans=[]
for i in [-1,1]:
    for j in [-1,1]:
        for k in [-1,1]:
            ans.append(sum(sorted([i*l[0]+j*l[1]+k*l[2] for l in xyz],reverse=True)[:m]))
print(max(ans))

Measured memory_bytes: 3316