akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define debug cerr << __LINE__ << endl
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;


int n, m;
vector<vector<int> > nolist;
vector<int> flg;
vector<vector<int> > mat;
vector<int> mark;

pair<int, int> bfs(int s){
	//cerr << "bfs(" << s << ")" << endl;
	int count = 0, half = 0;
	queue<int> q; q.push(s);q.push(1);
	while(!q.empty()){
		int now = q.front(); q.pop();
		int mark = q.front(); q.pop();
		//cerr << now << ":" << mark << endl; 
		flg[now] = mark;
		count++; if (mark==1) half++;
		for(int i=0;i<nolist[now].size();i++){
			int next = nolist[now][i];
			if (flg[next]==0){
				q.push(next); q.push(3 - mark);
				flg[next] = 3 - mark;
			}else{
				if (flg[next] != 3 - mark) return make_pair(-1, -1);
			}
		}
	}
	return make_pair(half, count - half);
}


int main(void){
	cin >> n >> m;
	mat = vector<vector<int> >(n, vector<int>(n));
	nolist = vector<vector<int> >(n);
	mark = vector<int>(n);
	flg = vector<int>(n);
	int tmp, tmp2;
	for(int i=0;i<m;i++){
		cin >> tmp >> tmp2; tmp--; tmp2--;
		mat[tmp][tmp2] = 1;
		mat[tmp2][tmp] = 1;
	}
	for(int i=0;i<n;i++)for(int j=0;j<n;j++){
		if (i==j) continue;
		if (mat[i][j]==0) nolist[i].push_back(j);
	}
	vector<pair<int, int> > siz;
	for(int i=0;i<n;i++){
		if (flg[i]==0){
			pair<int, int> ret = bfs(i);
			if (ret.first < 0 || ret.second < 0) {cout << -1 << endl; return 0;}
			siz.push_back(ret);
			cerr << i << "=>" << ret.first << " " << ret.second << endl;
		}
	}

	vector<int> dp(n+1); dp[0] = 1;
	for(int i=0;i<siz.size();i++){
		for(int j=n;j>=0;j--){
			if (dp[j]){
				if (j + siz[i].first <= n) dp[j + siz[i].first] = 1;
				if (j + siz[i].second <= n) dp[j + siz[i].second] = 1;
				if (siz[i].first>0 && siz[i].second>0) dp[j] = 0;
			}
		}
	}
	for(int i=0;i<=n;i++) cerr << i << "..." << dp[i] << endl;
	ll ans = LLONG_MAX;
	for(int i=n;i>=0;i--){
		if (dp[i]){
			ll val = i*(i-1)/2 + (n-i)*(n-i-1)/2;
			ans = min(ans, val);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4992
N,K = map(int,input().split())
x = list(map(int,input().split()))

ans = 10**9
for i in range(N-K+1):
    start,end = x[i],x[i+K-1]
    if end <= 0:
        ans = min(ans, abs(start)) 
    elif start <= 0:
        ans = min(ans, 2*min(abs(start), end)+max(abs(start), end))
    else:
        ans = min(ans, end)

print(ans)


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


int main(){
  int n;
  cin >> n;
  vector<tuple<string,int,int>> a;
  rep(i,0,n){
    string s;
    cin >> s;
    int point;
    cin >> point;
    point *=-1;
    a.emplace_back(s,point,i+1);
  }
  sort(a.begin(),a.end());

  for(auto p:a) cout << get<2>(p) << endl;

}

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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define REP64(i, s,  n) for(int64 i = s;i < (n);i++)
#define INF 999999999
#define MOD 1000000007
using namespace std;

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

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

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

int Q;
bool arr[100001];
int  cnt[100001];

// エラトステネスの篩(ふるい）
void eratosthenes(int64 n){
	for(int64 i = 0; i <= n; i++){
		arr[i] = true;
	}
	arr[0] = arr[1] = false;
	for(int64 i = 2; i * i <= n; i++){
		if(arr[i]){
			for(int64 j = 0; i * (j + 2) <= n; j++){
				arr[i *(j + 2)] = false;
			}
		}
	}
}

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

	cin >> Q;

	// 必要分作る
	eratosthenes(100000);

	cnt[0] = cnt[1] = 0;
	for(int i = 3; i <= 100000; i+=2) {
		if(arr[i] && arr[(i+1)/2])	cnt[i] = cnt[i-2] + 1;
		else						cnt[i] = cnt[i-2];
	}
	
	int l, r;
	int ans;
	REP(i, 0, Q) {
		cin >> l >> r;
		ans = cnt[r] - cnt[l-2];
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 1152
#(39)階数の0個数
while True:
    n=int(input())
    if n==0:
        break
    count=0
    
    for i in range(n-1):
        n=n*(i+1)
    
    while n%10==0:
        n=n//10
        count+=1
        
        if n%10>0:
            break
    print(count)


Measured memory_bytes: 5628
import java.util.*;
import java.util.Map.Entry;
 
 
 class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
	 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
	 static char[][] S;
    public static void main(String[] args) {
    
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long M = GCD(A,B);
        
        long ans=1;
        for(int i=2;i<Math.pow(M, 0.5);i++){
        	if(M%i==0) {
        		ans++;
        		while(M%i==0)M=M/i;
        	}
        }
        if(M!=1) {
        	ans++;
        }
        
        System.out.println(ans);        	
                		
    }
    
    static long GCD(long a,long b) {
  	  long tmp;
  	  long r;
  	  if(a<b) {
  		  tmp = a;
  		  a = b;
  		  b = tmp;				  
  	  }
  	  
  	  r = a % b;
  	  while(r!=0) {
  		  a=b;
  		  b=r;
  		  r=a%b;
  	  }
  	  
  	  return b;
    }
    
    
}

Measured memory_bytes: 23252
S = input()
p = S[0:2]
q = S[2:4]

p = int(p)
q = int(q)

p_year_flag = 0
p_month_flag = 0
q_year_flag = 0
q_month_flag = 0

if 1 <= p and p <= 12:
    p_month_flag = 1

if 0 <= p and p <= 99:
    p_year_flag = 1
    
if 1 <= q and q <= 12:
    q_month_flag = 1
    
if 0 <= q and q <= 99:
    q_year_flag = 1
    
YYMM_flag = 0
MMYY_flag = 0

if p_year_flag == 1 and q_month_flag == 1:
    YYMM_flag = 1
if p_month_flag == 1 and q_year_flag == 1:
    MMYY_flag = 1
    
if YYMM_flag == 1 and MMYY_flag == 1:
    print('AMBIGUOUS')
    
elif YYMM_flag == 1:
    print('YYMM')
    
elif MMYY_flag == 1:
    print('MMYY')
    
else:
    print('NA')

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

int main(){
    int n,k;
    cin>>n>>k;
    vector< pair<int,int> > s;
    long long MOD = 998244353;

    for(int i=0;i<k;i++){
        int l,r;
        cin>>l>>r;
        s.push_back(make_pair(l,r));
    }

    //sを用いてiにたどり着くまでの方法
    vector<long long> dp(n+1,0);
    //累積和
    vector<long long> cuml(n+1,0);
    dp[1]=1;
    cuml[1]=1;

    for(int i=2;i<n+1;i++){
        for(int j=0;j<k;j++){
            int l,r;
            if(i-s[j].first < 1) continue;
            r = i-s[j].first;
            l = max(1,i-s[j].second);

            dp[i] = (dp[i]+cuml[r]-cuml[l-1]+MOD)%MOD;
        }
        //累積和を更新する
        cuml[i] = (cuml[i-1]+dp[i])%MOD;
    }

    cout<<dp[n]<<endl;
    return 0;
}

Measured memory_bytes: 6220
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
char S[5];
int main(){
  int i;
  int res = 0;
  int tmp = 0;
  rd(S);
  for(i=(0);i<(3);i++){
    if(S[i]=='R'){
      tmp++;
    }
    else{
      tmp = 0;
    }
    chmax(res, tmp);
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200813-1 [beta]

// --- original code ---
// char S[5];
// {
//   int res = 0, tmp = 0;
//   rd(S);
//   rep(i,3){
//     if[S[i]=='R', tmp++, tmp = 0];
//     res >?= tmp;
//   }
//   wt(res);
// }


Measured memory_bytes: 3652
#include<stdio.h>

int main(){
	int i,j;
	int n;
	int debt;
	
	scanf("%d",&n);
	
        
	for(i=0;i<=n;i++){
		if(i==0){
			debt=100000;
		}else{
			debt+=debt*0.05;
			if(debt%1000!=0){
				debt/=1000;
				debt*=1000;
				debt+=1000;
			}
		}
	}
	printf("%d\n",debt);
	
	return 0;
}

Measured memory_bytes: 592
const MaxN=round(1e5)+10;
var A:array[0..MaxN] of longint;
    n,res:longint;

procedure nhap;
var i:longint;
begin

    readln(n);
    for i:=1 to n do
        readln(a[i]);
end;

procedure xuli;
var x:longint;
begin
    x:=1;res:=0;
    repeat
        x:=a[x];
        inc(res);
        if x=2 then
        begin
            writeln(res);
            halt;
        end;
    until res>n;
end;
procedure xuat;
begin
    writeln(-1);

end;

begin
    nhap;
    xuli;
    xuat;
end.


Measured memory_bytes: 512
#include<queue>
#include<string>

#include<vector>
#include<iostream>
using namespace std;

int main() {
	int N;
	cin >> N;

	vector<int> x(N), y(N), z(N);

	int h = 0;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> z[i];

		if (z[i] > h) {
			h = z[i];
		}
	}


	for (int ty = 0; ty <= 100; ty++) {
		for (int tx = 0; tx <= 100; tx++)
			for (int th = 200; th >=0; th--) {
				int s = 0;
				for (int i = 0; i < N; i++) {
					s = std::max(
						th + h -
						(tx < x[i] ? x[i] - tx : tx - x[i]) -
						(ty < y[i] ? y[i] - ty : ty - y[i])
						, 0) - z[i];
					if (s != 0)
						break;
				}
				if (s != 0)
					continue;
				else {
					cout << tx << ' ' << ty << ' ' << th + h << endl;
					return 0;
				}
			}
	}
	return 0;
}


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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
#define INF             1000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

void init(){
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

const int N = 2e3+5;

int main()
{
	init();
	int n; ll res = 0;
	int arr[N];
	cin >> n;
	lp(i, n)
		cin >> arr[i];
	sort(arr, arr+n);
	lp(i, n){
		lpi(j, i+1, n){
			int num = 0;
			int max_idx = lower_bound(arr, arr+n, arr[i] + arr[j]) - arr;
			int min_idx = upper_bound(arr, arr+n, arr[j] - arr[i]) - arr;
			if(i >= min_idx && i < max_idx)
				--num;
			if(j >= min_idx && j < max_idx)
				--num;
			num += (max_idx - min_idx);
			res += max(num, 0);
		}
	}
	cout << res/3;
	return 0;
}



Measured memory_bytes: 256
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n + 1 - i):
        if 10000 * i + 5000 * j + 1000 * (n - i - j) == y:
            print(i, j, n - i - j)
            exit()
print(-1, -1, -1)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  int N;
  int a[110];
  int sum = 0;
  int i;
  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  double ave = sum*1.0/N;
  int ave_int = (int)round(ave);
  int ans = 0;
  for (i = 0; i < N; i++) {
    ans += (a[i]-ave_int)*(a[i]-ave_int);
  }
  printf("%d", ans);
  return 0;
}


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


int bfs(string& S, string& T)
{
  queue< string > que;
  unordered_map< string, int > v;
  que.push(S);
  v[S] = 0;
  while(!que.empty()) {
    auto& p = que.front();
    int now = v[p];
    if(p == T) return(now);
    int match = 0;
    while(p[match] == T[match]) ++match;
    int ptrr = (T[match] - p[match] + 10) % 10;
    for(int j = match; j < p.size(); j++) {
      (p[j] += ptrr) %= 10;
      if(v.find(p) == v.end()) {
        v[p] = now + 1;
        que.push(p);
      }
    }
    que.pop();
  }
}
int main()
{
  int K;
  while(cin >> K, K) {
    string S, T;
    cin >> S >> T;
    for(int i = 0; i < K; i++) {
      S[i] -= '0';
      T[i] -= '0';
    }
    cout << bfs(S, T) << endl;
  }
}

Measured memory_bytes: 4184
//#pragma GCC oplmize(2)
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define ll long long
#define sc(x) scanf("%lld",&x)
#define scs(x) scanf("%s",x+1)
#define pr(x) printf("%lld\n",x)
#define prs(x) printf("%s\n",x)
using namespace std;
const int maxn=2e5+5;
const int mod=1e9+7;
const double pi=acos(-1.0);
const double eps = 1e-8;
ll n,a[105],s;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    sc(n);
    for(int i=1;i<=n;i++) sc(a[i]);
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            for(int k=j+1;k<=n;k++){
                if(a[i]!=a[j] && a[i]!=a[k] && a[j]!=a[k]){
                    if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[j]+a[k]>a[i]) s++;
                }
            }
        }
    }
    pr(s);
    return 0;
}

Measured memory_bytes: 3848
class Area
  def solve
    tsm = 0
    st = []
    ans = []

    s = gets.chomp
    (0...s.size).each do |i|
      if s[i] == "\\"
        st << i
      elsif s[i] == "/"
        unless st.empty?
          tsm += (i - st[-1])

          while (!ans.empty? && ans[-1][0] > st[-1])
            tsm += ans[-1][1]
            ans.pop
          end

          ans << [st.pop, tsm]
          tsm = 0
        end
      end
    end

    if ans.empty?
      puts 0
      puts 0
    else
      ans = ans.map{ |i| i[1] }
      puts ans.inject(:+)
      puts "#{ans.size} #{ans.join(" ")}"
    end

  end
end

if $0 == __FILE__
  Area.new.solve
end

Measured memory_bytes: 6312
<?php
    fscanf(STDIN,"%d",$N);

    // $list_a = explode(" ", trim(fgets(STDIN)));
    $flag=false;
    for($i=1;$i<=9;$i++){
        for($j=0;$j<=9;$j++){
            if($i*$j==$N){
                $flag=true;
                break;
            }
        }
    }

    if($flag){
        echo "Yes\n";
    }else{
        echo "No\n";
    }

    
    


Measured memory_bytes: 4732
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
 
using namespace std;
 
// →にx軸、↓にy軸を取る
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
 
int meiro[40][40][40][40];
// meiro[a][b][c][d] ... (a, b)から(c, d)へ移るのに壁があれば1、なければ0
int tesu[40][40];
int issearched[40][40];
int w, h;
 
void tansaku(int a, int b);
 
int main()
{
    while(1){
        cin >> w >> h;
        if(w == 0 && h == 0) break;
        for(int i = 0; i < w; i++){
            for(int j = 0; j < h; j++){
                tesu[i][j] = 0;
                issearched[i][j] = 0;
            }
        }
        for(int i = 0; i < h - 1; i++){
            for(int j = 0; j < w - 1; j++){
                cin >> meiro[j][i][j + 1][i];
                meiro[j + 1][i][j][i] = meiro[j][i][j + 1][i];
            }
            for(int j = 0; j < w; j++){
                cin >> meiro[j][i][j][i + 1];
                meiro[j][i + 1][j][i] = meiro[j][i][j][i + 1];
            }
        }
        for(int i = 0; i < w - 1; i++){
            cin >> meiro[i][h - 1][i + 1][h - 1];
            meiro[i + 1][h - 1][i][h - 1];
        }
        tansaku(0, 0);
        cout << tesu[w - 1][h - 1] << endl;
    }
    return 0;
}
 
void tansaku(int a, int b)
{
    queue<pair<int, int> > qu;
    qu.push(pair<int, int>(a, b));
    tesu[a][b] = 1;
    issearched[a][b] = 1;
    int x, y, next_x, next_y;
    while(1){
        if(qu.empty()) break;
        x = (qu.front()).first;
        y = (qu.front()).second;
        for(int i = 0; i < 4; i++){
            next_x = x + dx[i];
            next_y = y + dy[i];
            if(next_x < 0 || next_x >= w || next_y < 0 || next_y >= h) continue;
            if(issearched[next_x][next_y] == 0 && meiro[x][y][next_x][next_y] == 0){
                issearched[next_x][next_y] = 1;
                tesu[next_x][next_y] = tesu[x][y] + 1;
                qu.push(pair<int, int>(next_x, next_y));
            }
        }
        qu.pop();
    }
    return;
}

Measured memory_bytes: 8412
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

using namespace std;
constexpr long long int INF = std::numeric_limits<long long int>::max();
constexpr long long int NINF = std::numeric_limits<long long int>::min();

signed visited[100001][3];
int S, T;
vector<vector<int>> V;

void solve() {
  int N, M;
  cin >> N >> M;

  V.resize(N);
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    V[u - 1].push_back(v - 1);
  }

  cin >> S >> T;
  S--;
  T--;

  queue<tuple<int, int, int>> queue;
  queue.emplace(S, 0, 0);

  int ans = -1;
  while (!queue.empty()) {
    auto t = queue.front();
    queue.pop();

    int n = get<0>(t);
    int depth = get<1>(t);
    int len = get<2>(t);

    if (visited[n][depth]) {
      continue;
    }
    visited[n][depth] = 1;

    if (depth == 0 && n == T) {
      ans = len;
      break;
    }

    if (depth == 0) {
      depth = 2;
      len++;
    } else {
      depth--;
    }

    for (int v : V[n]) {
      queue.emplace(v, depth, len);
    }
  }

  cout << ans << endl;
}

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


Measured memory_bytes: 6912
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };




signed main() {
	ll n;
	vector<int>list;

	cin >> n;

	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		list.push_back(num);
	}

	int cnt = 0;
	bool flag = false;

	while (true)
	{
		bool flag2 = false;
		

		for (int i = 0; i < n ; i++) {
			if (list[i] <= 0) {
				if (flag == true) {
					//cnt++;
				}
				flag = false;
			}
			else if (list[i] >= 1) {
				if (flag == false) {
					cnt++;
				}
				flag = true;
				list[i]--;
			}

			if (list[i] > 0)flag2 = true;
		}

		if (flag2 == false)break;
		flag = false;
	}

	cout << cnt << endl;


	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <set>
#include <bitset>
#include <map>
#include <stack>
#include <algorithm>
#include <math.h>
#include <queue>
#include <vector>
#include <string.h>
#define mem(x,b) memset(x,b,sizeof(x))
#define mp(a,b) make_pair(a,b)
#define debug(a) cout<<a<<endl
#define maxn 200005
using namespace std;
typedef long long ll;
typedef double db;
const int mod=1e9+7;
int main()
{
    int a,b,c,k,ans=0;
    scanf("%d%d%d%d",&a,&b,&c,&k);
    if(a>=k){
    	ans+=k;
    }else{
    	ans+=a;
    	k-=a;
    	if(b<k){
    		k-=b;
    	}else{
    		k=0;
    	}
    	ans-=k;
    }
    printf("%d\n",ans);
    return 0;
}


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

const int P = 998244353; int poww(long long a , int b){int tms = 1; while(b){if(b & 1) tms = tms * a % P; a = a * a % P; b >>= 1;} return tms;}
int pot[200003] , N , K;
#define lowbit(x) ((x) & -(x))
struct bit{
	int arr[200003];
	void add(int x , int v){while(x <= N){arr[x] = (arr[x] + v) % P; x += lowbit(x);}}
	int qry(int x){int sum = 0; while(x){sum = (sum + arr[x]) % P; x -= lowbit(x);} return sum;}
}sum1 , sum2;

int main(){
	int ans = 0; cin >> N >> K; for(int i = 1 ; i <= N ; ++i) cin >> pot[i];
	int lft1 = 1ll * (K - 1) * poww(K , P - 2) % P , lft2 = 1ll * (K - 2) * poww(K , P - 2) % P;
	for(int i = 1 ; i <= N ; ++i){
		int p1 = sum1.qry(pot[i]) , p2 = i - 1 - sum1.qry(pot[i]) , r2 = max(i - K , 0);
		int q1 = sum2.qry(pot[i]) , q2 = (sum2.qry(N) - sum2.qry(pot[i]) + P) % P;
		sum1.add(pot[i] , 1); sum2.add(pot[i] , poww(lft1 , P - 1 - r2)); ans = (ans + p2 - 1ll * q2 * poww(lft1 , r2)) % P;

		int prob = 1ll * (q1 + q2) * poww(lft1 , r2) % P;
		ans = (ans + 1ll * prob * (P + 1 - lft1) % P * (P + 1 - poww(lft2 , N - K - r2)) % P * poww(P + 1 - lft2 , P - 2)) % P;
		ans = (ans + 1ll * prob * poww(lft2 , N - K - r2) % P * (P + 1) / 2) % P;
	}
	cout << ans; return 0;
}

Measured memory_bytes: 5972
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
    ll i=0,L,mod=1e9+7,ans=1,B[200000];
    string s;
    cin>>s;
    L=s.size();
    reverse(s.begin(),s.end());
    B[0]=1;
    rep(i,L) B[i+1]=B[i]*3%mod;
    rep(i,L){
        if(s[i]=='1')ans=(B[i]+2*ans%mod)%mod;
    }
    cout<<ans%mod;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();

        long n = x/500;

        //System.out.println("n:" + n);

        long amari = x - (500*n);

        long m = amari/5;

        //System.out.println("m:" + m);


        System.out.println(n*1000 + m*5);



    }

}

Measured memory_bytes: 21844
import java.util.*;

public class Main {
  public static void main(String [] args) {
	Scanner sc = new Scanner(System.in);
    char [] s = sc.next().toCharArray();
    Arrays.sort(s);
    System.out.println(((s[0] == s[1]) && (s[1] != s[2]) && (s[2] == s[3])) ? "Yes" : "No");
  }
}

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

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

int MOD = 1e9 + 7;
ll INF = 1e18;

int main() {
    string s;
    cin>>s;

    if(s[0] != 'A'){
         cout << "WA" << endl;
         return 0;
    }

    int n=s.size()-1;

    int sum=0, m;
    for(int i=2; i<n; i++){
        if(s[i] == 'C') {
            sum++;
            m=i;
        }
    }
    if(sum != 1){
        cout << "WA" << endl;
        return 0;
    }

    for(int i=1; i<=n; i++){
        if(i == m) continue;

        if(s[i] >= 'a' && s[i] <= 'z') continue;
        else {
            cout << "WA" << endl;
            return 0;
        }
    }
    cout << "AC" << endl;
}

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

#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define pb push_back
#define inf 1e+18L
#define MOD 1000000007

int main()
{
    FastIO 
    int k;
    cin >> k;
    queue<ll> q;
    rep(i,1,10) q.push(i);
    ll x;
    rep(i,0,k)
    {
        x = q.front();
        q.pop();
        if(x%10 != 0) q.push(10*x + (x%10) - 1);
        q.push(10*x + (x%10));
        if(x%10 != 9) q.push(10*x + (x%10) + 1);
    }
    cout << x << "\n";
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static int g(long x) {
        int res = 0;
        while (x > 0) {
            ++res;
            x /= 10;
        }
        return res;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        int res = Integer.MAX_VALUE;
        for (long i = 1; i * i <= N; ++i) {
            if (N % i == 0) {
                long a = N / i;
                res = Math.min(res, Math.max(g(i), g(a)));
            }
        }
        System.out.println(res);
    }
}

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

using namespace std;

const int MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];

  unordered_set<int> determined;
  {
    int prevH = 0;
    for (int i = 0; i < N; i++) {
      if (prevH < A[i]) {
        if (A[i] > B[i]) {
          printf("0\n");
          return 0;
        }
        prevH = A[i];
        determined.insert(i);
      }
    }
  }

  {
    int prevH = 0;
    for (int i = N - 1; i >= 0; i--) {
      if (prevH < B[i]) {
        if (B[i] > A[i]) {
          printf("0\n");
          return 0;
        }
        prevH = B[i];
        determined.insert(i);
      }
    }
  }

  int64_t result = 1;
  for (int i = 0; i < N; i++) {
    if (determined.count(i)) continue;
    result = result * min(A[i], B[i]);
    result %= MOD;
  }
  printf("%ld\n", result);

  return 0;
}


Measured memory_bytes: 5156
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
//#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;
int x, y, a, b, c;
int p[123456], q[123456], r[123456];
int ans = 0, sum = 0;
signed main() {
	cin >> x >> y >> a >> b >> c;
	for0(i, a)cin >> p[i];
	for0(i, b)cin >> q[i];
	for0(i, c)cin >> r[i];
	sort(p, p + a, greater<int>());
	sort(q, q + b, greater<int>());
	sort(r, r + c, greater<int>());
	for0(i, x)sum += p[i];
	for0(i, y)sum += q[i];
	ans = sum;
	int p1 = x - 1, p2 = y - 1;
	for0(i, c) {
		if (p1 < 0 && p2 < 0)break;
		if (p1 < 0) {
			sum += r[i] - q[p2];
			p2--;
		}
		else if (p2 < 0) {
			sum += r[i] - p[p1];
			p1--;
		}
		else {
			if (p[p1] <= q[p2]) {
				sum += r[i] - p[p1];
				p1--;
			}
			else {
				sum += r[i] - q[p2];
				p2--;
			}
		}
		ans = max(ans, sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

//ITPC dice4

class dice{
public:
    int top, bottom, right, left, front, back;
    void North();
    void East();
    void South();
    void West();
    void clockRotate();
};
void dice:: North(){
    int tmp = top;
    top = front;
    front = bottom;
    bottom = back;
    back = tmp;
}
void dice:: East(){
    int tmp = top;
    top = left;
    left = bottom;
    bottom = right;
    right = tmp;
}
void dice:: South(){
    int tmp = top;
    top = back;
    back = bottom;
    bottom = front;
    front = tmp;
}
void dice:: West(){
    int tmp = top;
    top = right;
    right = bottom;
    bottom = left;
    left = tmp;
}
void dice:: clockRotate(){
    int tmp = front;
    front = right;
    right = back;
    back = left;
    left = tmp;
}

bool sameDice(dice d1, dice d2){
    string s = "NRRRRNRRRRNRRRRNRRRRERRRRERRRRERRRR";
    rep(i, 0, s.size()){
        if(d1.top == d2.top && d1.front == d2.front && d1.right == d2.right && d1.back == d2.back && d1.left == d2.left && d1.bottom == d2.bottom){
            return true;
        }
        if(s[i] == 'N') d1.North();
        else if(s[i] == 'E') d1.East();
        else if(s[i] == 'S') d1.South();
        else if(s[i] == 'W') d1.West();
        else if(s[i] == 'R') d1.clockRotate();
    }
    return false;
}

signed main(){
    int n;
    vector<dice> dices;
    dice d;
    cin >> n;
    rep(i, 0, n){
        cin >> d.top >> d.front >> d.right >> d.left >> d.back >> d.bottom;
        dices. push_back(d);
    }
    rep(i, 0, n){
        rep(j, i + 1, n){
            if(sameDice(dices[i], dices[j])){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1232
import itertools
n=int(input())
a= list(map(int, input().split()))
a.sort()
aa = list(itertools.accumulate(a))
ans=1

for i in range(n-1):
    if aa[n-2-i]*2>=a[n-1-i]:
        ans+=1
    else:
        break

print(ans)

Measured memory_bytes: 63856
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pii>
#define vpipii vector<pipii>
#define vpiipi vector<piipi>
#define pb push_back
#define pob pop_back
#define pii pair<int,int>
#define pipii pair<int,pii>
#define piipi pair<pii,int>
#define pld pair<long double,long double>
#define mod 1000000007
// #define mod 1000000009
// #define mod 163577857 
// #define mod 998244353
#define rep(i,n) for (int i = 0; i < n; i++)
#define repp(i,a,b) for(int i = a ; i<b ; i++)
#define reppr(i,a,b) for(int i = a-1 ; i>=b ; i--)
#define repr(i,n) for (int i = n - 1; i >= 0; i--)
#define ff first
#define ss second
#define pc putchar_unlocked
#define gc getchar_unlocked
#define inf 9223372036854775807
#define infn -9223372036854775807
#define pi 3.14159265358979323846
#define eps 0.0000000001
#define sp << " " <<
#define setprec(x) cout << fixed << setprecision(x);
#define REVERSE(a) reverse(all(a));
#define SORT(a) sort(all(a));
#define all(n) n.begin(),n.end()
 
//GCD and LCM
    int gcd (int a, int b) { return b ? gcd (b, a % b) : a; }
    int lcm (int a, int b) { return a / gcd(a, b) * b; }
 
//Modular Exponentiation
    int powmod(int x,int y) 
    { 
        if (y == 0) return 1; 
        int p = powmod(x, y/2) % mod; 
        p = (p * p) % mod;   
        return (y%2 == 0)? p : (x * p) % mod; 
    }
 
//Modular Inverse
    int inverse(int a) 
    { 
       return powmod(a,mod-2); 
    }

//Binomial Coefficients
    int fact[500010], factinv[500010] , coefficientflag = 0;
    void Util_nCr()
    {
        fact[0] = 1 , factinv[0] = 1;
        repp(i,1,500010)
        {
            fact[i] = (fact[i-1] * i)%mod;
            factinv[i] = (factinv[i-1] * inverse(i))%mod;
        }
    }
    int nCr(int n , int r)
    {
        if(!coefficientflag) coefficientflag = 1 , Util_nCr();             
        return ((fact[n] * inverse(fact[n-r]) % mod * inverse(fact[r]))%mod) ;
    }

void solve();
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int t = 1;
    // cin >> t; 
    rep(i,t)
    {
        // cout << "Case #" << i+1 << ": ";
        solve();
    }
}

void solve() 
{
    int a[5];
    rep(i,5)
        cin >> a[i];
    rep(i,5)
    {
        if(a[i]==0)
            cout << i+1;
    }   
}

Measured memory_bytes: 3604
import java.util.Scanner;
import java.util.Arrays;
public class Main {
    public static int n,count;
    public static int[] a;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n=sc.nextInt();
        a=new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        sumDigits();
        for(int i=0;i<n;i++){
            if(i==n-1)System.out.printf("%d",a[i]);
            else System.out.printf("%d ",a[i]);
        }
        System.out.printf("\n%d\n",count);
        sc.close();
    }
    public static void sumDigits() {
        int flag=1;
        while(flag>0){
            flag=0;
            for(int j=n-1;j>=1;j--){
                if(a[j]<a[j-1]){
                    int b;
                    b=a[j];
                    a[j]=a[j-1];
                    a[j-1]=b;
                    flag=1;
                    count++;
                }
            }
        }
    }
}


Measured memory_bytes: 26508
function main(arg) {
  const inputs = arg.split("\n");
  const k = inputs[0];
  const [a, b] = inputs[1].split(" ");
  
  if (a % k == 0 || (Math.floor(a/k) + 1) * k <= b) {
    console.log("OK");
  } else {
    console.log("NG");
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29632
#include<stdio.h>
#define MAX 260
#define NIL -1

int Tree[MAX];

int n;

void maxHeapify(int i){
  int largest,exchange,r,l;
  l = getLeft(i);
  r = getRight(i);
  
  if(n>=l && Tree[l]>Tree[i])
    largest = r;
  if (largest != i){
    exchange =  Tree[i];
    Tree[i] = Tree[largest];
    Tree[largest] = exchange;
  }
  maxHeapify(largest);
}


int getParent(int i){
  return i/2;
}

int getLeft(int i){
  return (2*i);
}

int getRight(int i){
  return (2*i + 1);
}

main()
{
  int i;
  scanf("%d",&n);

  for(i=1; i<=n; i++){

    scanf("%d",&Tree[i]);

  }

  for(i=1; i<=n; i++){
    
    printf("node %d: key = %d, ",i,Tree[i]);
    if(getParent(i) != 0)printf("parent key = %d, ",Tree[getParent(i)]);
    if(getLeft(i) <= n) printf("left key = %d, ",Tree[getLeft(i)]);
    if(getRight(i) <= n)printf("right key = %d, ",Tree[getRight(i)]);
    printf("\n");
  }
  return 0;
}

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

int sum;
int a[110];

main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	sum/=n;
	long long ans=0,mn=1e9;
	for(int i=-100;i<=100;i++)
	{
		ans=0;
	for(int j=0;j<n;j++)
	{
		ans+=(a[j]-i)*(a[j]-i);
	}
		mn=min(ans,mn);
	}
	printf("%lld",mn);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 2);
    int s = 0;
    for(int i = 1; i <= N; ++i) {
        cin >> A[i];
        s += abs(A[i] - A[i - 1]);
    }
    s += abs(A[N]);
    for(int i = 1; i <= N; ++i) {
        bool prev = (A[i] - A[i - 1] >= 0), next = (A[i + 1] - A[i] >= 0);
        if(prev == next)
            cout << s << endl;
        else
            cout << s - min(abs(A[i] - A[i - 1]), abs(A[i + 1] - A[i])) * 2
                 << endl;
    }
    return 0;
}


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

int main()
{
    string str;
    int i,r=0;
    cin>>str;
    for(i=0;i<3;i++)
    {
        if(str[i]=='R')
            r++;
    }
    if(r==2)
    {
        if(str[0]=='R' && str[2]=='R')
            cout<<1;
        else
            cout<<2;
    }
    else
        cout<<r;
    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

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

		int ans = Math.min(n*a, b);
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
 
            double a = Integer.parseInt(sc.next());
            double b = Integer.parseInt(sc.next());
            double hour = Integer.parseInt(sc.next());
            double minute = Integer.parseInt(sc.next());

            double angle = Math.abs((hour + minute/60)*30 - minute*6);
            if(angle > 180) angle = 360 - angle;

            double ans = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2*a*b*Math.cos(Math.toRadians(angle)));

            System.out.println(ans);

        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

Measured memory_bytes: 35908
import java.util.Scanner;
//import java.io.*;
import java.util.Arrays;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		//InputStreamReader is = new InputStreamReader(System.in);
		//BufferedReader br = new BufferedReader(is);
		int n = scan.nextInt();
		String number[] = new String[n];
		int max[] = new int[n];
		int min[] = new int[n];
		for(int i = 0 ; i < n ; i++){
			number[i] = scan.next();
		}
		int order[] = new int[8];
		for(int i = 0 ; i < n ; i++){
			char text[] = number[i].toCharArray();
			for(int j = 0 ; j < 8 ; j++){
				order[j] = Character.getNumericValue(text[j]);
			}
			Arrays.sort(order);
			String maxText = String.valueOf(order[7]);
			for(int j= 6 ; j >= 0 ; j--){
				maxText = maxText + String.valueOf(order[j]);
			}
			String minText = String.valueOf(order[0]);
			for(int j = 1 ; j < 8 ; j++){
				minText = minText + String.valueOf(order[j]);
			}
			max[i] = Integer.parseInt(maxText);
			min[i] = Integer.parseInt(minText);
		}
		
		for(int i = 0 ; i < n ; i++){
			System.out.println(max[i]-min[i]);
		}
	}
}

Measured memory_bytes: 26068
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#define N 2010
typedef long long ll;
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
using namespace std;
const int P = 1e9 + 7;
inline ll quickpow(ll x, int k) {
	ll res = 1;
	while (k) {
		if (k & 1)	res = res * x % P;
		x = x * x % P;
		k >>= 1;
	}
	return res;
}
int n, m;
ll X;
struct Edge{
	int u, v, w;
}E[N];
bool cmp(const Edge &a, const Edge &b) {
	return a.w < b.w;
}
int cnt, Cnt;
int fa[N];
int find(int cur) {
	return fa[cur] == cur ? cur : fa[cur] = find(fa[cur]);
}
inline ll calc(int id) {
	ll res = E[id].w;
	for (int i = 1; i <= n; ++i)	fa[i] = i;
	fa[E[id].u] = E[id].v;
	for (int i = 1, ct = 0; i <= m && ct < n - 1; ++i) if (i != id) {
		int u = E[i].u, v = E[i].v, w = E[i].w;
		u = find(u), v = find(v);
		if (u == v)	continue;
		fa[u] = v; res += w; ++ct;
	}
	return res;
}
int main() {
	read(n), read(m), read(X);
	for (int i = 1; i <= m; ++i) {
		int u, v, w; read(u), read(v), read(w);
		E[i] = (Edge){u, v, w};
	}
	sort(E + 1, E + 1 + m, cmp);
	ll mn = calc(0);
	if (mn > X) {
		puts("0");
		return 0;
	}
	for (int i = 1; i <= m; ++i) {
		ll tmp = calc(i);
//		printf("tmp = %lld\n", tmp);
		if (tmp > X)	++Cnt;
		else if (tmp == X)	++cnt;
	}
	if (mn == X) {
		printf("%lld\n", ((quickpow(2, cnt) - 2) * quickpow(2, Cnt) % P + P) % P);
		return 0;
	}
//	printf("cnt = %d, Cnt = %d\n", cnt, Cnt);
	ll ans = 2ll * (quickpow(2, cnt) - 1) * quickpow(2, Cnt) % P;
	printf("%lld\n", (ans % P + P) % P);
	return 0;
}


Measured memory_bytes: 3244
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector< int > p(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    int ans = 0;
    for (int i = 1; i < n - 1; i++) {
        if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1]))
            ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int count;
	int money;
	
	while (1){
		scanf("%d", &money);
		
		if (!money){
			break;
		}
		
		money = 1000 - money;
		
		count = 0;
		while (money){
			if (money >= 500){
				money -= 500;
				count++;
			}
			else if (money >= 100){
				money -= 100;
				count++;
			}
			else if (money >= 50){
				money -= 50;
				count++;
			}
			else if (money >= 10){
				money -= 10;
				count++;
			}
			else if (money >= 5){
				money -= 5;
				count++;
			}
			else {
				money -= 1;
				count++;
			}
		}
		
		printf("%d\n", count);
	}
	
	return (0);
}

Measured memory_bytes: 0
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 
#include <bits/stdc++.h>
using namespace std;

#define    int                      long long int

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    ppi                      pair <int , pii>               
#define    sp(x)                    setprecision(x)

int32_t main()
{
    speed upp
    int n,m;
    cin>>n>>m;
    int ans=m*(m-1);
    ans/=2;
    ans+= (n*(n-1))/2;
    cout<<ans;
}

Measured memory_bytes: 256
import sys
import fractions
import math
import itertools

a,b=list(map(int,input().split()))
ans=0

if a>=b:
	ans+=a
	a-=1
else:
	ans+=b
	b-=1	
if a>=b:
	ans+=a
	a-=1
else:
	ans+=b
	b-=1	
print(ans)

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

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double db;
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mp make_pair
#define case_for(n) for(int i = 1 ; i <= n ; i ++) { cout<<"Case "<<i<<": "<<endl; solve();}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll power(ll a, ll b, ll p) { ll ans = 1; while (b) { if (b & 1) ans = ans * a % p; a = a * a % p, b /= 2; }return ans; }

db pi = 3.1415926535;

int a[100005],vis[100005],b[100005];
vi e[100005];
queue<int> qe;
int main()
{
	/*std::ios::sync_with_stdio(false);
	cin.tie(nullptr), cout.tie(0);*/
	//cout << tan(45 * pi / 180) << endl;
	//int t; cin >> t;
	/*while (t--)
	{
		solve();
	}
	//solve();*/
	memset(a, 0x3f3f3f3f, sizeof(a));
	int n, m; cin >> n >> m;
	for (int i = 0; i < m; i++)
	{
		int x, y; cin >> x >> y;
		e[x].pb(y);
		e[y].push_back(x);
	}
	
	qe.push(1);
	while (qe.size() != 0)
	{
		//cout << "!!" << endl;
		int s = qe.front();
		qe.pop();
		vis[s]++;
		for (int i = 0; i < e[s].size(); i++)
		{
			if (b[e[s][i]] == 0)
			{
				b[e[s][i]] = s;
				qe.push(e[s][i]);
			}
		}

	}
	for (int i = 2; i <= n; i++)
	{
		//cout << b[i] << " ";
		if (b[i] == 0)
		{
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	for (int i = 2; i <= n; i++) cout << b[i] << endl;
	return 0;
}
/*

*/

Measured memory_bytes: 11332
W, H, x, y, r = map(int, raw_input().split())

if 0 <= x <= W and 0 <= y <= H:
    rect = [(0, 0), (0, H), (W, 0), (W, H)]
    for a, b in rect:
        if min(abs(a-x), abs(b-y)) < r:
            print "No"
            break
    else:
        print "Yes"
else:
    print "No"

Measured memory_bytes: 6404
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef vector<bool> vb;
 
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()
 
ll n;
ll l,r;

 
void solve(){
 cin >> n;
 l=0,r=n;
 cout << 0 << endl;
 vector<string> s(n);
  cin >> s[0];
 if(s[0]=="Vacant") {
   return;
 }else { 
  while(1){
   ll m=(l+r)/2;
    cout << m << endl;
    cin >> s[m];
    if(s[m]=="Vacant") break;
    if((m%2&&s[0]!=s[m])||(m%2==0&&s[0]==s[m])) l=m+1;
    else r=m;
  }
 }
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  


Measured memory_bytes: 1620
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

int main(){
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(a+b,min(b+c, c+a)) << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


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

    turn_takahashi = True
    while True:
        if turn_takahashi:
            C -= B
            turn_takahashi = False
        else:
            A -= D
            turn_takahashi = True
        if C <= 0:
            return print("Yes")
        if A <= 0:
            return print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 68720
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>

#define REP(i,x) for(int i=0 ; i<(int)(x) ; i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long

using namespace std;

int N;
vector<int> T;
vector<int> V;
double memo[101][401][201];

double rec(int idx, int time, int v){
    if(memo[idx][time][v]!=0)return memo[idx][time][v];
    double res = -1e9;
    if(idx==N){
        if(v==0)res = 0;
    }else if(time==2*T[idx]){
        if(0<=v && v<=2*V[idx+1])res = rec(idx+1, 0, v);
    }else{
        if(0<=v+1 && v+1<=2*V[idx])res = max(res, v + 0.5 + rec(idx, time+1, v+1));
        if(0<=v-1 && v-1<=2*V[idx])res = max(res, v - 0.5 + rec(idx, time+1, v-1));
        if(0<=v   && v  <=2*V[idx])res = max(res, v + 0.0 + rec(idx, time+1, v+0));
    }
    memo[idx][time][v] = res;

    return res;
}

int main(){
    cin >> N;
    T.resize(N);
    V.resize(N);
    REP(i, N)cin >> T[i];
    REP(i, N)cin >> V[i];
    memset(memo, 0, sizeof(memo));
    printf("%.9f\n", rec(0, 0, 0)/4.0);
    return 0;
}


Measured memory_bytes: 66304
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);

        int n = cin.nextInt();
        int k = cin.nextInt();
        int s = cin.nextInt();

        int t = (s == 1000000000) ? s - 1 : s + 1;

        for (int i = 0; i < k; i++) System.out.printf("%d ", s);
        for (int i = k; i < n; i++) System.out.printf("%d ", t);
        System.out.println();
    }
}


Measured memory_bytes: 60704