akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(void){
	int sum=0;
	int x;
  	int number;
	scanf("%d",&number);
  	int a[number];
  	int b[number];
	for(int i=0;i<number;i++){
  		scanf("%d",a+i);
      	scanf("%d",b+i);
    	x=b[i]-a[i]+1;
    	sum+=x;
    }
  	printf("%d",sum);
}

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

#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;

using vecint = vector<int>;
using ll = int64_t;

int main()
{
  string s;
  cin>>s;
  cout<<s.substr(0,4)<<' '<<s.substr(4)<<endl;
  return 0;
}

Measured memory_bytes: 256
using System;
namespace pro
{
    class MainClass
    {
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());
            string[] str0 = Console.ReadLine().Split(' ');
            int[] b = new int[n];
            for(int i = 0; i < n-1; i++)
            {
                b[i] = int.Parse(str0[i]);
            }
            int[] a = new int[n];
            for(int i = 1; i < n-1; i++)
            {
                a[i] = Math.Min(b[i], b[i - 1]);
            }
            a[0] = b[0];
            a[n-1] = b[n - 2];

            int d = 0;
            for(int i = 0; i < n; i++)
            {
                d += a[i];
                
            }
            Console.WriteLine(d);
        }
    }
}

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

int main(){
	int n,v[111],menort = 0,maiort = 0,resp = 1e9;
	scanf("%d",&n);
	for(int i = 0;i < n;++i){
		scanf("%d",&v[i]);
	}
	int flag = 0;
	for(int t = 1;t < n;++t){
		for(int i = 0;i < n;++i){
			if(i < t){
				menort += v[i];
			}else{
				maiort += v[i];
			}
		}
		resp = min(resp,abs(maiort-menort));
		maiort = 0;
		menort = 0;
	}
	printf("%d\n",resp);

	return 0;
}

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

#define int long long

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

  vector<int> a(N);
  double sum = 0;  
  for ( int i = 0; i < N; i++ ) {
    cin >> a[i];
    sum += a[i];
  }

  sum /= (double)N;
  double sa = 1e18;
  int id;
  double EPS = 1e-9;
  for ( int i = 0; i < N; i++ ) {
    //  cout << sa << " " << abs(sum-a[i])+EPS << endl;
    if ( i == 0 ) {
      id = i;
      sa = abs(sum-a[i]);      
    }
    else if ( sa > abs(sum-a[i])+EPS ) {
      id = i;
      sa = abs(sum-a[i]);      
    }
  }

  cout << id << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<complex>
#include<iomanip>

using namespace std;

#define REP(i,s,e) for(int i=int(s);i<=int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)
#define pi 3.14159265358979


int main(void){

	int n;
	cin >> n;
	vector<long long>v(n);
	rep(i,n)
		cin >> v[i];

	sort(v.begin(),v.end(),greater<long long>());

	long long m1=0,m2=0; bool f=false;
	for(int i=0;i<=n-7;i++){
	  if(v[i]<v[i+1]+v[i+2]){
		for(int j=i+4;j<=n-3;j++){
			if(v[j]<v[j+1]+v[j+2]){
			   m1=v[i]+v[i+1]+v[i+2]+v[j]+v[j+1]+v[j+2];
					f=true; break;
				}
			}
		}
		   if(f) break;
	}

	f=false;
	for(int i=0;i<=n-6;i++){

		vector<long long>u(6);
		rep(k,6) u[k]=v[i+5-k];

		do{
			long long a=max(u[0],max(u[1],u[2])),
			          b=max(u[3],max(u[4],u[5])),
		              c1=u[0]+u[1]+u[2],
			          c2=u[3]+u[4]+u[5];

			if(a<c1-a && b<c2-b){
			    m2=c1+c2; f=true; break;
			}

		}while(next_permutation(u.begin(),u.end()));

		if(f) break;
	}

    cout << max(m1,m2) << endl;

	return 0;
}

Measured memory_bytes: 1796
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        int N;
        long[] A;
        PriorityQueue<Double> queue1 = new PriorityQueue<>(1,new TaskComparator1());


        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            A = new long[N];
            for (int i = 0; i < A.length; i++) {
                A[i] = sc.nextLong();
            }
        }

        for (int i = 0; i < A.length; i++) {
            queue1.offer((double)A[i]);
        }

        while(queue1.size() >= 2){
            double a = queue1.poll();
            double b = queue1.poll();
            double c = (double)(a + b) /(double)2;
            queue1.add(c);
        }

        System.out.println(queue1.poll());

    }

    static class TaskComparator1  implements Comparator{
        @Override
        public int compare(Object o1, Object o2) {
            Double x = (Double)o1;
            Double y = (Double)o2;
            if (x > y) {
                return 1;
            } else if (x < y) {
                return -1;
            } else{
                return 0;
            }
        }
    }

}


Measured memory_bytes: 22868
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>
#include <cmath>
#include <utility>
#include <map>
#include <functional>

using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)




int main() {
	int N, M, X;
	cin >> N >> M >> X;
	int A[1000] = { 0 };
	int B[1000] = { 0 };
	int i, j, k;
	rep(i, 0, M) {
		int t;
		cin >> t;
		A[t] = 1;
	}
	rep(i, 1, N) {
		B[i] = B[i - 1] +A[i];
	}
	cout << MIN(B[N-1] - B[X] , B[X] - A[X]);
	return 0;
}



Measured memory_bytes: 256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    A = [[int(s) - 1 for s in reversed(readline().split())] for _ in range(N)]

    M = N * (N - 1) // 2
    games = 0
    players = set(range(N))

    for d in range(1, M + 1):
        players, players_prev = set(), players
        for i in players_prev:
            if not A[i] or i in players:
                continue
            j = A[i][-1]
            if j not in players and i == A[j][-1]:
                players.add(i)
                players.add(j)
                A[i].pop()
                A[j].pop()
                games += 1

        if games == M:
            print(d)
            break

        if not players:
            print(-1)
            break

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 91736
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};

int main()
{
	ll a, b, k;
	cin >> a >> b >> k;
	if(k <= a)
		a -= k, k = 0;
	else
		k -= a, a = 0;
	b -= k;
	if(b < 0)
		b = 0;
	cout << a << ' ' << b;





	





	getchar();
	getchar();
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

s64 mypow(s64 x, s64 n)
{
    s64 ret = 1;
    while (n > 0)
    {
        if (n & 1) ret = (ret * x) % MOD;
        x = (x * x) % MOD;
        n >>= 1;
    }
    return ret;
}

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

    string s;
    cin >> s;

    const int a = 0;
    const int b = 1;
    const int c = 2;
    const int q = 3;

    vector< vs32 > pos(4);

    rep (i, s.size())
    {
        if (s[i] == '?')
        {
            pos[q].push_back(i);
        }
        else
        {
            pos[s[i] - 'A'].push_back(i);
        }
    }

    s64 ans = 0;
    rep (i, pos[b].size())
    {
        auto ita = lower_bound(pos[a].begin(), pos[a].end(), pos[b][i]);
        auto itc = lower_bound(pos[c].begin(), pos[c].end(), pos[b][i]);
        auto itq = lower_bound(pos[q].begin(), pos[q].end(), pos[b][i]);

        s64 numa = (ita == pos[a].begin() ? 0 : ita - pos[a].begin());
        s64 numc = pos[c].end() - itc;
        s64 numq = (itq == pos[q].begin() ? 0 : itq - pos[q].begin());

        ans += (((numa * mypow(3, numq) % MOD + numq * mypow(3, numq - 1) % MOD) % MOD) *
            ((numc * mypow(3, pos[q].size() - numq) % MOD + (pos[q].size() - numq) * mypow(3, pos[q].size() - numq - 1) % MOD) % MOD)) % MOD;
        ans %= MOD;
    }
    rep (i, pos[q].size())
    {
        auto ita = lower_bound(pos[a].begin(), pos[a].end(), pos[q][i]);
        auto itc = lower_bound(pos[c].begin(), pos[c].end(), pos[q][i]);

        s64 numa = (ita == pos[a].begin() ? 0 : ita - pos[a].begin());
        s64 numc = pos[c].end() - itc;

        ans += (((numa * mypow(3, i) % MOD + i * (mypow(3, i - 1)) % MOD) % MOD) *
                ((numc * mypow(3, pos[q].size() - i - 1) % MOD + (pos[q].size() - i - 1) * mypow(3, pos[q].size() - i - 2) % MOD) % MOD)) % MOD;
        ans %= MOD;
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 1104
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap

class Mod:
    def __init__(self, m):
        self.m = m

    def add(self, a, b):
        return (a + b) % self.m

    def sub(self, a, b):
        return (a - b) % self.m

    def mul(self, a, b):
        return ((a % self.m) * (b % self.m)) % self.m

    @lru_cache(maxsize=None)
    def div(self, a, b):
        return self.mul(a, pow(b, self.m-2, self.m))

    def pow(self, a, b):
        return pow(a, b, self.m)

@mt
def slv(N, X):
    M = Mod(10**9+7)
    ne = [1]
    for i in range(1, N+1):
        ne.append(M.mul(i, ne[i-1]))
    ans = 0
    p = 0
    for i in range(N-1):
        d = X[i+1] - X[i]
        p = M.add(p, M.div(ne[N-1], i+1))
        ans = M.add(ans, M.mul(d, p))
    return ans

def slv2(N, X):
    ans = 0
    s = Counter()
    for p in permutations(range(N-1)):
        x = X[:]
        for i in p:
            for j in range(i+1, N):
                if x[j]:
                    break

            ans += x[j] - x[i]
            s[(j, i)] += 1
            x[i] = None
    for i in range(N-1):
        for j in range(i+1, N):
            print(i, j, s[(j,i)])
    return ans

def main():
    N = read_int()
    X = read_int_n()
    print(slv(N, X))
    # print(slv2(N, X))

    # N = 10**4
    # X = list(range(1, N+1))
    # print(slv(N, X))


if __name__ == '__main__':
    main()


Measured memory_bytes: 99988
#include <iostream>
#include <bitset>

int main()
{	
	std::bitset<64> bs(0);
	
	int q; std::cin >> q;
	for (int i=0; i<q; i++) {
		int op, k;
		std::cin >> op;
		switch (op) {
		case 0:
			std::cin >> k;
			std::cout << bs.test(k) << std::endl;
			break;
		case 1:
			std::cin >> k;
			bs.set(k);
			break;
		case 2:
			std::cin >> k;
			bs.reset(k);
			break;
		case 3:
			std::cin >> k;
			bs.flip(k);
			break;
		case 4:
			std::cout << bs.all() << std::endl;
			break;
		case 5:
			std::cout << bs.any() << std::endl;
			break;
		case 6:
			std::cout << bs.none() << std::endl;
			break;
		case 7:
			std::cout << bs.count() << std::endl;
			break;
		case 8:
			std::cout << bs.to_ullong() << std::endl;
			break;
		}
	}
	return 0;
}



Measured memory_bytes: 3104
import java.util.*;
class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextInt();
        long b = sc.nextInt();
        long a00000 = a * 100000;
        long c = a00000 / b;
        long d = c / 100000;
        long f = c % 100000;
        String sf = ""+f;
        while(sf.length() < 5) sf = "0" + sf;
        //System.out.println("" + (a/b) + " " + (a%b) + " " + (a/(double)b));
        System.out.println("" + (a/b) + " " + (a%b) + " " + d + "." + sf);
    }
}

Measured memory_bytes: 17292
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int start = s.indexOf("A");
    int end   = s.lastIndexOf("Z");
    int length = end + 1 - start;
    System.out.println(length);    
  }
}




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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

ll func(ll b, ll n){
    ll ret = 0;
    while (n > 0){
        ret += n % b;
        n /= b;
    }
    return ret;
}

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

    ll ans = longinf;

    if (N == S){
        cout << N + 1 << endl;;
        return 0;
    }

    ll p;
    for (ll b = 2; b * b <= N; b++){
        if(func(b, N) == S){
                cout << b << endl;
                return 0;
        }
        p = b;
    }

    for(ll p = 1; p * p < N; p++){
        if(p > S) break;
        if((N - S + p) % p==0){
            ll y = (N - S + p) / p;
            if(y > S - p){
                ans=min(ans,y);
            }
        }
    }

    cout << (ans == longinf ? -1 : ans) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << '\n'; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 3005;

int n, t;
struct node {
    int a, b;   
    bool operator < (const node &A) const {
        return a < A.a;   
    }
}p[N];
int maxv[N];
int dp[N][N];

void run(){
    for(int i = 1; i <= n; i++) cin >> p[i].a >> p[i].b;
    sort(p + 1, p + n + 1);
    for(int i = n; i >= 1; i--) maxv[i] = max(maxv[i + 1], p[i].b);
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= t - 1; j++) {
            dp[i][j] = dp[i - 1][j];
            if(j >= p[i].a) dp[i][j] = max(dp[i][j], dp[i - 1][j - p[i].a] + p[i].b);
        }
        ans = max(ans, dp[i][t - 1] + maxv[i + 1]);
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    while(cin >> n >> t) run();
	return 0;
}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    string N;
    cin >> N;
    if(N[0]==N[1] and N[1]==N[2]){
        cout << "Yes" << endl;
        return;
    }
    if(N[1]==N[2] and N[2]==N[3]){
        cout << "Yes" << endl;
        return;
    }

    cout << "No" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
 
#define DEBUG(x) cerr << #x << " = " << x << endl
 
int costTable[50][50];
 
struct Node {
    int cost, numMove;
    vector<int> hist;
    Node() : cost(0), numMove(0), hist(vector<int>()) { }
 
    bool operator <(const Node& x) {
        if(cost != x.cost) return cost < x.cost;
        if(numMove != x.numMove) return numMove < x.numMove;
        return hist < x.hist;
    }
 
    Node next(int day, int hotelId, bool change) {
        Node res = *this;
        res.cost += costTable[hotelId][day];
        if(change) res.numMove++;
        res.hist.push_back(hotelId);
        return res;
    }
 
};
 
ostream& operator <<(ostream& os, const Node& x) {
    os << "Node(" << x.cost << ", " << x.numMove << ", { ";
    if(x.hist.empty() == false) {
        for(int i = 0; i < (int)x.hist.size() - 1; i++) {
            os << x.hist[i] << ", ";
        }
        os << *x.hist.rbegin() << ' ';
    }
    os << "})";
    return os;
}
 
int main() {
    int N, D; cin >> N >> D;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < D; j++) {
            cin >> costTable[i][j];
        }
    }
 
    static Node dp[50][51];
    static bool used[50][51];
    memset(used, 0, sizeof(used));
    for(int i = 0; i < N; i++) used[i][0] = false;
    for(int day = 0; day < D; day++) {
        for(int id = 0; id < N; id++) {
            for(int nextId = 0; nextId < N; nextId++) {
                if(id == nextId) {
                    if(used[nextId][day+1] == false || dp[id][day].next(day, nextId, false) < dp[nextId][day+1]) {
                        dp[nextId][day+1] = dp[id][day].next(day, nextId, false);
                        used[nextId][day+1] = true;
                    }
                }
                else {
                    if(used[nextId][day+1] == false || dp[id][day].next(day, nextId, true) < dp[nextId][day+1]) {
                        dp[nextId][day+1] = dp[id][day].next(day, nextId, true);
                        used[nextId][day+1] = true;
                    }
                }
            }
        }
    }
#if 0
    for(int i = 0; i < N; i++) {
        DEBUG(dp[i][1]);
    }
#endif
 
    Node ans = dp[0][D];
    for(int i = 0; i < N; i++) {
        if(dp[i][D] < ans) ans = dp[i][D];
    }
    cout << ans.cost << ' ' << ans.numMove << endl;
    for(int i = 0; i < (int)ans.hist.size(); i++) cout << ans.hist[i] + 1 << endl;
}

Measured memory_bytes: 1816
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
using ll = long long;

int main() {
    ll A,B,C;cin>>A>>B>>C;
    if((A==1 && B!=C) || B>C){cout<<0<<endl;}
    else {
        ll mn = (A-1)*B + C;
        ll mx = (A-1)*C + B;
        cout << mx - mn + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<stdio.h> 
using namespace std;
const long long mod=1000000007;
long long n,m,a[20];
long long fac[1000003],inv[1000003],cnt[1000003],bin[20];
long long f[18][1000003];
void add(long long &x,long long y){x+=y;if(x>=mod)x-=mod;}
long long qpow(long long a,long long b){
	if(b==1){
		return a;
	}
	long long ret=qpow(a,b/2);
	ret=ret*ret%mod;
	if(b&1){
		ret=ret*a%mod;
	}
	return ret;
}
inline long long C(long long n,long long m){
	if(n<m){
		return 0;
	}
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main(){
	cin>>n>>m;
	bin[0]=1,fac[0]=1,cnt[0]=1;
	inv[0]=1;
	for(long long i=1;i<=n;i++){
		bin[i]=bin[i-1]*2%mod;
	}
	for(long long i=1;i<=bin[n];i++){
		fac[i]=(fac[i-1]*i)%mod;
	}
	inv[bin[n]]=qpow(fac[bin[n]],mod-2);
	for(long long i=bin[n]-1;i;i--){
		inv[i]=inv[i+1]*(i+1)%mod;
	}
	for(long long i=1;i<=bin[n];i++){
		cnt[i]=(i&1)?mod-cnt[i>>1]:cnt[i>>1];
	}
	for(int i=1;i<=m;i++){
		cin>>a[i];
	}
	sort(&a[1],&a[m+1]);
	f[m+1][0]=1;
	for(int i=m;i;--i){
		for(int t=0;t<bin[n];++t){
        	if(f[i+1][t]){
				add(f[i][t],f[i+1][t]);
                int p=bin[n]-1-t;
                for(int j=0;j<n;++j){
                	if(!(t&(1<<j))){
                    	add(f[i][t|(1<<j)],1ll*C(p-a[i]+1,(1<<j)-1)*f[i+1][t]%mod*fac[1<<j]%mod);
					}
				}
            }
		}
	}
	long long ans=0;
	for(int i=0;i<=bin[n]-1;i++){
		ans=(ans+f[1][i]*fac[bin[n]-1-i]%mod*cnt[i]%mod)%mod; 
	}
	cout<<ans*bin[n]%mod<<endl;
	return 0;
}

Measured memory_bytes: 49408
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e15+1);
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int main(void){
	int n,m,l,i,j,k;cin>>n>>m>>l;
	int ar[100][100]={0};
	int br[100][100]={0};
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>ar[i][j];
		}
	}
	for(j=0;j<m;j++){
		for(k=0;k<l;k++){
			cin>>br[j][k];
		}
	}
	for(i=0;i<n;i++){
		for(k=0;k<l;k++){
			llint wa=0;
			for(j=0;j<m;j++){wa+=ar[i][j]*br[j][k];}
			cout<<wa;
			if(k<l-1){cout<<" ";}
		}
		cout<<endl;
	}
	RE;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define fi first
#define se second

using namespace std;

const int mod = 1e9+7;

int dp[2][305][305]={};
vector<pair<int,int>> seg[305];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,m; cin >> n >> m;
	
	while(m--){
		int l,r,x; cin >> l >> r >> x;
		seg[r].emplace_back(l,x);
	}
	
	dp[0][0][0]=1;
	for(int i=0;i<=n;i++){
		int cur = i&1, nxt=(i+1)&1;
		for(int j=0;j<=i;j++){
			for(int k=0;k<=j;k++){
				
				for(auto s:seg[i]){
					
					int cx=1+(j>=s.fi)+(k>=s.fi);

					//cout << dp[cur][j][k] << " " << j << " " << k << " " << cx << endl;
					
					dp[cur][j][k]*=(cx==s.se);
				}
				
				
				dp[nxt][j][k]=(dp[nxt][j][k]+dp[cur][j][k])%mod;
				dp[nxt][i][k]=(dp[nxt][i][k]+dp[cur][j][k])%mod;
				dp[nxt][i][j]=(dp[nxt][i][j]+dp[cur][j][k])%mod;
			}
		}
		
		if(i<n)
			memset(dp[cur],0,sizeof(dp[cur]));
	}
	
	int ans=0;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			ans=(ans+dp[n&1][i][j])%mod;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<queue>
#include<functional>
struct S{int x1,y1,x2,y2,c;}s,t;
struct C:std::binary_function<S,S,int>{int operator()(S a,S b){return a.c>b.c;}};
int main()
{
	int h,w,m[9][9],d[8][8][8][8],i,j,V=63,a[]={0,1,0,-1,0};
	while(scanf("%d%d",&w,&h),w)
	{
		for(i=0;i<h+2;++i)m[i][0]=m[i][w+1]=1;
		for(j=0;j<w+2;++j)m[0][j]=m[h+1][j]=1;
		for(i=1;i<=h;++i)for(j=1;j<=w;++j)
			if(scanf("%d",&m[i][j]),m[i][j]==4)m[s.y1=i][s.x1=j]=0;
			else if(m[i][j]==2)m[s.y2=i][s.x2=j]=0;
		memset(d,V,16384);
		s.c=0;
		std::priority_queue<S,std::vector<S>,C>q;
		q.push(s);
		d[s.y1][s.x1][s.y2][s.x2]=0;
		while(q.size())
		{
			s=q.top();q.pop();
			for(i=0;i<4;++i)
			{
				t=s;
				t.x1+=a[i];
				t.y1+=a[i+1];
				if(m[t.y1][t.x1]==1)continue;
				if(t.y1==t.y2&&t.x1==t.x2)
				{
					if(m[t.y2+a[i+1]][t.x2+a[i]]==1)continue;
					t.x2+=a[i];
					t.y2+=a[i+1];
					t.c++;
					if(m[t.y2][t.x2]==3)
					{
						printf("%d\n",t.c);
						goto E;
					}
				}
				if(d[t.y1][t.x1][t.y2][t.x2]<=t.c)continue;
				d[t.y1][t.x1][t.y2][t.x2]=t.c;
				q.push(t);
			}
		}
		puts("-1");
E:;
	}
	return 0;
}

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

int main() {
  
  string s;
  cin >> s;
  
  int n = s.size();
  int cnt1 = 0,cnt2 = 0;
  
  for ( int i = 0; i < n; i++){
    if ( i % 2 == 0 ){
      if ( s[i] != '1' ){
        cnt1++;
      }
    }else{
      if ( s[i] != '0' ){
        cnt1++;
      }
    }
  }
  
  for ( int i = 0; i < n; i++){
    if ( i % 2 == 0 ){
      if ( s[i] != '0' ){
        cnt2++;
      }
    }else{
      if ( s[i] != '1' ){
        cnt2++;
      }
    }
  }
  
  cout << min(cnt1,cnt2) << endl;   
  
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    map<ll, ll> mp;
    rep(i, n) {
        ll a;
        cin >> a;
        mp[a]++;
    }

    ll ans = 0;
    for(auto p : mp) {
        if(p.second%2 == 1) {
            ans++;
        }
    }
    
    out(ans);
    re0;
}

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

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++)
    {
        cin >> d[i];
    }

    int sumNum = 0;
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            sumNum += d[i] * d[j];
        }
    }
    cout << sumNum << endl;
}


Measured memory_bytes: 256
s = input()
s = list(s)

for i in range(len(s)):
  mod = i % 2 
  
  if mod == 0 and s[i] == "L":
    print("No")
    break
  if mod == 1 and s[i] == "R":
    print("No")
    break
else:
  print("Yes")

Measured memory_bytes: 38384
#include <iostream>
#include <string>

using namespace std;

string a, b, op;

int main()
{
	cin >> a >> op >> b;

	if (op == "+")
	{
		cout << stol(a) + stol(b) << endl;
	}
	else
	{
		cout << stol(a) - stol(b) << endl;
	}

	return 0;
}

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

using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<int> s(N);
	vector<int> animal(N);
	
	for (int i = 0; i < N; i++) {
		char in;
		cin >> in;
		if (in == 'o') s[i] = 0;
		else s[i] = 1;
	}

	for (int x = 0; x < 4; x++) {
		animal[0] = x & 1;
		animal[1] = x >> 1;
		for (int n = 2; n < N; n++) {
			animal[n] = s[n - 1] ^ animal[n - 1] ^ animal[n - 2];
		}
		if (animal[N - 2] ^ animal[N - 1] ^ animal[0] ^ s[N - 1] ||
			animal[N - 1] ^ animal[0] ^ animal[1] ^ s[0]) continue;
		for (int n = 0; n < N; n++) cout << (animal[n] ? "W" : "S");
		cout << endl;
		system("pause");
		return 0;
	}

	cout << -1 << endl;

	system("pause");
	return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define rep(i,s,n) for(int i = s;i<n;i++)
#define long long ll
using namespace std;
struct Num{
    int ai;
    int aj;
    int de;
};
int main()
{
    int n;
    while(cin>>n){
       // vector<int> a;
        int a[n];
        rep(i,0,n){
           // a.push_back(n);
            cin>>a[i];
        }
        //sort(a.begin(),a.end());
        sort(a,a+n);
        int num =a[n-1];
        int t = num/2;
        //int no = lower_bound(a,a+n,t);
        int no = (lower_bound(a, a + n, t))-a;
        int s = abs(a[no]-t);
        int s2 = abs(a[no-1]-t);
        int ab;
        int nn;
        if(s==s2){
            ab = s;
            nn =no;
        }else if(s>s2){
            ab = s2;
            nn = no-1;
        }else{
            ab =s;
            nn = no;
        }
        if(nn==n-1) cout<<num<<" "<<a[nn-1]<<endl;
        else cout<<num<<" "<<a[nn]<<endl;
    }
}


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

#define mod 1000000007
#define MAX_N 200010
long long inv[MAX_N];
long long factorial[MAX_N];
long long inv_factorial[MAX_N];

void GetInv(){
    for (int i = 1; i < MAX_N; i++) {
        if (i == 1) inv[i] = 1;
        else {
            inv[i] = (mod - (mod / i) * inv[mod % i]) % mod;
            if (inv[i] < 0) inv[i] += mod;
        }
    }
}
void GetFactorial(){
    factorial[0] = 1; inv_factorial[0] = 1;
    for (int i = 1; i < MAX_N; i++) {
        factorial[i] = factorial[i-1] * i;
        factorial[i] %= mod;
        inv_factorial[i] = inv_factorial[i-1] * inv[i];
        inv_factorial[i] %= mod;
    }
}

long long combination(int n, int r) {
    long long ret = factorial[n] * inv_factorial[r];
    ret %= mod;
    ret *= inv_factorial[n-r];
    return ret % mod;
}

long long modpow(int n, int r) {
    long long ret = 1; long long tmp = (long long) n;
    while (r != 0) {
        if (r % 2) ret *= tmp;
        tmp *= tmp; tmp %= mod; ret %= mod;
        r /= 2;
    }
    return ret;
}
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    GetInv(); GetFactorial();
    int n; cin >> n;
    vector<long long> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    vector<long long> sum(n+1, 0);
    for (int i = 0; i < n; i++) sum[i+1] = sum[i] + x[i];
    long long ans = factorial[n-1] * (x[n-1] - x[0]) % mod;
    for (int k = 1; k < n; k++) {
        long long curr = inv[n-k] * factorial[n-1] % mod;
        curr *= x[n-1] - x[k];
        ans = (ans + curr % mod) % mod;
    }
    for (int k = 1; k < n; k++) {
        long long curr = inv[n-k] * inv[n-k-1] % mod * factorial[n-1] % mod;
        curr *= ((sum[n-1] - sum[n-k-1]) - (sum[k+1] - sum[1])) % mod;
        ans = (ans + curr % mod) % mod;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int dp[5010][5010];
int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = n - 1; i >= 0; i--) {
        for (int j = n - 1; j >= 0; j--) {
            if (s[i] == s[j]) {
                dp[i][j] = dp[i + 1][j + 1] + 1;
            }
        }
    }
    int ans = 0;
    rep(i, 0, n - 1) {
        rep(j, i + 1, n) {
            int tmp = min(dp[i][j], j - i);
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 98048
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let stdin = stdin();
    let mut buf = String::new();
	stdin.lock().read_line(&mut buf);
	buf.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
	read::<String>().trim().split_whitespace()
        .map(|w| w.parse().ok().unwrap()).collect()
}

fn read_vec_char() -> Vec<char> {
    read::<String>().chars().collect()
}

fn read_mat<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_mat_char(n: usize) -> Vec<Vec<char>> {
    (0..n).map(|_| read_vec_char()).collect()
}

fn main() {
    let n = read::<usize>();
    let mut con: Vec<usize> = vec![0;n];
    for i in 0..n {
        let p = read::<usize>();
        if p == 1 {
            con[0] = 1;
        } else if con[p-2] == 0 {
            con[p-1] = 1;
        } else {
            con[p-1] = con[p-2] + 1;
        }
    }
    let max = con.iter().max().unwrap();
    println!("{}",n-max);
}


Measured memory_bytes: 6396
#include <iostream>
#include <algorithm>
#include <string> 
#include <math.h>
#include <vector>
#define rep(i,n) for(int i=0; i< int(n); i++)
using namespace std;


int main(){
	int n;
	int a[110];
	cin >> n;
	for(int i=0; i < n; i++){
		cin >> a[i];
	}
	sort(a, a+n, greater<int>());
	int Alice = 0;
	int Bob = 0 ;
	for(int i=0; i<n; i++){
		if(i%2==0) Alice += a[i];
		else Bob += a[i];
	}
	cout << Alice - Bob << endl;
} 



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

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

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

using namespace std;

using T = tuple<ll,ll>;
using Graph = vector<vector<T>>;

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

    ll k,n;
    cin >> k >> n;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];

    rep(i,0,n) a.push_back(a[i]+k);

    ll max_itv(-LL_MAX);
    ll e1, e2;
    rep(i,1,n+1)
    { 
        ll itv = a[i] - a[i-1];
        if (max_itv < itv)
            max_itv = itv, e1 = i, e2 = i-1; 
        //cout << a[i] << ' ' << a[i-1] << endl;
    }

    if (e1>n-1) e1 -= n;
    if (e2<e1) e2 += n;

    //cout << max_itv << ' ' << e1 << ' ' << e2 << endl;

    ll dist(0);
    rep(i,e1+1,e2+1)
    {
        ll itv = a[i] - a[i-1];
        dist += itv;
    }

    cout << dist << endl;

    return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (int i=0;i<N;i++)

//変数
int H, W;
vector<vector<char>> mp(50, vector<char>(50));
vector<vector<bool>> check(50, vector<bool>(50));

//解法
void solve() {
	rep(i, H) rep(j, W) {

		if (check[i][j] == false) {

			if (i - 1 >= 0 && mp[i - 1][j] == '#') {
				check[i][j] = true;
				check[i - 1][j] = true;
			}
			if (i + 1 < H && mp[i + 1][j] == '#') {
				check[i][j] = true;
				check[i + 1][j] = true;
			}
			if (j - 1 >= 0 && mp[i][j - 1] == '#') {
				check[i][j] = true;
				check[i][j - 1] = true;
			}
			if (j + 1 < W && mp[i][j + 1] == '#') {
				check[i][j] = true;
				check[i][j + 1] = true;
			}

			if (check[i][j] == false) {
				cout << "No";
				return;
			}

		}

	}
	cout << "Yes";

	return;
}

int main() {
	//入力
	cin >> H >> W;
	rep(i, H) rep(j, W) {
		char input;
		cin >> input;
		mp[i][j] = input;
		if (input == '#') {
			check[i][j] = false;
		}
		else {
			check[i][j] = true;
		}
	}
	solve();
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import Counter

n, *v = map(int, open(0).read().split())
c1 = Counter(v[::2]).most_common()
c2 = Counter(v[1::2]).most_common()

c1.append([0, 0])
c2.append([0, 0])

if c1[0][0] != c2[0][0]:
  print(n - c1[0][1] - c2[0][1])
else:
  print(min(n - c1[0][1] - c2[1][1], n - c1[1][1] - c2[0][1]))


Measured memory_bytes: 20520
import math
x = 0
y = 0
shi = 90
while 1:
    a,b = map(int, input().split(","))
    if a == 0 and b == 0:
        break
    else:
        x += a*math.cos(math.radians(shi))
        y += a*math.sin(math.radians(shi))
        shi -= b
print(int(x))
print(int(y))


Measured memory_bytes: 5712
#include<stdio.h>

int main(void){
    int n;
    long long k;
    long long h=0;
    scanf("%d",&n);
    int a[n];
    a[0] = 0;
    for(int i=1; i<=n; i++){
        scanf("%d",&a[i]);
    }
    for(int i=1; i<=n; i++){
        k = a[i-1]-a[i];
        if(k > 0){
            h += k;
            a[i] = a[i-1]; 
        }
    }

    printf("%lld",h);

    return 0;
}

Measured memory_bytes: 2508
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int w, h;
	cin >> w >> h;
	char s;
	cin >> s;
	for (int i = 0; i < w; i++) {
		if (i == 0 || i == w - 1) cout << "+";
		else cout << "-";
	}
	cout << endl;
	for (int i = 1; i < h - 1; i++) {
		for (int j = 0; j < w; j++) {
			if (j == 0 || j == w - 1) cout << "|";
			else if (i == h / 2 && j == w / 2) cout << s;
			else cout << ".";
		}
		cout << endl;
	}
	for (int i = 0; i < w; i++) {
		if (i == 0 || i == w - 1) cout << "+";
		else cout << "-";
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, a, b;
	cin >> n >> a >> b;

	if ((b - a) % 2 == 0) {
		dunk((b - a) / 2);
	}
	else {
		ll ans1 = min(b - 1, n - a);
		ll ans2 = 0;
		if (a - 1 <= n - b) {
			ans2 += a;
			b -= a;
			ans2 += (b - 1) / 2;
		}
		else {
			ans2 += n - b + 1;
			a += n - b + 1;
			ans2 += (n - a) / 2;
		}
		dunk(min(ans1, ans2));
	}


	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int k = a[0];
    repf(i,1,n) {
        k ^= a[i];
    }
    rep(i,n) {
        cout << (int)(k ^ a[i]) << " ";
    }
    cout << endl;
    return 0;
}

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

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

  for(int i=0; i<N; i++){
    string S;
    cin >> S;

    if(S=="Y"){
      cout << "Four" << endl;
      break;
    }

    if(i==N-1){
      cout << "Three" << endl;
    }
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static boolean enough(long a, long b, long[] enemyTairyoku, long t) {
		long count = 0;
		for(int i=0; i<enemyTairyoku.length; i++) {
			if(enemyTairyoku[i]>b*t) {
				count += (int)Math.ceil((enemyTairyoku[i]-b*t)/((double)a-b));
			}
		}
/*		if (count <= t)
			System.out.println(t + " yes");
		else
			System.out.println(t + " no");*/
		return count <= t;
	}
	public static long calcMinAttackNum(long a, long b, long[] enemyTairyoku) {
		long min = 0;
		long max = 1000000000;
		while(min+1<max) {
			long c = (min+max)/2;
			if(enough(a, b, enemyTairyoku, c)) {
				max = c;
			} else {
				min = c;
			}
//			System.out.println(min + " " + max);
		}
		return min == max ? min + 1 : max;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long a = sc.nextInt();
		long b = sc.nextInt();
		long[] enemyTairyoku = new long[n];
		for(int i=0; i<enemyTairyoku.length; i++)
			enemyTairyoku[i] = sc.nextInt();
		sc.close();

		System.out.println(calcMinAttackNum(a, b, enemyTairyoku));
	}
}



Measured memory_bytes: 61252
from decimal import *
N,A,B = map(int, input().split())

N -= 1
A -= 1
B -= 1

ans = 0
distAB = B - A

if distAB % 2 == 0:
    ans = Decimal(distAB) / Decimal(2)
else:
    if (N-B) < A:
        ans = (N-B+1) + (Decimal(distAB-1)/Decimal(2))
    else:
        ans = A+1 + (Decimal(distAB-1)/Decimal(2))

print(int(ans))

Measured memory_bytes: 5588
#include<stdio.h>
int main()
{
    while(1){
       int a,b,i,j,ans=0,c=0;
    scanf("%d%d",&a,&b);
    if(a==0 &&b==0){
        break;
    }
    for(i=1; i<=a+1; i++){
        for(j=1; j<=a+1; j++){
            if(j<=i){
                continue;
            }
            c=b-(i+j);
            if (c > j && c <= a){
                ans += 1;
            }

        }
    }

    printf("%d\n",ans);
    }
}


Measured memory_bytes: 2056
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <sstream>

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)

using namespace std;


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

    int N;
    char s;
    vector<char> S;
    vector<int> cum_sum;
    int count=0;
    cin >> N;
    cum_sum.push_back(0);
    REP(i,N){
        cin >> s;
        if(s == 'W') count++;
        cum_sum.push_back(count);
     } 

     int m = N;
     REPP(i,1,N+1) m = min(m,(cum_sum[i-1]+(N-i-(cum_sum[N]-cum_sum[i]))));
     cout << m << endl;

    return 0;
}

Measured memory_bytes: 2420
#include<stdio.h>

int main(void){
    int x, n, k, h[100000], i;

    scanf("%d%d",&n ,&k);
    for(i=0; i<n; i++){
        scanf("%d",&h[i]);
    }

    x = 0;  
    for(i=0; i<n; i++){
        if(h[i] >= k){
            x++;
        }
    }

    printf("%d\n",x);
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#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> H(N);
  rep(i,N) cin >> H[i];
  int temp = 1000000005;
  for (int i = N-1; i > 0; --i) {
    if (temp >= H[i]) temp = H[i];
    else if (temp == H[i] - 1) continue;
    else {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 3152
#include <stdio.h>

int stripe(int h, int w){//hを3分割した時の差の最小値を返す
	if(h%3){
		return w;
	}
	else return 0;
}

int t_shape(int h, int w){
	int sum = h*w;
	int a[3];
	int b[3];
	a[0] = (h/3)*w;
	b[0] = (h/3+1) * w;
	a[1] = (h-h/3)*(w/2);//[1] ≤ [2]
	b[1] = (h-h/3-1)*(w/2);
	a[2] = sum-a[0]-a[1];
	b[2] = sum-b[0]-b[1];
	int adif;
	int bdif;
	if(a[0] > a[2]){
		adif = a[0]-a[1];
	}else if(a[0] < a[1]){
		adif = a[2]-a[0];
	}else{
		adif = a[2]-a[1];
	}
	if(b[0] > b[2]){
		bdif = b[0]-b[1];
	}else if(b[0] < b[1]){
		bdif = b[2]-b[0];
	}else{
		bdif = b[2]-b[1];
	}
	if(adif < bdif){
		return adif;
	}else{
		return bdif;
	}
}

int main(void){
	int ans;
	int h, w;
	scanf("%d%d", &h, &w);
	if(stripe(h, w) > stripe(w, h)){
		ans = stripe(w, h);
	}else{
		ans = stripe(h, w);
	}
	if(ans > t_shape(h, w)){
		ans = t_shape(h, w);
	}
	if(ans > t_shape(w, h)){
		ans = t_shape(w, h);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128