akhauriyash/Code-Regression huggingface dataset:
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define name(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=(int)1e6 + 7;



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n ;
    vector<int>d(n);
    for(int & x : d)
        cin >> x;
    if(n > 23)
    {
        cout << 0 << '\n';
        return 0;
    }

    int ans = 0;
    for(int mask = 1; mask < (1 << 24) ; mask+=2){
        int used = 1;
        bool flag = true;
        for(int i = 0; i < n; i++){
            if(!(used & (1 << d[i])) && (mask & (1 << d[i]))) {
                used |= (1 << d[i]);
                continue;
            }
            if(!(used & (1 << (24 - d[i]))) && (mask & (1 << (24 - d[i])))) {
                used |= (1 << (24 - d[i]));
                continue;
            }
            flag = false;
            break;
        }
        if(flag){
            int last = 0;
            int cur = 24;

            for(int i = 1; i < 24; i++){
                if(mask & (1 << i)){
                    cur = min(cur , i - last);
                    last = i;
                }
            }
            cur = min(cur , 24 - last);
            ans = max(ans ,cur);
        }
    }

    cout << ans << '\n';


    return 0;
}



Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('ascii');

var input_stdin = "";
var input_stdin_array = "";
var input_currentline = 0;

process.stdin.on('data', function (data) {
    input_stdin += data;
});

process.on('SIGINT', function(){
    input_stdin_array = input_stdin.split("\n");
    main();
    process.exit();
});

process.stdin.on('end', function () {
    input_stdin_array = input_stdin.split("\n");
    main();    
});

function readLine() {
    return input_stdin_array[input_currentline++];
}

/////////////// ignore above this line ////////////////////

function main() {
	var s = readLine().split(" ");
	var A = parseInt(s[0]);
	var B = parseInt(s[1]);
	A += B;
	if (A > 23) A -= 24;
	console.log(A.toString());
}


Measured memory_bytes: 21192
#include <iostream>
#include <vector>
#include<algorithm>
#include <math.h>
#include <iomanip>
using namespace std;

int main() {
    int x, y, sum=0;
    cin >> x >> y;

    int third = 100000, second = 200000, first = 300000;
    int multi = 400000;

    if(x == 3){
        sum += third;
    }else if(x == 2){
        sum += second;
    }else if(x == 1){
        sum += first;
    }else{
        sum += 0;
    }

    if(y == 3){
        sum += third;
    }else if(y == 2){
        sum += second;
    }else if(y == 1){
        sum += first;
    }else{
        sum += 0;
    }

    if(x ==1 && y==1){
        sum += multi;
    }else{
        sum += 0;
    }

    cout << sum;

}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

num = 0
count = 0
s_list = [0]

for i in range(1, n):
  if(h[i - 1] >= h[i]):
    count += 1
  else:
    count = 0
  s_list.append(count)
print(max(s_list)) 


Measured memory_bytes: 14252
N = int(input())
s = [int(input()) for _ in range(N)]

sum_ = 0
for i in range(N):
    sum_ += s[i]

s_10 = [i for i in s if i % 10 != 0]

if sum_ % 10 == 0:
    if not s_10:
        print(0)
    else:
        print(sum_ - min(s_10))
else:
    print(sum_)

Measured memory_bytes: 3060
N = int(input())
A = []
Copy = []
for i in range(N):
    tmp = int(input())
    A.append(tmp)
    Copy.append(tmp)
Copy.sort()

Max_1 = Copy[-1]
Max_2 = Copy[-2]
for i in range(N):
    if A[i] == Max_1:
        print(Max_2)
    else:
        print(Max_1)

Measured memory_bytes: 14120
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<iomanip>
using namespace std;
#define INF 1<<20


struct edge{
	int to;
	int cost;
	edge() {};
	edge(int a, int b) {
		to = a;
		cost = b;
	}
};

struct Node {
	int pos;
	int cost;
	Node() {};
	Node(int a, int b) {
		pos = a;
		cost = b;
	}
	bool operator <(const Node& rhs) const {
		return cost > rhs.cost;
	}
};

void dijkistra(int st, int TO,int V,vector<vector<edge> > graph) {
	priority_queue<Node> q;
	vector<int> d(V);
	for (int i = 0;i < V;i++) {
		d[i] = INF;
	}
	d[st] = 0;
	q.push(Node(st, 0));
	while (!q.empty()) {
		Node s = q.top(); q.pop();
		int pos = s.pos;
for (int i = 0;i < graph[pos].size();i++) {
	int to = graph[pos][i].to;
	int cost = graph[pos][i].cost;
	if (d[pos] + cost < d[to]) {
		d[to] = d[pos] + cost;
		q.push(Node(to, d[to]));
	}

}
	}
	cout << d[TO] << endl;
}
int partition(int A[], int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p;j < r;j++) {
		if (x >= A[j]) {
			i = i + 1;
			swap(A[i], A[j]);
		}
	}
	swap(A[i + 1], A[r]);
	return i + 1;
}
void quicksort(int A[], int p, int r) {
	if (p < r) {
		int q = partition(A, p, r);
		quicksort(A, p, q - 1);
		quicksort(A, q + 1, r);
	}
}

int getNumberOfCoin(int C[], int n, int m) {
	int T[50000];
	for (int j = 0;j <= n;j++) {
		T[j] = INF;
	}
	T[0] = 0;
	for (int i = 0;i < m;i++) {
		for (int j = 0;j <= n;j++) {
			if (j - C[i] >= 0) {
				T[j] = min(T[j], T[j - C[i]] + 1);
			}
		}
	}
	return T[n];
}
int knapsack(int w, int n, int* v, int* ww) {
	int W[101][10001];
	for (int j = 0;j <= w;j++) {
		W[0][j] = 0;
	}
	for (int i = 0;i < n;i++) {
		for (int k = 0;k < n;k++) {
			for (int j = 0;j <= w;j++) {
				if (j - ww[k] < 0) {
					W[i + 1][j] = W[i][j];
				}
				if (j - ww[i] >= 0) {
					W[i + 1][j] = max(W[i][j], W[i][j - ww[k]] + v[k]);

				}
			}
		}
	}
	return W[n][w];
}
int fib(int n) {
	vector<int> v(n + 1);
	v[0] = 1;
	v[1] = 1;
	for (int i = 2;i < n + 1;i++) {
		v[i] = v[i - 2] + v[i - 1];
	}
	return v[n];
}
int isPrime(int x) {
	if (x <= 1) return false;
	if (x > 2 && x % 2 == 0) return false;
	for (int i = 2;i <= sqrt(x);i++) {
		if (x%i == 0) {
			return false;
		}
	}
	if (x == 2) return true;
	return true;
}
int gnc(int a, int b) {
	while (b%a != 0) {
		if (a > b) swap(a, b);
		else {
			b = b%a;
		}
	}
	return a;
}
int calc(int a, long long int b, long long int m) {
	if (b == 0) return 1;
	else if (b % 2 == 0) {
		long long int d = calc(a, b / 2, m);
		return (d*d) % m;
	}
	else {
		long long int d = calc(a, b -1, m);
		return (d*a) % m;
	}
}


int main() {
	int K, S;
	cin >> K >> S;
	vector<vector<int>> A(3,vector<int>(3*K+1));
	
	for (int i = 0;i <= K;i++) {
		A[0][i] = 1;
	}
	for (int i = 1;i < 3;i++) {
		for (int j = 0;j < 3 * K + 1;j++) {
			A[i][j] = 0;
		}
	}
	
	for (int i = 1;i<3;i++) {
		for (int j = 0;j <= i*K;j++) {
			for (int k = 0;k <= K;k++) {
				A[i][j + k] += A[i - 1][j];
			}
		}
	}
	cout << A[2][S] << endl;
	return 0;
	}




Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
    int X,Y,Z,tmp;
    cin>>X>>Y>>Z;
    tmp=X;
    X=Y;
    Y=tmp;
    tmp=X;
    X=Z;
    Z=tmp;
    cout<<X<<" "<<Y<<" "<<Z<<endl;;
    
    
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> s(M), c(M);
    REP(i, M) {
        cin >> s[i] >> c[i];
        s[i]--;
    }
    REP(n, 1000) {
        string sn = to_string(n);
        bool ok = true;
        REP(i, M) {
            if (sn[s[i]] != (char)(c[i] + '0')) {
                ok = false;
            }
        }
        if (ok && sn.size() == N) {
            cout << sn << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}

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

using namespace std;

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

    long long int ans = 0;
    cin >> a >> b >> c;


    if(a + b + 1 >= c) {

        ans = b + c;
    }
    else {

        ans = b + (a + b + 1);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)

ll N, a[111];

ll ans;
double aave;
ll i,j;

double abss(double a){
    return a < 0 ? -a : a;
}

int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld", &a[i]);
    }
    
    fornum(i,0,N){
        aave += a[i];
    }
    aave /= N;

    fornum(i,1,N){
        if(abss(a[i]-aave)<abss(a[ans]-aave)){
            ans = i;
        }
    }
    
    printf("%lld", ans);

    return 0;
}

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

using namespace std;

int main(){
	int n, ans = 0;
	string s;
	cin >> n >> s;
	ans = n;
	vector<int> a(n + 1);
	for(int i = 1; i <= n; i++){
		if(s[i - 1] == 'W'){
			a[i] = a[i - 1] + 1;
		}else{
			a[i] = a[i - 1];
		}
	}
	for(int i = 1; i <= n; i++){
		int t = a[i - 1] + (n - i - (a[n] - a[i]));
		ans = min(ans, t);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1796
while True:
    m, f, r = list(map(int,input().split()))
    if (m == -1) & (f == -1) & (r == -1):
        break
    if (m + f) < 30 or m == -1 or f == -1:
        print("F")
    elif (m + f) < 50 and r < 50:
        print("D")
    elif (m + f) < 65:
        print("C")
    elif (m + f) < 80:
        print("B")
    else:
        print("A")

Measured memory_bytes: 7604
#include <bits/stdc++.h>
using namespace std;
 
int64_t intceil(int64_t a, int64_t b){
    if(a >= 0){
        return (a+b-1)/b;
    }else{
        return a/b;
    }
}
int64_t intfloor(int64_t a, int64_t b){
    if(a < 0){
        return (a-b+1)/b;
    }else{
        return a/b;
    }
}
 
int main(){
    int64_t N, K;
    cin >> N >> K;
    vector<int64_t> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    sort(A.begin(), A.end());
 
    const int64_t INF = 1e18;
    int64_t ok = INF, ng = -INF-1;
    while(ok-ng>1){
        int64_t m = (ok+ng)/2;
        int64_t num = 0;
        for(int i=0; i<N; i++){
            if(A[i] < 0){
                int64_t v = intceil(-m, -A[i]);
                num += A.begin()+i - lower_bound(A.begin(), A.begin()+i, v);
            }else if(A[i] == 0){
                if(m >= 0) num += i;
            }else{
                int64_t v = intfloor(m, A[i]);
                num += upper_bound(A.begin(), A.begin()+i, v) - A.begin();
            }
        }
        (num >= K ? ok : ng) = m;
    }
    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pb push_back
#define f first
#define s second
#define mp make_pair
#define inlld(x) scanf("%lld", &x)
#define ind(x) scanf("%d", &x)
#define inlld2(x, y) scanf("%lld%lld", &x, &y)
#define inlld3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z)
#define ind2(x, y) scanf("%d%d", &x, &y)
#define ind3(x, y, z) scanf("%d%d%d", &x, &y, &z)

const int N=1e5+5;
const int MOD=1e9+7;

typedef long long ll;
typedef long double ld;

using namespace std;

ll n, a, b;

ll modpow(ll x, ll p, int m=MOD)
{
    if(p==1) return x;
    if(p==0) return 1;
    ll ret=modpow(x, p/2);
    ret=(ret*ret)%m;
    if(p%2)
        ret=(ret*x)%m;
    return ret;
}

int main()
{
    inlld3(n, a, b);
    ll ans=modpow(2LL, n);
    ans=(ans-1+MOD)%MOD;
    ll sub=1;
    for(int i=0; i<a; i++)
        sub=(sub*(n-i))%MOD;
    for(int i=2; i<=a; i++)
        sub=(sub*modpow(i, MOD-2))%MOD;
    ans=(ans-sub+MOD)%MOD;
    sub=1;
    for(int i=0; i<b; i++)
        sub=(sub*(n-i))%MOD;
    for(int i=2; i<=b; i++)
        sub=(sub*modpow(i, MOD-2))%MOD;
    ans=(ans-sub+MOD)%MOD;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int ans=(int)s.size();
	int cnt=0;
	rep(i,s.size()){
		if(s.at(i)=='S') cnt++;
		else{
			if(cnt>0){
				cnt--;
				ans-=2;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 720
#pragma GCC target ("arch=ivybridge,tune=ivybridge")
#include <cstdio>
#include <vector>
#include <utility>
#include <map>
 
/*
\cap_{u,v} \cup_{i\in (u,v) path} E_i
 
g(N) = |{E | {u,v\in M | \cup_{i\in (u,v) path} E_i} = N}|
G(N) = |{E | {u,v\in M | \cup_{i\in (u,v) path} E_i} \subseteq N}|
     = |{E | {u,v\in M-N | \cap_{i\in (u,v) path} !E_i}}|
*/
 
int n, m;
std::vector<int> E[50];
 
long long int M[20];
long long int A[1<<20];
std::map<std::pair<int, int>, int> edges;
 
long long int dfs(int u, int v, int p){
  if(u == v) return 0;
  for(int x: E[u]){
    if(x == p) continue;
    long long int b = dfs(x, v, u);
    if(b != -1) return (1LL << edges[{u, x}]) | b;
  }
  return -1;
}
 
int main(){
  scanf("%d", &n);
  for(int i = 0; i < n-1; i++){
    int a, b;
    scanf("%d%d", &a, &b);
    E[a-1].push_back(b-1);
    E[b-1].push_back(a-1);
    edges[{a-1,b-1}] = i;
    edges[{b-1,a-1}] = i;
  }
  scanf("%d", &m);
  for(int i = 0; i < m; i++){
    int a, b;
    scanf("%d%d", &a, &b);
    M[i] = dfs(a-1, b-1, -1);   
  }
  long long int ans = 1LL << (n-1);
  int k = 1;
  for(int i = 0; i < m; i++){
    for(int j = 0; j < (1<<i); j++, k++){
      A[k] = A[j] | M[i];
      long long int x = 1LL << (n-1-__builtin_popcountll(A[k]));
      ans += (1-2*__builtin_parity(k))*x;
    }
  }
 
  printf("%lld\n", ans);
  return 0;
}


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

int naive(int N, int K){
    deque<int> q; q.push_front(0);
    int T = N/K;
    for(int i=1;i<=T;i++){
        int rot = K % q.size();
        for(int j=0;j<rot;j++){
            int cur = q.front(); q.pop_front();
            q.push_back(cur);
        }
        q.push_front(i);
    }
    return q[(N%K)%q.size()];
}

int go(int N, int K){
    while(1){
        if(N%K==0) return N/K;
        if(N<K) return 0;
        if(N/K <= 1000) return naive(N, K);
        N -= N/K+1;
    }
}

int main(){
    int N; scanf("%d",&N);
    int g = 0;
    for(int i=0;i<N;i++){
        int a, k; scanf("%d%d",&a,&k);
        g ^= go(a, k);
    }
    printf(g ? "Takahashi\n" : "Aoki\n");
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

int main()
{
	string S;
	cin >> S;
	set<char> exist;
	for (auto i = 0; i < S.length(); ++i)
	{
		exist.insert(S[i]);
	}

	if (exist.size() == S.length())
	{
		cout << "yes" << endl;
	}
	else
	{
		cout << "no" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, N, P[250001];
	scanf("%d", &N);
	for (i = 1; i <= N * N; i++) scanf("%d", &(P[i]));
	
	int j, min[502][502] = {}, tmp;
	for (i = 1; i <= (N + 1) / 2; i++) {
		for (j = 1; j <= (N + 1) / 2; j++) {
			tmp = ((i < j)? i: j) - 1;
			min[i][j] = tmp;
			min[N-i+1][j] = tmp;
			min[i][N-j+1] = tmp;
			min[N-i+1][N-j+1] = tmp;
		}
	}
	
	int k, l, n, ans = 0, flag[502][502] = {}, q[250001][2], head, tail;
	for (n = 1; n <= N * N; n++) {
		k = (P[n] + N - 1) / N;
		l = (P[n] - 1) % N + 1;
		flag[k][l] = 1;
		ans += min[k][l]--;
		
		q[0][0] = k;
		q[0][1] = l;
		for (head = 0, tail = 1; head < tail; head++) {
			i = q[head][0];
			j = q[head][1];
			if (i > 1 && min[i-1][j] > min[i][j] + (flag[i-1][j] ^ 1)) {
				min[i-1][j] = min[i][j] + (flag[i-1][j] ^ 1);
				q[tail][0] = i - 1;
				q[tail++][1] = j;
			}
			if (i < N && min[i+1][j] > min[i][j] + (flag[i+1][j] ^ 1)) {
				min[i+1][j] = min[i][j] + (flag[i+1][j] ^ 1);
				q[tail][0] = i + 1;
				q[tail++][1] = j;
			}
			if (j > 1 && min[i][j-1] > min[i][j] + (flag[i][j-1] ^ 1)) {
				min[i][j-1] = min[i][j] + (flag[i][j-1] ^ 1);
				q[tail][0] = i;
				q[tail++][1] = j - 1;
			}
			if (i < N && min[i][j+1] > min[i][j] + (flag[i][j+1] ^ 1)) {
				min[i][j+1] = min[i][j] + (flag[i][j+1] ^ 1);
				q[tail][0] = i;
				q[tail++][1] = j + 1;
			}
		}
	}
	
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 6524
n = int(input())
d = dict()
for i in range(n):
    s = input()
    if not s in d:
        d[s] = 1
    else:
        d[s] += 1

sorted_d = sorted(d.items(), reverse=True, key=lambda x:x[1])
ans_list = []
for x in sorted_d:
    if x[1] == sorted_d[0][1]:
        ans_list.append(x[0])
    else:
        break

ans_list.sort()
print(*ans_list, sep='\n')


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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;

    if(a<b){
        if(b<c) cout<<"Yes"<<"\n";
        else cout<<"No"<<"\n";
    }
    else cout<<"No"<<"\n";
    return 0;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, k;
    cin >> n >> k;

    int64_t ans = 1;
    while (k <= n) {
        ++ans;
        n /= k;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    string in; cin >> in;
    int n = in.size();

    const int M = 'z' - 'a' + 1;
    vi hist(M);
    for(auto& c : in){
        hist[c - 'a']++;
    }

    bool ok = false;
    int var = 0;
    rep(i, 3) if(hist[i] >= 1) var++;

    if(var == 1){ if(n == 1) ok = true; }
    else if(var == 2){
        if(n <= 2) ok = true;
    }
    else {
        assert(var == 3);
        int mn = *min_element(begin(hist), begin(hist) + 3);
        assert(mn >= 1);

        ok = true;
        rep(i, 3){
            if(hist[i] >= mn + 2) ok = false;
        }
    }

    cout << (ok ? "YES":"NO") << endl;

    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h> 
using namespace std;
//#define int long long
#include<algorithm>
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<vi> vvi;
#define F first
#define S second
#define pb push_back
#define mk make_pair
#define M 1000000007
#define watch(x) cout << (#x) << " is " << (x) << endl
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define rep(i,a,b) for(int i = a; i<= b; i++)
#define all(c) c.begin(), c.end()
#define ws " "
#define ln "\n"
#define get(x) int x; cin >> x;
#define prt printf("hello world\n")
#define MOD 1e16 + 7;
#define pi atan(1)*4;
int main()
{   
    IOS;
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
        int n;
        cin >> n;
        vector<int> vec(n+1,0);
        int temp;
        rep(i, 1, n-1){
            cin >> temp;
            vec[temp]++;
        }

        rep(i,1,n){
            cout << vec[i] << ln;
        }
        return 0;
}


Measured memory_bytes: 3988
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int N = stdIn.nextInt();
			if(N == 0) break;
			int[] k = new int[N];
			
			for(int i = 0; i < N; i++) {
				k[i] = stdIn.nextInt();
			}
			int max = 0;
			int s = 0;
			for(int i = 0; i < N; i++) {
				if(max < k[i]) max = k[i];
				if(k[i] != 0) {
					s++;
				}
			}
			
			if(max < 2) {
				System.out.println("NA");
			}
			else {
				System.out.println(s+1);
			}
		}
	}
		
}

Measured memory_bytes: 158648
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#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;

class UnionFind {
public:
    
    vl parent;  // 親ノード
    vl Siz;  // 集合の大きさ

    // コンストラクタ
    UnionFind(ll n): parent(n), Siz(n, 1) {
        rep(i, n) {
            parent[i] = i;
        }
    }

    // n要素で初期化
    void init(ll n) {
        parent.resize(n);
        Siz.assign(n, 1);
        rep(i, n) {
            parent[i] = i;
        }
    }

    // xの属する集合の根を求める
    ll root(ll x) {
        if(parent[x] == x) {
            return x;
        }
        else {
            return parent[x] = root(parent[x]);
        }
    }

    // xとyの属する集合を併合
    void unite(ll x, ll y) {
        x = root(x);
        y = root(y);
        if(x == y) {
            return;
        }
        if(Siz[x] < Siz[y]) {
            swap(x, y);
        }
        Siz[x] += Siz[y];
        parent[y] = x;
    }
    
    // xとyが同じ集合に属するかどうか
    bool same(ll x, ll y) {
        return root(x) == root(y);
    }

    // xの属する集合の要素数を求める
    ll size(ll x) {
        return Siz[root(x)];
    }
    
};

int main() {
    ll n, m;
    cin >> n >> m;
 
    UnionFind Uni(n);
    Uni.init(n);
 
    rep(i, m) {
        ll x, y, z;
        cin >> x >> y >> z;
        x--;  y--;
        Uni.unite(x, y);
    }
 
    set<ll> st;
    rep(v, n) {
        st.insert(Uni.root(v));
    }
 
    ll renketuseibun = st.size();  // 連結成分の個数
 
    out(renketuseibun);
    re0;
}

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define llong long long
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

const int MOD = 1e9 + 7;

void solve()
{
  llong ans=1;

  int n; cin >> n;
  vector<int> d(n+1, 0);

  for (int i=2; i<=n; i++) {
    int x=i;
    for (int j=2; x>1; j++) {
      while (x%j == 0) {
        d[j]++;
        x /= j;
      }
    }
  }

  for (int i=0; i<n+1; i++) {
    if (d[i]>0) {
      ans = (ans * (d[i]+1)) % MOD;
    }
  }

  cout << ans << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define dbg(x) printf(" %d \n",x);
using namespace std;
int main()
{
    int a,v,b,w,t,dis,dif;
    double x;
    scanf("%d%d",&a,&v);
    scanf("%d%d",&b,&w);
    scanf("%d",&t);
    dis = b-a;
    dif = v-w;
    if(dif<=0)
    {
        printf("NO\n");
        return 0;
    }
    if(dis<0)dis*=-1;
    x = ceil(dis/(dif*1.0000));
    if(v>w&&x<=t)printf("YES\n");
    else printf("NO\n");
    return 0;
}


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

using namespace std;

int N, M;
int DpCost[101][101], DpTime[101][101];
const int INF = 1e8;


void solve() {
	for (int k = 1; k <= M; ++k) {
		for (int i = 1; i <= M; ++i) {
			for (int j = 1; j <= M; ++j) {
				if (i == j) {
					DpCost[i][j] = DpTime[i][j] = 0;
					continue;
				}
				DpCost[i][j] = min(DpCost[i][j], DpCost[i][k] + DpCost[k][j]);
				DpTime[i][j] = min(DpTime[i][j], DpTime[i][k] + DpTime[k][j]);
			}
		}
	}
}

int main() {
	int a, b, cost, time, k, r;

	while (cin >> N >> M, N) {
		for (int i = 1; i <= M; ++i) {
			fill(DpCost[i], DpCost[i] + 101, INF);
			fill(DpTime[i], DpTime[i] + 101, INF);
		}
		for (int i = 0; i < N; ++i) {
			cin >> a >> b >> cost >> time;
			DpCost[a][b] = DpCost[b][a] = cost;
			DpTime[a][b] = DpTime[b][a] = time;
		}
		solve();
		cin >> k;
		for (int i = 0; i < k; ++i) {
			cin >> a >> b >> r;
			if (r == 0) {
				cout << DpCost[a][b] << endl;
			}
			else {
				cout << DpTime[a][b] << endl;
			}
		}
	}

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5 + 9;
int n, m, v, p;
int a[N];

bool can(int k){  
  int tot = 0;
  for(int i = 1; i <= n; i ++ ){
    if(a[i] > a[k]){
      tot ++ ;
    }
  }
  if(tot < p) return true;
  int nw = a[k] + m;
  tot = 0;
  ll votes = m * 1ll * (v-1);
  for(int i = n; i >= 1; i --){
    if(a[i] > nw){
      tot ++ ;
      votes -= m;
    }
    else if(i != k){
      if(tot < p-1){
        tot ++ ;
        votes -= m;
      }
      else{
        votes -= min(m, nw - a[i]);
      }
    }
  }
  if(tot >= p || votes > 0) return false;
  return true;
}

int main(){
  fastIO;
  cin >> n >> m >> v >> p;
  for(int i = 1; i <= n; i ++ )
    cin >> a[i];
  sort(a + 1,a + n + 1);
  int l = 1, r = n;
  int mid;
  while(l < r){ // nothing beats a good ol' bin search
    mid = (l + r) / 2;
    if(can(mid)){
      r = mid;
    }
    else{
      l = mid + 1;
    }
  }
  cout << n - r + 1 << "\n";
  return 0;
}

Measured memory_bytes: 640
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;

int main() {
	int R0, W0, C, R;
	while (cin >> R0 >> W0 >> C >> R, R0) {
		int X = 0;
		while (R0 + X*R < C*W0) {
			X++;
		}
		cout << X << endl;
	}
	return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
const long long INF = (1LL << 32);
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

#define Endl endl

/*--------------------template--------------------*/


int main() {
	cin >> s;
	ans = 700;
	REP(i,3) {
		if (s[i] == 'o'){
			ans += 100;
		}
	}
	cout << ans << endl;
	
}

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

int main()
{
  int n;
  scanf("%d",&n);
  int t=(n/8)*2;
  static vector<int> ans;
  if(n==3){
    ans.push_back(2);
    ans.push_back(5);
    ans.push_back(63);
  }
  else{
  for(int x=0;x<t;x++){
    ans.push_back(6*x+2);
    ans.push_back(6*x+3);
    ans.push_back(6*x+4);
    ans.push_back(6*x+6);
  }
  if(n%8==1){
    ans.push_back(6*t+6);
  }
  else if(n%8==2){
    ans.push_back(6*t+2);
    ans.push_back(6*t+4);
  }
  else if(n%8==3){
    ans.push_back(6*t+2);
    ans.push_back(6*t+4);
    ans.push_back(6*t+6);
  }
  else if(n%8==4){
    ans.push_back(6*t+2);
    ans.push_back(6*t+3);
    ans.push_back(6*t+4);
    ans.push_back(6*t+9);
  }
  else if(n%8==5){
    ans.push_back(6*t+2);
    ans.push_back(6*t+3);
    ans.push_back(6*t+4);
    ans.push_back(6*t+6);
    ans.push_back(6*t+9);
  }
  else if(n%8==6){
    ans.push_back(6*t+2);
    ans.push_back(6*t+3);
    ans.push_back(6*t+4);
    ans.push_back(6*t+8);
    ans.push_back(6*t+9);
    ans.push_back(6*t+10);
  }
  else if(n%8==7){
    ans.push_back(6*t+2);
    ans.push_back(6*t+3);
    ans.push_back(6*t+4);
    ans.push_back(6*t+6);
    ans.push_back(6*t+8);
    ans.push_back(6*t+9);
    ans.push_back(6*t+10);
  }
  }
  for(int i=0;i<n;i++){
    printf("%d%c",ans[i],i<n-1?' ':'\n');
  }
  return 0;
}



Measured memory_bytes: 512
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)

c = 0
(1..(n-1)).each do |i|
  if (a[i] - a[i-1]) < 0
    c += (a[i-1] - a[i])
    a[i] -=  (a[i] - a[i-1])
  end
end

puts c

Measured memory_bytes: 30360
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll inf = 1e9;
int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int> cb(n, 0), cw(n, 0);
    int b = 0, w = 0;
    REP(i,1,n){
        if(s[i-1] == '#')b++;
        cb[i] = b;
    }
    for(int i=n-2;i>=0;i--){
        if(s[i+1] == '.')w++;
        cw[i] = w;
    }
    int mi = inf;
    rep(i,n)mi = min(mi, cw[i]+cb[i]);
    cout << mi << endl;
    
    return 0;
}

Measured memory_bytes: 2180
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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

string MINUSINF = "-";
long long match[10] = {2,5,5,4,5,6,3,7,6};
string dp[11000];

void chmax(string &a, string b){
    if(a == MINUSINF) a=b;
    else if(a.size() < b.size()) a=b;
    else if(a.size()==b.size()){
        if(a<b) a=b;
    }
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    ll a=1,b=1;
    REP(i,n){
        int x,y;
        cin>>x>>y;
        ll n = max((a - 1) / x + 1, (b - 1) / y + 1);
        a = n * x;
        b = n * y;
    }
    cout<<a+b<<endl;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
	"math"
)

func main() {
	var N, idx int
	var A, T, H, min float64
	fmt.Scan(&N, &T, &A)
	min = 99999
	for i := 0; i < N; i++ {
		fmt.Scan(&H)
		w := math.Abs(A - (T - H*0.006))
		if w < min {
			min = w
			idx = i
		}
	}
	fmt.Println(idx + 1)
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <deque>
#include <map>
#include <iomanip>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cstring>
//#pragma warning(disable:4996)

using namespace std;


/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
#define		it(x)  x.begin() 
#define		all(x)  x.begin(), x.end()
#define		pb(x)   push_back(x)
constexpr int           inf = 0x3f3f3f3f;
constexpr long long 	INF = 9123456789123456789;
constexpr long long     MOD = 1000000007LL;
/*************************************************/
template<class T>
void MN(T& a, T b) {
    if (a > b) a = b;
}

int main() {
    int i;
    int dp1 = 0;
    int dp2 = 1073709056;
    int nx1;
    int nx2;

    int N; string S;
    cin >> S;
    N = S.size();
    S = "0" + S;

    for (i = 0; i <= N; i++)
        S[i] -= '0';

    
    for (i = N; i >= 0; i--) {
        nx1 = nx2 = 1073709056;
        //다음 숫자에서 빌려오지 않음
        MN(nx1, dp1 + S[i]);
        MN(nx1, (dp2 + 1) + S[i]);
        //다음 숫자에서 10빌려옴
        MN(nx2, dp1 + 10 - S[i]);
        MN(nx2, dp2 + (10 - S[i]) - 1); //원래 현재에서 빌린 1을 하나 위에서 빌려오는 것으로 해결되므로 -1을 가중해준다.

        dp1 = nx1;
        dp2 = nx2;
    }

    cout << dp1 << '\n';
    return 0;
}

Measured memory_bytes: 2308
#include<cstdio>
#define max(a,b) ((a)>(b)?(a):(b))
#define maxn 5005
using namespace std;
int dist[maxn],goin[maxn],q[maxn*maxn];
int v[maxn],first[maxn],get[maxn];
int n,m,p;
struct enode{
	int y,nxt,z;
}e[maxn*2];
int tot=0;
void bfs(int s){
	int head=1,tail=1;
	q[1]=s,get[s]=1;
	while (head<=tail){
		int x=q[head];
		for (int i=first[x];i>=0;i=e[i].nxt)
		if (e[i].z==-1e9){
			int y=e[i].y;
			if (!get[y]) get[y]=1,q[++tail]=y;
		}
		head++;
	}
}
bool spfa(){
	if (!get[1]) return 0;
	int head=1,tail=1;
	q[1]=v[1]=1,goin[1]=1;
	dist[1]=0;
	while (head<=tail){
		int x=q[head++];
		if (goin[x]>n) return 0;
		v[x]=0;
		for (int i=first[x];i>=0;i=e[i].nxt)
		if (e[i].z!=-1e9){
			int y=e[i].y;
			if (get[y]&&dist[y]<dist[x]+e[i].z) {
				dist[y]=dist[x]+e[i].z;
				if (!v[y]) v[y]=1,q[++tail]=y,goin[y]++;
			}
		}
	}
	return 1;
}
void adde(int x,int y,int z){
	e[tot].nxt=first[x];
	e[tot].y=y;
	e[tot].z=z;
	first[x]=tot++;
}
int main(){
	scanf("%d%d%d",&n,&m,&p);
	for (int i=1;i<=n;i++)
	first[i]=-1,dist[i]=-1e9;
	for (int i=1;i<=m;i++){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		adde(x,y,z-p);
		adde(y,x,-1e9);
	}
	bfs(n);
	if (spfa()) printf("%d\n",dist[n]==-1e9?-1:max(dist[n],0));else printf("-1\n");
	return 0;
}

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

using namespace std;

/*

        Bismillahir Rahmanir Rahim
        Problem :
        Problem Link :
        Topics :
        Solver : Masud Parves
        I Love Code More than Sharks Love Blood <3
*/

#define ff first
#define ss second
#define mp make_pair
#define SZ(a)           (int)a.size()
#define all(a)  a.begin(), a.end()
#define allr(a)  a.rbegin(), a.rend()


#define sf(a)           scanf("%d",&a)
#define sff(a,b)        scanf("%d %d",&a,&b)
#define sfff(a,b,c)     scanf("%d %d %d",&a,&b,&c)

#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define fr(i,b,a) for(int i=(b);i>=(a);i--)

#define CIN ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define TEST_CASE(t) for(int zz=1 ; zz<=t ; zz++)
#define PRINT_CASE printf("Case %d: ",zz)
#define endl            "\n"
#define Debug(x)            cout<<#x " = "<<(x)<<endl
#define NOT_VISITED 0
#define IS_VISITED 1
#define WHITE 0
#define GRAY , DP[1
#define BLACK 2

int fx[4]= {1,-1,0,0};
int fy[4]= {0,0,1,-1};

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N  (1<<pos);}
//int Reset(int N,int pos){return N= N & ~(1<<pos);}
//bool Check(int N,int pos){return (bool)(N & (1<<pos));}
/*------------------------------------------------*/

const double PI = acos(-1.0);
const double EPS = 1e-6;
const int MOD = (int)1e9+7;
const int maxn = (int)2e5+5;


typedef long long ll;
const ll inf = 5e18+100;
typedef unsigned long long ull;
typedef pair<ll, int> plli;
typedef pair<int, ll> pill;
typedef vector<int> vi;
int n, a[maxn];
ll DP[maxn];


ll cal(int pos){
	if(pos==n-1 ){
		return 0LL;
	}
	
	ll &ret = DP[pos];

	if(ret != -1) return ret;
	ret = 0;

	ret = abs(a[pos]-a[pos+1])+cal(pos+1);
	if(pos+2<n){
		ret = min(ret, abs(a[pos]-a[pos+2])+cal(pos+2));
	}
	return ret;
}

void solve(){

	cin >> n;
	f0(i, n){
		cin >> a[i];
	}

	memset(DP, -1 , sizeof(DP));
	cout << cal(0) << endl;
  
    return;
}

int main()
{
    CIN

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    //cout << "Fi Amanillah" << endl;

    int t = 1;
    //cin >> t;

    while(t--){
        solve();
    }

    return 0;
}

Measured memory_bytes: 10252
#include<iostream>
#include<cstring>
using namespace std;
int main(){
   char ch1[55],ch2[55];
  while(cin>>ch1>>ch2){
 int m=strlen(ch1);
 int n=strlen(ch2);
 if(m<=n)
 for(int i=0;i<m;i++)
 {cout<<ch1[i];
 cout<<ch2[i];}
 else
    for(int i=0;i<n;i++)
 {cout<<ch1[i];
 cout<<ch2[i];}
 if(m>n)
 for(int j=n;j<m;j++)
 cout<<ch1[j];
 else
    for(int k=m;k<n;k++)
    cout<<ch2[k];
 cout<<endl;
}
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{	
	int n,k,d,a,t[105]={},sum=0;
	cin>>n>>k;
	for(int i=0;i<k;i++)
	{
		cin>>d;
		for(int j=0;j<d;j++)
		{
			cin>>a;
			t[a]++;
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(t[i]==0)sum++;
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 3584
#include <cstdio>
#include <algorithm>
#define rg register int
#define rep(a, b, c) for(rg a=b; a<=c; ++a)
 
int a[102];
 
inline int read() {
    int x=0; char ch=getchar();
    while(ch<'0'||ch>'9') ch=getchar();
    while(ch>='0'&&ch<='9') {
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x;
}
 
int main() {
    int n; n=read();
    int ans=0;
    rep(i, 1, n+n) a[i]=read();
    std::sort(a+1, a+n+n+1);
    for(rg i=1; i<=2*n; i+=2) ans+=a[i];
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
  int parent;
  int left;
  int right;
};

struct Node T[MAX];
int n;

void preParse(int);
void inParse(int);
void postParse(int);

int main()
{
  int i,v,l,r,root;

  scanf("%d",&n);
  for(i = 0; i < n; i++){
    T[i].parent = NIL;
  }
  for(i = 0; i < n; i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if(l != NIL)T[l].parent = v;
    if(r != NIL)T[r].parent = v;
  }

  for(i = 0; i < n; i++)if(T[i].parent == NIL)root = i;

  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");
  
   return 0;
}

void preParse(int u)
{
  if(u == NIL)return;
  printf(" %d",u);
  preParse(T[u].left);
  preParse(T[u].right);
}

void inParse(int u)
{
  if(u == NIL)return;
  inParse(T[u].left);
  printf(" %d",u);
  inParse(T[u].right);
}

void postParse(int u)
{
  if(u == NIL)return;
  postParse(T[u].left);
  postParse(T[u].right);
  printf(" %d",u);
}



Measured memory_bytes: 2144
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
	double a, b, c, d, e, f;
	while (cin >> a >> b >> c >> d >> e >> f) {
		double y = (a*f-d*c)/(-d*b+a*e);
		double x = (c-b*y)/a;
		cout << fixed << setprecision(3) << x << " " << y << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define U [1<<17]={}
#define G(a)((c=A[a]+A[P[a]]+C[a])%k?c:0)
typedef long long L;using namespace std;map<L,L>T U;L P U,E U,Z U,H U,C U,A U,O U,X U,B U,k,n,a,b,c,p;char s U;
L D(L a){L d;Z[a]=1;for(map<L,L>::iterator I=T[a].begin();I!=T[a].end();I++)
    d=I->first,d-P[a]?P[d]=a,E[d]=E[a]+1,C[d]=I->second,D(d),Z[a]+=Z[d],!H[a]|Z[H[a]]<Z[d]?H[a]=d:0:0;}
L M(L i){return i?B[i]+M(i^i&-i):0;}
L S(L x,L i){for(x=G(x)+M(i++)-M(i);i<1e5;i+=i&-i)B[i]+=x;}
L K(L f){p=X[f];n=X[b];return p-n?M(O[E[p]<E[n]?p=n,a=b,b=f,a:f])-M(O[p])+G(p)+K(P[p]):abs(M(O[f])-M(O[b]));}
main(){for(cin>>n>>k;++p<n;T[a][b]=T[b][a]=c)cin>>a>>b>>c;
       for(D(b=p=0);p<n;p++)if(!p|H[P[p]]-p)for(a=p;!b|a;S(a=H[a],O[a]=b++))X[a]=p;
       for(cin>>a;cin>>s>>a>>b;*s&2?cout<<K(a)<<endl,0:A[a]+=b,S(H[a],O[a]),a&&S(a,O[a]-1));}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    int M = A + B + C;

    int ans = max(A, max(B, C));
    while((3 * ans - M)%2 != 0){
        ans ++;
    }
    cout << (3 * ans-M) / 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;
//emplace_back next_permutation tie get

typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define OUT(a) cout<<(a)<<endl;

void myrot(vector<int> &a){
    auto it=a.end()-1;
    REPN(i,2,a.size()-1){
        if(*(a.end()-i)<*it or (it==a.end()-i+1 and *it==*(a.end()-i))) it=a.end()-i;
    }
    rotate(a.begin(),it,a.end());
    if(a[0]==a[2] && a[1]>a[3]) swap(a[1],a[3]);
    return;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    map<vector<int>,int> a;
    LL ans=0;
    int n; cin >> n;
    vector<vector<int>> c(n,vector<int>(4));
    REP(i,n){
        cin >> c[i][0] >> c[i][1] >> c[i][2] >> c[i][3];
        myrot(c[i]);
        a[c[i]]++;
    }
    REP(i,n){
        FOR(j,i+1,n){
            a[c[i]]--;
            a[c[j]]--;
            //a.erase(c[i]);
            //a.erase(c[j]);
            vector<vector<int>> sid(4,vector<int>(4));
            REP(k,4){
                bool e[4]={};
                LL tmp=1;
                REP(l,4){
                    sid[l][0]=c[i][l];
                    sid[l][1]=c[j][(1-l+4)%4];
                    sid[l][2]=c[j][(-l+4)%4];
                    sid[l][3]=c[i][(l+1)%4];
                }
                REP(l,4) myrot(sid[l]);
                REP(l,4){
                    //int cnt=a.count(sid[l]);
                    int cnt=a[sid[l]];
                    tmp*=cnt;
                    if(cnt>0){
                        //a.erase(sid[l]);
                        a[sid[l]]--;
                        e[l]=true;
                    }
                    if(sid[l][0]==sid[l][3]) tmp*=4;
                    else if (sid[l][0]==sid[l][2] && sid[l][1]==sid[l][3]) tmp*=2;
                }
                //REP(l,4) if(e[l]) a.insert(sid[l]);
                REP(l,4) if(e[l]) a[sid[l]]++;
                ans+=tmp;
                /*if(tmp>0){
                    cout << i <<' '<< j << endl;
                    REP(l,4)cout << c[i][l]<< ' ';
                    REP(l,4)cout << c[j][l]<< ' ';
                    cout << tmp<<endl;
                }*/
                rotate(c[j].begin(),c[j].begin()+1,c[j].end());
            }
            a[c[i]]++;
            a[c[j]]++;

            //a.insert(c[i]);
            //a.insert(c[j]);
        }
        //a.erase(c[i]);
        a[c[i]]--;

    }
    cout <<ans <<endl;

    return 0;
}


Measured memory_bytes: 140032
from sys import stdin
from decimal import Decimal
N = int(stdin.readline().rstrip())
A = []
B = []
for i in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    A.append(a)
    B.append(b)
    
A.sort()
B.sort()

if N % 2 == 0:
    n = N // 2
    med1 = A[n-1] + A[n]
    med2 = B[n-1] + B[n]
    print(med2-med1+1)
else:
    ans = B[N//2] - A[N//2] + 1
    print(ans)

Measured memory_bytes: 26084
/*input

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}


int main(){
	IOS;
	string s,t;
	cin>>s>>t;
	cout<<t<<s;
	return 0;
}


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

int main() {
  long long x;
  long long tmp = 100;
  long long counter = 0;
  cin >> x;
  while(tmp < x) {
    tmp += tmp * 0.01;
    counter++;
  }
  cout << counter << endl;
  return 0;
}

Measured memory_bytes: 3636