akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

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

int main()
{
    int n, x[200], y[200], h[200];
    cin >> n;
    REP(i, n)
    {
        cin >> x[i] >> y[i] >> h[i];
    }

    for (int i = 0; i <= 100; i++)
    {
        for (int j = 0; j <= 100; j++)
        {
            int q[200];
            bool w = true;
            REP(k, n)
            {
                q[k] = -abs(i - x[k]) - abs(j - y[k]);
            }

            int k_ = 0;
            while (h[k_] == 0)
                k_++;
            int e = -q[k_] + h[k_];

            REP(k, n)
            {
                if (e != -q[k] + h[k])
                    if (!(e <= -q[k] + h[k] && h[k] == 0))
                        w = false;
            }

            if (w)
            {
                cout << i << " " << j << " " << e << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a[10000];
int main(){
	int i,j,k,m,n;
	scanf("%s",a+1);
	n=strlen(a+1);
	int sum=0,maxs;
	for(i=1;i<=n;i++){
		if(a[i]=='A'||a[i]=='G'||a[i]=='C'||a[i]=='T'){
			sum++;
			maxs=max(maxs,sum);
		}
		else sum=0;
	}
	printf("%d\n",maxs);
	return 0;
}

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

using namespace std;

typedef long long LL;

#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define LEN(a) int((a).size())
#define SORT(a) sort((a).begin(), (a).end())
#define CLR(a) memset((a), 0, sizeof(a))

const double EPS = 1e-10;

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    for (int i = 0; i < n; i++) cin >> l[i];

    int cnt = 1;
    int pos = 0;
    for (int i = 0; i < n; i++) {
        pos += l[i];
        if (pos > x) break;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}


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

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>
#include <fstream>

using namespace std;
using ll = long long;

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i*i <= n; ++i) {
        if (n%i == 0) {
            ret.push_back(i);
            if (i != 1 && i*i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

template<typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct ToUpper {
    char operator()(char c) { return toupper(c); }
};

struct ToLower {
    char operator()(char c) { return tolower(c); }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int N;
    cin >> N;
    vector<double> A(N);
    cin >> A;


    auto solve = [&]() {
        SORT(A);
        FOR(i, 1, N) {
            A[i] = (A[i - 1] + A[i]) / 2;
        }
        return A[N - 1];
    };

    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int r = Integer.parseInt(strArr[0]);
		int D = Integer.parseInt(strArr[1]);
		int x = Integer.parseInt(strArr[2]);
		for (int i = 0; i < 10; i++) {
			x = r * x - D;
			System.out.println(x);
		}
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 21076
import sys


primes = [2]

def solv(num):
    p1 = 0
    p2 = 0
    if num < primes[-1]:
        p1 = filter(lambda x: x < num, primes)[-1]
        lis = filter(lambda x: num < x, primes)
        if lis:
            p2 = lis[0]
    else:
        for p in prime_list(num * 2):
            primes.append(p)
            if num < p:
                p2 = p
                break
            else:
                if p < num:
                    p1 = p
    return (p1, p2)


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]



for line in sys.stdin:
    number = int(line)
    p1, p2 = solv(number)
    print ' '.join(map(str, [p1, p2]))

Measured memory_bytes: 6828
#include <iostream>
#include <string>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.length() - 1] == b[0] && b[b.length() - 1] == c[0])
		cout << "YES";
	else
		cout << "NO";
}

Measured memory_bytes: 3532
ans = -1
a = 0
K = int(input())
if K % 2 == 0:
    ans = -1
elif K % 5 == 0:
    ans = -1
else:
    for i in range(0, K):
        a = (10 * a + 7) % K
        if a == 0:
            ans = i + 1
            break
print(ans)

Measured memory_bytes: 9180
#include <iostream>
#include <string>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n;
string s;

int main() {
	int i;
	
	cin >> n >> s;
	
	int ans = 0;
	for (i = 1; i < n; i++) {
		if (s[i - 1] != s[i]) {
			ans++;
		}
	}
	ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
typedef long long ll;
using namespace std;
int main(void){
    string c;cin>>c;
    if(c[0]==c[1]&&c[1]==c[2])cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
}



Measured memory_bytes: 256
c11,c12,c13 = map(int,input().split())
c21,c22,c23 = map(int,input().split())
c31,c32,c33 = map(int,input().split())

if ((c21 - c11) == (c22 - c12) == (c23 - c13) and
    (c31 - c11) == (c32 - c12) == (c33 - c13)):
    print("Yes")

else:
    print("No")

Measured memory_bytes: 3060
#include<stdio.h>
#define INF 1000000
#define rep(i,n) for((i)=0;(i)<=(int)(n);(i)++)
void warshall_floyd(void);
int min(int,int);

int graph[10][10],n;

int main(void){
  int a,b,c,i,j,sum[10],ans1,ans2;

  while(scanf("%d",&n),n){

    rep(i,9)sum[i]=0;
    ans1=INF;

    rep(i,9){
      rep(j,9){
	graph[i][j]=INF;
      }
      graph[i][i]=0;
    }
    
    rep(i,n-1){
      scanf("%d %d %d",&a,&b,&c);
      graph[a][b]=graph[b][a]=c;
    }
    warshall_floyd();

    rep(i,9)
      rep(j,9)
	if(graph[i][j]<INF)sum[i]+=graph[i][j];

    rep(i,9){
      if(ans1>sum[i] && sum[i]>0){
	ans1=sum[i];
	ans2=i;
      }
    }
    printf("%d %d\n",ans2,ans1);
  }
  return 0;
}

void warshall_floyd(void){
  int i,j,k;

  rep(k,9)
    rep(i,9)
      rep(j,9)
	graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
}

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

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 1; i <= 100; ++i) {
        int cnt = 0;
        for(int j = 0; j < n; ++j) {
            cnt += a[j] >= i;
        }
        if(cnt >= i) ans = i;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3076
fun main(args: Array<String>) {
    val n = readInt()
    val d = readIntList()

    var ans = 0
    for (i in 0 until n) {
        for (j in i+1 until n) {
            ans += d[i] * d[j]
        }
    }
    println(ans)
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 36440
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

int i,j,k,N,L,XA[100000],XB[100000],XM[100000],minA,minB,minM,A,B,M,a,b,c;

char S[15];

int main()
{
  cin>>A>>B>>M;
  
  minA=100001;
  for(i=0;i<A;i++)
  {
    cin>>XA[i];
    minA=min(XA[i],minA);
  }
  
    minB=100001;
  for(i=0;i<B;i++)
  {
    cin>>XB[i];
    minB=min(XB[i],minB);
  }
  
    minM=200001;
  for(i=0;i<M;i++)
  {
    cin>>a>>b>>c;
    a--;
    b--;
    minM=min(minM,XA[a]+XB[b]-c);
    
  }
  
  minM=min(minM,minA+minB);
  
  cout <<minM;
  
  
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
using PII = pair<ll, ll>;
#define FOR(i,a,n) for(ll i=(ll)a; i<(ll)n; ++i)
#define REP(i,n) FOR(i,0,n)

int main() {
	int N;
	cin >> N;
	vector<string>s(N);
	for (auto &i : s)cin >> i;
	for (int i = 1; i <= 5; i++) {
		set<string>st;
		string t(i, 'a');
		while (t[0] <= 'z') {
			st.insert(t);
			t.back()++;
			int cnt = i - 1;
			while (cnt&&t[cnt] > 'z') {
				t[cnt--] = 'a';
				t[cnt]++;
			}
		}
		for (auto j : s) {
			for (int k = 0; k + i <= j.size(); k++) {
				string u;
				for (int l = 0; l < i; l++) {
					u.push_back(j[k + l]);
				}
				st.erase(u);
			}
		}
		if (!st.empty()) {
			cout << *st.begin() << endl;
			return 0;
		}
	}
}



Measured memory_bytes: 50632
from math import gcd
from functools import reduce
import sys
input = sys.stdin.readline


def lcm(a, b):
    return a*b // gcd(a, b)


def count_factor_2(num):
    count = 0
    while num % 2 == 0:
        num //= 2
        count += 1
    return count


def main():
    n, m = map(int, input().split())
    A = list(map(lambda x: x//2, set(map(int, input().split()))))

    check = len(set(map(count_factor_2, A)))
    if check != 1:
        print(0)
        return

    lcm_a = reduce(lcm, A)
    step = lcm_a * 2
    ans = (m + lcm_a) // step
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 18208
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  double x,h;
  cin >> x >> h;
  while(x != 0 && h != 0){
    double hi = sqrt((x*0.5)*(x*0.5)+h*h);
    printf("%.6lf\n",x*x + 2.0*(hi*x));
    cin >> x >> h;
  }
  return (0);
}

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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

constexpr int sz = 1123;
LL x[sz];
LL y[sz];
LL z[sz];
int N, M;
LL t[sz];

int main() {
	while (cin >> N >> M) {
		LL ret = -1e14;

		for (int i : range(N)) {
			cin >> x[i] >> y[i] >> z[i];
		}
		for (int a : {-1, 1})
			for (int b : {-1, 1})
				for (int c : {-1, 1}) {
					LL ans = 0;
					for (int i : range(N))
						t[i] = x[i] * a + y[i] * b + z[i] * c;
					sort(t, t + N);
					reverse(t, t + N);
					for (int i : range(M))ans += t[i];
					chmax(ret, ans);
				}
		cout << ret << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll V, T;
string S;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

template <typename T>
class BIT {
public:
    int n;            // 要素数
    vector<T> bit[2]; // データの格納先
    BIT(int n_) { init(n_); }
    void init(int n_) {
        n = n_ + 1;
        for (int p = 0; p < 2; p++)
            bit[p].assign(n, 0);
    }

    void add_sub(int p, int i, T x) {
        for (int idx = i; idx < n; idx += (idx & -idx)) {
            bit[p][idx] += x;
        }
    }
    void add(int l, int r, T x) { // [l,r) に加算
        add_sub(0, l, -x * (l - 1));
        add_sub(0, r, x * (r - 1));
        add_sub(1, l, x);
        add_sub(1, r, -x);
    }

    T sum_sub(int p, int i) {
        T s(0);
        for (int idx = i; idx > 0; idx -= (idx & -idx)) {
            s += bit[p][idx];
        }
        return s;
    }
    T sum(int i) { return sum_sub(0, i) + sum_sub(1, i) * i; }
};

signed main() {
    cin >> N >> K;
    vector<ll> a(N);
    cin >> a;
    int cnt = 0;
    int k = 0;
    while (cnt != N && k < K) {
        cnt = 0;
        BIT<int> bt(N);
        k++;
        REP(i, N) {
            int j = i + 1;
            int l = max(1LL, j - a[i]);
            int r = min(N + 1, j + a[i] + 1);
            bt.add(l, r, 1);
        }
        REP(i, N) {
            a[i] = bt.sum(i + 1) - bt.sum(i);
        }
        REP(i, N) {
            if (a[i] == N) {
                cnt++;
            }
        }
    }
    REP(i, N) {
        cout << a[i] << " ";
    }
}

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

#define ll long long

using namespace std;
const int N = 2e5 + 5;
ll a[N];
int n;
ll get(ll m) {
	ll ret = 0;
	for (int i = 0; i < n; i++) {
		ret += abs(a[i] - (m + i + 1));
	}
	return ret;
}
int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int s = -1e9, e = 1e9;
	ll ans = 2e18;
	while (s <= e) {
		int mid = (s + e) >> 1;
		ll s1 = get(mid), s2 = get(mid + 1);
		ans = min(ans, min(s1, s2));
		if (s2 <= s1)
			s = mid + 1;
		else
			e = mid - 1;

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



Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=1e9+7;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

ll n;


void solve(){
  cin >> n;
  vll num(n,0);
  rep(i,0,n-1) {
    ll a;
    cin >> a;
    --a;
    num[a]++;
  }
    
  rep(i,0,n) cout << num[i] << endl;
  
 
}

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

Measured memory_bytes: 4784
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(){
  	int n,l;
  	scanf("%d %d",&n,&l);
  	char string[n+1][l+1];
  	for( int i=0; i<n; i++){
     	scanf(" %s",string[i]); 
    }
  	for(int i=0; i<n; i++){
     	for(int j=0; j<n-1-i; j++){
         	if(strcmp(string[j],string[j+1]) > 0 ){
                char *temp = malloc(l+1);
                strcpy(temp,string[j]);
                strcpy(string[j],string[j+1]);
                strcpy(string[j+1],temp);
                free(temp);
            }
        }
    }
  	for( int i=0; i<n; i++){
     	printf("%s",string[i]); 
    }
    putchar('\n');
 	return 0; 
}


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

int main() {
	string S;
	cin >> S;
	if ("KIHBR" == S) cout << "YES";
	else if ("AKIHBR" == S) cout << "YES";
	else if ("KIHABR" == S) cout << "YES";
	else if ("KIHBAR" == S) cout << "YES";
	else if ("KIHBRA" == S) cout << "YES";
	else if ("AKIHABR" == S) cout << "YES";
	else if ("AKIHBAR" == S) cout << "YES";
	else if ("AKIHBRA" == S) cout << "YES";
	else if ("KIHABAR" == S) cout << "YES";
	else if ("KIHABRA" == S) cout << "YES";
	else if ("KIHBARA" == S) cout << "YES";
	else if ("AKIHABAR" == S) cout << "YES";
	else if ("AKIHABRA" == S) cout << "YES";
	else if ("AKIHBARA" == S) cout << "YES";
	else if ("KIHABARA" == S) cout << "YES";
	else if ("AKIHABARA" == S) cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc160/tasks/abc160_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

int d[2001][2001];
int N, X, Y;
void warshall_floyd(int n) {
    vector<int> v;
    v.push_back(X);
    v.push_back(Y);
    for (auto k : v) {         // 経由する頂点
        REP(i, n) {            // 始点
            FOR(j, i + 1, n) { // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> X >> Y;
    REP(i, N) REP(j, N) { d[i][j] = abs(i - j); }
    X--, Y--;
    d[X][Y] = 1;
    d[Y][X] = 1;
    warshall_floyd(N);
    vector<int> ans(N);
    REP(i, N) FOR(j, i + 1, N) {
        int t = d[i][j];
        if (t < N)
            ans[t]++;
    }
    FOR(i, 1, N) { cout << ans[i] << "\n"; }

    return 0;
}


Measured memory_bytes: 31616
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <map>

using namespace std;

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

	string S;
	cin >> S;

	map<char, int> char_cnt;

	for (char e : S)
	{
		char_cnt[e]++;
	}

	if (abs(char_cnt['a'] - char_cnt['b']) <= 1 && abs(char_cnt['a'] - char_cnt['c']) <= 1 && abs(char_cnt['b'] - char_cnt['c']) <= 1)
	{
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}

	return 0;
}


Measured memory_bytes: 512
x1, y1, x2, y2 = gets.chomp.split(" ").map(&:to_i)

x3 = 1 * (x2 - x1) + (-1) * (y2 - y1) + x1
y3 = 1 * (x2 - x1) + 1 * (y2 - y1) + y1

x4 = 1 * (x3 - x2) + (-1) * (y3 - y2) + x2
y4 = 1 * (x3 - x2) + 1 * (y3 - y2) + y2

puts [x3, y3, x4, y4].join(" ")

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
typedef long long ll;
const int INF = 1<<29;
const int N = 1e6 + 9;
ll a[N];
int main()
{
    fio;
    ll n;
    cin >> n;
    string s;
    map <string, ll> m;
    map <string, ll> :: iterator it;
    for(int i = 0; i < n; i ++)
    {
        cin >> s;
        m[s] ++;
    }
    ll maxx = -1;
    for(it = m.begin(); it != m.end(); it ++)
    {
        maxx = max(maxx, it->second);
    }
    for(it = m.begin(); it != m.end(); it ++)
    {
        if(it->second == maxx){
            cout << it->first << endl;
        }
    }
    return 0;
}


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

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

  if((N.at(2)=='7')||(N.at(1)=='7')||(N.at(0)=='7'))
    cout << "Yes";
  else
    cout << "No";

return 0;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <cstring>

char s[6];
bool f;

int main(){
	scanf("%s", s);
	for(int i=0; i<strlen(s)-1; ++i)
		if(s[i] == 'A' && s[i+1] == 'C')
			f = true;
	if(f) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
//constexpr int MOD = 10e9+7;
//constexpr int INF = 1LL << 60;
inline int in() {int x; cin >> x; return x;}
template <typename T> inline void out(const T& x) {cout << x << endl;}
template <class T> inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}
template <class T> inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}
void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 
  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//
int t[100010];
int x[100010];
int y[100010];


signed main()
{
  ios();
  int N = in();
  FOR(i,1,N+1) cin >> t[i] >> x[i] >> y[i] ;
  t[0] = 0;
  x[0] = 0;
  y[0] = 0;
  rep(i,N)
  {
    int d = abs(x[i+1] - x[i]) + abs(y[i+1] -y[i]);
    int dt = t[i+1] -t[i];
    if(!(d % 2 == dt%2 && d <= dt))
    {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;


}


Measured memory_bytes: 1408
<?php
fscanf(STDIN,"%d %d",$A,$B);
$result = 0;
for($i=0;$i<2;$i++){
  if($A>=$B){
    $result += $A;
    $A = $A-1;
  }else{
    $result += $B;
    $B = $B-1;
  }
}
echo $result;






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

class Card{
public:
  int n;
  char rgb;
  bool operator <(const Card &c) const {
    if(rgb != c.rgb) return rgb < c.rgb;
    if(n != c.n) return n < c.n;
    return false;
  }
  bool operator ==(const Card &c) const {
    if(rgb == c.rgb && n == c.n) return true;
    return false;
  }
};

Card card[9];

struct Used{
  bool u[9];
  Used() {
    for(int i = 0; i < 9; i++) {
      u[i] = false;
    }
  }
};

bool rec(Used u) {
  bool flag = false;
  for(int i = 0; i < 9; i++) {
    if(!u.u[i]) {
      flag = true;
      int cnt = 1;
      Used newU = u;
      newU.u[i] = true;
      for(int j = i+1; j < 9; j++) {
	if(u.u[j]) continue;
	if(card[j] == card[i]) {
	  cnt++;
	  newU.u[j] = true;
	  if(cnt == 3) {
	    if(rec(newU)) return true;
	    break;
	  }
	}
      }
      cnt = 1;
      newU = u;
      newU.u[i] = true;
      for(int j = i+1; j < 9; j++) {
	if(u.u[j]) continue;
	if(card[j].rgb == card[i].rgb && card[j].n - cnt == card[i].n) {
	  cnt++;
	  newU.u[j] = true;
	  if(cnt == 3) {
	    if(rec(newU)) return true;
	    break;
	  }
	}
      }
      return false;
    }
  }
  if(!flag) return true;
  return false;
}

int main() {
  int T;
  cin >> T;
  for(int t = 0; t < T; t++) {
    for(int i = 0; i < 9; i++)
      cin >> card[i].n;
    for(int i = 0; i < 9; i++)
      cin >> card[i].rgb;
    sort(card, &card[9]);
    if(rec(Used())) cout << 1 << endl;
    else cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
 int K,N;
 char a[5];
 char b[5];
 int count=0;
 int n,M;
 cin >> K >> N;
  for(int i; i<5 ; i++){
   a[i]=N%10;
   b[i]=K%10;
   K= K/10;
   N= N/10; 
    }
  int AF =10*a[4]+a[3];
  int AB =10*a[1]+a[0];
  int BF =10*b[4]+b[3];
  int BB =10*b[1]+b[0];
  int FA =10*a[3]+a[4];
  int FB =10*b[3]+b[4];  
  
  if(AF==BF){
    if(AB>=FA && BB<= FB){
      n=1;
    }else if(AB>=FA || BB<= FB){
      n=0;
    }else{
      n=-1;
    }
    M= a[2]-b[2]+n;
  }else{
   if(FA>AB){
   count += a[2];
 }else{
   count += a[2]+1;
 }
  if(BB>FB){
    count += 9-b[2];
  }else{
    count += 10-b[2];
  }
    M=(AF-BF-1)*10;
  }   
  cout << count + M << endl;
 }

Measured memory_bytes: 3552
#include <iostream>
#include <cmath>
using namespace std;
 
int X;
float ans;

int main(void){
    cin >> X;
    ans = 0;
    
    for(int i = 1; i <= (X/2) + 1; i++){
        for(int j = 1; j <= (X/2) + 1; j++){
            int pownum = pow(i, j);
            if(pownum <= X) ans = fmax(ans, pow(i, j));
            else break;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
 
  $a = array_map('intval', explode(" ", trim(fgets(STDIN))));

  $color = array_fill(0, 10, 0);
  $other = 0;
  for ($i=0; $i<$n; $i++) {
    if($a[$i] < 400){
      $color[0]++;
    }else if($a[$i] < 800){
      $color[1]++;
    }else if($a[$i] < 1200){
      $color[2]++;
    }else if($a[$i] < 1600){
      $color[3]++;
    }else if($a[$i] < 2000){
      $color[4]++;
    }else if($a[$i] < 2400){
      $color[5]++;
    }else if($a[$i] < 2800){
      $color[6]++;
    }else if($a[$i] < 3200){
      $color[7]++;
    }else{
      $other++;
    }      
  }

  $ans = 0;
  for ($i=0; $i<count($color); $i++) {
    if($color[$i] > 0){
      $ans++;
    }
  }

  $min = $ans;

  if($ans == 0){
    $min = 1;
  }

  $max = $ans + $other;

  echo $min." ".$max;


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int N, C, K;
    cin >> N >> C >> K;
    vector<int> T(N);
    rep(i, N) cin >> T[i];
    sort(all(T));

    int ans = 0, cnt = 0, l = 0;
    rep(i, N) {
        if (cnt == 0) {
            cnt++;
            l = T[i] + K;
        } else {
            if (T[i] <= l) cnt++;
            else ans++, cnt = 1, l = T[i] + K;
            if (cnt % C == 0) ans++, cnt = 0;
        }
    }
    if (cnt) ans++;
    cout << (C == 1 ? N : ans) << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 3000001 + 5;
int n,m,A,B,C,tot,n1,n2,n3,g;
long long ans;
struct hh{
	int num,f;
}ma[MAXN];

bool cmp(hh x,hh y){
	return x.num > y.num;
}

void solve(){
	cin >> n >> m >> A >> B >> C;
	for(int i = 1;i <= A;i ++) scanf("%d",&g),ma[++ tot].num = g,ma[tot].f = 1;
	for(int i = 1;i <= B;i ++) scanf("%d",&g),ma[++ tot].num = g,ma[tot].f = 2;
	for(int i = 1;i <= C;i ++) scanf("%d",&g),ma[++ tot].num = g,ma[tot].f = 3;
	sort(ma + 1,ma + tot + 1,cmp);
	for(int i = 1;i <= tot;i ++){
		if(ma[i].f == 1){
			if(n1 < n) n1 ++,ans += ma[i].num;
		}
		else if(ma[i].f == 2){
			if(n2 < m) n2 ++,ans += ma[i].num;
		}
		else{
			ans += ma[i].num;
			n3 ++;
		}
		if(n1 + n2 + n3 >= n + m) break;
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    public static class MyExtensions
    {
        public static string Slice(this string str, int start = 0, int stop = 0)
        {
            if (start > str.Length || stop > str.Length || start < 0 || stop < 0)
                return "";

            if (stop == 0) stop = str.Length;
            return str.Substring(start, stop - start);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            ABC081_B();
        }

        static void ABC081_A()
        {

        }

        static void ABC081_B()
        {
            var N = ReadInt();
            var A = ReadIntInputs();
            var ans = 0;
            while (A.All(x => x % 2 == 0))
            {
                A = A.Select(x => x / 2).ToList();
                ans++;
            }
            Console.WriteLine(ans);
        }

        static void ABC082_B()
        {
            var s = string.Join("", Console.ReadLine().OrderBy(x => x));
            var t = string.Join("", Console.ReadLine().OrderByDescending(x => x));

            var ok = true;
            for (var i = 0; i < s.Length; i++)
            {
                if (i < t.Length && s[i] < t[i])
                {
                    Console.WriteLine("Yes");
                    return;
                }

                if (s[i] != t[i])
                    ok = false;
            }
            if (ok && s.Length < t.Length)
            {
                Console.WriteLine("Yes");
                return;
            }
            Console.WriteLine("No");
        }

        public static IEnumerable<int> Range(int start, int stop)
        {
            if (start < 0 || stop < 0)
                throw new Exception("0未満");

            if (start > stop || (start == 0 && stop == 0))
                return new List<int>();

            return Enumerable.Range(start, stop - start);
        }

        public static bool IsDigit(string str)
        {
            var i = 0;
            return int.TryParse(str, out i);
        }

        public static int DigitsSum(long num)
        {
            return num.ToString().Select(x => x.ToString()).Sum(int.Parse);
        }

        public static int[] ToIntArray(string str)
        {
            return str.Select(x => x.ToString()).Select(int.Parse).ToArray();
        }

        public static string Read()
        {
            return Console.ReadLine();
        }

        public static IList<int> ReadIntInputs()
        {
            return Read().Split(' ').Select(int.Parse).ToList();
        }

        public static int ReadInt()
        {
            return int.Parse(Read());
        }

        public static IList<string> ReadInputs()
        {
            return Read().Split(' ').ToList();
        }
    }
}

Measured memory_bytes: 13396
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

struct data{
  ll d,v;
  void c(){
    ll x = __gcd(d,v);
    d/=x;
    v/=x;
  }
};

int n;
data t[10];
ll u[10],size;

ll lcm(ll a,ll b){
  return a/ __gcd(a,b) * b;
}

ll gcd(ll a,ll b){
  return __gcd(a,b);
}

void change(){
  ll x = t[0].d;
  for(int j=1;j<n;j++)x=gcd(x,t[j].d);
  for(int j=0;j<n;j++)t[j].d/=x;
}
void de();

int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      cin>>t[i].d>>t[i].v;
      t[i].c();
    }
    change();
    for(int i=1;i<n;i++){
      for(int j=0;j<n;j++)t[j].d*=t[(j+i)%n].v;
      change();
    }//i

    
    for(int i=0;i<n;i++){
      //cout<<t[i].d<<endl;
      
      size=0;

      for(int j=1;j<n;j++){
	ll y = t[(j+i)%n].d;
	y = y / gcd(y,t[i].d);
	for(int k=0;k<size;k++)y=y/gcd(y,u[k]);
	if(y>1)u[size++]=y;
      }


      ll ans=1;
      for(int j=0;j<size;j++)ans*=u[j];
      cout<<ans<<endl;
    }
    
  }
  return 0;
}
void de(){
    /*
    ll y = t[0].d;
    for(int i=1;i<n;i++){
      y=lcm(y,t[i].d);
    }
    for(int i=0;i<n;i++){
      cout<<y/t[i].d<<endl;
    }
    */
}

Measured memory_bytes: 1164
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <cstdint>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

constexpr ll inf = INT64_MAX / 4;
constexpr ll mod = 1000000007;

inline char ss(int x, int y, vector<string> &s) {
    if (x < 0 || y < 0 || x >= s.size() || y >= s[0].size()) return '#';
    else return s[x][y];
}

#define UP 0
#define DOWN 1
#define RIGHT 2
#define LEFT 3

int d[2000][2000][4];
int h, w;

inline int dd(int x, int y, int z) {
    if (x < 0 || y < 0 || x >= h || y >= w) return 0;
    return d[x][y][z];
}

int main() {
    cin >> h >> w;
    vector<string> s(h);
    for (auto &e:s) cin >> e;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (ss(i, j, s) != '#') {
                if (dd(i - 1, j, DOWN) != 0) d[i][j][DOWN] = dd(i - 1, j, DOWN) - 1;
                else {
                    int i2 = i;
                    while (ss(i2, j, s) != '#') i2++;
                    d[i][j][DOWN] = (i2 - i);
                }
                if (dd(i, j - 1, RIGHT) != 0) d[i][j][RIGHT] = dd(i, j - 1, RIGHT) - 1;
                else {
                    int j2 = j;
                    while (ss(i, j2, s) != '#') j2++;
                    d[i][j][RIGHT] = (j2 - j);
                }
                d[i][j][UP] = dd(i - 1, j, UP) + 1;
                d[i][j][LEFT] = dd(i, j - 1, LEFT) + 1;
            }
        }
    }
    int r = 0;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
            r = max(r, dd(i, j, 0) + dd(i, j, 1) + dd(i, j, 2) +
                       dd(i, j, 3) - 3);
    cout << r << endl;
}

Measured memory_bytes: 66816
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

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

typedef long long int int64;



const int N = 30;
char str[N], s[N];
const int ALP = 26;

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

    scanf("%s", str);
    int n = strlen(str);
    if (n < ALP)
    {
        set <char> ss;
        for (int i = 0; i < n; i++)
            ss.insert(str[i] );
        for (char x = 'a'; x <= 'z'; x++)
            if (!ss.count(x) )
            {
                printf("%s%c\n", str, x);
                return 0;
            }
        throw;
    }
    for (int i = 0; i < ALP; i++)
        s[i] = str[i];
    if (next_permutation(str, str + ALP) )
    {
        int pos = 0;
        while (str[pos] == s[pos] ) pos++;
        str[pos + 1] = 0;
        printf("%s\n", str);
        return 0;
    }
    printf("-1\n");



	return 0;
}



Measured memory_bytes: 768
#include <stdio.h>

int n,A[20];

int solve(int i,int m){//全組み合わせを試す
  if(m == 0)return 1;
  if(i>=n)return 0;
  int res = solve(i+1,m)||solve(i+1,m-A[i]);//resの中で再起している?
}

int main(){
  int q,M,i;

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

  scanf("%d",&q);

  for(i = 0; i < q; i++){
    scanf("%d",&M);
    if(solve(0,M))printf("yes\n"); //solveが1なら真になるからif文に直接書く
    else printf("no\n");
  }
  return 0;
}
//やりかたがよく分からなかったため他人のソースコードを映しました。



Measured memory_bytes: 2108
#include <iostream>
#include <algorithm>
#define io ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int N=1e5+10;
//char s[N];
int a[N],b[N];
void solve(){
    int n,x,t;
    cin>>n>>x>>t;
    int sum=0,ans=0;
    while(sum<n){
        sum+=x;
        ans++;
    }
    cout<<ans*t<<endl;
}
int main(){
    io;
    //int T;cin>>T;
    //while(T--)
        solve();
}


Measured memory_bytes: 3184
H,W,K=map(int,input().split())
m=[]
for _ in range(H):
    m.append([1 if s=='#' else 0 for s in input()])


def cnt(m_in):
    ans = 0
    for r in m_in:
        ans +=sum(r)
    return ans

def paintred(lr,lc):
    #print(m)
    '''
    m_ans = m
    for i in range(H):
        if lr[i] == 1:
            m_ans[i]=[0]*W
    for i in range(W):
        if lc[i] == 1:
            for j in range(H):
                m_ans[j][i]=0
    '''
    m_ans = [[0]*W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if lr[i]==0 and lc[j]==0 and m[i][j]==1:
                m_ans[i][j]=1
    return m_ans
        

def f(l):
    #print(l)
    if len(l) == (H+W):
        lr=l[:H]
        lc=l[H:]
        m_tmp=paintred(lr,lc)
        #print(m_tmp,lr,lc,cnt(m_tmp))
        if cnt(m_tmp) == K:
            #print('a')
            return 1
        else:
            #print('b')
            return 0
    ans = 0
    for binary in [0,1]:
        ans += f(l+[binary])
        #print(binary,ans)
    return ans
#print(paintred([0,0],[1,1,0]))
print(f([]))

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

using namespace std;

int main()
{
    int n;
    int a[21];
    int ans = 0;
    int ma = 0;
    scanf("%d",&n);
    for(int i = 1;i <= n;i++)
    {
        scanf("%d",&a[i]);
        if(ma <= a[i])
        {
            ans++;
            ma = a[i];
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

result = 0

for i in range(N):    
    
    if A[i] > B[i]:
        result += B[i]
        A[i] -= B[i]
        B[i] = 0
    else:
        result += A[i]
        B[i] -= A[i]
        A[i] = 0
        
    if A[i+1] > B[i]:
        result += B[i]
        A[i+1] -= B[i]
        B[i] = 0
    else:
        result += A[i+1]
        B[i] = A[i+1]
        A[i+1] = 0

print(result)
    
    
    
    

Measured memory_bytes: 18392
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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 (a>b) { a=b; return 1; } return 0; }

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

	int n;
	cin >> n;

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

	ll ans = 0;
	ll mx = 0;
	rep(i, n){
		ans += max(mx - a[i], 0ll);
		chmax(mx, a[i]);
	}

	cout << ans << endl;
}


Measured memory_bytes: 4728
#include<iostream>

using namespace std;

int main()
{
	int r,c;
	int arr[101][101] = {0};

	cin >> r>>c;
	for (int i = 0; i != r; ++i)
	{
		for (int j = 0; j != c; ++j)
		{
			cin >> arr[i][j];
			arr[i][c] += arr[i][j];
			arr[r][j] += arr[i][j];
			arr[r][c] += arr[i][j];
		}
		
	}
	
	++r;
	++c;
	for (int i = 0; i != r; ++i)
	{
		for (int j = 0; j != c; ++j)
		{
			cout << arr[i][j];
			if (j == c - 1)
			{
				cout << endl;
			}
			else
			{
				cout << " ";
			}
		}
	}
	
	return 0;

}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll dp[100100][15];
const ll mod = pow(10,9)+7;

int main() {
  string s;
  cin >> s;
  int n = s.length();
  
  dp[0][0] = 1;
  FOR(i,0,n-1){
    if(s[i]=='?'){
      FOR(j,0,9){
        FOR(k,0,12){
          dp[i+1][(k*10+j)%13] += dp[i][k];
          dp[i+1][(k*10+j)%13] %= mod;
        }
      }
    }
    else{
      int ref = (int)(s[i]-'0');
      FOR(k,0,12){
        dp[i+1][(k*10+ref)%13] += dp[i][k];
        dp[i+1][(k*10+ref)%13] %= mod;
      }
    }
  }

  cout << dp[n][5] << endl;

}



Measured memory_bytes: 12288
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD = 1000000007;

     signed main(){
           int n;
           cin>>n;
          int l,r,ans=0;
          for(int i=0;i<n;i++){
                  cin>>l>>r;
                  ans+=r-l+1;
          }
        cout<<ans;
}

        


Measured memory_bytes: 256
using System;
class Program
{
  static void Main(string[] args)
  {
    var t=Read(2);
    var n=t[0];
    var k=t[1];
    long[] h=new long[n];
    for(var i=0;i<n;i++){
      h[i]=Read();
    }
    Array.Sort(h);
    long m=1000000000;
    for(var i=k-1;i<n;i++){
      m=((h[i]-h[i-k+1])<m)?(h[i]-h[i-k+1]):m;
    }
    Write(m);
  }

  static void Write(string s) { Console.WriteLine(s); return; }
  static void Write(long n) { Console.WriteLine(n.ToString()); return; }
  static string ReadStr() { return Console.ReadLine(); }
  static string[] ReadStrs() { return Console.ReadLine().Split(' '); }
  static long Read() { return long.Parse(Console.ReadLine()); }
  static long[] Read(long n) {
    long[] p = new long[n];
    string[] t = Console.ReadLine().Split(' ');
    for(long i = 0; i < n; i++) { p[i] = long.Parse(t[i]); }
    return p;
  }
  static long abs(long n) { return (n > 0) ? n : -n; }
  static long gcd(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = gcd(p, n[i]); } return p; }
  static long gcd(long a, long b) { return (a==0)?b:gcd(b % a, a); }
  static long lcm(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = lcm(p, n[i]); } return p; }
  static long lcm(long a, long b) { return a * b / gcd(a, b); }
  static long max(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p>n[i])?p:n[i]; } return p; }
  static long min(params long[] n) { long p = n[0]; for (long i = 1; i < n.Length; i++) { p = (p<n[i])?p:n[i]; } return p; }
  static void YN(bool t) { Console.WriteLine(t ? "YES" : "NO"); }
  static void Yn(bool t) { Console.WriteLine(t ? "Yes" : "No"); }
  static void yn(bool t) { Console.WriteLine(t ? "yes" : "no"); }
  static string clip(string s, int start, int count) {
    if (start + count < s.Length) { s = s.Remove(start + count); }
    if (start > 0) { s = s.Remove(0, start); }
    return s;
  }
}


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

char arr[110][110];
int mem[110][110];

int main()
{
    int h, w;
    scanf("%d%d", &h, &w);
    for(int i = 0; i < h; i++)
        scanf("%s", arr[i]);

    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            if(i == 0 && j == 0)
                mem[i][j] = (arr[i][j] == '#');
            else
            {
                mem[i][j] = 1e9;

                if(i > 0)
                    mem[i][j] = min(mem[i][j], mem[i - 1][j] + (arr[i - 1][j] == '.' && arr[i][j] == '#'));

                if(j > 0)
                    mem[i][j] = min(mem[i][j], mem[i][j - 1] + (arr[i][j - 1] == '.' && arr[i][j] == '#'));
            }
        }
    }
    
    printf("%d\n", mem[h - 1][w - 1]);
    return 0;
}


Measured memory_bytes: 256
use std::vec::Vec;
use std::cmp::max;
use std::cmp::min;

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let a: Vec<i64> = read_vec();
    
    let mut dp = vec![vec![vec![0; 2]; n]; n];

    for w in 0..n {
        for i in 0..n {
            let j = i + w;
            if j >= n {
               break
            }

            if j == i {
               dp[i][j][0] = a[i];
               dp[i][j][1] = - a[i];
            } else {
               dp[i][j][0] = max(dp[i+1][j][1] + a[i], dp[i][j-1][1] + a[j]);
               dp[i][j][1] = min(dp[i+1][j][0] - a[i], dp[i][j-1][0] - a[j]);
            }
        }
    }
    println!("{}", dp[0][n-1][0]);
}


Measured memory_bytes: 405884
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

string s;

int main(){
	cin>>s;
	reverse(s.begin(),s.end());
	int n=s.size();
	int dp[2]={0,inf};
	for(int i=0;i<n;i++){
		int DP[2]={inf,inf},t=s[i]-'0';
		for(int j=0;j<10;j++) for(int k=0;k<2;k++){
			int I=0,x=t+j+k;
			if(x>=10) I=1;
			x%=10;
			DP[I]=min(DP[I],dp[k]+j+x%10);
		}
		dp[0]=DP[0];
		dp[1]=DP[1];
	}
	cout<<min(dp[0],dp[1]+1)<<endl;
}

Measured memory_bytes: 1412
#include<iostream>
#include<vector>
using namespace std;
int n,m,p;
vector<int> x;
bool input(){
  x.clear();
  if(!(cin>>n>>m>>p))return false;
  if(n==0&&n==m&&m==p)return false;
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    x.push_back(tmp);
  }
  return true;
}

int solve(){
  int all=0;
  for(int i=0;i<x.size();i++){
    all+=x[i];
  }
  int hit = x[m-1];
  all*=(100-p);
  if(hit==0)return 0;
  else return all/hit;
}

int main(){
  while(input())cout<<solve()<<endl;
}

Measured memory_bytes: 1216
#include <stdio.h>

using namespace std;

int main() {
    int n, a, b, c;

    scanf("%d", &n);
    scanf("%d", &a);
    scanf("%d", &b);

    int count = 0;

    for (int i = 2; i < n; i++) {
        scanf("%d", &c);
        if ((a < b && b < c) || (a > b && b > c)) count++;
        a = b;
        b = c;
    }
    
    printf("%d\n", count);

    return 0;
}


Measured memory_bytes: 128