akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;


struct Seg
{
	long long l, r;
	Seg() : l(), r() {}

	void read()
	{
		scanf("%lld%lld", &l, &r);
	}

	bool operator < (const Seg &A) const
	{
		if (r + l != A.r + A.l)
			return r + l < A.r + A.l;
		return l < A.l;
	}
};

const int N = 5005;
Seg s[N];

long long dp[N / 2][N / 2][2];

long long INF = (long long) 1e18;
void updDp(long long &a, long long b)
{
	a = min(a, b);
}

int main(int,  char **)
{
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		s[i].read();
	sort(s, s + n);

	for (int i = 0; i <= n / 2; i++)
		for (int j = 0; j <= n / 2; j++)
			for (int t = 0; t < 2; t++)
				dp[i][j][t] = INF;
	
//	int ptr = 0;
//	while (ptr < n && s[ptr + 1].l + s[ptr + 1].r == s[ptr].l + s[ptr].r)
//		ptr++;
//	swap(s[0], s[ptr / 2] );
//	int sti = 0;
	long long std = 0;
//	if (n % 2 == 1)
//	{
//		sti = 1;
//		std = (n / 2) * 1LL * (s[0].l + s[0].r);
//	}
	dp[n / 2][n / 2][n % 2] = std;

	for (int i = 0; i < n; i++)
	{
		for (int rl = 0; rl <= n / 2; rl++)
		{
			for (int t = 0; t < 2; t++)
			{
				int rr = n - i - rl - t;
				if (rr < 0 || rr > n / 2) continue;
				
				if (rl != 0)
					updDp(dp[rl - 1][rr][t], (rl - 1) * 1LL * (s[i].l + s[i].r) + s[i].r + dp[rl][rr][t] );
				if (rr != 0)
					updDp(dp[rl][rr - 1][t], (rr - 1) * 1LL * (s[i].l + s[i].r) + s[i].l + dp[rl][rr][t] );
				if (t == 1)
					updDp(dp[rl][rr][0], dp[rl][rr][1] + (n / 2) * 1LL * (s[i].l + s[i].r) );
			}
		}
	}
	long long ans = dp[0][0][0];
	printf("%lld\n", ans);


	return 0;
}



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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

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

ll INF = LLONG_MAX / 10;

int main() {
	int x, y; cin >> x >> y;
	cout << (x <= 8 && y <= 8 ? "Yay!" : ":(") << endl;
}


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

int main()
{
	int n;
	cin >> n;
	string s = to_string(n);
	int div = 0;
	for (int i = 0; i < s.length(); i++)
		div += (s[i] - '0');
	if (n%div == 0)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 256
const line = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n');

const maxHeapify = (arr, i) => {
    const l = i * 2;
    const r = l + 1;
    let max;

    if (l <= arr.length && arr[l-1] > arr[i-1]) {
        max = l;
    } else {
        max = i;
    }
    if (r <= arr.length && arr[r-1] > arr[max-1]) {
        max = r;
    }

    if (max !== i) {
        const tmp = arr[i-1];
        arr[i-1] = arr[max-1];
        arr[max-1] = tmp;
        maxHeapify(arr, max);
    }

};

const buildMaxHeap = arr => {
    for (let i = Math.floor(arr.length / 2); i > 0; i--) {
        maxHeapify(arr, i);
    }

    return arr;
};

const data = line[1].split(' ').map(Number);
console.log(' ' + buildMaxHeap(data).join(' '));



Measured memory_bytes: 106932
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second

int n;
string s;
int ans[110];

int main() {
	cin >> n;
	REP(i, n) {
		int cnt[110] = {};
		string s;
		cin >> s;
		REP(j, s.size()) {
			cnt[(s[j] - 'a')]++;
		}
		REP(j, 27) {
			if (i == 0)ans[j] = cnt[j];
			else ans[j] = min(ans[j], cnt[j]);
		}
	}
	REP(i, 27) {
		REP(j, ans[i]) {
			cout << (char)('a' + i);
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main() {
    char text[1001], word[11], end[] = "END_OF_TEXT";
    int cou = 0;
    scanf("%10s", word);
    
    while (1) {
        scanf("%s", text);
        if (!(strcmp(text, end))) {break;}
        
        for (int i=0; text[i]!='\0'; i++) {
            text[i] = tolower(text[i]);
        }
        
        if (!(strcmp(text, word))) {cou++;}
    }
    
    printf("%d\n", cou);
    return 0;
}



Measured memory_bytes: 2056
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
  string s;
  cin>>s;
  string s1,s2;
  while(1){
    s.pop_back();
    if(s.size()%2!=0){
      continue;
    }
    s1=s.substr(0,s.size()/2);
    s2=s.substr(s.size()/2);
    if(s1==s2){
      cout<<s.size()<<endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
# input
N = int(input())

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

ans = N

for i in range(N + 1):
    tmp = 0
    a_6 = Base_10_to_n(i, 6)
    for j in a_6:
        tmp += int(j)
    a_9 = Base_10_to_n(N - i, 9)
    for k in a_9:
        tmp += int(k)
    if tmp < ans:
        ans = tmp

print(ans)   




Measured memory_bytes: 3060
#include <iostream>
#include <string>
using namespace std;
int w,h;
string mp[51];
void check() {
  for(int i=0;i<h;i++) 
    cout << mp[i] << endl;
  cout <<"--------------------"<<endl;
}

void saiki(int x,int y,char sta){
  int dx[4] = {0,0,-1,1};
  int dy[4] = {1,-1,0,0};
  for(int i=0;i<4;i++) {
    int nx = x+dx[i];
    int ny = y + dy[i];
    if(nx < 0 || ny < 0 || nx >=w || ny >=h) continue;
    if(mp[ny][nx] == '.'){
      mp[ny][nx] = sta;
      saiki(nx,ny,sta);
    }else if((sta == '1' && mp[ny][nx] == '2') || (sta == '2' && mp[ny][nx] == '1')) {
      mp[ny][nx] = '3';
      saiki(nx,ny,sta);
    } 
  }
}

int main() {

  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;

    for(int i=0;i<h;i++) cin >> mp[i];

    for(int i=0;i<h;i++) 
      for(int j=0;j<mp[i].size();j++) {
	if(mp[i][j] == 'W') saiki(j,i,'1');//,check();
	else if(mp[i][j] == 'B') saiki(j,i,'2');//,check();
      }

    int ans[2]={0,0};
    for(int i=0;i<h;i++) 
      for(int j=0;j<mp[i].size();j++) {
	if(mp[i][j] == '1') ans[1]++;
	else if(mp[i][j] == '2') ans[0]++;
      }
    
    // check();
      cout << ans[0] <<" "<<ans[1] <<endl;
  }

  return  0;

}

Measured memory_bytes: 1364
# @uthor : Kaleab Asfaw
from sys import stdin, stdout
# Fast IO
# from math import gcd

def input():
	a = stdin.readline()
	if a[-1] == "\n": a = a[:-1]
	return a
def print(*argv, end="\n", sep=" "):
	n = len(argv)
	for i in range(n):
		if i == n-1: stdout.write(str(argv[i]))
		else: stdout.write(str(argv[i]) + sep)
	stdout.write(end)
# Others
mod = 10**9+7
def lcm(x, y): return (x * y) / (gcd(x, y))
def fact(x, mod=mod):
	ans = 1
	for i in range(1, x+1): ans = (ans * i) % mod
	return ans
def arr2D(n, m, default=0):
	lst = []
	for i in range(n): temp = [default] * m; lst.append(temp)
	return lst
def sortDictV(x): return {k: v for k, v in sorted(x.items(), key = lambda item : item[1])}

def solve(n, k):
	cnt = 0
	for i in range(k, n+2):
		# print(((i/2)*(n+n-i+1)), ((i*(i-1))/2), i)
		cnt += ((i/2)*(n+n-i+1)) - ((i*(i-1))/2) + 1
		cnt = cnt % mod
	return int(cnt)

n, k = list(map(int, input().split()))
print(solve(n, k))

Measured memory_bytes: 63952
#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	int ans = 0;
	if (A + B < C * 2) {
		ans = A * X + B * Y;
	} else {
		if (X < Y) {
			ans = C * 2 * X + min(B, 2 * C) * (Y - X);
		} else {
			ans = C * 2 * Y + min(A, 2 * C) * (X - Y);
		}
	}

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


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

int	main()
{
    int n,j;
    long long ans = 0;
    int mx = 0;
    cin>>n;
    vector<int> input(n);
    for (int i=0;i<n;i++)
    {
        cin>>j;
        input[i]=j;
        mx = max(mx, j);
        ans += mx - input[i];
    }
    cout << ans << endl;
}

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

long long int k,a,b;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>k>>a>>b;
	if (a%k==0 || b%k==0 || a/k<b/k) cout<<"OK";else cout<<"NG";
}


Measured memory_bytes: 3644
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		FastScanner in = new FastScanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskC {
		FastScanner in;
		PrintWriter out;
		int n;
		boolean local = false;
		int[] seq = {0, 1, -1};

		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			this.in = in;
			this.out = out;
			if (local) {
				n = seq.length;
			} else {
				n = in.nextInt();
			}
			int l = 0;
			int r = n - 1;
			int lv = send(l);
			if (lv < 0) {
				return;
			}
			int rv = send(r);
			if (rv < 0) {
				return;
			}
			while (r - l > 2) {
				int m = (l + r) / 2;
				if (m % 2 != 0) {
					++m;
				}
				int mv = send(m);
				if (mv < 0) {
					return;
				}
				if (mv == lv) {
					l = m;
				} else {
					r = m;
				}
			}
			if (send(l + 1) < 0) {
				return;
			}
			if (send(l + 2) < 0) {
				return;
			}
			throw new AssertionError();
		}

		private int send(int i) {
			if (local) {
				return seq[i % n];
			}

			out.println(i % n);
			out.flush();
			String s = in.next();
			if (s.equals("Vacant")) {
				return -1;
			}
			if (s.equals("Male")) {
				return 0;
			}
			if (s.equals("Female")) {
				return 1;
			}
			throw new AssertionError();
		}

	}

	static class FastScanner {
		private BufferedReader in;
		private StringTokenizer st;

		public FastScanner(InputStream stream) {
			in = new BufferedReader(new InputStreamReader(stream));
		}

		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					String rl = in.readLine();
					if (rl == null) {
						return null;
					}
					st = new StringTokenizer(rl);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}

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

	}
}



Measured memory_bytes: 23844
#![allow(unused_imports)]
use std::io;
use std::cmp::*;
use std::collections::HashMap;
#[allow(dead_code)]
const M: i64 = 1e9 as i64 + 7;

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}
#[allow(dead_code)]
fn read<T>() -> T where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().trim().parse().unwrap()
}
#[allow(dead_code)]
fn readv<T>() -> Vec<T> where T: std::str::FromStr, T::Err : std::fmt::Debug {
    read_line().split(' ').map(|a| a.trim().parse().unwrap()).collect()
}

fn main() {
    let input = readv::<i32>();
    let (a, b) = (input[0], input[1]);
    if a + b >= 10 {
        println!("{}", "error");
    } else {
        println!("{}", a + b);
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
#define LM 55555
using namespace::std;


long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int a) {
	if (a < 0) {
		return -a;
	}
	return a;
}

long long A,B,C,H,W,X,Y,N, M,num,x,ans;
string s[1000], t;
bool a, b, c;
int main() {
	cin >>H>>W;

	if (H <= 8 && W <= 8) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define AC ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define for0 for(i=0;i<n;i++) cin>>a[i];
#define for1 for(i=1;i<=n;i++) cin>>a[i];
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define vpp vector< pair <ll,ll> > vp;
#define sortvecp(v) sort(v.begin(), v.end(), sortbysec);
#define map1 map<ll,ll> mapy;
#define mod 998244353
#define MAXN 998244353
#define INF 1e18
using namespace std;
bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.F<b.F);
}
string a,b,c;
ll dp[210][210][210];
int main(){
    //memset(dp,-1,sizeof dp);
    ll t,n,i,j,k;
    cin>>n;
    ll a=n%10;
    if(a==3) cout<<"bon";
    else if(a==1||a==0||a==6||a==8) cout<<"pon";
    else cout<<"hon";
 }


Measured memory_bytes: 3640
#include"bits/stdc++.h"

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

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;

/* 採点コード
	vector<int> t(D);
	rep(i, D) {
		cin >> t[i];
		t[i]--;
	}
	vector<int> last(26, 0);

	int v = 0;
	rep(i, D) {
		v += s[i][t[i]];
		last[t[i]] = i+1;
		rep(j, 26) {
			v -= c[j] * (i + 1 - last[j]);
		}
		cout << v << endl;
	}
	*/

int main(void) {
	srand(time(NULL));
	int D; cin >> D;
	vector<int> c(26, 0);
	rep(i, 26)cin >> c[i];
	vector<vector<int>> s(D, vector<int>(26, 0));
	rep(i, D)rep(j, 26)cin >> s[i][j];

	vector<int> t(D, 0);
	rep(i, D)t[i] = rand() % 26;
	vector<int> ans=t;
	int best = 0;

	auto start = clock();
	while (clock() - start < 1500) {
		int idx = rand() % D;
		t[idx] = rand() % 26;

		//採点
		vector<int> last(26, 0);
		int v = 0;
		rep(i, D) {
			v += s[i][t[i]];
			last[t[i]] = i + 1;
			rep(j, 26) {
				v -= c[j] * (i + 1 - last[j]);
			}
		}
		//採点
		if (best <= v) {
			ans = t;
		}
	}

	for (auto x : ans) {
		cout << x + 1 << endl;
	}
	/*
	vector<int> last(26, 0);

	t = ans;

	int v = 0;
	rep(i, D) {
		v += s[i][t[i]];
		last[t[i]] = i + 1;
		rep(j, 26) {
			v -= c[j] * (i + 1 - last[j]);
		}
	}
	*/
	return 0;
}

Measured memory_bytes: 3724
n, m, q = map(int, input().split())
arr = [list(map(int, input().split())) for _ in range(q)]

ans = 0
for i1 in range(1, m+1):
    for i2 in range(i1, m+1):
        for i3 in range(i2, m+1):
            for i4 in range(i3, m+1):
                for i5 in range(i4, m+1):
                    for i6 in range(i5, m+1):
                        for i7 in range(i6, m+1):
                            for i8 in range(i7, m+1):
                                for i9 in range(i8, m+1):
                                    for i10 in range(i9, m+1):
                                        tmp = 0
                                        A = [i1, i2, i3, i4, i5, i6, i7, i8, i9, i10]
                                        for a, b, c, d in arr: 
                                            if A[b-1] - A[a-1] == c:
                                                tmp += d
                                        ans = tmp if tmp > ans else ans

print(ans)

Measured memory_bytes: 9148
/*
 *  Lang    : C++
 *  Author  : little_angel
 */

#include <bits/stdc++.h>

using namespace std;
#define int long long

const int mod = 1e9L + 7;

int power(int x, int y) {
    int res = 1;
    while (y) {
        if (y & 1)res = res * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return res;
}

inline int inv(int x) {
    return power(x, mod - 2);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int h, w, n;
    cin >> h >> w >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;
    sort(a.begin(), a.end());
    n++;
    a.emplace_back(h, w);
    vector<int> dp(n);

    vector<int> fact(200123), rfact(200123);
    fact[0] = 1;
    for (int i = 1; i < 200123; i++)fact[i] = i * fact[i - 1] % mod;
    rfact[200122] = inv(fact[200122]);
    for (int i = 200121; i >= 0; i--)rfact[i] = (i + 1) * rfact[i + 1] % mod;

    // number of paths
    auto ncr = [&](int n, int r) -> int {
        return fact[n + r] * rfact[r] % mod * rfact[n] % mod;
    };

    for (int i = 0; i < n; ++i) {
        dp[i] = ncr(a[i].first - 1, a[i].second - 1);
        for (int j = i - 1; j >= 0; --j) {
            if (a[j].second <= a[i].second)
                dp[i] = (dp[i] - (dp[j] * ncr(a[i].first - a[j].first, a[i].second - a[j].second) % mod) + mod) % mod;
        }
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define  INF 1ll<<60
signed main(){
	int a,b;
	cin>>a>>b;
	if(b==1){
		cout<<0<<endl;
		return 0;
	}
	if(a>=b){
		cout<<1<<endl;
		return 0;
	}
	int soma=1;
	b-=a;
	a--;
	while(b>0){
		b-=a;
		soma++;
	}
	cout<<soma<<endl;
}

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

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

  long long N;
  cin >> N;
  vector<long long> H(N);
  for(long long i = 0; i < N; ++i) {
    cin >> H[i];
  }
  reverse(H.begin(), H.end());

  long long ans = 0, max_num = 0;
  long long now_height = H[0], now_num = 0;


  for(long long i = 1; i < N; ++i) {
    if(now_height <= H[i]) {
      max_num++;
      now_height = H[i];
    }
    else {
      max_num = 0;
      now_height = H[i];
    }
    ans = max(max_num, ans);
  }

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


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

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n);
    int sum = 0;
    for (auto& x : xs) {
        std::cin >> x;
        sum ^= x;
    }

    for (auto x : xs) std::cout << (sum ^ x) << " ";
    std::cout << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3984
N, M = map(int, input().split())
a = list(int(input()) for _ in range(M))

MOD = pow(10, 9) + 7

MAP = [0] * (N + 1)

for x in a:
    MAP[x] = -1

MAP[0] = 1 
for i in range(N):
    if MAP[i] < 0:
        continue

    MAP[i] %= MOD
    if i + 1 <= N and MAP[i+1] >= 0:
        MAP[i+1] += MAP[i]
    if i + 2 <= N and MAP[i+2] >= 0:
        MAP[i+2] += MAP[i]

print(MAP[N] % MOD)


Measured memory_bytes: 7836
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n,m,c,cnt=0,a;
    cin >> n >> m >> c;
    vll b(m);
    rep(i,m) cin >> b[i];
    rep(i,n){
        ll sum=0;
        rep(j,m){
            cin >> a;
            sum+=a*b[j];
        }
        sum+=c;
        if(sum>0) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n = int(input())
a = list(myinput())

# b = []
c = []
for i in range(n):
    # b.append(i+a[i])
    if i<a[i]:
        pass
    else:
        c.append(i-a[i])
# print(b)
# print(c)

c.sort()
# print(c)

ans = 0
for i in range(n):
    m = i + a[i]
    a1 = bisect_left(c,m)
    a2 = bisect_right(c,m)
    ans += a2 - a1
print(ans)


Measured memory_bytes: 101192
#include<stdio.h>

int main(){
  int i, j, x, y;
  int b, q1, q2, c1, c2;

  while(1){
    scanf("%d", &q1);
    if(q1 == 0) break;

    scanf("%d %d %d %d", &b, &c1, &c2, &q2);

    for(i=1, x=-1, y=-1; i<=q2; ++i){
      if(b < i*c1) break;
      j = (b - i*c1)/c2;
      if(i + j < q1) break;
      x = i;
      y = j;
    }

    if(x == -1) printf("NA\n");
    else printf("%d %d\n", x, y);
  }
  return 0;
}

Measured memory_bytes: 612
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
#define FOR(i,a,b) for(long long int i=a;i<b;i++)
#define sz(s) (long long int)(s).size()
#define pb push_back
#define mp make_pair
const ll inf = 1000000000;
const ll MOD = 1000000007;
vector<vector<ll> > g(100001);
ll dp[100001];
bool visited[100001];
void dfs(ll u){
    ll i, v;
    visited[u] = true;
    for(i=0;i<g[u].size();i++){
        v = g[u][i];
        if(!visited[v]){
            dfs(v);
        }
        dp[u] = max(dp[u], 1 + dp[v]);
    }
}

int main(void){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);   
    cout.tie(NULL);
    register ll i,j,k,x,y,m,n,t,q,temp,sum=0,count=0,f=1, ans = -1;
    cin>>n>>m;
    for(i=0;i<m;i++){
        cin>>x>>y;
        x--;
        y--;
        g[x].pb(y);
    }    
    for(i=0;i<n;i++){
        if(!visited[i]){
            dfs(i);        
        }
    }
    for(i=0;i<n;i++){
        ans = max(ans, dp[i]);
    }
    cout<<ans;
}    
	

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
#define AC 0
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>s;
	int sum=0;
	for(int i=0;i<s.size();i++) sum+=s[i]-'0';
	if(sum%9) cout<<"No";
	else cout<<"Yes";
	return AC;
}


Measured memory_bytes: 3780
import java.util.*;

public class Main {
    private static Scanner scanner;

    public static int[] inputIntArray(int n) {
        int[] res = new int[n];
        for (int i = 0; i < n; ++i) {
            res[i] = scanner.nextInt();
        }

        return res;
    }

    // public static String[] <T> ToStringArray(T[] arr) {
    // String[] res = new String[arr.length];
    // for(int i = 0; i < arr.length; ++i) {
    // res[i] = String.valueOf(arr[i]);
    // }

    // return res;
    // }

    private static List<Integer> asIntergerList(int[] arr) {
        List<Integer> intList = new ArrayList<Integer>();
        for (int i = 0; i < arr.length; i++) {
            intList.add(arr[i]);
        }

        return intList;
    }

    private static int[][] deepCopy(int[][] arr) {
        int[][] res = new int[arr.length][];
        for (int i = 0; i < arr.length; ++i) {
            res[i] = arr[i].clone();
        }

        return res;
    }

    private static String asString(int[][] arr) {
        String str = new String();

        for (int i = 0; i < 2; ++i) {
            str += "" + arr[i][0] + arr[i][1] + arr[i][2] + arr[i][3];
        }

        return str;
    }

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

        while (true) {
            String s = scanner.next();

            if ("-".equals(s)) {
                break;
            }

            int m = scanner.nextInt();

            for (int i = 0; i < m; ++i) {
                int h = scanner.nextInt();
                s = s.substring(h, s.length()) + s.substring(0, h);
            }
            System.out.println(s);
        }
    }
}



Measured memory_bytes: 26460
#include <iostream>
#include <algorithm>

int N;
std::string S;

int main(void){
    std::cin >> N;
    std::cin >> S;

    int x = 0;
    int max = 0;
    for(auto it=S.begin(), _END=S.end(); it != _END; ++it){
        if(*it == 'I'){
            x += 1;
            max = std::max(max,x);
        }else{
            x -= 1;
        }
    }
    std::cout << max << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;

int main(void){
    string s;
    cin>>s;
    cout<<s;
    if(s[s.size()-1]=='s') cout<<'e';
    cout<<"s"<<endl;
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int x, y, z, k;
    cin >> x >> y >> z >> k;
    int a[x], b[y], c[z];
    for (int i = 0; i < x; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < y; i++) {
        cin >> b[i];
    }
    for(int i = 0; i < z; i++) {
        cin >> c[i];
    }
    vector<int> v;
    for (int i = 0; i < x; i++) {
        for (int j = 0; j < y; j++) {
            v.push_back(a[i] + b[j]);
        }
    }
    sort(v.rbegin(), v.rend());
    vector<int> d;
    for (int i = 0 ; i < min(k, sz(v)); i++) {
        d.push_back(v[i]);
    }
    vector<int> ans;
    for (int i = 0; i < z; i++) {
        for (int j = 0; j < sz(d); j++) {
            ans.push_back(c[i] + d[j]);
        }
    }
    sort(ans.rbegin(), ans.rend());
    for (int i = 0; i < k; i++) {
        cout << ans[i] << "\n";
    }
}

Measured memory_bytes: 43140
package main

import "fmt"

func main() {
	var n int
	var s string
	fmt.Scan(&n)
	m := make(map[string]bool)
	for i := 0; i < n; i++ {
		fmt.Scan(&s)
		m[s] = true
	}
	fmt.Println(len(m))
}


Measured memory_bytes: 18888
import { readFileSync } from 'fs'
const input = readFileSync("/dev/stdin", "utf8")
const [K, X] = input.split(' ').map(v => parseInt(v))
const MIN = -10000, MAX = 10000
const minValue = Math.max(X - K + 1, MIN)
const maxValue = Math.min(X + K - 1, MAX)
let result = ''
for (let i  = minValue; i <= maxValue; i++) {
  result += i.toString() + ' '
}
console.log(result)

Measured memory_bytes: 7372
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  std::string s;
  cin >> s;
  std::bitset<1000001> bit;
  bool allzero = true;
  for (int si = 0; si < s.size(); si++) {
    if (s[si] == '0') {
      bit[si] = false;
    } else {
      bit[si] = true;
      allzero = false;
    }
  }
  if (allzero) {
    cout << n << endl;
    return 0;
  }
  int left = 0, right = 0;
  int chain;
  int result;
  if (bit[left]) {
    chain = 0;
  } else {
    chain = 1;
    while (right < n && !bit[right]) {
      right++;
    }
  }
  result = right - left + 1;
  while (right < n - 1) {
    right++;
    // cerr << "\033[93m" << left << " " << right << "\033[m" << endl;
    if (bit[right]) {
      // nothing
    } else {
      if (chain < k) {
        while (right < n && !bit[right]) {
          right++;
        }
        chain++;
      } else {
        while (left < n && bit[left]) {
          left++;
        }
        while (left < n && !bit[left]) {
          left++;
        }
        while (right < n && !bit[right]) {
          right++;
        }
      }
    }
    if (right == n) right = n - 1;
    // cerr << "\033[93m" << left << " " << right << "\033[m" << endl;
    result = std::max(result, right - left + 1);
    result = std::min(result, n);
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 576
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,M,K = inpl()

for x in range(N+1):
    for y in range(M+1):
        tmp = x*M+y*N-x*y*2
        if tmp == K:
            print('Yes')
            sys.exit()
print('No')


Measured memory_bytes: 49000
#include <iostream>
using namespace std;
struct score{
    int first,second,last;
};
struct status{
    score turn[11];
    int point;
    int id;
};

status flame[41];
int m;

void INPUT(int i);
void RESULT(int i);
int strike(int i,int t);
int spair(int i,int t);

int main(void){
    cin>>m;
    while(m!=0){
        for(int i=1;i<=m;i++){
            INPUT(i);
            RESULT(i);
        }
        status sub;
        for(int i=1;i<m;i++){
            for(int j=i+1;j<=m;j++){
                if(flame[i].point<flame[j].point||(flame[i].point==flame[j].point&&flame[i].id>flame[j].id)){
                    sub=flame[i];
                    flame[i]=flame[j];
                    flame[j]=sub;
                }
            }
        }
        for(int i=1;i<=m;i++){
            cout<<flame[i].id<<' '<<flame[i].point<<endl;
        }
        cin>>m;
    }
}

void INPUT(int i){
    cin>>flame[i].id;
    for(int j=1;j<=10;j++){
        flame[i].turn[j].first=0;
        flame[i].turn[j].second=0;
        flame[i].turn[j].last=0;
        if(j!=10){    
            cin>>flame[i].turn[j].first;
            if(flame[i].turn[j].first!=10){cin>>flame[i].turn[j].second;}
        }
        else{
            cin>>flame[i].turn[j].first;
            cin>>flame[i].turn[j].second;
            if(flame[i].turn[j].first+flame[i].turn[j].second>=10){
                cin>>flame[i].turn[j].last;
            }
        }
    }
}

void RESULT(int i){
    int p;
    p=0;
    for(int j=1;j<=10;j++){
        if(j!=10){
            if(flame[i].turn[j].first==10){
                p+=strike(i,j);
            }
            else if(flame[i].turn[j].first+flame[i].turn[j].second==10){
                p+=spair(i,j);
            }
            else{
                p+=flame[i].turn[j].first+flame[i].turn[j].second;
            }
        }
        else{
            p+=flame[i].turn[j].first+flame[i].turn[j].second+flame[i].turn[j].last;
        }
    }
    flame[i].point=p;
}

int spair(int i,int t){
    int p;
    p=10+flame[i].turn[t+1].first;
    return p;
}

int strike(int i,int t){
    int p;
    p=10;
    p+=flame[i].turn[t+1].first;
    if(flame[i].turn[t+1].first!=10||t==9){
        p+=flame[i].turn[t+1].second;
    }
    else{
        p+=flame[i].turn[t+2].first;
    }
    return p;
}


Measured memory_bytes: 3092
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define BIG 1000007
int min(int a,int b){
    if(a<b) return a;
    else return b;
}
int main(){
    int N,Ma,Mb;
    scanf("%d %d %d",&N,&Ma,&Mb);
    int a[42],b[42],c[42];
    for(int i=0;i<N;i++)
        scanf("%d %d %d",a+i,b+i,c+i);
    int DP[42][402][402];
    memset(DP,BIG,sizeof(DP));
    DP[0][0][0] = 0;
    DP[0][a[0]][b[0]] = c[0];
    for(int i=1;i<N;i++){
        for(int j=0;j<402;j++){
            for(int k=0;k<402;k++){
                if(j-a[i]<0 || k-b[i]<0)
                    DP[i][j][k] = DP[i-1][j][k];
                else
                     DP[i][j][k]= min(DP[i-1][j][k],DP[i-1][j-a[i]][k-b[i]]+c[i]);

            }
        }
    }
    int ans = BIG;
    for(int i=1;i*Ma<402 && i*Mb<402;i++){
        ans = min(ans,DP[N-1][i*Ma][i*Mb]);
    }
    if(ans == BIG) printf("-1");
    else printf("%d",ans);
}

Measured memory_bytes: 28248
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <queue>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll a, b;
    cin >> a >> b;

    cout << 6 - a - b << endl;

    return 0;
}


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

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    int now = 0;
    for (int i = 0; i < k; i++){
        if (now == 0){
            int tmp = a / 2;
            a = tmp;
            b += tmp;
            now = 1;
        }
        else {
            int tmp = b / 2;
            b = tmp;
            a += tmp;
            now = 0;
        }
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        List<BigDecimal> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            String value = sc.next();
            if("0".equals(value)) {
                System.out.println("0");
                return;
            } else {
                list.add(new BigDecimal(value));
            }

        }
        BigDecimal x = BigDecimal.valueOf(Math.pow(10, 18));
        BigDecimal result = BigDecimal.valueOf(1);
        for (BigDecimal decimal : list) {
            if (result.compareTo(x) > 0) {
                break;
            } else {
                result = result.multiply(decimal);
            }
        }
        if (result.compareTo(x) > 0) {
            System.out.println("-1");
        } else {
            System.out.println(result.stripTrailingZeros().toPlainString());
        }
    }
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  cin >> n;
  int a[200001] = {}, b[200001];
  rep(i, 0, n) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(a, a + n);
  int t = a[n / 2 - 1], tt = a[n / 2];
  rep(i, 0, n) {
    if(b[i] <= t) {
      cout << tt << endl;
    }else {
      cout << t << endl;
    }
  }
}


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

time = 0
result = "Yes"
jobs.sort(key=lambda x:x[1])

for job in jobs:
  time += job[0]
  if time > job[1]:
    result = "No"
    break

print(result)

Measured memory_bytes: 53720
INF = 1 << 60
nb_stones = int(input())
heights   = [int(x) for x in input().split()]
DP = [INF for _ in range(nb_stones)]
DP[0] = 0
DP[1] = DP[0] + abs(heights[1] - heights[0])
for i in range(1, nb_stones):
    DP[i] = min(DP[i-1] + abs(heights[i] - heights[i-1]), DP[i-2] + abs(heights[i] - heights[i-2]))
print(DP[nb_stones - 1])

Measured memory_bytes: 13924
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

void solve() {
  int n;
  scan(n);
  vi ans(n, 0);
  rep (i, n-1) {
    int a;
    scan(a);
    --a;
    ans[a] += 1;
  }
  rep (i, n) {
    print(ans[i]);
  }
}

int main() {
  solve();
  return 0;
}


Measured memory_bytes: 3672
#include <stdio.h>
int main (void)
{
  int a=0,b=0,c=0,i;
  char s[4];
  scanf("%s",s);


  for(i=0;i<3;i++){
    if(s[i]=='a') a=1;
    if(s[i]=='b') c=1;
    if(s[i]=='c') b=1;
  }

  if((a==1 && b==1) && c==1) puts("Yes");
  else puts("No");

  return 0;
}


Measured memory_bytes: 128
import java.io.*;
import java.util.StringTokenizer;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int x = in.nextInt();
        int[] a = in.nextIntArray(n);

        long ans = 0;
        for (int i=0; i < n-1; i++) {
            if (a[i] + a[i+1] > x) {
                int diff = (a[i] + a[i+1]) - x;
                ans += diff;
                int toSubtract = Math.min(diff, a[i+1]);
                a[i+1] -= Math.min(diff, a[i+1]);
                diff -= toSubtract;
                a[i] -= diff;
            }
        }

        out.println(ans);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


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

class Main {
	public static final int M = 48828125;
	public static boolean[] H = new boolean[M];	
    public static void main( String[] args ) {
        try {
 	      	BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );

        	int n = Integer.parseInt( kb.readLine( ) );
			String[] str = new String[3];
			for( int i=0; i<n; i++ ) {
				str = kb.readLine( ).split( " " );
				if( "insert".equals( str[0] ) ) {
					insert( str[1] );
				} else if( "find".equals( str[0] ) ) {
					if( find( str[1] ) ) {
						System.out.println( "yes" );
					} else {
						System.out.println( "no" );
					}
				}
			}
        } catch( IOException e ) {
            System.err.println( e );
        }
    }
    
   public static int getChar( char ch )
   {
		if( ch == 'A') {
			return 1;
		} else if( ch == 'C') {
			return 2;
		} else if( ch == 'G') {
			return 3;
		} else if( ch == 'T') {
			return 4;
		}
		return 0;
	}
	public static int getKey( String str )
	{
		int i;
		int key = 0, base = 1;
		char[] str2 = str.toCharArray() ;
		for ( i=0; i<str.length( ); i++ ) {
			key += base*( getChar( str2[i] ) );
			base *= 5;
		}
		return key;
	}
	
	public static boolean find( String str )
	{
		if( true == H[ getKey( str ) ] ) {
			return true;
		} else {
			return false;
		}
	}
	
	public static void insert( String str )
	{
		H[ getKey( str ) ] = true;
		return;
	}	
}

Measured memory_bytes: 205016
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string[] cin = Console.ReadLine().Split();

        int a = int.Parse(cin[0]);
        int b = int.Parse(cin[1]);
        int k = int.Parse(cin[2]);

        int cnt = 0;
        int ans = 0;
        for (int i = 100; 0 < i; i--)
        {
            if (a % i == 0 && b % i == 0) cnt++;
            if (cnt == k)
            {
                ans = i;
                break;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>; 
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> void re(T& x) { cin >> x; }
template<typename T> 
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "/home/o_o/MyCodes/pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007  

void solve(){
	int n ; 
	re(n);
	int cnt = 0 ;
	int cur = 0 ;
	rep(i,0,n){
		int a ; 
		cin >> a ; 
		cur = max(cur,a); 
		cnt+=cur-a;
	}
	cout << cnt << endl;
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();













#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		
		if (a*c <=b ) {
			System.out.println(c);
		}else {
			int count = 0;
			for (int i = 1; i <= c ; i++) {
				if(i*a <= b) {
					count++;
				}else {
					break;
				}
			}
			System.out.println(count);
		}
		sc.close();
	}
}

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

int main() {

	int h, w, a, b;

	cin >> h >> w >> a >> b;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (i < b && j < a || i >= b && j >= a) {
				cout << 0;
			}
			else {
				cout << 1;
			}
		}
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
string i;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a=0,b;
  char r,e;
  cin >>r>>e;
  if(r=='D') a++;
  if(e=='D') a++;
  if(a%2>0) cout <<"D\n";
  else cout <<"H\n";
  return 0;
}


Measured memory_bytes: 256