akhauriyash/Code-Regression huggingface dataset:
N = int(input())
As = list(map(int, input().split(" ")))
Bs = list(map(int, input().split(" ")))


res = 0
tmp = 0

for i in range(N):
	if As[i] >= (Bs[i] + tmp):
		res += Bs[i] + tmp
		tmp = 0
	else:
		res += As[i]		
		tmp = Bs[i] + min(0, tmp - As[i])

res += tmp if (As[N] - tmp) > 0 else As[N]

print(res)

Measured memory_bytes: 18624
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0,w=1;char ch=' ';
	while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
	if(ch=='-') w=-1,ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q*w;
}
const int N=200005,LIM=524290,inf=0x3f3f3f3f;
int n,V,m;
int bin[21],x[N],L[N],f[LIM],g[LIM],in[21][N],ans[N],mi[N];
vector<int> seg[21];

void prework() {
	seg[m].push_back(0);
	for(RI i=2;i<=n;++i)
		if(x[i]-x[i-1]>V) seg[m].push_back(i-1);
	seg[m].push_back(n);
	int now=1;
	for(RI i=1;i<seg[m].size();++i)
		while(now<=seg[m][i]) in[m][now]=i,++now;
}
void work1() {
	for(RI i=0;i<bin[m]-1;++i) {
		for(RI j=0;j<m;++j)
			if(!(i&bin[j]))
				f[i|bin[j]]=max(f[i|bin[j]],seg[j+1][in[j+1][f[i]+1]]);
	}
}
void work2() {
	for(RI i=0;i<bin[m];++i) g[i]=n+1;
	for(RI i=0;i<bin[m]-1;++i) {
		for(RI j=0;j<m;++j)
			if(!(i&bin[j]))
				g[i|bin[j]]=min(g[i|bin[j]],seg[j+1][in[j+1][g[i]-1]-1]+1);
	}
}
void work3() {
	for(RI i=0;i<=n;++i) mi[i]=inf;
	for(RI i=0;i<bin[m];++i)
		mi[f[i]]=min(mi[f[i]],g[(bin[m]-1)^i]);
	for(RI i=n-1;i>=0;--i) mi[i]=min(mi[i],mi[i+1]);
}

int main()
{
	n=read(),V=read();
	bin[0]=1;for(RI i=1;i<=20;++i) bin[i]=bin[i-1]<<1;
	for(RI i=1;i<=n;++i) x[i]=read();
	prework();while(V) V>>=1,++m,prework();
	work1(),work2(),work3();
	for(RI i=1;i<seg[0].size();++i) {
		int L=seg[0][i-1]+1,R=seg[0][i];
		if(mi[L-1]<=R+1) for(RI j=L;j<=R;++j) ans[j]=1;
	}
	for(RI i=1;i<=n;++i) puts(ans[i]?"Possible":"Impossible");
	return 0;
}

Measured memory_bytes: 26612
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define int ll
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
#define N 1000010
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
pii a[N]; deque<pii> q[N]; char c[N]; int s[N],ans[N];
signed main()
{	int n,m,tag=0; cin>>n; scanf("%s",c+1); cin>>m;
	for(rint i=1;i<=m;i++) scanf("%lld",&a[i].first),a[i].second=i;
	sort(a+1,a+m+1);
	for(rint i=1;i<=n;i++)
	{	for(rint j=1;j<=m;j++)
		if(!q[j].empty()&&i-q[j].front().first>=a[j].first)
		{	if(j!=m) q[j+1].push_back(q[j].front()),s[j+1]+=q[j].front().second;
			s[j]-=q[j].front().second; q[j].pop_front();
		}
		if(c[i]=='D') q[1].push_back(mp(i,tag)),s[1]+=tag;
		else if(c[i]=='M') tag++;
		else if(c[i]=='C')
		{	ll sum=0;
			for(rint j=1;j<=m;j++) sum+=tag*q[j].size()-s[j],ans[a[j].second]+=sum;
		}
	}
	for(rint i=1;i<=m;i++) cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 694656
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
 
typedef long long ll;
 
 
int main(){
	int n,k;
	cin >> n >> k;
	string s;
	cin >> s;
	
	ll res = 0;
	
	for(int i=1;i<n;++i){
		if(s[i-1] == s[i]) res++;
	}
	
	int fukou = n-1 -res;
	if(k*2 >= fukou){
		cout << n-1 <<endl;
	}else{
		res += k*2;
		cout << res <<endl;
	}
	return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define rep(I,N) for(int I = 0; I < (int)(N); I++)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 30)
typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
map<string, int> money;
map<string, vector<string> > LESP;
int solve(string make){
	vector<string> item = LESP[make];
	ll mini = INF;
	ll cost = 0;
	if(item.size() == 0)return money[make];
	rep(i, item.size()){
		if(!LESP[item[i]].empty()){
			//cout << "item" << endl;
			cost += min(money[item[i]], solve(item[i]));
		}else{
			cost += money[item[i]];
		}
	}
	return cost;
}

int main(void){
	int n, m;
	while(cin >> n, n){
		money.clear();
		LESP.clear();
		string MAKE;
		rep(i, n){
			string s;
			ll cost;
			cin >> s >> cost;
			money[s] = cost;
		}
		cin >> m;
		rep(i, m){
			string s;
			cin >> s;
			int num;
			cin >> num;
			vector<string> v;
			rep(j, num){
				string L;
				cin >> L;
				v.push_back(L);
			}
			LESP[s] = v;
		}
		cin >> MAKE;
		ll ans = min(money[MAKE], solve(MAKE));
		FIN(ans);

	}


	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}
/*
8
wood 3000000
string 800
rice 36
water 10
racket 5000
microphone 9800
onigiri 140
guitar 98000
3
racket 2 wood string
onigiri 2 rice water
guitar 3 racket microphone onigiri
guitar
*/

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

int main() {
  ll M = 0;
  cin >> M;
  vector<int>A(M);
  rep(i,M){
    cin >> A[i];
  }
  ll count = 0;
  if(M == 2){
    cout << "YES";
    return 0;
  }
  rep(i,M){
    if(A[i] != i + 1){
      count++;
    }
  }
  if(count == 0 || count == 2){
    cout << "YES";
  }
  else{
    cout << "NO";
  }
}
    

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

struct Data{
	bool val;
	int pos;
};

bool expression(const string&,int);
Data clause(const string&,int);
Data lite(const string&,int);
Data variable(const string&,int);

bool expression(const string& str,int pos){
	Data d;
	bool res = false;

	if(str[pos] == '('){
		d = clause(str,pos+1);
		pos = d.pos + 1;
		res |= d.val;
	}

	if(pos == str.size()) return res;

	if(str.substr(pos,2) == "|("){
		res |= expression(str,pos+1);
	}

	return res;
}

Data clause(const string& str,int pos){
	Data res;
	Data d1 = lite(str,pos);
	res.val = d1.val;

	pos = d1.pos;
	while(str[pos] == '&'){
		Data d2 = lite(str,pos+1);
		pos = d2.pos;
		res.val &= d2.val;
		res.pos = d2.pos;
	}

	return res;
}

Data lite(const string& str,int pos){

	if(str[pos]=='~'){
		Data d = variable(str,pos+1);
		d.val = !d.val;
		return d;
	}
	else{
		Data d = variable(str,pos);
		return d;
	}
}

Data variable(const string& str,int pos){
	Data d;
	d.pos = pos;
	d.val = 0;
	if(isdigit(str[pos])){
		Data d;
		d.pos = pos+1;
		d.val = (str[pos]-'0' == 1) ? true : false;
		return d;
	}
}

vector<string> split(string delim,string str){
	vector<string> res;
	str += delim;
	for(int i=0;i<str.size();i++){
		for(int j=1;i+j<=str.size();j++){
			if(str.substr(i,j).find(delim) != string::npos){
				string tmp = str.substr(i,j-1);
				if(str.substr(i,j-1).size() >0 ) res.push_back(tmp);
				i+=j-1;
				break;
			}
		}
	}

	return res;
}

int main(){
	string str;
	while(cin >> str){
		if(str == "#") break;

		vector<string> clause = split("|",str);

		bool isok = false;
		for(int i=0;i<clause.size();i++){
			string tmp = clause[i];

			map<char,int> alpha;
			int idx = 0;
			for(int j=0;j<tmp.size();j++){
				if(isalpha(tmp[j]) && alpha.find(tmp[j]) == alpha.end()){
					alpha[tmp[j]]=idx++;
				}
			}

			int size = alpha.size();

			for(int S=0;S<=(1<<size)-1;S++){
				int val[3];
				for(int j=0;j<size;j++){
					val[j] = (S >> j) & 1;
				}

				for(int j=0;j<clause[i].size();j++){				
					if(isalpha(clause[i][j])){
						tmp[j] = val[alpha[clause[i][j]]] + '0';
					}
				}

				if(expression(tmp,0)){
					isok = true;
					break;
				}
			}
		}

		printf("%s\n",isok ? "yes" : "no");

	}
}

Measured memory_bytes: 1188
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
#include <random>
#include <ctime>
#include <chrono>

using namespace std;

long long t, n, m, u, v, q, k, p;
const int N = 1e6 + 1e5 + 500;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;

long long arr[N];
bool mark[N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  cin >> n;
  long long sol = 0;
  
  for (int i = 1; i <= n; ++i) {
    cin >> v;
    arr[v]++;
    mark[v] = true;
  }
  
  for (int i = 1; i < N; ++i) {
    if (arr[i] >= 2) mark[i] = false;
    if (arr[i] == 0) continue;
    for (int j = 2 * i; j < N; j += i) mark[j] = false;
  }
  
  for (int i = 1; i < N; ++i) if (mark[i]) sol++;
  cout << sol << endl;
  
}





















Measured memory_bytes: 12500
#include <iostream>
using namespace std;
int main(void){
    int n,i;
    int t[110000], x[110000], y[110000];
    cin>>n;
    t[0]=x[0]=y[0]=0;
    for (int i = 0; i < n; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];
    bool can = true;
    for(i=0;i<n;i++){
        int dt = t[i+1]-t[i];
        int dist= abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
        if(dt<dist) can= false;
        if(dist%2!=dt%2) can = false;
    }
    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

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

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

int main(){
    long long n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;

    long long ans = 0;

    for(long long i = 0; i < n; i++){
        if(a[i] == b[i] and b[i] == c[i] and c[i] == a[i]) continue;
        else if(a[i] != b[i] and b[i] != c[i] and c[i] != a[i]) ans += 2;
        else if(a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) ans++;
    }

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

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

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

    int n, a, b;
    cin >> n >> a >> b;
    int p = n * a;
    if (p == b) {
        cout << b;
    } else if (p < b) {
        cout << p;
    } else {
        cout << b;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N; cin >> N;
    vector<int> a(N);
    REP(i,N) cin >> a[i];
    int now = 0;
    REP(i,N) {
        if (a[i]==now+1) now++;
    }
    cout << (now==0?-1:N-now) << endl;
    return 0;
}

Measured memory_bytes: 1152
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = getLine >> readInts >>= putStrLn . which "APPROVED" "DENIED" . all f

f x = odd x || x `mod` 3 == 0 || x `mod` 5 == 0

Measured memory_bytes: 508
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,k,s
    integer(int32), allocatable:: ans(:)

    read*, n,k,s
    allocate(ans(n))
    ans(:) = 1000000000
    if (s == 1000000000) ans(:) = 999999999
    ans(1:k) = s
    print*, ans(:)
end program name

Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,n) for(lli i=0;i<n;i++)
#define repb(i,n) for(lli i=n-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
#define all(X) X.begin(),X.end()
#define iterate(X) for(it=X.begin();it!=X.end();it++)
lli combi(lli n,lli k)
{
    lli ans=1;
    k=k>n-k?n-k:k;
    lli j=1;
    for(;j<=k;j++,n--)
    {
        if(n%j==0)
        {
            ans*=n/j;
        }else
        if(ans%j==0)
        {
            ans=ans/j*n;
        }else
        {
            ans=(ans*n)/j;
        }
    }
    return ans;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli findlcm(vector <lli> arr, lli n)
{
    lli ans = arr[0];
    for (lli i = 1; i < n; i++)
        ans = (((arr[i] * ans)) /
                (gcd(arr[i], ans)));

    return ans;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n,l;
    cin>>n>>l;
    vector <pair<lli,lli> > arr;
    lli sum=0;
    rep(i,n){
    	arr.pb(mp(abs(l+i),i));
    	sum+=(l+i);
	}
	sort(all(arr));
	cout<<sum-(l+arr[0].sc);
    return 0;
}


Measured memory_bytes: 256
while (line = gets)
  a, b, c, d, e, f = line.chop.split(/\s+/).map { |s| s.to_f }
  #puts a, b, c, d, e, f

  if (a != 0)
    b /= a
    c /= a
    e -= d * b
    f -= d * c
    y = f / e
    x = c - b * y
  else
    y = c / b
    x = (f - e * y) / d
  end

  printf("%.3f %.3f\n", x, y)
end

Measured memory_bytes: 6144
#include <iostream>
#include <cstdlib>
using namespace std;
const int inf=1e9+5;
int main()
{
    int n,k,a[100005],dp[100005];
    cin >> n >> k;
    for (int i=1;i<=n;i++)
    {
        cin >> a[i];
        dp[i]=inf;
    }
    dp[1]=0;
    for (int i=1;i<=n;i++)
    {
        for (int j=i+1;j<=i+k && j<=n;j++)
        {
            dp[j]=min(dp[i]+abs(a[j]-a[i]),dp[j]);
        }
    }
    cout << dp[n];
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
//ABC swap
int main(){
    int a,b,c,tmp;
    cin>>a>>b>>c;
    tmp=a;
    a=b;
    b=tmp;
    tmp=a;
    a=c;
    c=tmp;
    cout<<a<<' '<<b<<' '<<c<<endl;
}


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


/* エイリアス */
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define endl '\n'

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define em emplace


/* 関数マクロ */
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n, m) for (ll i = n; i <= m; ++i)
#define rep3(i, n, m) for (ll i = n; i >= m; --i)
#define all(v) v.begin(), v.end()
#define si(v) int(v.size())
#define UNIQUE(v) sort(all(v)), v.erase(unique(all(v)),v.end())


/* 定数 */
const ll mod = 1e9 + 7;
const ll infll = (1LL << 62) - 1;
const ll inf = (1LL << 30) - 1;


/* その他 */
template<class S, class T> inline bool chmax(S &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class S, class T> inline bool chmin(S &a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> using pq = priority_queue<T>;
template<class T> using pqg = priority_queue<T, vector<T>, greater<T>>;


signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);
  
  ll a, b, c, k; cin >> a >> b >> c >> k;
  if (k <= a) cout << k << endl;
  else if (k <= a + b) cout << a << endl;
  else if (k <= a + b + c) cout << a - (k - (a + b)) << endl;
}

Measured memory_bytes: 3596
#include<iostream>
#define FOR(i,a,b) for(int i=(a);i<(b);++i) 
#define REP(i,n) FOR(i,0,n)
#define EACH(x,a) for(auto& (x):(a))
#define ALL(obj) (obj).begin(),(obj).end()
#define Yes(n) cout<<((n)?"Yes":"No")<<endl;
using namespace std;
using ll=long long;
const int INF=1e9;
const ll LINF=1e18;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  int A, B, C; cin>>A>>B>>C;

  if(B>A*C) cout<<C<<endl;
  else cout<<B/A<<endl;
  return 0;
}


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

using namespace std;

using ll = long long;

const int MAXV = 200000;

// 1 3 1 2 3 2 3

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll K;
    cin >> n >> K;
    vector<int> a(n);
    vector<int> conv(n, -1);
    vector<int> prv(MAXV + 1, -1);
    vector<int> fst(MAXV + 1, -1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (prv[a[i]] == -1) {
            prv[a[i]] = i;
            fst[a[i]] = i;
        } else {
            conv[prv[a[i]]] = i + 1 - prv[a[i]];
            prv[a[i]] = i;
        }
    }

    if (n == 1) {
        if (K % 2 == 1) cout << a[0] << "\n";
        return 0;
    }

    for (int i = 1; i <= MAXV; i++) {
        if (fst[i] == -1) continue;
        conv[prv[i]] = fst[i] + n + 1 - prv[i];
    }

    ll cur = 0;
    ll cycle = 0;
    while (true) {
        ll nex = cur + conv[cur % n];
        if (nex > n * K) break;
        cur = nex;
        if (cur % n == 0) {
            cycle = cur / n;
            break;
        }
    }

    if (cycle > 0) K %= cycle;

    cur = 0;
    while (true) {
        ll nex = cur + conv[cur % n];
        if (nex > n * K) {
            cur %= n;
            break;
        }
        if (nex == n * K) {
            cur = n;
            break;
        }
        cur = nex;
    }

    vector<int> ans;
    vector<int> cnt(MAXV + 1, 0);
    for (int i = cur; i < n; i++) {
        if (cnt[a[i]]) {
            while (cnt[a[i]]) {
                cnt[ans.back()]--;
                ans.pop_back();
            }
        } else {
            ans.push_back(a[i]);
            cnt[a[i]]++;
        }
    }

    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << " \n"[i + 1 == ans.size()];
    }
    return 0;
}

Measured memory_bytes: 6388
s=input()
k=int(input())
if s[0]!="1":
    print(s[0])
else:
    cnt=0
    for i in range(len(s)):
        if s[i]=="1":
            cnt+=1
        else:
            break
    if cnt>=k:
        print(1)
    else:
        print(s[cnt])

Measured memory_bytes: 61852
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

struct Team{
  string name;
  int win,lose,drow,score,zyun;
};

int main(){
  int i,j,n,max,k,c=0,z;
  Team t[11],tmp;
  while(1){
    cin >> n;
    if(n == 0) break;

    if(c != 0) cout << endl;
    c = 1;

    for(i=0;i<n;i++){
      cin >> t[i].name >> t[i].win >> t[i].lose >> t[i].drow;
      t[i].score = t[i].win * 3 + t[i].drow;
      t[i].zyun = i;
    }

    for(i=0;i<n;i++){
      max = t[i].score;
      for(j=i;j<n;j++){
	if(max < t[j].score) max = t[j].score;
      }
      z = n;
      for(j=i;j<n;j++){
	if(max == t[j].score && z > t[j].zyun){
	  z = t[j].zyun;
	  k = j;
	}
      }
      tmp = t[k];
      t[k] = t[i];
      t[i] = tmp;
    }

    for(i=0;i<n;i++) cout << t[i].name << "," << t[i].score << endl;

  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <bitset>
#include <fstream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#define Debug 0
//#include <boost/multiprecision/cpp_int.hpp>

const double EPS = (1e-10);


using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const Int MOD = 1000000007;

Int mod_pow(Int x, Int n) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % MOD; //ビット演算(最下位ビットが1のとき)
        x = (x * x) % MOD;
        n >>= 1; //右シフト(n = n >> 1)
    }
    return res;
}

//最大公約数
template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

//最小公倍数
template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int a[101];

int main(){
    int tmp;
    while (cin >> tmp) {
        a[tmp]++;
    }
    int ma = -1;
    for (int i = 1; i <= 100; i++) {
        ma = max(ma, a[i]);
    }
    vector<int> ans;
    for (int i = 1; i <= 100; i++) {
        if (ma == a[i]) ans.push_back(i);
    }
    for (auto i: ans) {
        cout << i << endl;
    }
}




Measured memory_bytes: 3136
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

struct UnionFind {
    vector<int> par, w;
    
    UnionFind(int n) : par(n, -1), w(n, 0) { }
    void init(int n) { par.assign(n, -1); w.assign(n, 0); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) {
            ++w[x];
            return false;
        }
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        w[x] += w[y];
        ++w[x];
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
 
    int wei(int x) {
        return w[root(x)];
    }
};

void solve() {
	int n, m; cin >> n >> m;
    vector<bool> po(n, 0);
    vector<int> cnt(n, 1);
    po[0] = 1;
    rep(i, m) {
        int x, y; cin >> x >> y;
        -- x; -- y;
        cnt[x] --;
        cnt[y] ++;
        if(po[x]) {
            po[y] = 1;
            if(cnt[x] == 0) {
                po[x] = 0;
            }
        }
    }
    int ans = 0;
    rep(i, n) {
        if(po[i]) ++ ans;
    }
    cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

int n,ans,mm;
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)	{
		int x;
		cin >> x;
		ans += x;
		mm = max(mm,x);
	}
	cout << ans - mm / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class AAlready2018 {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    string s;
	    in >> s;
	    out << "2018" << s.substr(4, s.length()) << endl;
	}
};


int main() {
	AAlready2018 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
import sys

n, *p = map(int, sys.stdin.read().split())

def main():
    mi = float('inf')
    res = 0
    for i in range(n):
        if p[i] <= mi:
            res += 1
            mi = p[i]
    return res

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 25116
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if(n == 1){
        cout << "Hello World\n";
    }else{
        int a,b;
        cin >> a >> b;
        cout << a+b << "\n";
    }
    return 0;
}


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

struct rect{
    int h, w;
    rect(int h, int w) : h(h), w(w) {}
    bool operator <(const rect other) const{
        if(h*h + w*w == other.h*other.h+other.w*other.w){
            return h < other.h;
        }else{
            return h*h+w*w < other.h*other.h+other.w*other.w;
        }
    }
};

int main(){
    int H, W;
    while(cin >> H >> W, H+W){
        rect base(H, W);
        rect ans(300,300);
        for(int h = 1; h <= 150; h++){
            for(int w = h+1; w <= 150; w++){
                if(h == H && w == W)    continue;
                rect now(h,w);
                if(base < now && now < ans) ans = now;
            }
        }
        cout << ans.h << " " << ans.w << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int a[100005],b[100005],c[100005];
int n;
long long ans=0;
int main() {
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  sort(a,a+n);
  for(int i=0; i<n; i++) {
    cin >> b[i];
  }
  for(int i=0; i<n; i++) {
    cin >> c[i];
  }
  sort(c,c+n);
  for(int i=0; i<n; i++) {
    int aa=lower_bound(a,a+n,b[i])-a;
    int cc=upper_bound(c,c+n,b[i])-c;
    cc=n-cc;
    ans+=(long long)aa*cc;
  }
  cout << ans << endl;
}


Measured memory_bytes: 1408
import sys
input = sys.stdin.readline
H,W=map(int,input().split())
s=[]
s.append("".join("#" for _ in range(W+2)))
cnt=0
for i in range(H):
    ss=input().strip()
    s.append("#"+ss+"#")
    for w in range(W):
        if ss[w]==".":
            cnt+=1

s.append("".join("#" for _ in range(W+2)))
#print(s)
import sys
sys.setrecursionlimit(300000)
def solv(h,w,cnt):
    #print(h,w)
    #print(a)
    #print(s)
    if a[h][w]>cnt+1 and s[h][w]==".":
        a[h][w]=cnt+1
        solv(h-1,w,cnt+1)
        solv(h,w-1,cnt+1)
        solv(h+1,w,cnt+1)
        solv(h,w+1,cnt+1)
    return

a=[[1000000]*(W+2) for _ in range(H+2)]
solv(1,1,0)
print(cnt-a[-2][-2] if a[-2][-2]!= 1000000 else -1)


Measured memory_bytes: 5108
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>

#define int long long
#define double long double
#define incin(n) int (n); cin >> (n)
#define uniq(v) sort((v).begin(),(v).end()); (v).erase(unique((v).begin(),(v).end()),(v).end());
#define steprap(i,n,s) for(int (i)=0;i<(s)*(n);(i)+=(s))
#define rap(i,n) steprap((i),(n),1)

using intV = std::vector<int>;

using namespace std;
namespace math
{
	double PI = 3.14159265359;
	int step(int n);
	int ncr(int n,int r);
	int npr(int n,int r);
	int gcm(int a,int b);
	int lcm(int a,int b);

	int step(int n){
		if(n<=1){
			return 1;
		}else{
			return n * step(n-1);
		}
	}
	int ncr(int n,int r){
		for(int i=1;i<r;i++){
			n *= n-i;
		}
		for(int i=1;i<r;i++){
			r *= r-1;
		}
		return n/r;
	}
	int npr(int n,int r){
		for (int i = 1; i < r; ++i)
		{
			n *= n-1;
		}
		return n;
	}
	int gcm(int a,int b){
		int p=max(a,b);
		int q=min(a,b);
		int r;
		while(true){
			if(p%q==0){
				return q;
			}
			r = p%q;
			p=q;
			q=r;
		}
	}
}

using namespace std;
// using StringMap = std::vector<std::vector<char>> map(h+2,vector<char>(w+2,'#'));
namespace tmp {
    template <typename T> bool inArry(T x,vector<T> v);
    template <typename T> void input(int n,vector<T> &v);

    template <typename T> bool inArry(T x,vector<T> v){
        int l = v.size();
        for(int i=0;i<l;i++){
            if(x==v[i]){
                return true;
            }
        }
        return false;
    }
    
    template <typename T> void input(int n,vector<T> &v){
        for(int i=0;i<n;i++){
            cin >> v.at(i);
        }
    }
}

using namespace std;

signed main (){
	int n,k,x,y;
	cin >> n>>k>>x>>y;
	if(k<n){
		cout<<x*k+y*(n-k)<<endl;
	}else{
		cout<<x*n<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#!python3

import sys

def resolve():
    N = int(input())
    C = sys.stdin.readline().strip()

    ans = 0
    R = [0] * N
    W = [0] * N

    if C[0] == "W":
        W[0] += 1
    else:
        R[0] += 1

    for i in range(1, N):
        W[i] += W[i-1] + (1 if C[i] == "W" else 0)
        R[i] += R[i-1] + (1 if C[i] == "R" else 0)

    if W[-1] == 0 or R[-1] == 0:
        print(0)
        return

    print(W[R[-1]-1])

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 71064
/* ex4_2: Colon
    Jun_JPN */

#include <stdio.h>
#include <math.h>

int main(void){

    long double s_hand, l_hand, hour, min, rad, length;

    scanf("%Lf %Lf %Lf %Lf", &s_hand, &l_hand, &hour, &min);

    /* 長針と短針のなす角radを計算
        0時方向ベクトルと長針がなす偏角theta1は(min/60)*2*M_PI
        0時方向ベクトルと短針がなす偏角theta2は(hour/12)*2*M_PI + (min/60)*(1/12)*2*M_PI
        よって，rad = |theta1-theta2|である */
    rad = (60*hour - 11*min)/360 * M_PI;    //負の数をとっても良い

    /* 余弦定理で求める長さlengthを計算
        なす角の大きさが0，M_PIラジアンのときも余弦定理の式は成り立つ
        rad<0でも余弦定理の式は成り立つ */

    length = sqrt(l_hand*l_hand + s_hand*s_hand - 2*l_hand*s_hand*cos(rad));

    printf("%.20Lf\n", length);

    return 0;
}

Measured memory_bytes: 2588
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define EN() PRS("");
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int main(void){
  int n,m,a,sum;
  while(1){
    sum=0;
    scanf("%d %d",&n,&m);
    if(n+m<1)return 0;
    FOR(n){
      scanf("%d",&a);
      sum+=min(a,m/n);
    }
    PRN(sum);
  }
  return 0;
}



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

int main()
{
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    reverse(t.begin(), t.end());
    cout << (s < t ? "Yes" : "No") << "\n";
    return 0;
}

Measured memory_bytes: 256
import numpy as np
a,b,k=map(int,input().split())
n=list(map(int,input().split()))
m=list(map(int,input().split()))
n.insert(0,0)
m.insert(0,0)
n=np.array(n)
m=np.array(m)
n=n.cumsum()
m=m.cumsum()
ans=0
j=len(m)-1
for i in range(len(n)):
    if n[i]>k:
        break
    while m[j]>k-n[i]:
        j-=1
    ans=max(ans,i+j)
print(ans)

Measured memory_bytes: 58744
#include <bits/stdc++.h>
#define ll long long int
#include<list>
#include<algorithm>
#define ld long double
#define pb push_back
#define FF first
#define SS second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repr(a,b,c) for(a=b-1;a>=c;a--)
#define PLL pair<ll, ll>
#define inf 100000001
#define mod 1000000007
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define PQ priority_queue
#define rep1 for(i=1;i<=n;i++)
#define VLL vector<ll>
#define EF else if
const double pi  =3.141592653589793238463;
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(), A.end());
#define REVERSE(A) reverse(A.begin(), A.end());
#define UMP unordered_map
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define test4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define test5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define test6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
using namespace std;
/*
    //string with spaces
    std::string str;
    std::getline(std::cin >> std::ws, str);
*/
ll myXOR(unsigned long long int x, unsigned long long int y)
{
    return (x|y)&(~x|~y);   
}
ll powerLL(ll x, ll n) 
{ 
    ll result = 1; 
    while (n) { 
        if (n & 1) 
            result = result * x % mod; 
        n = n / 2; 
        x = x * x % mod; 
    }
    return result; 
}
ll findMaxGCD(ll arr[], ll n) 
{ 
    ll high = 0; 
    for (ll i = 0; i < n; i++) 
        high = max(high, arr[i]); 
  
    ll count[high + 1] = {0}; 
    for (ll i = 0; i < n; i++) 
        count[arr[i]]++; 
  
    ll counter = 0; 
    ll res = -1;
    for (ll i = high; i >= 1; i--) 
    { 
        ll j = i; 
        counter = 0; 
        while (j <= high) 
        { 
            if(count[j] >=2) {
               res = j; 
               break; 
            }
            else if (count[j] == 1){
                counter++;          
            }
            j += i; 
            if (counter == 2){
                res = i;
                break; 
            }
        } 
        if(res!=-1) break;
    }
    return res;
} 
int main()
{
    fastio
    ll a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r, t,u,w,x,y,z;
    string str, ss, str1;
    cin>>n;
    ll arr[n];
    rep(i,0,n){
        cin>>arr[i];
    }
    ll gcd = findMaxGCD(arr, n);
    // test1(gcd);
    if(gcd==1) cout<<"pairwise coprime";
    else{
        gcd = arr[0];
        rep(i,1,n){
            gcd = __gcd(arr[i], gcd);
        }
        if(gcd==1) cout<<"setwise coprime";
        else cout<<"not coprime";
    }
}

Measured memory_bytes: 19228
#include <stdio.h>

int main(void){
  long long n;
  scanf("%lld",&n);
  
  long long a[n+1];
  long long b[n];
  
  for(int i = 0;i<n+1;i++){
    scanf("%lld",&a[i]);
  }
  for(int j = 0;j<n;j++){
    scanf("%lld",&b[j]);
  }
  long long s=0;
  for(int m = n-1;m>=0;m--){
    if(a[m+1] >b[m]){
      s = s+b[m]; 
      b[m] = 0;
    }else{
      s = s+a[m+1];
      b[m] = b[m]-a[m+1];
    }
    if(b[m]>0){
      if(b[m]>a[m]){
        s = s+a[m];
        a[m] = 0;
      }else{
        s = s +b[m];
        a[m] = a[m]-b[m];
      }
    }//ifbm
  }//for
  printf("%lld\n",s);
  
  return 0;
}
      


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define INF 100000000
typedef long long ll;

int main(){
    ll a,b;
    cin>>a>>b;
    if((a*b)%2==0)cout<<"Even";
    else cout<<"Odd";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i,n) cin >> a[i];

  vector<int> sell;
  vector<int> buy;
  bool hold = false;

  REP(i,n-1){
    if(hold){
      if(a[i] > a[i+1] ){
        sell.push_back(a[i]);
        hold = false;
      }
    }

    if(!hold){
      if(a[i] < a[i + 1]){
        buy.push_back(a[i]);
        hold = true;
      }
    }
  }

  if(buy.empty()){
    cout << 1000 << endl;
    return 0;
  }

  if(sell.size() != buy.size()){
    sell.push_back(a[n-1]);
  }

  //
  // for(auto x: buy) cout << x << " ";
  // cout << endl;
  //
  // for(auto x: sell) cout << x <<" ";
  // cout <<  endl;



  ll sum = 1000;
  ll nmb = 0;
  
  REP(i,sell.size()){
    nmb =  sum/buy[i];
    sum %= buy[i];
    //sell
    sum += nmb*sell[i];
    nmb = 0;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  string M;
  cin >> H >> W;
  
  vector<string> edge(W+2, "#");
  for(int i=0; i<W+2; i++){
    cout << edge.at(i);
  }
  cout << endl;
  
  for(int i=0; i<H; i++){
    cout << "#";
    cin >> M;
    cout << M;
    cout << "#" <<endl;
  }
  
  for(int i=0; i<W+2; i++){
    cout << edge.at(i);
  }
  cout << endl;
}

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

#define precise(n,k) fixed<<setprecision(k)<<n

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

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

    int n ;
    

    cin >> n;

    if(n <= 999) {
        cout << "ABC"<<endl;
    } else {
        cout << "ABD" << endl;
    }
   
 
   return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  ll a,b; cin >> a >> b;
  cout << max(0LL, a-b) << endl;
}


Measured memory_bytes: 384
fun main(args: Array<String>) {
  val N = readLine()!!.toInt()
  var ans = "No"
  for (i in 1..9) {
    if (N%i == 0) {
      if (1 <= N/i && N/i <= 9) {
         ans = "Yes"
      }
    }
  }
  println(ans)
}

Measured memory_bytes: 31776
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto c1 = readln.chomp;
    auto c2 = readln.chomp;
    writeln(c1[0] == c2[2] && c1[1] == c2[1] && c1[2] == c2[0] ? "YES" : "NO");
}

Measured memory_bytes: 256
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

A, B, C, D = map(int, input().split())

CD = C*D//gcd(C, D)

count1 = (B // C - A // C)
count2 = (B // D - A // D)
count3 = (B // CD - A // CD)

if A % C == 0:
    count1 += 1

if A % D == 0:
    count2 += 1

if A % CD == 0:
    count3 += 1 

print(B - A + 1 - ((count1 + count2) - count3))


Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
int a,b,zu[1001],dis[1001],ans,n,cou;
int main(){
    for(;;){
        ans=0,n=0,cou=0;
        cin>>a>>b;
        if(a==0&&b==0)break;
        for(int i=0;i<a;i++){
            cin>>zu[i];
        }
        for(int i=0;i<b;i++){
            cin>>dis[i];
        }
        for(int i=0;i<b;i++){
            ans=ans+dis[i]+zu[n+dis[i]];
            n=ans;
            cou++;
            if(ans>=a)break;
        }
        cout<<cou<<endl;
    }
return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
 
int gcd(int a, int b) {
  if (a < b) {
    return gcd(b,a);
  }
  if (b == 0) {
    return a;
  }
  else {
    return gcd(b,a%b);
  }
}
int main() {
  int N, ans;
  cin >> N >> ans;
  
  for (int i = 0; i < N-1; i++) {
    int a;
    cin >> a;
    ans = gcd(ans,a);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n,t,f; cin >> n;
  t = n;
  f = 0;
  while (t > 0) {
    /* code */
    f += t%10;
    t /= 10;
  }
  std::cout << (n%f ? "No" : "Yes") << '\n';
}


Measured memory_bytes: 256
S = gets.chomp.chars.map &:to_i

N = S.size

TARG = 753

min = TARG

for i in 0..(N - 3) do
    num = S[i]*100 + S[i + 1]*10 + S[i + 2]
    min = [min, (num - TARG).abs].min
end

p min


Measured memory_bytes: 1788
n,m = map(int,input().split())
ac = [False]*n
count = [0]*n
a=0
b=0
for _ in range(m):
    p,s = input().split()
    if s == 'AC':
        if ac[int(p)-1]==False:
            ac[int(p)-1]=True
            a+=1
            b+=count[int(p)-1]
    else:
        if ac[int(p)-1]==False:
            count[int(p)-1]+=1
            
print(str(a)+' '+str(b))

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

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll a[5];
	rep(i,0,5) cin >> a[i];
	ll k;
	cin >> k;
	sort(a,a+5);
	if(a[4]-a[0]<=k) cout << "Yay!";
	else cout << ":(";
	return 0;
}
/* The judge is never wrong! Your code is buggy 
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */

Measured memory_bytes: 256
N,K = map(int, input().split())
h = sorted([int(input()) for _ in range(N)])[::-1]

diff = 10 ** 10
for i in range(N):
    if i + K - 1 <= N - 1:
        diff = min(diff, h[i] - h[i+K-1])
    else:
        break

print(diff)

Measured memory_bytes: 8280
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  sort(allr(h));
  int mn = 2e9;
  for (int i = 0; i+k-1 < n; i++) {
    int cnt = h[i] - h[i+k-1];
    mn = min(mn, cnt);
  }
  cout << mn << endl;
  return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;

namespace ABC139_B
{
    class Program
    {
        static void Main(string[] args) {
            string[] input = Console.ReadLine().Split();
            long a = long.Parse(input[0]);
            long b = long.Parse(input[1]);

            long sasikomi = 1;
            long ans = 0;
            while(b > sasikomi) {
                ans++;
                sasikomi += a - 1;
            }

            
            Console.WriteLine(ans);
        }
    }
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define MAX_NUM 45
#define INF INT_MAX/2

void solve(int n)
{
	int p[MAX_NUM], t[MAX_NUM];
	rep(i, 1, n+1) cin >> p[i] >> t[i];

	int dp[MAX_NUM][4];
	rep(i, 0, n + 1) rep(j, 0, 4) dp[i][j] = INF;
	if (t[1] >= p[1]) dp[1][1] = p[1];

	rep(i, 1, n+1)
	{
		bool ok = true;
		rep(j, 0, 4) if (dp[i][j] != INF) ok = false;
		if (ok)
		{
			cout << "NG " << i << endl;
			return;
		}

		if (i != n)
		{
			rep(j, 0, 4)
			{
				if (dp[i][j] == INF) continue;

				int canusetime = t[i + 1] - t[i];
				
				if ((p[i] * (j + 1) + p[i + 1]) <= canusetime)
					dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + p[i] + p[i + 1]);

				if ((abs(p[i] - p[i + 1]) * (j + 1)) <= canusetime)
					if (j != 3)
						dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + abs(p[i] - p[i + 1]));
			}
		}
		else
		{
			int ans = INF;
			rep(j, 1, 4)
			{
				ans = min(ans, dp[n][j] + p[n]);
			}
			cout << "OK " << ans << endl;
		}
	}
}

int main()
{
	while (1)
	{
		int n; cin >> n;
		if (n == 0) return 0;

		solve(n);
	}
}

Measured memory_bytes: 3012