akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

  // vector<vector<vector<int> > > DP =  vector<vector<vector<int> > >(100001,vector<vector<int> >(2,vector<int>(2,0)));
void solve(void)
{
  int N;
  cin>>N;
  string data;
  cin>>data;
  vector<int> W(N+1,0),E(N+1,0);
  for (int i = 0; i < N; i++)
  {
    if(data[i] =='W')
    {
      W[i]++;
    }
    else
    {
      E[i]++;
    }
    
  }
  for (int i = 0; i < N-1; i++)
  {
    W[i+1] += W[i];
    E[N-i-2] += E[N-1-i];
  }
  // DEBUG(W);
  // DEBUG(E);
  int ANS = INF;
  for (int i = 0; i < N; i++)
  {
    chmin(ANS,W[i]+E[i]-1);
  }
  cout<<ANS<<endl;
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 5396
#include <iostream>
#include <cmath>
template <class Type> class Point {
    Type x;
    Type y;
public:
    Point(const Type& f = Type(), const Type& s = Type()) : x(f), y(s) { }
    Type get_x() const { return x; }
    Type get_y() const { return y; }
    void set(const Type& x, const Type& y)  {this->x = x; this->y = y;}
    void print()  { std::cout << "(" << this->x << ", " << this->y << ")\n"; }
    void answer() { std::cout <<  static_cast<int>(this->x) << '\n' << static_cast<int>(this->y) << std::endl; }
};
int main()
{
    Point<double>   point;
    char            comma;
    for (double distance, angle, sum_angle = 0; std::cin >> distance >> comma >> angle && (distance || angle);) {
        point.set(point.get_x() + distance * sin(sum_angle), point.get_y() + distance * cos(sum_angle));
        sum_angle += angle * M_PI / 180;
    }
    point.answer();
}

Measured memory_bytes: 1232
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
using namespace std;
int main(void){
    vector<int> v(3,0);
    cin>>v[0]>>v[1]>>v[2];
    sort(v.begin(),v.end());
    cout<<v[0]+v[1]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
    // 頂点数と辺数
    int N, M,c=0; cin >> N >> M;
    int ab[N+5]={0};
    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    // BFS のためのデータ構造
    vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
            ab[nv+1]=v+1;
            
        }
    }

    // 結果出力 (各頂点の頂点 0 からの距離を見る)
    for (int v = 0; v <N; ++v) 
    {if(dist[v]==-1){
    c++;
    cout<<"No"<<endl;
    break;}}
    if(c==0){
    cout<<"Yes"<<endl;
    for (int v = 2; v <=N; ++v) 
    cout<<ab[v]<<endl;}
}

Measured memory_bytes: 10508
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    string s,t;
    cin >> s >> t;

    int n=s.length();
    int m=t.length();

    int ans=INT_MAX;
    for (int i=0;i<=n-m;i++)
    {
        int local=0;
        for (int j=0;j<=m-1;j++)
        {
            if (s[i+j]!=t[j])
            {
                local++;
            }
        }
        ans=min(ans,local);
    }

    cout << ans << endl;

    return 0;
}


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

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

  int H; cin >> H;
  int W; cin >> W;
  int N; cin >> N;
  int m = max(H, W);

  int ans = (N + m - 1) / m;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
package main

import (
    "bufio"
    "fmt"
    "os"
)

var r = bufio.NewReader(os.Stdin)

func main() {
    var a,b,c int
    fmt.Fscan(r,&a)
    fmt.Fscan(r,&b)
    fmt.Fscan(r,&c)
    
    if a < b && b < c{
        fmt.Println("Yes")
    }else{
        fmt.Println("No")
    }
}



Measured memory_bytes: 1140
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef long double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define sortvec(a) sort(a.begin(), a.end())
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
#define cerr if(true)cerr
void print(){cout<<endl;}
template<typename T,typename... Args>
void print(T a, Args... args) {cout<<a<<" ";print(args...);}
lli llipowerp(lli x, lli y, lli p=LLONG_MAX)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1) res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli binarySearch(vector<int> arr, int l, int r, int x)
{
    if (r >= l)
    {
        lli mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
template <typename T>
inline void printvec(vector<T> inp){
    for(auto it:inp) cout<<it<<" ";
    cout << endl;
}
//---------------------------------------------------------------------------------
vector<lli> w,v;

lli n, W;
lli dp[(lli)1e5+5][101];
lli fill(lli Wr,lli Nr){
    if(dp[Wr][Nr]!=-1) return dp[Wr][Nr];
    if(Nr<=0) return 0;
    lli maxv=fill(Wr,Nr-1);
    if(w[Nr]<=Wr){
        maxv=max(fill(Wr-w[Nr],Nr-1)+v[Nr],maxv);
    }
    dp[Wr][Nr]=maxv;
    return dp[Wr][Nr];


}
int main(){
    
    cin>>n>>W;
    w.resize(n+1);
    v.resize(n+1);
    fori(n) {
        cin >> w[i+1]>>v[i+1];
    }
    memset(dp,-1,sizeof(dp));
    cout<<fill(W,n)<<endl;

}


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

#define SIZE 100001
typedef long long Int;

Int min(Int a, Int b) {
	if (a > b) return b;
	return a;
}

int main() {
	int N, M, A[SIZE], B[SIZE], C[SIZE], P[SIZE];
	int D[SIZE];
	Int res = 0;
	int count = 0;

	scanf("%d%d", &N, &M);
	for (int i = 0;i < M;i++) {
		scanf("%d", &P[i]);
	}
	for (int i = 1;i < N;i++) {
		scanf("%d%d%d", &A[i], &B[i], &C[i]);
	}

	for (int i = 0;i <= N;i++) {
		D[i] = 0;
	}
	for (int i = 0;i + 1 < M;i++) {
		if (P[i] < P[i + 1]) {
			D[P[i]]++;
			if (P[i + 1] < N) {
				D[P[i + 1]]--;
			}
		}
		else {
			D[P[i + 1]]++;
			if (P[i] < N) {
				D[P[i]]--;
			}
		}
	}
	for (int i = 1;i < N;i++) {
		count += D[i];
		res += min((Int)A[i] * count, C[i] + (Int)B[i] * count);
	}

	printf("%lld\n", res);
	/*
	for (int i = 0;i < N;i++) {
		printf("%d ", D[i]);
	}
	*/

	return 0;
}

Measured memory_bytes: 2980
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int main(){
	LL n,m;
	LL i,j,k;
	LL a,b,c;
	LL s=0;
	cin>>a>>b>>n;
	if(b<=1e6){
		for(i=0;i<b && i<=n;i++){
			c=a*i/b-a*(i/b);
			s=max(s,c);
		}
	}else{
		for(i=0;i<=1e6;i++){
			if(n<i*b)break;
			c=min((i+1)*b-1,n);
			c=a*c/b-a*i;
			s=max(s,c);
		}
	}
	cout<<s<<endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	int n, k;
	cin >> n >> k;
	if (n <= k){
		cout << 1 << endl;
		return 0;
	}
	n -= 2*k;
	cout << (n+k-1)/(k-1) + 2 << endl;
	return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define prin(a) cout<<(a)<<endl
using ll=int64_t;
using namespace std;

//define gcd and lcm (using 64bit)
ll gcd(ll a,ll b){
    if (a < b) {
        //^はxor(bitwise operator)。以下三行でswap(a,b)を行っている。
        a ^= b;
        b ^= a;
        a ^= b;
    }
    //only when b==0,this program finds that b means false and returns a.
    return b ? gcd(b, a % b) : a;
}

ll lcm(ll a,ll b){
    return a * b / gcd(a, b);
}


int main(){
    string wea[]={"Sunny","Cloudy","Rainy"};
    string s;
    cin>>s;
    rep(i,3){
        if(wea[i]==s){
            cout<<wea[((i+1)%3)]<<endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
/*
    If they say
    Who cares if one more light goes out?
    In a sky of a million stars
    It flickers, flickers
    Who cares when someone's time runs out?
    If a moment is all we are
    We're quicker, quicker
    Who cares if one more light goes out?
    Well I do
*/

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

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a) / gcd(a,b)) * (b)
#define all(x)  x.begin(),x.end()

#define ll long long
#define ull unsigned long long
#define VI vector<int>
#define VLL vector<ll>
#define VS vector<string>
#define MPII map<int, int>
#define SET set<int>
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io   ios_base::sync_with_stdio(false);cin.tie(0),cout.tie(0);

ll MOD = 1e9+7;

ll add(ll a, ll b)
{
    a+=b; a%=MOD;
    if(a<0) a+=MOD;
    return a;
}
ll mult(ll a, ll b)
{
    if(a>MOD) a%=MOD;
    if(b>MOD) b%=MOD;
    ll ans=(a*b)%MOD;
    if(ans<0) ans+=MOD;
    return ans;
}
ll pw(ll a, ll b)
{
    ll r=1;
    while(b){
        if(b&1) r=mult(r,a);
        a=mult(a,a);
        b>>=1;
    }
    return r;
}

int nod(ll n){

    // Store to temporary variable.
    ll temp = n, count=0;

    while(temp != 0) {

        // Increment counter
        count++;

        // Remove last digit of 'temp'
        temp /= 10;
    }
    return count;
}

void solve(){
    ll n;
    cin>>n;
    ll a[n];
    ll zero=0;
    for(int i = 0 ; i < n ; i++){
        cin>>a[i];
        if(a[i]==0)zero++;
    }
    if(zero>0){cout<<0<<endl;return;}
    ll ans=1;
    for(int i=0; i < n ; i++){
        if(a[i ] <=1000000000000000000/ ans ){
            ans *=a[i];
        }else{
            printf("-1\n");
            return;
        }
    }
    cout<<ans<<endl;
}

int main(){
    fast_io;
    ll t, k=0;
    t=1;
    while(t--){
        //k++;
        //cout<<"Case "<<k<<": ";
        solve();
    }
}



Measured memory_bytes: 4372
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
int n;
ll dp[3010][3010],a[3010];
bool vis[3010][3010];
ll solve(int i,int j,bool ok)
{
    if(i==j)
    {
        if(!ok)
            return a[i];
        return -a[i];
    }
    ll &ret=dp[i][j];
    if(vis[i][j])
        return ret;
    vis[i][j]=1;
    if(!ok)
        ret=max(a[i]+solve(i+1,j,!ok),a[j]+solve(i,j-1,!ok));
    else
        ret=min(-a[i]+solve(i+1,j,!ok),-a[j]+solve(i,j-1,!ok));
    return ret;
}
int main()
{
    ios::sync_with_stdio(0);
    cin>>n;
    for(int i=0; i<n; i++)
        cin>>a[i];
    cout<<solve(0,n-1,0);
    return 0;
}


Measured memory_bytes: 78592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = 1001001001;

using Graph = vector<vector<int> >;

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

  Graph G(n);
  rep(i, m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> dist(n, -1);
  vector<int> parent(n);
  queue<int> que;

  dist[0] = 0;
  que.push(0);
  
  while(!que.empty()){
    int v = que.front();
    que.pop();
    for(int nv : G[v]){
      if(dist[nv] != -1) continue;
      dist[nv] = dist[v] + 1;
      parent[nv] = v;
      que.push(nv);
    }
  }

  cout << "Yes" << endl;
  REP(i, 1, n-1){
    cout << parent[i] + 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 10656
#include <stdio.h>
int main(){
    int a, b;
    char str[5];
    scanf("%d %d", &a, &b);
    if(a < b){
        printf("a < b\n");
    }else if(a > b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
    
    return 0;
}


Measured memory_bytes: 2012
#include <stdio.h>
#include <string.h>

int main (void)
{
  int i,bcount=0,count=0;
  int wcount=0,min;
  char s[100000];

  scanf("%s",s);
  //printf("%s\n",s);

  
  //black
  for(i=0;i<strlen(s);i++){
    if(i%2==0)
      if('1'==s[i]) bcount++;
    if(i%2==1)
      if('0'==s[i]) bcount++;
  }

  //white
  for(i=0;i<strlen(s);i++){
    if(i%2==0)
      if('0'==s[i]) wcount++;
    if(i%2==1)
      if('1'==s[i]) wcount++;
    if(s[i]== 'NULL') break;
       //printf("%d\n",wcount);
  }
  
  
  if(bcount>wcount) min=wcount;
  else min=bcount;
  
  //printf("B=%d,W=%d\n",bcount,wcount);
  
  printf("%d",min);

  return 0; 
}

Measured memory_bytes: 256
#include <stdio.h>

int gcd2(int x, int y)
{
    int temp;
    if (x > y)
    {
        temp = x;
        x = y;
        y = temp;
    }
    while (x != 0)
    {
        temp = y % x;
        y = x;
        x = temp;
    }
    return y;
}

int gcd3(int x, int y, int z)
{
    int temp1, temp2;
    temp1 = gcd2(x, y);
    temp2 = gcd2(y, z);
    return gcd2(temp1, temp2);
}

int main(void)
{
    int c, d, e, K, ans = 0;
    scanf("%d", &K);
    for (c = 1; c <= K; ++c)
    {
        ans += c;
        for (d = c + 1; d <= K; ++d)
        {
            ans += 6 * gcd2(c, d);
            for (e = d + 1; e <= K; ++e)
            {
                ans += 6 * gcd3(c, d, e);
            }
        }
    }
    printf("%d", ans);
    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b;cin>>a>>b;
  	if((a*10+b*10)/2==((a+b)/2)*10){
    	cout<<(a+b)/2<<endl;
    }else{
    	cout<<(a+b)/2+1<<endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n, x;
  scanf("%d %d", &n, &x);
  
  int m, all=0, min=1000, sum;
  for(int i=0; i<n; i++){
    scanf("%d", &m);
    all += m;
    if( m <= min ){ min = m; }
  }
  sum = n + ( (x-all) /min );
  printf("%d", sum);
  return 0;
}

Measured memory_bytes: 1728
#include<iostream>
#include<algorithm>
#include<cstring>
#include<set>
#include<vector>
#include<queue>
#include<cmath>
#include<memory.h>
#include<ctime>
#include<cstdio>

using namespace std;

long long a[100005],b[100005],c[100005];

int main()
{
	int n;
	long long ans=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
	}
	for(int i=1;i<=n;i++)
	{
		cin>>c[i];
	}	
	sort(a+1,a+n+1);
	sort(b+1,b+n+1);
	sort(c+1,c+n+1);
	long long an=0,cn=0;	
	for(int i=1;i<=n;i++)
	{
		while(a[an+1]<b[i]&&an+1<=n)
		{
			an++;
		}
        while(c[cn+1]<=b[i]&&cn+1<=n)
        {
        	cn++;
		}        
		ans+=an*(n-cn);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2560
from collections import *
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse = True)
ans = a[0]
n -= 2
i = 1
while(n > 0):
	ans += a[i]
	n -= 1
	if(n == 0):
		break
	ans += a[i]
	n -= 1
	i += 1
print(ans)

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

int main(){
  int N; cin >> N;
  int A[100], B[100], A1[100], A2[100];
  for(int i = 1; i <= N - 1; i++){
    cin >> B[i];
  }
  for(int i = 1; i <= N; i++){
    A1[i] = 1e9; A2[i] = 1e9;
  }
  for(int i = 1; i <= N - 1; i++){
    A1[i] = B[i];
    A2[i + 1] = B[i];
  }
  for(int i = 1; i <= N; i++){
    A[i] = min(A1[i], A2[i]);
  }
  int ans = 0;
  for(int i = 1; i <= N; i++){
    ans += A[i];
  }
  cout << ans << endl;
}



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

int K;
int x[32] ={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main() {
  std::cin >> K;
  --K;
  std::cout << x[K] << std::endl;
}


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

using namespace std;

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

  vector<long long> a(n), b(n);
  for (long long& val : a) cin >> val;
  for (long long& val : b) cin >> val;

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

  long long lo = 0, hi = 1LL << 50;
  while (lo < hi) {
    const long long x = (lo + hi) / 2;

    long long cnt = k;
    for (int i = 0; i < n && cnt >= 0; ++i) {
      cnt -= max(0LL, a[i] - x / b[i]);
    }

    if (cnt >= 0) {
      hi = x;
    } else {
      lo = x+1;
    }
  }
  
  cout << lo << endl;

  return 0;
}


Measured memory_bytes: 3328
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>

#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

int main() {
    int N;
    cin >> N;
    int X = 1000;
    while(X < N) {
        X += 1000;
    }

    cout << X - N << endl;

    return 0;
}


Measured memory_bytes: 3184
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
import functools
import itertools
import math
INF = float('inf')
MOD = 10**9+7

def dijkstra(s, edges):
    dist = [INF] * len(edges)
    dist[s], h = 0, []
    heappush(h, (0, s))
    while (len(h)):
        dv, v = heappop(h)
        if dv > dist[v]:
            continue
        for u, cost in edges[v]:
            if dv + cost < dist[u]:
                dist[u] = dv + cost
                heappush(h, (dist[u], u))
    return dist

N, M, L = map(int, input().split())
es = [[INF] * N for i in range(N)]
for i in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    es[a][b] = es[b][a] = c
for i in range(N):
    es[i][i] = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            tmp = es[i][k] + es[k][j]
            if tmp < es[i][j]:
                es[i][j] = tmp
es2 = [[] for i in range(N)]
for i in range(N-1):
    for j in range(i+1, N):
        if es[i][j] <= L:
            es2[i].append((j, 1))
            es2[j].append((i, 1))
dist = [dijkstra(i, es2) for i in range(N)]
Q = int(input())
for i in range(Q):
    s, t = map(lambda x: int(x)-1, input().split())
    ans = dist[s][t]
    if ans == INF:
        ans = 0
    print(ans-1)


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

using namespace std;
const int MAXN=10005;
int P=1e9+7,d,len;
char k[MAXN];
long long a[MAXN],dp[10005][105];

long long dfs(int pos,int tot,bool lim)
{
//	cout<<pos<<' '<<tot<<' '<<lim<<endl;
	if(pos==len+1)
	{
		if(tot==0)	return 1;
		return 0;
	} 
	if(!lim&&dp[pos][tot]!=-1) return dp[pos][tot];
	
	long long ret=0 ,  up=lim?a[pos]:9  ;
	
	for(int i=0;i<= up  ;++i)
	{
		ret=(ret+dfs(pos+1,(tot+i)%d, lim&&i==a[pos] ))%P;
		
		//(ret+=dfs(pos+1,(tot+i)%d, lim&&i==a[pos] ) )%=P;
	}
	
	if(!lim) dp[pos][tot]=ret;
	return ret;
}

int main()
{
	memset(dp,-1,sizeof(dp));
	scanf("%s",k+1);
	scanf("%d",&d);
	len=strlen(k+1);
	for(int i=1;i<=len;++i)
	{
		a[i]=k[i]-'0';
	}
	
	long long ans=(dfs(1,0,1)-1+P)%P;  
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 12796
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int N, mn = MOD;
ll sum = 0;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    F0R(i,N) {
        int a,b; cin >> a >> b;
        sum += b;
        if (a > b) mn = min(mn,b);
    }
    if (mn == MOD) cout << 0;
    else cout << sum-mn;
}

// read the question correctly (is y a vowel?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<queue>
#include<string>
using namespace std;

int main(){

	int N, K;
	cin >> N >> K;
	vector<int>L(N);
	for (int i = 0; i < N; i++)
		cin >> L[i];

	sort(L.begin(), L.end());
	reverse(L.begin(), L.end());
	int ans = 0;
	for (int i = 0; i < K; i++)
		ans += L[i];

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

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int w , h ,c;
char t[26][26];
int dx[] = {1 , -1 , 0 ,0};
int dy[] = {0 , 0 ,1 , -1};
bool input(){
//	cout <<'a';
 	cin >> h >>w;
 	if(w == 0)return false;
 	//cout << 'a';
 	for(int i = 0;i < 25;i++){
		for(int j = 0 ;j < 25 ; j++){
			t[i][j] = 0;
		}
	}
//	cout << 'a';
	for(int i = 0;i < w ;i++){
		for(int j = 0;j < h ;j++){
			cin >> t[i][j];
		}
	}
	
	return true;
}

void dfs(int  x,int y){
	t[x][y] = '&';
	for (int i = 0;i < 4;i++){
		int nx = x + dx[i];
		int ny = y + dy[i];

		if(0 <= nx && nx <= w && 0 <= ny && ny <= h && t[nx][ny] == '.')dfs(nx , ny);
	}
	return;
}

void solve(){
	for(int i = 0;i < w;i++){
		for(int j = 0;j < h;j++){
			if(t[i][j] == '@'){
				dfs(i,j);
			}
		}
	}
	int ans = 0;
	for(int i = 0;i < w;i++){
		for(int j = 0;j < h;j++){
//			cout << t[i][j];
			if(t[i][j] == '&'){
				
				ans++;
			}
		}
//		cout << endl;
	}

	cout << ans << endl;
	return;
}

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

}	



Measured memory_bytes: 3032
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        var scaner = new Scanner(System.in);
        var a = scaner.nextInt();
        var b = scaner.nextInt();
        var c = scaner.nextInt();
        var k = scaner.nextInt();

        long ans = 0;


        if (a < k) {
            ans += a;
            k -= a;
        } else {
            ans += k;
            k -= k;
        }
        
        if (b <= k) {
            k -= b;
        } else {
            k = 0;
        }

        ans += (-1 *k);


        System.out.println(ans);
        scaner.close();
    }

}


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

int main () {
  int A, B;
  char op;
  cin >> A >> op >> B;
  
  if (op == '+') {
    cout << A+B << endl;
  }
  
  else if (op == '-') {
    cout << A-B << endl;
  }
}

Measured memory_bytes: 256
#include <cstdint>
#include <utility>
#include <vector>

using namespace std;

size_t partition(uint32_t array[], size_t start, size_t end)
{
  int32_t mid = array[end];
  int32_t less_than = 0;
  for (uint32_t i = start; i < end; i++) {
    if (array[i] <= mid) {
      swap(array[less_than], array[i]);
      less_than++;
    }
  }
  swap(array[end], array[less_than]);
  return less_than;
}

#if !defined(TEST)
#include <iostream>
#include <vector>

static vector<uint32_t> vec;
int32_t main()
{
  uint32_t n;
  cin >> n;

  for (uint32_t i = 0; i < n; i++) {
    uint32_t val;
    cin >> val;
    vec.push_back(val);
  }
  size_t mid = partition(&vec[0], 0, vec.size() - 1);

  for (uint32_t i = 0; i < vec.size(); i++) {
    if (i != 0) cout << " ";
    if (i == mid) cout << "[";
    cout << vec[i];
    if (i == mid) cout << "]";
  }

  cout << endl;

  return 0;
}
#endif

Measured memory_bytes: 3420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k;
int s,f,t;
int p[200005];
int vis[200005];
int cr[200005];
int flag;
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)  p[i]=i;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&t);
        p[i]=t;
    }
    for(int i=1;;i=p[i])
    {
        if(!vis[i])
        {
            vis[i]=1;
        }
        else
        {
            vis[i]=2;
            break;
        }
        s++;   // 走 s 步绕环一周
    }
    int temp;
    for(int i=1;;i=p[i])
    {
        if(vis[i]==2)
        {
            temp=i;
            break;
        }
        f++;     // 走 f 步进入环
        if(k==f)
        {
            cout<<p[i];
            return 0;
        }
    }
    int c=s-f;  // 环的大小
    for(int i=0;i<c;i++)
    {
        cr[i]=temp;
        temp=p[temp];
    }
    int les=(k-(ll)f)%(ll)c;
    cout<<cr[les];
    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl
inline int ceil10(int n) { n+=(10-n%10)%10; return n; }

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int N,X; cin>>N>>X;
    vector<int> L(N); cin>>L;

    int ans = 1;
    int D = 0;
    rep(i, N) {
        D += L[i];
        if (D <= X)
            ans++;
        else
            break;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#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 (1 << 30)
#define LLINF (1LL << 60)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

ll dp[100][2];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, p;
    cin >> n >> p;
    vector<ll> a(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    dp[0][0] = 1;
    for (ll i = 0; i < n; i++)
    {
        dp[i + 1][0] += dp[i][0];
        dp[i + 1][1] += dp[i][1];
        if (a[i] % 2 == 1)
        {
            dp[i + 1][0] += dp[i][1];
            dp[i + 1][1] += dp[i][0];
        }
        else
        {
            dp[i + 1][0] += dp[i][0];
            dp[i + 1][1] += dp[i][1];
        }
    }
    cout << dp[n][p] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define R register
using namespace std;
const int N = 2e6+200;
template <class Ruby> inline void read(Ruby &x)
{
	x=0;
	char ch=getchar(), w=0;
	while(!isdigit(ch))w=(ch=='-'), ch=getchar();
	while(isdigit(ch))x=(x<<1)+(x<<3)+(ch^48), ch=getchar();
	x=w?-x:x;
}
int n, m;
int visited[N];
string a;
int main()
{
	read(n), read(m);
	int ans1=0, ans2=0;
	for(R int i=1, qa; i<=m; i++)
	{
		read(qa), cin>>a;
		if(a=="AC")
		{
			if(visited[qa]==1)continue;
			else ans1++, ans2-=visited[qa], visited[qa]=1;
		}
		else 
		{
			if(visited[qa]==1)continue;
			else visited[qa]--;
		}
	}
	cout<<ans1<<" "<<ans2<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N,M,X;
int C[20];
int A[20][20];

signed main(){
	cin>>N>>M>>X;
	REP(i,N){
		cin>>C[i];
		REP(j,M){
			cin>>A[i][j];
		}
	}
	int ans=INF;
	REP(Bit,1<<N){
		bool B[20]={};
		int num[20]={};
		int sum=0;
		REP(i,N){
			if(Bit&(1LL<<i)){
				B[i]=1;
			}
		}
		REP(i,N){
			if(B[i]==1){
				sum+=C[i];
				REP(j,M){
					num[j]+=A[i][j];
				}
			}
		}
		bool flag=true;
		REP(i,M){
			if(num[i]<X){
				flag=false;
			}
		}
		if(flag){
			ans=min(ans,sum);
		}
	}
	if(ans==INF){
		cout<<-1<<endl;
	}
	else{
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3636
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<ll>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];

    multimap<ll, int> mp;
    rep(i, n) mp.emplace(a[i], i);

    vvi dp(1, vi(1));
    int i = 0;
    ll ans = 0;
    for(auto itr = mp.end(); itr != mp.begin();) {
        itr--;
        dp.emplace_back(vi(i+2, 0));
        rep(j, i+2) {
            if(j) chmax(dp[i+1][j], dp[i][j-1] + itr->first*abs(itr->second-j+1));
            if(j != i+1) chmax(dp[i+1][j], dp[i][j] + itr->first*abs(itr->second-(n-1-(i-j))));
            chmax(ans, dp[i+1][j]);
        }
        i++;
    }
    cout << ans << endl;
}

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

ll gcd(ll a, ll b){return b==0 ? a : gcd(b, a%b);}

int main()
{
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int ans = a[0];
  rep(i, n) ans = gcd(ans, a[i]);
  cout << ans << endl;

  return 0;
}

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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define pb push_back
#define f first
#define s second
#define INF 1000000000000
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

const int MAXN = 100100, MAXK = 25;
const ll MOD = 1e9+7;

ll dp[MAXN];
ll h[MAXN];

int main()
{
    FAST_IO;

    int n, k; cin >> n >> k;
    FOR(i, 1, n) cin >> h[i];

    //dp[2] = abs(h[2]-h[1]);
    FOR(i, 2, n) dp[i] = INF;
    FOR(i, 2, n) FOR(j, max(1, i-k), i-1)
        dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main() {
	int a, b, c ;
	cin >> a >> b >> c;
	if (a == 5 && b == 5 && c == 7) {
		cout << "YES" << endl;

	}
	else if (a == 5 && b == 7 && c == 5) {
		cout << "YES" << endl;
	}
	else if (a == 7 && b == 5 && c == 5) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long       ll;
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
const int INF = 1234567890;

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int n;
    cin >> n;
    int t[n], x[n], y[n];
    fore(i, 0, n) {
    	cin >> t[i] >> x[i] >> y[i];
    }
    int a = 0, b = 0;
    int actTime = 0;
    fore(i, 0, n) {
    	int d = abs(x[i] - a) + abs(y[i] - b);
    	if (d > t[i] - actTime) {
    		cout << "No" << '\n';
    		return 0;
    	}
    	if (d <= t[i] - actTime) {
    		actTime += d;
    		a = x[i];
    		b = y[i];
    		if ((t[i] - actTime)%2 == 1) {
    			cout << "No" << '\n';
    			return 0;
    		}
    		else actTime = t[i];
    	}
    }
    cout << "Yes" << '\n';
    return 0;
}
// PLUS ULTRA!

Measured memory_bytes: 4768
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static int A = 'a';
    static int B = 'b';
    static int C = 'c';

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var x = int.Parse(spl[0]);
        var y = int.Parse(spl[1]);
        var a = int.Parse(spl[2]);
        var b = int.Parse(spl[3]);
        var c = int.Parse(spl[4]);

        var apples = new List<Apple>();

        spl = input.ReadLine().Split(' ');
        for (int i = 0; i < a; i++) {
            apples.Add(new Apple(A, int.Parse(spl[i])));
        }

        spl = input.ReadLine().Split(' ');
        for (int i = 0; i < b; i++) {
            apples.Add(new Apple(B, int.Parse(spl[i])));
        }

        spl = input.ReadLine().Split(' ');
        for (int i = 0; i < c; i++) {
            apples.Add(new Apple(C, int.Parse(spl[i])));
        }

        apples.Sort((v1, v2) => v2.x - v1.x);

        var xx = x;
        var yy = y;

        List<Apple> choiceAB = new List<Apple>();

        for(int i=0; i<apples.Count; i++) {
            var apl = apples[i];
            if(apl.color == A && xx > 0) {
                choiceAB.Add(apl);
                xx--;
            }else if(apl.color == B && yy > 0) {
                choiceAB.Add(apl);
                yy--;
            }
        }

        var idx = choiceAB.Count - 1;
        foreach(var apl in apples) {
            if (apl.color == A || apl.color == B) continue;
            if(apl.x > choiceAB[idx].x) {
                choiceAB[idx] = apl;
                idx--;
                if (idx == 0) break;
            } else {
                break;
            }
        }

        long sum = 0;
        foreach(var apl in choiceAB) {
            sum += apl.x;
        }
        return sum;
    }

    class Apple
    {
        public int color;
        public int x;

        public Apple(int co, int x) {
            this.color = co;
            this.x = x;
        }
    }
}

Measured memory_bytes: 44200
#include <stdio.h>

int main(){

  int W,H,x,y,r;

  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  if(x-r>=0 && y-r>=0 && x+r<=W && y+r<=H){
    printf("Yes\n");
  }
  else printf("No\n");


  return 0;
}



Measured memory_bytes: 2616
import itertools


def resolve():
    N, M = map(int, input().split())
    ans = 0

    if N > 1:
        ans = len(
            list(itertools.combinations(list(range(N)), 2))
        )
    if M > 1:
        ans += len(
            list(itertools.combinations(list(range(M)), 2))
        )

    print(ans)

resolve()

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
const int maxn = 220;
int a[maxn],b[maxn],c[maxn];
int ans,n,k;
int x,y;
int Ma,Mb;
int inf=2000000;
int dp[50][500][500];
int main()
{
    cin>>n>>Ma>>Mb;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    for(int i=0;i<=40;i++)
    {
        for(int j=0;j<=400;j++)
        {
            for(int z=0;z<=400;z++)
            {
                dp[i][j][z]=inf;
            }
        }
    }
    dp[0][0][0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<=400;j++)
        {
            for(int z=0;z<=400;z++)
            {
                if(dp[i][j][z]==inf) continue;
                dp[i+1][j][z]=min(dp[i][j][z],dp[i+1][j][z]);
                dp[i+1][j+a[i]][z+b[i]]=min(dp[i+1][j+a[i]][z+b[i]],dp[i][j][z]+c[i]);
            }
        }
    }
    int Minx=inf;
    for(int i=1;i<=400;i++)
    {
        for(int j=1;j<=400;j++)
        {
            if(i*Mb==j*Ma)
            {
                Minx=min(Minx,dp[n][i][j]);
            }
        }
    }
    if(Minx==inf)
    {
        cout<<"-1";
    }
    else
    {
        cout<<Minx;
    }
    return 0;
}

Measured memory_bytes: 40832
#include <iostream>
#include <cstdio>
int n, m, s, a[105][105], b[105][105];
int main() {
	int i, j, k, x, y, z;
	scanf("%d%d", &n, &m);
	for(i=1; i<=n; i++) for(j=1; j<=n; j++) b[i][j] = 1e9;
	while(m--) {
		scanf("%d%d%d", &x, &y, &z);
		a[x][y] = a[y][x] = b[x][y] = b[y][x] = z;
	}
	for(k=1; k<=n; k++) for(i=1; i<=n; i++) for(j=1; j<=n; j++)
		b[i][j] = std::min(b[i][j], b[i][k] + b[k][j]);
	for(i=1; i<=n; i++) for(j=i+1; j<=n; j++)
		s += (a[i][j] > b[i][j]);
	printf("%d", s);
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
 
using namespace std;
 
int main(){
	int k;cin>>k;
  	string s;cin>>s;
  	if(s.size() <= k) cout<<s;
  	else{
     	for(int i=0;i<k;i++){
        	cout<<s[i];
        }
      	cout<<"...";
    }
	  
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <set>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
  long long l[100101],n;
  cin>>n;
  l[0]=2;
  l[1]=1;
  for(int i=2; i<=n; i++)l[i]=l[i-1]+l[i-2];
  cout<<l[n]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >>d;
    long long ans = 0;
    for (int i = 0; i < 3010; i++) {
        for(int j = 0; j < 3010; j++) {
            if(i * a + j * b <= d && (d - i * a - j * b) % c == 0) {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque

def main():
    S1 = deque([])
    S2 = deque([])
    Sum = 0
    S = raw_input()
    for i,j in enumerate(S):
        if j == '\\': S1.append(i)
        elif j == '/' and len(S1) > 0 :
            k = S1.pop()
            Sum += i - k
            a = i - k
            while len(S2)>0 and S2[len(S2)-1][0] > k:
                a += S2.pop()[1]
            S2.append([k,a])

    ans = []
    while len(S2)>0:
        ans.append(S2.pop()[1])
    ans = ans[::-1]
    print sum(ans)
    print len(ans),
    for i in xrange(len(ans)):
        print ans[i],
    print
    return 0

main()
    

Measured memory_bytes: 7332
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.math.BigInteger;
import java.util.*;

public class Main {
	public Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new aoj0112().doIt();
	}
	class aoj0112{
		long waitsum(int a[]){
			long result = 0;
			long sum = 0;
			for(int i = 0;i < a.length;i++){
				result = result + sum;
				sum = sum + a[i];
			}
			return result;
		}
		void doIt() {
			while(true){
				int n = sc.nextInt();
				int a[] = new int [n];
				if(n == 0)break;
				for(int i = 0;i < n;i++)a[i] = sc.nextInt();
				Arrays.sort(a);
				System.out.println(waitsum(a));
			}
		}
	}
}

Measured memory_bytes: 45164
#include<bits/stdc++.h>
#define lli long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define test lli t;cin>>t;while(t--)
#define arrin lli n;cin>>n;lli a[n];for(lli i=0;i<n;i++)cin>>a[i]
#define floop for(lli i=0;i<n;i++)
#define mod 1000000007
#define defvec vector<lli>v
#define ub upper_bound
#define pb push_back
#define bs binary_search
using namespace std;

int main()
{   lli a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    lli n;
    cin>>n;
    cout<<a[n-1]<<endl;
    
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	int N, ans=0;
	int P[200005];

	cin >> N;
	rep(i,N) cin >> P[i];

	int dp[200005]={};
	rep(i,N){
		dp[ P[i] ] = dp[P[i] - 1] + 1;
		chmax(ans, dp[P[i]]);
	}

	cout << N-ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<set>
#include<map>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main() {
    int N; cin>>N;
    N--;
    int C[N],S[N],F[N]; REP(i,N) cin>>C[i]>>S[i]>>F[i];
    REP(i,N) {
        int t = 0;
        FOR(j,i,N) {
            t += max(S[j]-t,0);
            t += (F[j]-t%F[j])%F[j]+C[j];
        }
        cout<<t<<endl;
    }
    cout<<0<<endl;
}



Measured memory_bytes: 256