akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{
	int d, g;
	scanf("%d %d", &d, &g);
	int i, j;
	int p[11], c[11];
	for (i = 0; i < d; i++)
		scanf("%d %d", &p[i], &c[i]);
	int ans = 1000000009;
	int max = 1;
	for (i = 0; i < d; i++)
		max *= 2;
	int q, count, s;
	int v[11], pp[11];
	for (i = 0; i < max; i++)
	{
		q = i;
		s = 0;
		count = 0;
		for (j = 0; j < d; j++)
		{
			v[j] = q % 2;
			q /= 2;
		}
		for (j = 0; j < d; j++)
			pp[j] = 0;
		for (j = 0; j < d; j++)
		{
			if (v[j] == 1)
			{
				s += 100 * (j + 1) * p[j] + c[j];
				count += p[j];
			}
		}
		while (s < g)
		{
			q = 0;
			for (j = d - 1; j >= 0; j--)
			{
				if (v[j] == 0 && pp[j] < p[j])
				{
					s += 100 * (j + 1);
					pp[j]++;
					count++;
					q++;
					break;
				}
			}
			if (q == 0)
				break;
		}
		if (ans > count)
			ans = count;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String character = "";
		for (int i = 0 ; i < s.length() ; i++) {
			if (s.charAt(i) == '0') {
				character += "0";
			}
			if (s.charAt(i) == '1') {
				character += "1";
			}
			if (character.length() != 0 && s.charAt(i) == 'B') {
				character = character.substring(0,character.length() - 1);
			}
		}
		System.out.println(character);
	}
}

Measured memory_bytes: 21716
#define _DEBUG 1

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

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define check(s)
#endif

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

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

void solve(ll N, ll A, ll B) {
  ll s = N / (A + B);
  ll r = N % (A + B);
  ll c;
  if (r <= A) {
    c = r;
  } else {
    c = A;
  }
  ll answer = s * A + c;

  cout << answer << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You
// use the default template now. You can remove this line by using your custom
// template)
int main() {
  ll N;
  scanf("%lld", &N);
  ll A;
  scanf("%lld", &A);
  ll B;
  scanf("%lld", &B);
  solve(N, A, B);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int ball = 0;
    int people = 0;
    int ans = 0;

    cin >> ball >> people;

    if(people == 1){
        ans = 0;
    }else{
        ans = ball - people;
    }

    cout << ans << endl; 

    return 0;
}

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

long long n,a,b;
long long output;

void calu(){
    long long syo = n/(a+b);
    long long amari = n % (a+b);
    // cout << syo << endl;
    // cout << amari << endl;
    output = syo * a;
    if (amari != 0){
        if (amari <= a){
            output += amari;
        }else{
            output += a;
        }
    }
}

int main(){
    cin >> n >> a >> b;
    calu();
    cout << output;
    return 0;
}

Measured memory_bytes: 888
import math
N,M=map(int,input().split())
d=abs(N-M)
if d>1:
  print(0)
elif d==1:
  ans=math.factorial(N)*math.factorial(M)%(10**9+7)
  print(ans)
else:
  ans=math.factorial(N)*math.factorial(M)*2%(10**9+7)
  print(ans)

Measured memory_bytes: 5184
// Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

// Macro
#define rep(i, N) for(int i=0; i<(int)N; i++)
#define rrep(i, N) for(int i=(int)N-1; i>=0; i--)

// Type
template <typename T> using P = pair<T, T>;
using ll = long long;
using ull = unsigned long long;

// Constants
const ll INF = 1e18;
const ll MOD = 1000000007;

int N, Q;
string S;

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

  int _sum[N];
  _sum[0] = 0;

  rep(i, N-1) {
    _sum[i + 1] = _sum[i] + (S.substr(i, 2) == "AC");
  }

  rep(i, Q) {
    int l, r;
    cin >> l >> r;
    cout << _sum[r-1] - _sum[l-1] << endl;
  }

  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int digsum(int n) {
	int res = 0;
	while (n > 0) {
		res += n % 10;
		n /= 10;
	}
	return res;
}
int main() {
	int n,a;cin >> n;
	a = digsum(n);
	if (n % a == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#include <set>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <cmath>
#define INF 1000000007
using namespace std ;

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

	string sa,sb,sc ;
	cin>>sa>>sb>>sc ;

	int i = 0, j = 0, k = 0 ;

	int next = 0 ;

	while(1)
	{
		if(next == 0)
		{
			if(i == sa.size()){cout<<"A"<<endl ; return 0 ;}
			next = sa[i] - 'a' ;
			++i ;
		}
		else if(next == 1) 
		{
			if(j == sb.size()){cout<<"B"<<endl ; return 0 ;}
			next = sb[j] - 'a' ;
			++j ;
		}

		else
		{
			if(k == sc.size()){cout<<"C"<<endl ; return 0 ;}
			next = sc[k] - 'a' ;
			++k ;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();

		int N = Integer.parseInt(line);
		int x = 0;
		int i = 0;
		for(i = 3; i <= N; i++){
			x = i;
			if(x % 3 == 0){
				System.out.print(" "+i);
			}else{
				while(x!=0){
	                if(x%10==3){
	                    System.out.print(" " + i);
	                    break ; 
	                }
	                x = x/10; 
	            }
			}
		}
		System.out.printf("\n");
	}

}

Measured memory_bytes: 22140
# -*- coding: utf-8 -*-
s = input()

ans = 1
i = 2
tmp = s[0]
tmp2 = 1
while i <= len(s):
    if s[tmp2:i] != tmp:
        #print('a', i)
        tmp = s[tmp2:i]
        tmp2 = i
        ans += 1
        i += 1
    else:
        #print('b', i)
        i += 1
print(ans)


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

int main(void){
    ll a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
// @DateTime:    2020-04-22 17:06:03
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("-Ofast", "-funroll-all-loops", "-ffast-math")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <algorithm>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define SZ(a) int(a.size())
#define ALL(x) (x).begin(), (x).end()
#define trav(a, x) for (auto &a : x)
#define close \
    std::ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c)         \
    (sort(c.begin(), c.end()), \
     c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define CASET    \
    int ___T;    \
    cin >> ___T; \
    for (int __CS = 1; __CS <= ___T; __CS++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count());
int rnd(int x) { return mrand() % x; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
LL bin(LL x, LL n, LL MOD) {
    LL ret = MOD != 1;
    for (x %= MOD; n; n >>= 1, x = x * x % MOD)
        if (n & 1) ret = ret * x % MOD;
    return ret;
}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const double PI = acos(-1.0);
constexpr int maxn = 1e6 + 10;
constexpr int mod = 1e9 + 7;
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr ull base = 2333, P_1 = 19260811, P_2 = 999998639;
void add(int &a, int b) {
    a += b;
    if (a >= mod) a -= mod;
}
void dec(int &a, int b) {
    a -= b;
    if (a < 0) a += mod;
}
bool cmp(pii &a, pii &b) {
    if (a.second == b.second) return a.first < b.first;
    return a.second > b.second;
}
pii a[maxn];
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int x, l;
        cin >> x >> l;
        a[i] = {x - l, x + l};
    }
    sort(a, a + n, cmp);
    // for (int i = 0; i < n; i++) {
    //     printf("%d    %d\n", a[i].fi, a[i].se);
    // }
    int ans = 1;
    int ll = a[0].fi;
    for (int i = 1; i < n; i++) {
        // cout << " ll == " << ll << "   a[" << i << "].se===" << a[i].second
        //      << endl;
        if (a[i].se <= ll) {
            ll = a[i].fi;
            ans++;
        } else {
            ll = max(ll, a[i].first);
        }
    }
    cout << ans << endl;
}

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


int main() {
  ll N, L;
  cin >> N >> L;

  int min = -400000;
  for (int i = 0; i < N; i++) {
    if (abs(min) > L + i ) {
      min = L + i;
    }
  }

  int ans = 0;

  for (int i = 0; i < N; i++) {
    if (L + i != min) {
      ans += L+i;
    }
  }
  
  cout << ans << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
n=input()
k=int(input())


if int(n)<1000:
    c=0
    for i in range(1,int(n)+1):
       if len(str(i))-str(i).count("0")==k:
           c+=1
else:
    n_l=len(n)
    c=0
    if k==1:
        c=int(n[0])+9*(n_l-1)
    elif k==2:
        for i in range(2,n_l):
            c+=9*9*(i-1)
        c+=(int(n[0])-1)*9*(n_l-1)
        
        for i in range(1,n_l):
            if int(n[i])>0:
                c+=int(n[i])+(n_l-i-1)*9
                break

    else:
        for i in range(3,n_l):
            c+=9**3*((i-1)*(i-2)/2)
                    
        c+=(int(n[0])-1)*9*9*((n_l-1)*(n_l-2)/2)
        
        flag_i=False
        flag_j=False
        for i in range(1,n_l):
            if int(n[i])>0:
                flag_i=True
                for j in range(i+1,n_l):
                    if int(n[j])>0:
                        flag_j=True
                        break
            if flag_i:
                break
        if flag_i:
            c+=(int(n[i])-1)*9*(n_l-i-1)
            c+=9*9*((n_l-i-1)*(n_l-i-2)*0.5)
            if flag_j:
                c+=(int(n[j]))+9*(n_l-j-1)
                
print(int(c))

Measured memory_bytes: 3064
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if (op=='+'):
        print(a+b)
    elif (op=='-'):
        print(a-b)
    elif (op=='*'):
        print(a*b)
    elif (op=='/'):
        print(int(a/b))
    else:
        break
    


Measured memory_bytes: 5596
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

ll a[3];
int main() {
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	ll x = a[2] - a[1];
	ll y = a[2] - a[0];

	if (!(x & 1) && !(y & 1)) { // even even
		cout << (x + y) / 2 << endl;
	}
	else if ((x + y) & 1) { //odd even
		cout << (x + y) / 2 + 2 << endl;
	}
	else { //odd odd
		cout << (x + y) / 2 << endl;
	}
	return 0;
}

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

ll N, Q, A[100000], X[100000];
ll sum[100001], se[100001], so[100001];

bool check(ll x, ll a, ll b) {
  return abs(A[b] - x) < abs(A[a] - x);
}

ll solve(ll x) {
  ll l = 1, h = N + 1;
  while (h - l > 1) {
    ll m = (l + h) / 2;
    ll p = (m + 1) / 2;
    ll q = m / 2;
    if (check(x, N - m, N - p)) h = m;
    else l = m;
  }
  return (sum[N] - sum[N - (l + 1) / 2]) + (N % 2 == 0 ? so[N - l] : se[N - l]);
}

int main(void) {
  cin >> N >> Q;
  REP(i, 0, N) cin >> A[i];
  REP(i, 0, Q) cin >> X[i];

  REP(i, 0, N) sum[i + 1] = sum[i] + A[i];
  REP(i, 0, N) se[i + 1] = se[i] + (i % 2 == 0 ? A[i] : 0);
  REP(i, 0, N) so[i + 1] = so[i] + (i % 2 == 1 ? A[i] : 0);

  REP(i, 0, Q) cout << solve(X[i]) << endl;
}

Measured memory_bytes: 5632
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	          ll N,T;
	          cin >> N >> T;
	          ll time=0,s=0,d=0;
	          for(i=1;i<=N;i++){
	        	  ll t;
        	     cin >> t;
	        	  if(t<time){
	        		  time=t+T;
	        		  s=t+T;
	        	  }else{
	        		  time=t+T;
	        		  d+=t-s;
	        		  s=t+T;
	        	  }

	          }

	          cout << s-d << endl;



	          return 0;
}


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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()

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

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

int a,b;
int main(){
    ios::sync_with_stdio(false);
    cin >> a >> b;
    // 0になる
    if (a<=0 && 0<=b) {
        cout << "Zero" << endl;
    }
    // 負になる
    else if (a < 0 && b < 0) {
        if ( (abs(a-b)+1) % 2 == 0 ) cout << "Positive" << endl;
        else cout << "Negative" << endl;
    }
    else cout << "Positive" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//ifstream cin("lineup.in");
//ofstream cout("lineup.out");
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
int main(){
    IOS;
    long long n;
    cin>>n;
    if(n%2){
	cout<<0<<endl;
    }
    else{
	n/=2;
	long long ans=0;
	while(n>1){
	    ans+=n/5;
	    n/=5;
	}
	cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
// 解き直し.
// https://img.atcoder.jp/arc075/editorial.pdf
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define a first
#define b second
#define all(x) x.begin(), x.end()
LL a[202020], aCum[202020], b[202020], c[202020];

// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT{
    int n;
    vector<T> d;
    BIT(int n = 0) : n(n), d(n + 1) {}
    void add(int i, T x = 1){
        for(i++; i <= n; i += i & -i) d[i] += x;
    }
    T sum(int i){
        T x = 0;
        for(i++; i; i -= i & -i) x += d[i];
        return x;
    }
    T sum(int l, int r){
        return sum(r - 1) - sum(l - 1);
    }
};

int main(){
    
    // 1. 入力情報.
    int N;
    LL K;
    scanf("%d %lld", &N, &K);
    rep(i, N) scanf("%lld", &a[i]);
    
    // 2. 累積和.
    rep(i, N) aCum[i + 1] = aCum[i] + a[i];
    
    // 3. 数列 b を 計算.
    rep(j, N) b[j + 1] = aCum[j + 1] - (LL)(j + 1) * K;
    // rep(j, N + 1) printf("%lld ", b[j]);
    // puts("");
    
    // 4. 大小関係を保ったまま, 0 ～ N に 圧縮.
    // -> p.a: 圧縮前の値(b[0] ～ b[N]), p.b: 圧縮後の値(0 ～ N).
    map<LL, int> m;
    rep(j, N + 1) m[b[j]] = 1;
    int idx = -1;
    for(auto &p : m) p.b = ++idx;
    // for(auto &p : m) printf("a=%lld b=%d\n", p.a, p.b);
    rep(j, N + 1) c[j] = m[b[j]];
    
    // 5. 0 ～ N の 出現回数 を 保持しながら, 集計.
    BIT<LL> ft(N + 1);
    LL ans = 0;
    rep(j, N + 1){
        // c[j]以下 の 値が, c[0] ～ c[j - 1] で 何回出現したかを集計.
        ans += ft.sum(0, c[j] + 1);
        
        // c[j] を 反映.
        ft.add(c[j], 1);
    }
    
    // 6. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 23556
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        String ans = "Yes";
        
        int p_t = 0;
        int p_x = 0;
        int p_y = 0;
        
        for(int i = 0; i < n; i++){
            int t = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();
            
            int diff = Math.abs(x-p_x) + Math.abs(y-p_y);
            if(diff > t-p_t || Math.abs(t-p_t - diff)%2==1){
                ans = "No";
                break;
            }
            p_t = t;
            p_x = x;
            p_y = y;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 87348
#include<cstdio>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    // puts("-1");
    int a = 1;
    int num = n % 10;
    int mod[4] = {10, 100, 1000, 10000};
    // puts("0");
    for(int i = 0; i < 3; i++){
        // puts("1");
        if ((n % mod[i+1]) / mod[i] == num){
            a++;
            if (a == 3) {
                puts("Yes");
                return 0;
            }
        } else {
            a = 1;
            num = (n % mod[i+1]) / mod[i];
        }
    }
    puts("No");
}

Measured memory_bytes: 888
#include <cstdio>
#include <vector>

const int size = 10001;
bool isprime[size];

int main() {
    isprime[0] = false;
    isprime[1] = false;
    for (int i = 2; i < size; ++i) {
        isprime[i] = true;
    }
    for (int i = 2; i < size; ++i) {
        if (isprime[i]) {
            for (int j = 2; i * j < size; ++j) {
                isprime[i * j] = false;
            }
        }
    }
    
    int n;
    while (scanf("%d", &n) != EOF) {
        std::vector<int> v;
        for (int i = 1; i <= n; ++i) {
            v.push_back(i);
        }
                
        int ans = 0;
        auto rit = v.rbegin();
        for (auto it = v.begin(); it != v.end(); ++it) {
            if (isprime[*rit++] && isprime[*it]) {
                ++ans;
            }
        }
        printf("%d\n", ans);
    }
}

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

struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n, -1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -d[find(x)]; }
};

int main() {
    int N, M; cin >> N >> M;
    UnionFind uf(N);
    
    int ans = N - 1;
    for (int i = 0; i < M; i++) {
        int A, B; cin >> A >> B;
        A--, B--;
        if (!uf.same(A, B)) {
            uf.unite(A,B);
            ans--;
        } 
    }
    cout << ans << endl;
    return 0;
}

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

#define xx first
#define yy second

#define MAX_N 300000

using namespace std;

const int sqrInf = (int)(1e9) - 1;

int n, m;/*
int a[1009][1009];

string s;

const int dl[] = {-1, 1, 0, 0};
const int dc[] = {0, 0, 1, -1};

int sl, sc;
int xl, xc;

priority_queue <pair<pair<int, int>, int>, vector<pair<pair<int, int>, int>>, greater<pair<pair<int, int>, int>> > q;

int dp[1009][1009];
int viz[1009][1009];

void solve()
{
    dp[sl][sc] = 0;
    q.push({{0, sl}, sc});

    while(q.size() > 0)
    {
        auto cr = q.top();
        q.pop();

        int l = cr.xx.yy;
        int c = cr.yy;

        if(viz[l][c] == 0)
        {
            viz[l][c] = 1;

            for(int d = 0; d < 4; d ++)
            {
                int nl = l + dl[d];
                int nc = c + dc[d];

                if(nl >= 1 && nl <= n && nc >= 1 && nc <= m)
                {
                    if(a[nl][nc] == 0)
                    if(dp[l][c] < dp[nl][nc])
                    {
                        dp[nl][nc] = dp[l][c];
                        q.push({{dp[nl][nc], nl},nc });
                    }
                }
            }

            for(int nl = l - 2; nl <= l + 2; nl ++)
            {
                for(int nc = c - 2; nc <= c + 2; nc ++)
                {
                    if(nl >= 1 && nl <= n && nc >= 1 && nc <= m)
                    {
                        if(a[nl][nc] == 0)
                        if(dp[l][c] + 1 < dp[nl][nc])
                        {
                            dp[nl][nc] = dp[l][c] + 1;
                            q.push({{dp[nl][nc], nl},nc });
                        }
                    }
                }
            }
        }
    }
}
*/
int lin[MAX_N + 1];
int col[MAX_N + 1];

unordered_map <int, int> ap[MAX_N + 1];

int q;
pair<int, int> b[MAX_N + 1];

int dl;
int xl[MAX_N + 1];

int dc;
int xc[MAX_N + 1];

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

    cin >> n >> m >> q;
    for(int i = 1; i <= q; i ++)
    {
        int l, c;
        cin >> l >> c;
        lin[l] ++;
        col[c] ++;
        ap[l][c] = 1;

        b[i] = {l, c};

    }

    int rez = 0;
    int ml = 0, mc = 0;
    for(int i = 1; i <= q; i ++)
    {
        ml = max(ml, lin[b[i].xx]);
        mc = max(mc, col[b[i].yy]);
    }

    int cnt = 0;
    for(int i = 1; i <= q; i ++)
    {
        rez = max(rez, lin[b[i].xx] + col[b[i].yy] - 1);

        if(lin[b[i].xx] + col[b[i].yy] == ml + mc)
            cnt ++;
    }

    for(int i = 1; i <= n; i ++)
    {
        if(lin[i] == ml)
            xl[++ dl] = i;
    }

    for(int j = 1; j <= m; j ++)
    {
        if(col[j] == mc)
            xc[++ dc] = j;
    }

    rez = ml + mc;

    if(cnt == dl * dc)
        rez --;


    cout << rez << "\n";

    return 0;
}


Measured memory_bytes: 45764
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        System.out.println(s.substring(0,5) + " " + s.substring(6,6+7) + " " + s.substring(14, 14+5));
    }
}


Measured memory_bytes: 21204
#include<stdio.h>
int main()
{
  int a, b, x, y, z;
  
  if( scanf("%d", &a) == 1);
  if( scanf("%d", &b) == 1);
  
  x = a + b;
  y = a - b;
  z = a * b;
  
  if(x>=y)
   if(x>=z)
     printf("%d", x);
  if(y>x)
   if(y>=z)
     printf("%d", y);
  if(z>x)
   if(z>y)
     printf("%d", z);
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>

using namespace std;
/*
void swap(char& x, char &y)
{
	char tmp = x; x = y; y = tmp;
}

void sort(char a[])
{
	for (int i=0; i<15; i++) {
		for (int j=14; j>i; j--) {
			if (a[j-1] > a[j]) swap(a[j-1], a[j]);
		}
	}
}
*/
bool isWin(int p[], int depth)
{
	if (depth == 4) {
		for (int i=1; i<=9; i++) {
			if (p[i]==2) return true;
		}
		return false;
	}
	else { // depth < 4
		for (int i=1; i<=9; i++) {
			if (p[i]>=3) {
				p[i] -= 3;
				bool success = isWin(p, depth+1);
				p[i] += 3;
				if (success) return true;
			}
		}
		for (int i=1; i<=7; i++) {
			if (p[i]>0 && p[i+1]>0 && p[i+2]>0) {
				p[i]--; p[i+1]--; p[i+2]--;
				bool success = isWin(p, depth+1);
				p[i]++; p[i+1]++; p[i+2]++;
				if (success) return true;
			}
		}
		return false;
	}
}

int main()
{
	char hand[14];
	
	while ( cin >> hand ) {
		int count_pai[10] = {0};
		for (int i=0; i<13; i++) count_pai[hand[i]-'0']++;
		bool first_output = true;
		for (int pai=1; pai<=9; pai++) {
			if (count_pai[pai] == 4) continue;
			count_pai[pai]++;
			if ( isWin(count_pai, 0) ) {
				if (first_output) first_output = false;
				else cout << " ";
				cout << pai;
			}
			count_pai[pai]--;
		}
		if ( first_output ) cout << 0;
		cout << endl;
	}
			
	return 0;
}

Measured memory_bytes: 2996
n,m = map(int,input().split())

red = [0 for i in range(n)]
amount = [1 for i in range(n)]
red[0] = 1
for _ in range(m):
    x,y = map(int,input().split())
    amount[x-1] -= 1
    amount[y-1] += 1
    if red[x-1]:
      red[y-1] = 1
    if amount[x-1] == 0:
      red[x-1] = 0
ans = 0
for r,a in zip(red, amount):
  if r > 0 and a > 0:
    ans += 1



print(ans)

Measured memory_bytes: 4760
#include <stdio.h>
#include <math.h>

double ceil(double);
int main(void){
  
  int H, W, N, ans;

  scanf("%d%d%d", &H, &W, &N);
  if(H > W){
    ans = ceil((double)N / (double)H);
  }
    else
    {
    ans = ceil((double)N / (double)W);
    }
    printf("%d", ans);
    
    return(0);
    }    
    

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

int main() {
    int n;
    cin >> n;
    vector<ll> march (5);
    for(int i=0; i<n; i++){
        string st;
        cin >> st;
        if(st.at(0) == 'M') march.at(0)++;
        if(st.at(0) == 'A') march.at(1)++;
        if(st.at(0) == 'R') march.at(2)++;
        if(st.at(0) == 'C') march.at(3)++;
        if(st.at(0) == 'H') march.at(4)++;
    }
    ll ans = 0;
    for(int i=0; i<3; i++){
        for(int j=i+1; j<4; j++){
            for(int k=j+1; k<5; k++){
                ans += march.at(i)*march.at(j)*march.at(k);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 764
#include <iostream>
using namespace std;
int main(){
  int n;
  long long int y;
  cin >> n >> y;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n-i;j++){
      int k=n-i-j;
       if((i*1000+j*5000+k*10000)==y){
         cout <<k<<" "<< j<<" "<< i<<endl;
         return 0;
       }
      }
    }
  cout <<-1<<" "<<-1<<" "<<-1<<endl;
}


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

using namespace std;

int main(){
    int n = 5,k, c = 0;
    int arr[n];
    for (int i = 0; i < n; i++){
        cin >> arr[i];
    }
    for (int i = 0; i < n ;i++){
        (arr[i] == 0) ? c = (i + 1):k = 0;
    }
    cout << c;
    return 0;
}




Measured memory_bytes: 3604
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
 
struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};
 
typedef struct node * NodePointer;
 
NodePointer nil;
 
NodePointer listSearch(int key){
  NodePointer x;
  for(x = nil->next;x!=nil;x=x->next){
  if(x->key==key)return x;
  }
  return NULL;
}
 

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;

}
 
void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}
 
void deleteNode(NodePointer t){
 
 
  t->next->prev=t->prev;
  t->prev->next=t->next;
 
  free(t);
}
 
void deleteFirst(){
  NodePointer t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}
 
void deleteLast(){
  NodePointer t = nil->prev;
  if (t==nil)return;
  deleteNode(t);
}
 
void delete(int key){
  NodePointer t=listSearch(key);
  if(t==NULL)return;
  deleteNode(t);
}
 
 
void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
 
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
 
 
}
 
int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", com, &key);
    if ( com[0] == 'i' ) {insert(key); np++; size++;}
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
    if ( com[6] == 'F' ) deleteFirst();
    else if ( com[6] == 'L' ) deleteLast();
      } else {
    delete(key); nd++; 
      }
      size--;
    }
  }
 
  printList();
  return 0;
}


Measured memory_bytes: 32992
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define MAXN 100005

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	ll h,w; cin>>h>>w;
	
	if(h==1 || w==1){
		cout<<1<<'\n';
		return 0;
	}
	
	ll ans=0;
	ans+=((h+1)/2) * ((w+1)/2);
	ans+=((h)/2) * ((w)/2);
	
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}


Measured memory_bytes: 3620
n = int(input())
list1 = []
for i in range(n):
    get = input()
    list1.append(get)
print("AC x {}".format (list1.count("AC")))
print("WA x {}".format (list1.count("WA")))
print("TLE x {}".format (list1.count("TLE")))
print("RE x {}".format (list1.count("RE")))


Measured memory_bytes: 16256
n = int(raw_input())
d = [100 for i in range(n)]
G = [0 for i in range(n)]
v = [[0 for i in range(n)] for j in range(n)]
 
def Bread(s):
    for e in range(n):
        if v[s][e] == 1:
            if d[e] > d[s] + 1:
                d[e] = d[s]+1
                Bread(e)
 
for i in range(n):
    G = map(int, raw_input().split())

    for j in range(G[1]):
        v[G[0]-1][G[j+2]-1] = 1

d[0] = 0
 
for i in range(n):
    Bread(i)

for i in range(n):
    if d[i] == 100:
        d[i] = -1

for i in range(n):
    print i+1, d[i]

Measured memory_bytes: 6492
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
long long f[maxn],s[maxn];
long long ans;
int main()
{
    int n,x;
    cin>>n;
    f[0]=0,s[0]=0;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        f[i]=f[i-1]+x;
        s[i]=s[i-1]^x;
    }
    int L=1;
    ans=0;
    for(int R=1;R<=n;R++)
    {
        while((f[R]-f[L-1])!=(s[R]^s[L-1])) L++;
        ans+=R-L+1;
    }
    cout<<ans;
}


Measured memory_bytes: 3328
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string s;
	cin >> s;
	bool ok=0;
	for(int i=0; i<2&&!ok; i++){
		if(s[i]==s[i+1]&&s[i+1]==s[i+2]){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}	


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<int, int> > vp;
typedef pair<int, int> pr;
typedef tuple<int, int, int> ti;

#define FOR(i, a, b) for (int i = (a), _b = (b); i < _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i > _a; i--)
#define pb push_back
#define print(v) cout << v << '\n'
#define pr_vec(v)   for (auto i: v) cout << i << ' '
#define vin(v)  for (auto &i: v)    cin >> i

ld pi = 3.141592653589793238;
ll M = 1e9 + 7;

int gcd(int a, int b) {
    if (a == 0) return b;

    return gcd(b % a, a);
}

bool is_prime(ll n) {
    if (n == 2) return true;
    if (n < 2) return false;
    if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2) {
        if (n % i == 0) return false;
    }

    return true;
}

bool is_palindrome(string s) {
    return equal(s.rbegin(), s.rend(), s.begin());
}

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

    ll t, n, m, k, q, x, y;
    string s;
    bool flag;

    cin >> t;
    vi a, b;
    while (t--) {
        cin >> n >> m;
        a.pb(n);
		b.pb(m);
    }

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

    if (a.size() % 2) {
        x = a[a.size() / 2];
        y = b[b.size() / 2];
        print(y - x + 1);

    } else {
        x = a[a.size() / 2] + a[a.size() / 2 - 1];
        y = b[b.size() / 2] + b[b.size() / 2 - 1];
        print(y - x + 1);
    }

    return 0;
}

Measured memory_bytes: 5136
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
vector<int> v[20010];
int main(){
	int n,x,y,l,r,z,i,j,w,a=1145141919;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>x>>y;x+=10000,y+=10000;
		w=(int)sqrt((int)a);
		for(j=max(0,x-w);j<=min(20005,x+w);j++){
			l=0,r=v[j].size();
			while(l<r){
				z=(r+l)/2;
				a=min(a,(x-j)*(x-j)+(y-v[j][z])*(y-v[j][z]));
				if(v[j][z]<y)l=z+1;
				else r=z;
			}
		}
		v[x].push_back(y);
	}
	cout<<a<<endl;
	return 0;
}

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

using namespace std;

 

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
  
 	long long int  n;
 	cin >> n;
  	if (n % 1000 == 0) cout << 0;
  	else cout << 1000 - n % 1000;


	
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define rvc(i,S) for(int i=0;i<(int)S.size();++i)
#define fore(i,x) for(int i = head[x] ; i ; i = e[i].next)
#define mp make_pair
#define pb push_back
#define maxn 1005
#define ll long long 
#define fi first
#define se second
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
int n,x,y;
string s1,s2,s3;
int main()
{  cin>>n;
  cin>>s1>>s2>>s3;
  int sum=0;
  for(int i=0;i<n;i++)
  { if(s1[i]==s2[i]&&s2[i]==s3[i]) continue;
    else
      {if(s1[i]==s2[i]||s1[i]==s3[i]||s2[i]==s3[i]) sum++;
	   else  sum+=2;
	  }
  }
	cout<<sum<<endl;
return 0;	
}

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

#define int long long
#define ll long long
#define vi vector <int>
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>b;i--)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define MOD 1000000007
#define PI 3.14159265359
/*

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>

using namespace __gnu_pbds;
typedef tree<pii,null_type,less <pii>,rb_tree_tag,tree_order_statistics_node_update>ind_set;
*/
///*X.find_by_order("index")
///X.order_of_key("key")



#define deb(x) cerr<<#x<< " : " <<x<<"\n";
#ifndef local
	#define deb(x) ;
#endif
///----------------------------------------------------------------------------------

int n;
string s;

void solve()
{
	int l;cin>>n>>l;

	int ans=(n)*(l+l+n-1)/2;
	int sub=MOD;
	rep(i,0,n)
	{
		sub=min(sub,abs(l+i));
	}
	if (l>0)ans-=sub;
	else if (l+n-1<0)ans+=sub;
	else ans-=sub;
	cout<<ans;

}
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    #ifdef local
    ///freopen("input.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    #endif

    clock_t qwertyuiop = clock();
    int t=1;
    ///cin>>t;
    rep(a,0,t)
    {
        ///cout<<"Case #"<<a+1<<": ";
        solve();
    }
    #ifdef local
	{qwertyuiop = clock() - qwertyuiop;double time_taken = ((double)qwertyuiop)/CLOCKS_PER_SEC;cerr<<fixed<<setprecision(5)<<"\n\nTime Taken : "<<time_taken<<" seconds\n";}
	#endif
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (size_t i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (size_t k = 1; k < v.size(); k++)
	{
		for (size_t j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
ll repeat_squaring(ll n, ll p, ll m)
{
	if (p == 0)
		return 1;
	if (p % 2 == 0)
	{
		ll t = repeat_squaring(n, p / 2, m);
		return t * t % m;
	}
	return n * repeat_squaring(n, p - 1, m);
}

int main()
{
	double w, h, x, y;
	cin >> w >> h >> x >> y;
	if (w / 2 == x && h / 2 == y)
	{
		cout << w * h / 2 << " " << 1 << endl;
	}
	else
	{
		cout << w * h / 2 << " " << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// abc176_c
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
  int N;
  cin>>N;
  vector<int> A(N);
  ll ans = 0;
  rep(i, N) cin>>A[i];
  int beforeMax = A.front();
  for(auto x : A) {
    if (beforeMax > x) {
      ans += beforeMax - x;
    }
    beforeMax = max(beforeMax, x);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3960
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;

int main(){

  int n,i,j,x[10000],a;
  long long sum,sum2;

  while(1){
    sum=0;
    sum2=0;
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++){
      scanf("%d",&x[i]);
    }
    sort(x,x+n);
    sum=x[0];
    for(i=1;i<n;i++){ 
      sum2+=sum;
      sum+=x[i];
    }
    printf("%lld\n",sum2);
  }
  return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<30;

int main() {
  string S; cin >> S;
  reverse(S.begin(), S.end());
  const string s[4] = {"maerd", "remaerd", "esare", "resare"};
  int itr = 0;
  while(itr != S.size()) {
    bool matched = false;
    for(int i = 0; i < 4; i++) {
      if(S.substr(itr, s[i].size()) == s[i]) {
        itr += s[i].size();
        matched = true;
      }
    }
    if(!matched) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}



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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] sx = Console.ReadLine().Split(' ');
            string[] sy = Console.ReadLine().Split(' ');
            int[] d = new int[n];
            double p1=0, p2=0, p3=0, p4=0;

            for(int i=0;i<n;i++)
            {
                d[i] = Math.Abs(int.Parse(sx[i]) - int.Parse(sy[i]));
                p1 += d[i];
                p2 += Math.Pow(d[i], 2);
                p3 += Math.Pow(d[i],3);
                p4 = (p4 > d[i]) ? p4 : d[i];
            }

            Console.WriteLine("{0:.000000}",p1);
            Console.WriteLine("{0:.000000}",Math.Sqrt(p2));
            Console.WriteLine("{0:.000000}",Math.Pow(p3,(double)1/(double)3));
            Console.WriteLine("{0:.000000}",p4);
        }
    }
}

Measured memory_bytes: 9508
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)				// repeat
#define repr(i, begin, end) for (ll i = begin - 1; end <= i; i--)		// repeat reverse

#endif

class NyaGadgetCpp17
{
public:
	/**
	@brief 最大公約数を計算する関数
	@note
	 aとbの最大公約数を返す
	**/
	template <typename T> static T Gcd(T a, T b)
	{
		return b ? Gcd(b, a % b) : a;
	}
};

int main(void)
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	a = a - 1;

	ll ans1 = a - ((a / c) + (a / d) - (a / ((c * d) / NyaGadgetCpp17::Gcd(c, d))));
	ll ans2 = b - ((b / c) + (b / d) - (b / ((c * d) / NyaGadgetCpp17::Gcd(c, d))));

	cout << ans2 - ans1;
	return 0;
}


Measured memory_bytes: 256
INF = 10**30

class Rmax():
	def __init__(self, size):
		#the number of nodes is 2n-1
		self.n = 1
		while self.n < size:
			self.n *= 2
		self.node = [0 for _ in range(2*self.n-1)]

	def Access(self, x):
		return self.node[x+self.n-1]

	def Update(self, x, val):
		x += self.n-1
		self.node[x] = val
		while x > 0:
			x = (x-1)//2
			self.node[x] = max(self.node[2*x+1], self.node[2*x+2])
		return

	#[a, b)
	def Get(self, a, b, k=0, l=0, r=-1):
		if r < 0:
			r = self.n

		if a >= r or b <= l:
			return 0
		elif a <= l and b >= r:
			return self.node[k]
		else:
			vl = self.Get(a, b, 2*k+1, l, (l+r)//2)
			vr = self.Get(a, b, 2*k+2, (l+r)//2, r)
			return max(vl, vr)

n = int(input())
H = list(map(int, input().split()))
A = list(map(int, input().split()))
dp = Rmax(n)
for h, a in zip(H, A):
	h -= 1
	opt = dp.Get(0, h) + a
	if opt > dp.Access(h):
		dp.Update(h, opt)

#print(dp.node)
print(dp.Get(0, n))

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

using namespace std;

int main(int argc, char *argv[]) {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int K;
    cin >> K;

    char c = S[K - 1];

    for (int i = 0; i < S.size(); i++) {
        if (S[i] != c) {
            S[i] = '*';
        }
    }

    cout << S << endl;
    return 0;
}


Measured memory_bytes: 256
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
class N{
public:
  string s;
  int ln;
  N(){
  }
  N(int n){
    s.assign(n,'0');
    ln=n;
  }
  N(string t){
    s=t;
    ln=s.length();
    update();
  }
  N plus(const N& t){
    int i;
    N u(max(ln,t.ln)+1);
    int c=0;
    for(i=0;i<max(ln,t.ln);++i){  
      int p=(ln-i-1<0?0:s[ln-i-1]-'0')+(t.ln-i-1<0?0:t.s[t.ln-i-1]-'0')+c;
      u.s[u.ln-i-1]=p%10+'0';
      c=p/10;
    }
    u.s[u.ln-i-1]=c+'0';
    u.update();
    return u;
  }
  void update(){
    int i;
    for(i=0;i<ln-1&&s[i]=='0';++i);
    s.erase(0,i);
    ln-=i;
  }
};
int main(){
  int i;
  int n;
  cin>>n;
  for(i=0;i<n;++i){
    string s,t;
    cin>>s>>t;
    N a(s),b(t);
    N c=a.plus(b);
    if(c.ln>80)
      cout<<"overflow"<<endl;
    else
      cout<<c.s<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

//Main
var sc = bufio.NewScanner(os.Stdin)

const MAX = 1000000000000000000

var N int

func main() {
	sc.Split(bufio.ScanWords)
	N = nextInt()
	A := make([]string, N)
	for i := 0; i < N; i++ {
		a := nextStr()
		A[i] = a
		if a == "0" {
			fmt.Println(0)
			return
		}
	}

	//0がないとき
	var ans, b int64
	ans = 1
	b = MAX
	for _, a := range A {
		aa, _ := strconv.ParseInt(a, 10, 64)
		if aa > b {
			fmt.Println(-1)
			return
		}
		ans *= aa
		b /= aa
	}

	fmt.Println(ans)

}


Measured memory_bytes: 6712