akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back


int MOD=1000000007;
int N,M,P;
char S[15];
int ans=0;



signed main(){
    scanf("%lld",&N);
    scanf("%s",S);
    if(N>=3200) printf("%s\n",S);
    else printf("red\n");
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <utility>
#include <sstream>
#include <numeric>
#include <iterator>

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
// #define ll long long
typedef long long ll;
typedef pair<int, int> P;



int main(int argc, const char * argv[]) {

  double n,d;
  cin >> n >> d;
  double mm = n/((d*2.0)+1.0);
  cout << ceil(mm) << endl;

  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 2000005
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vp vector<pii>
#define all(v) v.begin(),v.end()
#define lb(v,x) lower_bound(all(v),x)
#define ub(v,x) upper_bound(all(v),x)
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

ll mexp(ll a, ll b){
    ll ans=1;
    a%=MOD;
    while(b){
        if(b&1) ans=ans*a%MOD;
        b>>=1;
        a=a*a%MOD;
    }
    return ans;
}

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

const int N = 1005;

ll cnt[N][N];
bool a[N][N];

int main(){
    IOS
    
    int h,w;
    cin>>h>>w;
    FOR(i,1,h+1){
        FOR(j,1,w+1){
            char c;
            cin>>c;
            if(c=='.'){
                a[i][j]=1;
            }
            else{
                a[i][j]=0;
            }
        }
    }
    cnt[1][1]=1;
    FOR(i,1,h+1){
        FOR(j,1,w+1){
            if(a[i][j]==0){
                continue;
            }
            if(a[i][j-1] && a[i-1][j]){
                cnt[i][j]=(cnt[i][j-1]+cnt[i-1][j])%MOD;
            }
            else if(a[i][j-1]){
                cnt[i][j]=cnt[i][j-1];
            }
            else if(a[i-1][j]){
                cnt[i][j]=cnt[i-1][j];
            }
        }
    }
    cout<<cnt[h][w];
    cerr<<1.0/CLOCKS_PER_SEC<<endl;
    return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  char a,b;
  rep(i,5){a=0;b=0;
    cin>>a>>b;
    if(a==0)break;
    if(a!='h'||b!='i'){cout<<"No"<<endl;return 0;}
  }
  cout<<"Yes"<<endl;return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N  = 200010;
int c[N],d[N],a[N],n,m;
int main(){
	scanf("%d%d",&n,&m);
	for(int i = 1;i<=n;i++){
		int x;
		scanf("%d",&x);
		a[i] =x;
		c[x]++;
	}
	for(int i = 1;i<=n;i++){
		for(int j  = max(1,i-c[i]+1);j<=i;j++) d[j]++;
	}
	int ans =0;
	for(int i =1;i<=n;i++) if(d[i]==0) ans++;
	int x,y;
	//printf("%d %d\n",ans,d[2]);
	while(m--){
		scanf("%d%d",&x,&y);
		if(a[x]-c[a[x]]+1>0){
			d[a[x]-c[a[x]]+1]--;
			if(d[a[x]-c[a[x]]+1]==0) ans++;
		}
		c[a[x]]--;
		a[x] =y;
		c[y]++;
		//printf("YYY%d",ans);
		//printf("%d %d\n",y-c[y]+1,d[y-c[y]+1]);
		if(y-c[y]+1>0){
			d[y-c[y]+1]++;
			//printf("YYU\n");
			//printf("%d %d\n",y-c[y]+1,d[y-c[y]+1]);
			if(d[y-c[y]+1]==1) ans--; 
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
using namespace std;
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n, m[N][N];
int color[N], d[N], f[N], tt;
void dfs_visit(int u) {
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for (v = 0; v < n; v++) {
        if (m[u][v] == 0)continue;
        if (color[v] == WHITE) {
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}
void dfs() {
    int u;
    for (u = 0; u < n; u++)color[u] = WHITE;
    tt = 0;
    for (u = 0; u < n; u++) {
        if (color[u] == WHITE)dfs_visit(u);
    }
    for (u = 0; u < n; u++) {
        printf("%d %d %d\n", u + 1, d[u], f[u]);
    }
}
int main() {
    int u, v, k, i, j;
    cin >> n;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            m[i][j] = 0;
        }
    }
    for (i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (j = 0; j < k; j++) {
            cin >> v;
            v--;
            m[u][v] = 1;
        }
    }
    dfs();
    return 0;
}


Measured memory_bytes: 3224
#include <cstdio>
#define MOD 1000000007
#define INF 1e9
#define eps 1e-6
typedef long long ll;

ll x, y, xx, yy, inv[2000010], prod[2000010], ans;

int main(){

    scanf("%lld%lld", &x, &y);
    if((x + y) % 3){
        puts("0");
        return 0;
    }
    xx = x - (x + y) / 3;
    yy = y - (x + y) / 3;
    if(x < 0 || y < 0)
        puts("0");
    else{
        inv[0] = inv[1] = 1;
        for(ll i = 2; i <= (xx + yy); i++)
            inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
        for(ll i = 2; i <= (xx + yy); i++)
            inv[i] = inv[i - 1] * inv[i] % MOD;
        prod[0] = 1;
        for(ll i = 1; i <= (xx + yy); i++)
            prod[i] = prod[i - 1] * i % MOD;
        ans = prod[xx + yy] * inv[xx] % MOD * inv[yy] % MOD;
        printf("%lld\n", ans);
    }

    return 0;
}

Measured memory_bytes: 14464
n=int(input())
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
A=[a,b,c,d,e]
ans=0
if min(A)>=n:
    ans=5
else:
    if n%min(A)==0:
        ans=n//min(A)+4
    else:
        ans=n//min(A)+5
print(ans)

Measured memory_bytes: 3064
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define x first
#define y second

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

template <class T>
void read(T &x)
{
	char ch;
	for (ch=getchar();(ch<'0'||ch>'9')&&ch!='-';) ch=getchar();
	x=0;int t=1;if (ch=='-') {ch=getchar();t=-1;}
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	x*=t;
}

char s[10];

int main()
{
	#ifndef ONLINE_JUDGE
		//freopen("input.txt","r",stdin);
		//freopen("output.txt","w",stdout);
	#endif
	scanf("%s",s);
	int n=strlen(s);
	for (int i=0;i<n-1;i++) if (s[i]=='A'&&s[i+1]=='C') {puts("Yes");return 0;}
	puts("No");
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<vector>
#include <fstream>
#include<math.h>
#include <numeric>
#include<algorithm>

using namespace std;

int main(){
    int k,x;
    cin >> k >> x;
    if (x <= k*500){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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

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

  ll a, b;
  cin >> a >> b;
  cout << a * b << endl;
  return 0;
}


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

struct Card
{
	char suit;
	char value;
};

void bubble(vector<Card> &A,int N)
{
	for(int i=0;i<N;++i)
	{
		for(int j=N-1;j>=i+1;--j)
		{
			if(A[j].value<A[j-1].value)
			{
				Card t=A[j];
				A[j]=A[j-1];
				A[j-1]=t;
				
			}

		}
		
	}
}

void selection(vector<Card> &A,int N)
{
	for(int i=0;i<N;++i)
	{
		int min=i;
		for(int j=i+1;j<N;++j)
		{
			if(A[j].value<A[min].value)
			min=j;
		 } 
		if(min!=i)
		{
			Card temp=A[min];
			A[min]=A[i];
			A[i]=temp;
		}
	}
}


void print(vector<Card> A,int N)
{
	for(int i=0;i<N;++i)
	{
		if(i>0)
		cout<<" ";
		
		cout<<A[i].suit<<A[i].value;
	}
	cout<<endl;
}

bool compare(vector<Card> A,vector<Card> B,int N)
{
	for(int i=0;i<N;++i)
	{
		if(A[i].suit!=B[i].suit)
		{
			return false;
		}
	}
	return true;
}
int main ()
{
	int n;
	Card a;
	vector<Card> b1,b2;
	cin>>n;
	for(int i=0;i<n;++i)
	{
		cin>>a.suit>>a.value;
		b1.push_back(a); 
		b2.push_back(a);
	}
	
	
	
	bubble(b1,n) ;
	selection(b2,n);
	
	print(b1,n);
	cout<<"Stable"<<endl;
	print(b2,n);
	if(compare(b1,b2,n))
	{
		cout<<"Stable"<<endl;
	}
	else
	cout<<"Not stable"<<endl;
	
	return 0;
}


Measured memory_bytes: 3164
from sys import stdin
from collections import Counter
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
Q = int(stdin.readline().rstrip())
ans = sum(A)
cnt = Counter(A)

for i in range(Q):
    B,C = [int(x) for x in stdin.readline().rstrip().split()]
    cnt_b = cnt[B]
    cnt_c = cnt[C]
    if B <= C:
        ans += cnt_b*(C-B)
        print(ans)
    else:
        ans -= cnt_b*(B-C)
        print(ans)

    cnt[C] += cnt_b
    cnt[B] = 0

Measured memory_bytes: 23952
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoders {
	class Program {
		static void Main(string[] args) {
var row1 = retreiveIntArray();
			var row2 = retreiveIntArray();
			var row3 = retreiveIntArray();

			var inputCount = 3;

			// 不正な入力は処理しない
			if (row1.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			if (row2.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			if (row3.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}


			//列の正解を作る
			var col1 = new int[] { row1[0], row2[0], row3[0] };
			var col2 = new int[] { row1[1], row2[1], row3[1] };
			var col3 = new int[] { row1[2], row2[2], row3[2] };

			//斜めの正解を作る
			var diagonal1= new int[] { row1[0], row2[1], row3[2] };
			var diagonal2 = new int[] { row1[2], row2[1], row3[0] };


			var inputNums = retreiveInputNums();

			//ビンゴになる正解のあつまり
			int[][] bingos = { row1, row2,row3, col1, col2, col3, diagonal1, diagonal2 };

			var result = checkBingo(bingos, inputNums);

			//答えの出力
			var ans = result ? "Yes" : "No";
			Console.WriteLine(ans);

		}

		private static bool checkBingo(int[][] bingos,int[] inputnums) {

			foreach (var bingo in bingos) {
				var result = bingo.Select(n => inputnums.Contains(n)).All(t => t);
				//ビンゴになった時点で処理を止める
				if (result) {
					return true;
				}
			}

			return false;
		}


		/// <summary>
		/// 順番に与えられる数値を配列に格納する
		/// </summary>
		/// <returns></returns>
		private static int[] retreiveInputNums() {
			var N = int.Parse(Console.ReadLine());
			var inputNums = new int[N];
			for (int i = 0; i < N; i++) {
				inputNums[i] = int.Parse(Console.ReadLine());
			}

			return inputNums;
		} 

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray =  Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static int[] retreiveIntArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var intArray = inputArray.Select(s => int.Parse(s));
			return intArray.ToArray();
		}
	}
}



Measured memory_bytes: 13524
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	int N;
	vector<int> a;
	cin>>N;
	a.resize(N);
	rep(i,N) cin>>a[i];
	vector<int> b = a;
	sort(all(b));
	rep(i,N){
		if(a[i]<b[N/2]) cout<<b[N/2]<<endl;
		else cout<<b[N/2-1]<<endl;
	}
}


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

int main(){
  int N, sum;
  cin >> N;
  sum = 0;
  int M = N;

  while (true){
    sum += M % 10;
    M /= 10;
    if (M == 0){
      break;
    }
  }
  if (N % sum == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:

int main() {
  string s; cin >> s;
  int w; cin >> w;
  int count = w;
  string ans = "";
  for(int i = 0; i < s.length(); i++) {
    if(w == count) {
      ans.push_back(s[i]);
      count = 0;
    }
    count++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fore(x,a,b) for(int x=a, qwerty=b; x<qwerty; x++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define pb push_back
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fst first
#define snd second
#define mset(a,v) memset((a),(v),sizeof(a))
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
using namespace std;
typedef long long ll;
ll dp[512][512],sp[512][512],a[512],n;
int main(){FIN;
	cin>>n;
	fore(i,0,n)cin>>a[i];
	fore(i,0,n)fore(j,i,n){
		ll s=0;fore(k,i,j+1)s+=a[k];
		sp[i][j]=s;
	}
	fore(l,1,n){
		fore(i,0,n){
			int j=min(ll(i+l),n-1);
			if(i==j)continue;
			ll &r=dp[i][j];
			r=dp[i][i]+dp[i+1][j]+a[i]+sp[i+1][j];
			fore(k,i+1,j)r=min(r,dp[i][k]+dp[k+1][j]+sp[i][k]+sp[k+1][j]);
		}
	}
	cout<<dp[0][n-1]<<"\n";
}

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

int main()
{
	int n;
	cin>>n;
	string blue[n];
	
	for(int i=0; i<n; i++)
	{
		cin>>blue[i];
	}
	
	int m;
	cin>>m;
	string red[m];
	
	for(int i=0; i<m; i++)
	{
		cin>>red[i];
	}
	
	int ans=0;
	for(int i=0; i<n; i++)
	{
		string word=blue[i];
		int count=0;
		
		for(int j=0; j<n; j++)
		{
			if(blue[j]==word) count++;
		}
		   
		for(int j=0; j<m; j++)
		{
			if(red[j]==word) count--;
		}  
		
		ans=max(ans,count); 	
	}
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define BOOST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ll long long
#define test(t) ll t ; cin>>t ; while(t--)
ll mulmod(ll a, ll b, ll mod){ll res = 0;a = a % mod;while (b > 0){if (b % 2 == 1)res = (res + a) % mod;a = (a * 2) % mod;b /= 2;}return res % mod;}
ll n;
int main(){
	BOOST;
	cin >> n;
	ll arr[n];
	for(ll i = 0 ; i < n ; ++i){
		cin >> arr[i];
	}
	ll ans = 0;
	for(int i = 0 ; i < n ; ++i){
		ans += arr[i] - 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
H, W = map(int ,input().split())
ans = []
for i in range(1,H):
    a = W * i
    if W % 2 == 0:
        b = W//2 * (H-i)
        c = W//2 * (H-i)
    else:
        b = W//2 * (H-i)
        c = (W+1)//2 * (H-i)
    maxtmp = max(a, b, c)
    mintmp = min(a, b, c)
    tmp = maxtmp - mintmp
    ans.append(tmp)

for i in range(1,W):
    a = H * i
    if H % 2 == 0:
        b = H//2 * (W-i)
        c = H//2 * (W-i)
    else:
        b = H//2 * (W-i)
        c = (H+1)//2 * (W-i)
    maxtmp = max(a, b, c)
    mintmp = min(a, b, c)
    tmp = maxtmp - mintmp
    ans.append(tmp)

if W % 3 == 0:
    ans.append(0)
else:
    ans.append(H) 

if H % 3 == 0:
    ans.append(0)
else:
    ans.append(W)

ans = min(ans)
print(ans) 


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

const int N = 1e6 + 5;
ll factors[N];
void solve() {
	ll n;
	cin >> n;
	for (ll i = 1; i < n + 1; i++) {
		for (ll j = i; j < n + 1; j += i) {
			factors[j]++;
		}
	}
	ll ans = 0;
	for (ll c = 1; c < n; c++) {
		ans += factors[n - c];
		// ll z = (ll)sqrt(n-c);
		// if(z*z == )

	}
	cout << ans;

}


int main() {
	int ntc = 1;
	while (ntc--) {
		solve();
	}
}

Measured memory_bytes: 11420
N = int(input())
G = [[] for i in range(N)]
for v in range(N):
    for w, c in enumerate(map(int, input().split())):
        if c != -1:
            G[v].append((w, c))

from heapq import heappush, heappop, heapify
used = [0]*N
que = [(c, w) for w, c in G[0]]
used[0] = 1
heapify(que)

ans = 0
while que:
    cv, v = heappop(que)
    if used[v]:
        continue
    used[v] = 1
    ans += cv
    for w, c in G[v]:
        if used[w]:
            continue
        heappush(que, (c, w))
print(ans)



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

int main()
{
    int a, b, c, x, y, minCost;

    int cost = 0;

    cin >> a >> b >> c >> x >> y;

    if (a + b > c * 2)
    {
        minCost = c * 2;
    }
    else
    {
        minCost = a + b;
    }

    while (x > 0 && y > 0)
    {
        cost += minCost;
        x -= 1;
        y -= 1;
    }

    while (x > 0)
    {
        if (c * 2 < a)
        {
            cost += c * 2;
        }
        else
        {
            cost += a;
            x -= 1;
        }
    }
    while (y > 0)
    {
        if (c * 2 < b)
        {
            cost += c * 2;
            y -= 1;
        }
        else
        {
            cost += b;
            y -= 1;
        }
    }

    cout << cost;

    return 0;
}

Measured memory_bytes: 256
N , D = map(int , input().split())
X = [list(map( int , input().split())) for i in range(N)]

import numpy as np    

correct = 0

for i in range(N-1):
    for j in range(i+1 , N):
        x = np.array(X[i])
        y = np.array(X[j])
        z = sum(np.power((x - y), 2)) ** (1/2)
        
        if z % 1 == 0:
            correct += 1
    
print(correct)

Measured memory_bytes: 12508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
//const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
       return (a.first > b.first);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;


      cin>>n;

      ll ara[n+2],dp[n+2];

      dp[0]=dp[1]=0;

      ara[0]=0;

      for(i=1; i<=n; i++)
      {
          cin>>ara[i];

          if(i==2)
          {
              dp[i]=abs(ara[i]-ara[i-1]);
          }

          else if(i>2)
          {
        dp[i]=min(dp[i-1]+abs(ara[i-1]-ara[i]),dp[i-2]+abs(ara[i]-ara[i-2]));
          }
      }

      cout<<dp[n]<<endl;



}



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

//siringの式を計算する関数
int shiki(string &A){
  int ans=A[0]-'0';
  for(int i=1;i<A.size();i+=2){
    if(A[i]=='+')ans+=A[i+1]-'0';
    if(A[i]=='-')ans-=A[i+1]-'0';
  }
  return ans;
}
void ablepattern(int I,string N,string &K){
  if(N.size()==7){
    if(shiki(N)==7)K=N;
    return;
  }
  N=N.insert(I,"+");
  ablepattern(I+2,N,K);
  N=N.replace(I,1,"-");
  ablepattern(I+2,N,K);
  return;
}
  
   
int main() {
  int i,L=0,flag=1;
  string N;
  cin>>N;
  int I=1;
  string K;
  ablepattern(I,N,K);
  
  cout<<K<<"=7"<<endl;
}

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

int main() {
  long long int N;
  cin >> N;
  
  long long int ans = 1;
  for (long long int i = 1; i <= N; i++) {
    ans = (ans * i) % 1000000007;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let mut buf: String = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.trim().split_whitespace();
    let mut n: i32 = iter.next().unwrap().parse::<i32>().unwrap();
    let mut y: i32 = iter.next().unwrap().parse::<i32>().unwrap();

    let mut bill: [i32; 3] = [0; 3];
    let md: i32 = (y % 5000) / 1000;
    bill[0] += md;
    n -= md;
    y -= md * 1000;
    while y / 5000 < n {
        bill[0] += 5;
        n -= 5;
        y -= 5000;
        if n < 0 {
            println!("-1 -1 -1");
            return ();
        }
    }
    bill[2] = (y - 5000 * n) / 5000;
    bill[1] = n - bill[2];
    if bill[1] < 0 || bill[2] < 0 {
        println!("-1 -1 -1");
    } else {
        println!("{} {} {}", bill[2], bill[1], bill[0]);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define msp multiset < pair < long long , long long > > S;
#define pll pair<lli, lli>
#define mll map<lli, lli>            //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x) // also valid for set and multiset
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
lli n;
lli a[101],b[101];
lli dp[101][100001];
lli rec(lli i,lli w){
	if(w<0)return INT_MIN;
	if(i==n)return 0;
	//if(w<0)return INT_MIN;
	if(dp[i][w]!=-1)return dp[i][w];
	return dp[i][w]=(max(b[i]+rec(i+1,w-a[i]),rec(i+1,w)));
}


int main()
{
 //	ios::sync_with_stdio(0);
 //   cin.tie(0);
    lli w;
    cin>>n>>w;
    //memset(dp,-1,(n+1)*(w+1));
    for(lli i=0;i<=n;i++)for(lli j=0;j<=w;j++)dp[i][j]=-1;
	//loop(i,0,n)loop(j,0,w)cout<<dp[i][j]<<" ";
    for(lli i=0;i<n;i++)cin>>a[i]>>b[i];
	cout<<rec(0,w);
    return 0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int n;
    cin >> n;
    map <string, int> a;
    string b;
    a["AC"] = 0;
    a["WA"] = 0;
    a["TLE"] = 0;
    a["RE"] = 0;
    rep(i,0,n) {
        cin >> b;
        if (b == "AC") {
            a["AC"]++;

        } else if (b == "WA"){
            a["WA"]++;

        } else if (b == "TLE") {
            a["TLE"]++;

        } else {
            a["RE"]++;

        }
    }
    cout << "AC x " << a["AC"] << endl;
    cout << "WA x " << a["WA"] << endl;
    cout << "TLE x " << a["TLE"] << endl;
    cout << "RE x " << a["RE"] << endl;
}

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

namespace ConsoleApplication19
{
    class Program
    {
        static void Main(string[] args)
　　　　{
　　　　　　int a = int.Parse(Console.ReadLine());
　　　　　　int b =0;
　　　　　　if(a%10==1)
　　　　　　{
　　　　　　	b++;
　　　　　　	a=a-1;
　　　　　　}
　　　　　　if(a%100==10)
　　　　　　{
　　　　　　	b++;
　　　　　　	a=a-10;
　　　　　　}
　　　　　　if(a%1000==100)
　　　　　　{
　　　　　　	b++;
　　　　　　	a=a-100;
　　　　　　}
　　　　　　if(a%10000==1000)
　　　　　　{
　　　　　　	b++;
　　　　　　	a=a-1000;
　　　　　　}
　　　　　　if(a%100000==10000)
　　　　　　{
　　　　　　	b++;
　　　　　　	a=a-10000;
　　　　　　}
　　　　　　if(a%1000000==100000)
　　　　　　{
　　　　　　	b++;
　　　　　　}
　　　　　　Console.WriteLine(b);
　　　　　　        }
   }
}



Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    string s;
    cin >> n >> s;
    vector<int> l(n+1,0),r(n+1,0);
    rep(i,n) l[i+1] = l[i]+(s[i] == 'W');
    rrep(i,n) r[i] = r[i+1]+(s[i] == 'E');
    int ans = inf;
    rep(i,n) chmin(ans,l[i]+r[i+1]);
    cout << ans << endl;
}


Measured memory_bytes: 2964
n,m = map(int,input().split())
a = []
[a.append(list(map(int,input().split()))) for _ in range(n)]
a.sort(key=lambda x:x[0])
price, hon, max_hon = 0, 0, 0
for i in a:
    max_hon+=i[1]
    if max_hon > m:
        break
    else:
        price+=i[0]*i[1]
        hon+=i[1]
print(price + i[0]*(m - hon))

Measured memory_bytes: 28912
import java.util.*;
class Restraunt{
  private int id ;
  private String name ;
  private int score ;

  Restraunt(int id,String name,int score){
    this.id = id;
    this.name = name;
    this.score = score;
  }
  public int idget(){
    return this.id;
  }
  public String nameget(){
    return this.name;
  }
  public int scoreget(){
    return this.score;
  }
}

class Judge implements Comparator<Restraunt>{
  public int compare(Restraunt r1, Restraunt r2){
    int nam = r1.nameget().compareTo(r2.nameget());
    if(nam == 0){
      nam = -Integer.valueOf(r1.scoreget()).compareTo(Integer.valueOf(r2.scoreget()));
    }
    return nam;
  }
}

public class Main{

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();



    List<Restraunt> list = new ArrayList<Restraunt>();
    for(int i=0; i<n; i++){
      Restraunt r = new Restraunt(Integer.valueOf(i+1).intValue(),sc.next(),Integer.valueOf(sc.next()).intValue());
      list.add(r);
    }
    //for(Restraunt restraunt:list){
      //System.out.println("id:"+restraunt.idget()+" name:"+restraunt.nameget()+" score:"+restraunt.scoreget());
    //}
    Collections.sort(list,new Judge());
    for(Restraunt restraunt:list){
      System.out.println(restraunt.idget());
    }




  }
}

Measured memory_bytes: 21844
inf = float("inf")
N, M = map(int, input().split())
edges = []
for _ in range(M):
    a, b, c = map(int, input().split())
    edges.append((a - 1, b - 1, c))
d = [-inf] * N
d[0] = 0
for i in range(N):
    for a, b, c in edges:
        if d[b] < d[a] + c:
            d[b] = d[a] + c
for i in range(N):
    for a, b, c in edges:
        if d[b] < d[a] + c:
            d[b] = inf
print(d[N - 1])


Measured memory_bytes: 3316
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
const int dm = 1 << 21;
char dn[dm], * di = dn;

char S[100001], T[100001];

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


	int k = 0;
	while ((ct = getchar_unlocked()) >= 'A') {
		S[k + 1] = S[k] + ct - '@';
		if (S[k + 1] >= 3) S[k + 1] -= 3;
		k++;
	}
	k = 0;
	while ((ct = getchar_unlocked()) >= 'A') {
		T[k + 1] = T[k] + ct - '@';
		if (T[k + 1] >= 3) T[k + 1] -= 3;
		k++;
	}
	int Q = getint();
	rep(i, Q) {
		int a = getint() - 1;
		int b = getint();
		int c = getint() - 1;
		int d = getint();
		a = S[a] - S[b];
		if (a < 0) a += 3;
		c = T[c] - T[d];
		if (c < 0) c += 3;

		if (a != c) {
			*di++ = 'N';
			*di++ = 'O';
			*di++ = '\n';
		}
		else {
			*di++ = 'Y';
			*di++ = 'E';
			*di++ = 'S';
			*di++ = '\n';
		}
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>

void PrintRectangle(int Height, int Width)
{
    for(int i = 0; i < Height; ++i){
        for(int j = 0; j < Width; ++j){
            printf("#");
        }
        printf("\n");
    }
    printf("\n");
}

int main()
{
    while(1){
        int Height = 0;
        int Width = 0;
        scanf("%d %d", &Height, &Width);
        if(Height == 0 && Width == 0) return 0;
        PrintRectangle(Height, Width);
    }
    return 0;
}


Measured memory_bytes: 2596
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    char a, b;
    cin >> a >> b;
    if (a > b)
        cout << ">" << endl;
    else if (a < b)
        cout << "<" << endl;
    else
        cout << "=" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	string s;
	cin>>s;
	ll n = s.size();

	ll dp[2020][2];
	REP(i,0,2){
		REP(j,0,2020){
			dp[j][i] = 0;
		}
	}

   	dp[s[0]-'0'][0] = 1;
   	REP(i,0,2) dp[0][i] = 1;

   	ll curr = 1;
   	ll sum = 1;

   	REP(i,1,n){

   		REP(j,0,2019){
   			ll v = ((10*j + s[i] - '0') % 2019);
   			dp[v][curr] += dp[j][curr^1]; 
   		}
   		sum += dp[0][curr];

   		curr ^= 1;

   		REP(j,0,2019){
   			dp[j][curr] = 0;
   		}
   		dp[0][curr] = 1;
   	}
   	
   	cout<<sum - n<<endl;
	return 0;
}



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

/* #pragma */
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int GCD(int a,int b){return b?GCD(b,a%b):a;}
long long GCD(long long a, long long b){return b ? GCD(b, a%b) : a;}
int LCM(int a, int b){return a * b / GCD(a, b);}
long long LCM(long long a, long long b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
const int INF = 1001001001;
const long long LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const double EPS = 1e-9;
const int dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right

//#define int long long

//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//chcp 65001

signed main()
{
	int h, w; cin >> h >> w;
	vector<string> v(h);

	for(int i = 0, i_len = (int)h; i < i_len; ++i){
		cin >> v[i];
	}

	for(int i = 0, i_len = (int)h; i < i_len; ++i){
		for (int j = 0; j < w; ++j)
		{
			int cnt{};
			for (int k = 0; k < 8; ++k)
			{
				int x{};int y{};
				x = i+dx[k]; y = j+dy[k];
				if(0 > x || h <= x || 0 > y || w <= y)continue;
				if(v[x][y] == '#'){
					cnt++;
				}
			}
			if(v[i][j] != '#')cout << cnt;
			else cout << '#';
		}
		cout << endl;
		
	}
	return 0;
}

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

long long layers[51];
long long pat[51];
map<string, long long> M;

long long solve(long long a, long long b){
	//cout<<a<<" "<<b<<endl;
	
	if(b<=0){
		return 0;
	}else if(b==layers[a]){
		return pat[a];
	}else if(b>layers[a]){
		return pat[a]+1+solve(a, b-layers[a]-1);
	}else{
		return solve(a-1, b-1);
	}
}

int main(){
	pat[0]=1;
	layers[0]=1;
	for(int i=1;i<=50;i++){
		pat[i]=2*pat[i-1]+1;
		layers[i]=2*layers[i-1]+3;
	}
	long long n,x;
	cin>>n>>x;
	cout<<solve(n,x)<<endl;
	
}

Measured memory_bytes: 256
S = gets.chomp!.chars
ops = ['+', '-']
(1 << 3).times do |i|
  formula = "#{S[0]}#{ops[i >> 0 & 1]}#{S[1]}#{ops[i >> 1 & 1]}#{S[2]}#{ops[i >> 2 & 1]}#{S[3]}"
  ans = eval(formula)
  if ans == 7
    puts "#{formula}=7"
    break
  end
end

Measured memory_bytes: 14284
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n=1e5+20;
	vector<char> is_prime(n+1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= n; i++) {
	    if (is_prime[i] && (long long)i * i <= n) {
	        for (int j = i * i; j <= n; j += i)
	            is_prime[j] = false;
	    }
	}
	int x;
	cin >> x;
	for (; !is_prime[x]; x++);
	cout << x;
	return 0;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

if sum(a) < sum(b):
    print(-1)
    exit()
else:
    sub = []
    sub = [0 for i in range(n)]
    for i in range(n):
        sub[i] = a[i] - b[i]
    ans = 0
    sub.sort()
    pool = 0
    index = 0
    k = -1
    while sub[index] < 0:
        ans += 1
        while sub[index] + pool < 0:
            pool += sub[k]
            sub[k] = 0
            k -= 1
            ans += 1
        pool += sub[index]
        index += 1
print(ans)



Measured memory_bytes: 83888
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
l = LI()
ans = 0
for i in l:
    if i == 1:
        ans += 300000
    elif i == 2:
        ans += 200000
    elif i == 3:
        ans += 100000
if l[0] == l[1] == 1:
    ans += 400000
print(ans)

Measured memory_bytes: 4076
N, D = map(int, input().split())

S = []
for _ in range(N):
        data = list(map(int,input().split()))
        S.append(data)


res=0

for i in range(N):
        for j in range(i+1,N):
                dist=0
                for d in range(D):
                        dist += (S[i][d] - S[j][d])**2

                if (dist ** 0.5).is_integer():
                        res+=1


print(res)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int maxn=112345;
int h,w,n,a[maxn],b[maxn];
long long num[10];
set<pii> st,vis;
inline void add(int x,int y) {
    int cnt=0;
    for (int i=x-1;i<=x+1;++i)
        for (int j=y-1;j<=y+1;++j)
            if (st.find(pii(i,j))!=st.end())
                ++cnt;
    ++num[cnt];
}
int main()
{
    scanf("%d%d%d",&h,&w,&n);
    for (int i=1;i<=n;++i) {
        scanf("%d%d",&a[i],&b[i]);
        st.insert(pii(a[i],b[i]));
    }
    for (int i=1;i<=n;++i) {
        int x=a[i],y=b[i];
        for (int j=x-1;j<=x+1;++j)
            for (int k=y-1;k<=y+1;++k) {
                if (j<=1||j>=h||k<=1||k>=w) continue;
                if (vis.find(pii(j,k))!=vis.end()) continue;
                vis.insert(pii(j,k));
                add(j,k);
            }
    }
    int sum=0;
    for (int i=0;i<10;++i) sum+=num[i];
    num[0]+=1ll*(h-2)*(w-2)-sum;
    for (int i=0;i<10;++i)
        cout<<num[i]<<endl;
    return 0;
}


Measured memory_bytes: 51388
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())

x = abs(a-b)
if v == w:
    print("NO")
    exit()
tt = x / (v-w)

if t >= tt and tt > 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 9184
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

  int n, l;
  cin >> n >> l;
  int ans = 0, absmin = INF;
  reps(i, n){
    ans += l;
    if(abs(0, absmin) > abs(0, l)){
      absmin = l;
    }
    l ++;
  }
  cout << ans - absmin << '\n';
  return 0;
}


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

int n,m,slen,plen,comb1,comb2,num;
string str[20];
int s[10], id[30];
bool head[10];
vector<int> can,comb[6];
vector<int> pre[1<<10], suf[1<<10];
bool use[10];

void rec_pre(int d, int sum){
  if(d == plen){
    pre[comb1].push_back(sum);
    return;
  }

  for(int i=0;i<plen;i++){
    if(!use[i]){
      if(can[i] == 0 && head[d])continue;
      use[i] = true;
      rec_pre(d+1,sum + s[d] * can[i]);
      use[i] = false;
    } 
  }
}

void rec_suf(int d, int sum){
  if(d == slen){
    suf[comb1].push_back(sum);
    return;
  }
  
  for(int i=0;i<slen;i++){
    if(!use[i]){
      if(can[i] == 0 && head[d+plen])continue;
      use[i] = true;
      rec_suf(d+1,sum + s[d+plen] * can[i]);
      use[i] = false;
    } 
  }
}

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

  int lim = 1<<10;
  for(int i=1;i<6;i++){
    int tmp = (1<<i)-1;
    while(tmp < lim){
      comb[i].push_back(tmp);
      int x = tmp & -tmp, y = tmp + x;
      tmp = ( ( (tmp & ~y) /x ) >> 1) | y;
    }
  }

  while(cin >> n,n){
    vector<char> v;
    for(int i=0;i<n;i++){
      cin >> str[i];
      for(int j=0;j<str[i].size();j++){
	v.push_back(str[i][j]);
      }
    }

    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());

    m = v.size();
    for(int i=0;i<m;i++)id[v[i]-'A'] = i;

    for(int i=0;i<m;i++){
      s[i] = 0; head[i] = false;
    }

    for(int i=0;i<n;i++){
      if(str[i].size()>1)head[id[str[i][0]-'A']] = true;

      int tmp = (i==n-1?-1:1);
      for(int j=str[i].size()-1;j>=0;j--){
	s[id[str[i][j]-'A']] += tmp;
	tmp *= 10;
      }
    }

    if(m==1){
      if(s[0] == 0 && !head[0])cout << 1 << endl;
      else cout << 0 << endl;
      continue;
    }

    plen = m/2; slen = m-plen;
    for(int i=0;i<10;i++)use[i] = false;

    for(int i=0;i<comb[plen].size();i++){
      comb1 = comb[plen][i];
      pre[comb1].clear();

      can.clear();
      for(int j=0;j<10;j++){
	if( (comb1>>j)&1 )can.push_back(j);
      }
      rec_pre(0,0);
      sort(pre[comb1].begin(),pre[comb1].end());
    }
    
    for(int i=0;i<comb[slen].size();i++){
      comb1 = comb[slen][i];
      suf[comb1].clear();

      can.clear();
      for(int j=0;j<10;j++){
	if( (comb1>>j)&1 )can.push_back(j);
      }

      rec_suf(0,0);
      sort(suf[comb1].begin(),suf[comb1].end());
    }

    int ans = 0;
    for(int i=0;i<comb[plen].size();i++){
      for(int j=0;j<comb[slen].size();j++){
	comb1 = comb[plen][i]; comb2 = comb[slen][j];
	if(!(comb1&comb2)){
	  for(int k=0;k<pre[comb1].size();k++){
	    if(!k || (pre[comb1][k] != pre[comb1][k-1])){
	      num = upper_bound(suf[comb2].begin(),suf[comb2].end(),-pre[comb1][k])
		- lower_bound(suf[comb2].begin(),suf[comb2].end(),-pre[comb1][k]);
	    }
	    ans += num;
	  }
	}
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1624
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);




int main() {
    ll n,m;
    cin>>n>>m;
   priority_queue<ll> a;
    rep(i,n){
        ll b;
        cin>>b;
        a.push(b);
    }
    while(m>0){
        m--;
        ll k=a.top();
        a.pop();
        k=k/2;
        a.push(k);
    }
    ll ans=0;
    rep(i,n){
        ans+=a.top();
        a.pop();
    }
    cout<<ans<<endl;



    return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<string>
using namespace std;	
int main(){
	string s;
	cin >> s;
	int n=s.size()/2;
	int cnt=0,j=s.size()-1;
	for(int i=0;i<n;i++){
		if(s[i]!=s[j]) cnt++;
		j--;
	}
	cout << cnt << endl;
	return 0;
}	

Measured memory_bytes: 256
N = int(input())
L = [list(map(int, input().split())) for i in range(N)]

l = [[0, 0, 0]]
l.extend(L)

flag = True
for c in range(1, len(l)):
    dt = l[c][0] - l[c-1][0]
    dist = abs(l[c][1] - l[c-1][1]) + abs(l[c][2] - l[c-1][2])

    if dist > dt or (dist % 2) != (dt % 2):
        flag = False

print("Yes" if flag else "No")


Measured memory_bytes: 28020
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] In = Console.ReadLine().Split(' ');
            int a = int.Parse(In[0]);
            int b = int.Parse(In[1]);
            if ((a + b) % 2 == 0) Console.WriteLine((a + b) / 2);
            else Console.WriteLine("IMPOSSIBLE");
        }
    }
}


Measured memory_bytes: 27380
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long K,A,B;
    string ans = "NG";
    cin >> K >> A >> B;
    for (long long i = A; i<=B; ++i){
        cerr << i << ' ';
        if (i%K==0) ans = "OK";
    }
    cout << ans;
}


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

int main() {
  char c;
  cin >> c;

  if (c=='a'||c=='i'||c=='u'||c=='e'||c=='o') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
from collections import deque
INFTY = 1000
N = int(input())
S = [list(map(int,list(input()))) for _ in range(N)]
G = {i:[] for i in range(1,N+1)}
for i in range(N-1):
    for j in range(i+1,N):
        if S[i][j]==1:
            G[i+1].append(j+1)
            G[j+1].append(i+1)
heap = deque([(1,0)])
hist = [0 for _ in range(N+1)]
col = [-1 for _ in range(N+1)]
hist[1] = 1
col[1] = 0
flag = 0
while heap:
    x,c = heap.popleft()
    for y in G[x]:
        if hist[y]==0:
            col[y] = 1-c
            heap.append((y,1-c))
            hist[y]=1
        else:
            if col[y]!=1-c:
                flag = 1
                break
    if flag==1:break
if flag==1:
    print(-1)
else:
    dist = [[INFTY for _ in range(N+1)] for _ in range(N+1)]
    for i in range(N):
        for j in range(N):
            if i==j:
                dist[i+1][j+1]=0
            if S[i][j]==1:
                dist[i+1][j+1]=1
    for k in range(1,N+1):
        for i in range(1,N+1):
            for j in range(1,N+1):
                dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j])
    dmax = 0
    for i in range(1,N+1):
        for j in range(1,N+1):
            dmax = max(dmax,dist[i][j])
    print(dmax+1)

Measured memory_bytes: 75320
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s, x;
  cin >> s;
//  x = s/100 + (s/10 - s/100 * 10) + (s/1 - s/10 * 10);
  x = s - s/10 * 9 - s/100 * 9;
  cout << x << endl;
}

Measured memory_bytes: 3624