akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>

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

using namespace std;

int n,pttn[20];
char B[5][201];

int ans;
void dfs(int i,int x,int now){
	if(ans<=now) return;
	if(i==10){
		ans=now;
		return;
	}

	for(;;x++){
		bool ok=true;
		rep(j,n) if(B[pttn[j]][x+j]=='X') { ok=false; break; }
		if(ok){
			rep(j,n) B[pttn[j]][x+j]='X';
			dfs(i+1,x+1,x+n);
			rep(j,n) B[pttn[j]][x+j]='.';
		}

		bool end=true;
		rep(y,5) if(B[y][x]=='X'){ end=false; break; }
		if(end) break;
	}
}

int main(){
	for(;scanf("%d",&n),n;){
		rep(i,5){
			scanf("%s",B[i]);
			for(int j=n;j<10*n;j++) B[i][j]='.';
		}

		rep(j,n) rep(i,5) if(B[i][j]=='X') pttn[j]=i;

		ans=10*n;
		dfs(1,1,n);
		printf("%d\n",ans);
	}

	return 0;
}

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

using namespace std;

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;

  int start = max(A,C);
  int end = min(B,D);
  int result = max(end - start, 0);
  cout << result;

  return 0;
}


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

int fall(vector<vector<int>>&field, vector<vector<int>>&pino,int l) {
	int y = 0;
	for ( y = 0; y < field.size() - pino.size(); ++y) {
		bool ok = true;
		for (int i = 0; i < pino.size(); ++i) {
			for (int j = 0; j < pino[i].size(); ++j) {
				if (pino[i][j]) {
					if (field[y + i+1][l + j])ok = false;
				}
			}
		}
		if (!ok) {
			break;
		}
	}
	for (int i = 0; i < pino.size(); ++i) {
		for (int j = 0; j < pino[i].size(); ++j) {
			if (pino[i][j]) {
				assert(!field[y + i][l + j]);
				field[y + i][l + j] = true;
			}
		}
	}
	int delline = 0;
	for (int i = y + pino.size() - 1; i >= y; --i) {
		while (all_of(field[i].begin(), field[i].end(), [](const int a) {return a == 1; })) {
			transform(field[i].begin(), field[i].end(), field[i].begin(), [](const int a) {return false; });
			for (int j = i- 1; j >= 0; --j) {
				swap(field[j], field[j + 1]);
			}
			delline += 1;
		}
	}
	return delline;
}

int main() {
	int N;
	while (cin>>N,N) {
		int sum = 0;
		vector<vector<int>>field(5*N, vector<int>(5));
		while(N--){
			int d, p, q; cin >> d >> p >> q; q--;
			sum += p;
			vector<vector<int>>pino(d == 1 ? 1 : p, vector<int>(d == 2 ? 1 : p, 1));
			sum -= fall(field, pino, q) * 5;
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 3192
#include<iostream>

using namespace std;

int main(void)
{
  int n; cin>>n;
  int i=n%10;
  
  if(i==3){puts("bon");}
  else if((i==0)||(i==1)||(i==6)||(i==8)){puts("pon");}
  else{puts("hon");}
  
  return 0;
}

Measured memory_bytes: 3620
n = gets.to_i
nodes = n.times.map{ gets.split.map(&:to_i) }
d = nodes.map { [_1, _2, _1 + _2, _1 - _2] }.sort_by{_3}
d1max = d.last[2]
d1min = d.first[2]
d = d.sort_by{_4}
d2max = d.last[3]
d2min = d.first[3]
puts [d1max - d1min, d2max - d2min].max


Measured memory_bytes: 50876
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    static int N = 0;
    static int K = 0;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        N = Integer.parseInt(sc.next());
        K = Integer.parseInt(sc.next());
        List<Integer> deq = new ArrayList<>();

        for (int i = 0; i < N; i++) {

            deq.add(Integer.parseInt(sc.next()));
        }
        //左右から取るパターンで試行0回の場合の価値
        deq.add(0);
        deq.add(0,0);

        sc.close();

        //最大値は10^7*100 = 10^9だからintで足りるはず
        int ans = 0;

        //左端からスタート(0～K回)
        for (int l = 0; l <= K; l++) {

            //右端からスタート(0~K回)
            for (int r = N+1; r >= (N+1)-(K-l); r--) {

                //試行回数がデキューの要素数を超えたらもう終了させる
                if (N+1 <= l + (N+1-r)) {

                    break;
                }

                List<Integer> hasJuwel = new ArrayList<>();

                for (int i = 0; i <= l; i++) {

                    hasJuwel.add(deq.get(i));
                }

                for (int i = N+1; i >= r; i--) {

                    hasJuwel.add(deq.get(i));
                }

                int hand_sum = 0;

                //foreach構文を使った手持ちの宝石の合計
                for(int i : hasJuwel) {

                    hand_sum += i;
                }

                //昇順でソート
                Collections.sort(hasJuwel);

                //試行回数が余っていればその分だけ価値が低い順で宝石を戻すことが出来る
                for (int i = 0; i < Math.min(K-l-(N+1-r), l + (N+1-r)); i++) {

                    if(hasJuwel.get(i) < 0) {

                        hand_sum -= hasJuwel.get(i);
                    }
                }
                ans = Math.max(ans, hand_sum);
            }
        }

        System.out.println(ans);
    }

}


Measured memory_bytes: 25044
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define i_inf int(1e9)
#define i_half_inf int(1e5)
#define ll_inf ll(1e9)*ll(1e9)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = i_half_inf;
ll N;
ll a[MAX_N], b[MAX_N];

void solve() {
    ll ans = 0, added = 0;
    repr(i, N) {
        a[i] += added;
        if (a[i] % b[i] != 0) {
            ll temp = (b[i] - a[i] % b[i]);
            ans += temp;
            added += temp;
        }
    }
    cout << ans << endl;
}

int main() {
    cin >> N;
    rep(i, N) cin >> a[i] >> b[i];
    solve();
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define mod 1000000007
#define pll pair<long long,long long>
using namespace std;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
bool prime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return true;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    if(n<30)cout<<"No";
    else cout<<"Yes";
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <set>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <sstream>
#include <map>
#include <cmath>
#include <stack>

using namespace std;

inline int sum(vector<vector<int>>& v, set<int>& rows, set<int>& cols) {
    int out = 0;
    for (int i = 0; i < v.size(); i++) {
        if (rows.count(i))
            continue;
        for (int j = 0; j < v[i].size(); j++) {
            if (cols.count(j))
                continue;
            out += v[i][j];
        }
    }
    return out;
}

typedef long long ll;
int main() {
    int h, w, k; cin >> h >> w >> k;
    vector<vector<int>> v(h); char temp;
    for (int i = 0; i < h; i++) {
        v[i].resize(w);
        for (int j = 0; j < w; j++) {
            cin >> temp;
            if (temp == '#')
                v[i][j] = 1;
            else
                v[i][j] = 0;
        }
    }
    int result = 0;
    set<int> rows;
    set<int> cols;
    // if (sum(v, rows, cols) == k) result++;
    for (int i = 0; i <= h; i++) {
        for (int j = 0; j <= w; j++) {
            vector<int> selector(h);
            fill(selector.begin(), selector.begin() + i, 1);
            do {
                for (int i = 0; i < h; i++) {
                    if (selector[i]) {
                        rows.insert(i);
                    }
                }
                vector<int> selectorcol(w);
                fill(selectorcol.begin(), selectorcol.begin() + j, 1);
                do {
                    for (int i = 0; i < w; i++) {
                        if (selectorcol[i]) {
                            cols.insert(i);
                        }
                    }
                    if (sum(v, rows, cols) == k) {
                        result++;
                    }// {
                    // for (int t : rows) cout << t << " ";
                    // cout << "\n";
                    // for (int t : cols) cout << t << " ";
                    // cout << "\n\n";
                    // }
                    cols.clear();
                } while (prev_permutation(selectorcol.begin(), selectorcol.end()));
                rows.clear();
            } while (prev_permutation(selector.begin(), selector.end()));

        }
    }
    cout << result;

}

// std::string bitmaski(i, 1);
// bitmaski.resize(h+1, 0);

// do {
//     for (int x = 0; x < h; ++x)
//         if (bitmaski[x]) rows.insert(x);

//     std::string bitmaskj(j, 1);
//     bitmaskj.resize(w+1, 0);
//     do {
//         for (int z = 0; z < w; ++z)
//             if (bitmaski[z]) cols.insert(z);

//         if (sum(v, rows, cols) == k) {
//             result++;
//         } {
//             for (int t : rows) cout << t << " ";
//             cout << "\n";
//             for (int t : cols) cout << t << " ";
//             cout << "\n";
//         }
//     } while (std::prev_permutation(bitmaskj.begin(), bitmaskj.end()));

// } while (std::prev_permutation(bitmaski.begin(), bitmaski.end()));

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(), h.end());
  k = min(n,k);
  ll ans = 0;
  rep(i,k) {
    h.pop_back();
  }
  rep(i,h.size()) ans += h[i];
  cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val p = readLine()!!.split(" ").map { it.toInt() }.toMutableList()
    var cnt = 0
    val a = mutableListOf<Int>()
    for (i in p) a.add(i)
    a.sort()
    for (i in 0 until n) {
        if (p[i] != a[i]) cnt++
    }
    println(
        if (cnt > 2) "NO"
        else "YES"
    )
}

Measured memory_bytes: 37908
def main():
    from itertools import accumulate as ac
    n, m, q = map(int, input().split())
    ten = [list(map(lambda x:x == "1", list(input()))) for _ in [0]*n]
    xy = [list(map(int, input().split())) for _ in [0]*q]
    ans = [0]*q

    hen = [[0]*m]+[None]*n
    for i in range(n):
        temp = [0]
        for j in range(m-1):
            temp.append(ten[i][j] & ten[i][j+1])
        hen[i+1] = list(ac(temp))
    for i in range(n):
        for j in range(1, m):
            hen[i+1][j] += hen[i][j]

    for i, (x1, y1, x2, y2) in enumerate(xy):
        ans[i] = -hen[x2][y2-1]-hen[x1-1][y1-1] + \
            hen[x2][y1-1]+hen[x1-1][y2-1]

    hen = [[0]*(m+1)]+[None]*(n-1)
    for i in range(n-1):
        temp = [0]
        for j in range(m):
            temp.append(ten[i][j] & ten[i+1][j])
        hen[i+1] = list(ac(temp))
    for i in range(n-1):
        for j in range(1, m+1):
            hen[i+1][j] += hen[i][j]

    for i, (x1, y1, x2, y2) in enumerate(xy):
        ans[i] -= hen[x2-1][y2]+hen[x1-1][y1-1] - \
            hen[x2-1][y1-1]-hen[x1-1][y2]

    del hen

    ten = [[0]*(m+1)]+ten
    for i in range(1, n+1):
        ten[i] = [0]+list(ac(ten[i]))
    for i in range(n):
        for j in range(1, m+1):
            ten[i+1][j] += ten[i][j]

    for i, (x1, y1, x2, y2) in enumerate(xy):
        print(ans[i]+ten[x2][y2]+ten[x1-1][y1-1]-ten[x2][y1-1]-ten[x1-1][y2])


main()


Measured memory_bytes: 235704
import java.util.*;
public class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int [] a = new int [n]; for (int i = 0; i < n; i++) a[i] = sc.nextInt();
        int [] dp = new int[n];
        dp[0] = 0; dp[1] = Math.abs(a[1] - a[0]);
        for (int i = 2; i < n; i++) {
            dp[i] = Math.min(dp[i - 1] + Math.abs(a[i] - a[i - 1]), dp[i - 2] + Math.abs(a[i] - a[i - 2]));
        }
        System.out.println(dp[n-1]);
    }


}

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

int main()
{
	int n, j, count = 0;
	cin >> n;
	int *p = new int[n];

	for (int i = 0; i < n; i++) cin >> p[i];

	for (int i = n; i > 0; i--) {
		for (int j = 0; j < i - 1; j++) {
			if (p[j] > p[j + 1]) {
				swap(p[j], p[j + 1]);
				count++;
			}
		}
	}
	for (j = 0; j < n - 1; j++)
		cout << p[j] << " ";
	cout << p[j] << "\n" << count << "\n";

	delete[] p;
	return 0;
}

Measured memory_bytes: 1200
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define endl '\n'
const int mod=1e9+7,u=1e5+5;

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

    int n,k;
    cin>>n>>k;
    int w[n+1],val[n+1];
    for(int i=1;i<=n;i++){
        cin>>w[i]>>val[i];
    }   

    int dp[n+1][k+1];
    for(int i=0;i<=n;i++){
        dp[i][0]=0;
    }
    for(int i=0;i<=k;i++){
        dp[0][i]=0;
    }

    for(int i=1;i<=n;i++){
        for(int j=1;j<=k;j++){
            dp[i][j]=dp[i-1][j];
            if(w[i]<=j){
                dp[i][j]=max(dp[i-1][j-w[i]]+val[i],dp[i][j]);
            }
        }
    }
    cout<<dp[n][k];

    return 0;
}

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

int main(){
    //入力
    int A,B,C;
    cin >> A >> B >> C;

    //出力
    if(A==B){
        cout << C << endl;
    }else if(A==C){
        cout << B << endl;
    }else{
        cout << A << endl;
    }
}

Measured memory_bytes: 256
// AOJ 2352 Divisor
// 2018.4.10 bal4u

#include <stdio.h>
#include <string.h>

#define MAX 202
int   hi[MAX],  to[MAX][MAX];
char seen[MAX];
int  match[MAX];

int bpm(int u);
int bipartiteMatching(int m, int n)
{
    int u, max;

    memset(match, -1, (m+n)*sizeof(int));
    max = 0;
    for (u = 0; u < m; u++) {
        memset(seen, 0, m+n);
        if (bpm(u)) max++;
    }
    return max;
}

int bpm(int u)
{
    int i, v;

    for (i = 0; i < hi[u]; i++) {
        v = to[u][i];
        if (seen[v]) continue;
        seen[v] = 1;
        if (match[v] < 0 || bpm(match[v])) {
            match[u] = v, match[v] = u;
            return 1;
        }
    }
    return 0;
}

int in()
{
    int n = 0, c = getchar_unlocked();
    do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
    return n;
}

int  x[102]; int N;
char f[102]; int sz;
int  a[102];

int calc(int n, int *a)
{
    int i, j;

    memset(hi, 0, (sizeof(int)*n)<<1);
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) if (j != i) {
            if (a[i] % a[j] == 0) to[i][hi[i]++] = n+j;
        }
    }
    return n-bipartiteMatching(n, n);
}

int main()
{
    int i, j, k, ans;

    N = in();
    for (i = 0; i < N; i++) x[i] = in();

    // 課題文の条件を満たす集合Sの大きさを確定させる
    ans = calc(N, x);

    if (ans == 1) { puts("1"); return 0; }      // Sの大きさは1の場合、無条件にx[0]が答え

    memset(f, 1, N);    // f[i]=1：答えかその候補者、0：除外すべきx[i]

    sz = 0;             // 先頭x[0]から一つずつ確定していく。確定したx[i]の個数はsz
    for (i = 0; i < N; i++) {
        // x[i] を答えの集合Sに入れることができるか
        for (j = 0; j < i; j++) if (f[j]) {
            if (!(x[i] % x[j]) || !(x[j] % x[i])) break;
        }
        if (j < i) { f[i] = 0; continue; }      // 確定した集合Sの他メンバーと衝突するので不適合

        // x[i] を集合Sのメンバーにする
        k = 0; for (j = i+1; j < N; j++) if (f[j]) {
            if (x[i] % x[j] && x[j] % x[i]) {   // 残りのx[j]からx[i]と衝突しないものを選ぶ
                a[k++] = x[j];
            } else f[j] = 2;
        }
        
                                                // calc(k, a) は残りのx[j]で作れる集合の大きさ
        if (calc(k, a) + sz + 1 == ans) {       // 確定した集合Sの大きさ（=ans）と同じ
            // 結論として、x[i]を集合Sに入れるべきだ
            if (++sz == ans) break;
            for (j = i+1; j < N; j++) if (f[j] == 2) f[j] = 0;
        } else {
            // 結論として、x[i] は不適切で除外すべきだ
            f[i] = 0;
            for (j = i+1; j < N; j++) if (f[j] == 2) f[j] = 1;
        }
    }
    memset(f+i+1, 0, N-(i+1));                  // 残りのx[i]をすべて除外

    // 確定したx[i]を出力して終了
    k = 0; for (i = 0; i < N; i++) if (f[i]) {
        if (k) putchar(' '); else k = 1;
        printf("%d", i+1);
    }
    putchar('\n');
    return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;



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

	int K;
	cin >> K;
	int ans = 0;
	rep(i,K){
		rep(j,K){
			rep(k,K){
				ans += __gcd(__gcd(i+1,j+1), k+1);
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    string S;
    cin >> S;
    ll count_zero=0, count_one=0;
    for(size_t i=0;i<S.size(); i++)
    {
        if(S[i]=='0') count_zero++;
        else count_one++;
    }
    cout << min(count_zero, count_one)*2 << endl;

#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 603, mod = 1e9 + 7;
int n, m, k, to[N], f[N][N], g[N], pre[N], ans;
inline void qmo(int &x){x += (x >> 31) & mod;}
int main(){
    scanf("%d%d", &n, &m); k = n << 1;
    for(Rint i = 1, x, y;i <= m;++ i){
        scanf("%d%d", &x, &y); to[x] = y; to[y] = x;
    }
    g[0] = 1;
    for(Rint i = 1;i <= n;++ i) g[i] = g[i - 1] * ((i << 1) - 1ll) % mod;
    for(Rint i = 1;i <= k;++ i) pre[i] = pre[i - 1] + !to[i];
    for(Rint i = 1;i <= k;++ i)
        for(Rint j = i + 1;j <= k;j += 2)
            if(!(pre[j] - pre[i - 1] & 1)){
                bool flag = true;
                for(Rint l = i;l <= j && flag;++ l)
                    flag &= !to[l] || to[l] >= i && to[l] <= j;
                if(!flag) continue;
                int t = pre[j] - pre[i - 1] >> 1;
                f[i][j] = g[t];
                for(Rint l = i + 1;l < j;l += 2)
                    qmo(f[i][j] -= (LL) f[i][l] * g[pre[j] - pre[l] >> 1] % mod);
                qmo(ans += (LL) f[i][j] * g[n - m - t] % mod - mod);
            }
    printf("%d", ans);
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include<time.h>
#include<cmath>
using namespace std;


int main(void)
{
	int A, B, C;
	scanf("%d", &A);
	scanf("%d", &B);
	if (A == 1 && B == 2 || A == 2 && B == 1)
	{
		printf("3");
	}
	else if (A == 1 && B == 3 || A == 3 && B == 1)
	{
		printf("2");
	}
	else
		printf("1");



	


	return 0;
}


Measured memory_bytes: 888
b = input()

if b == "A":
  b = b.replace("A","T")
  print(b)
  exit()
elif b == "T":
  b = b.replace("T","A")
  print(b)
  exit()
elif b == "G":
  b = b.replace("G","C")
  print(b)
  exit()
elif b == "C":
  b = b.replace("C","G")
  print(b)
  exit()

Measured memory_bytes: 2940
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int A, B;
  cin >> A >> B;
  if(A <= 8 && B <= 8)
    cout << "Yay!" << endl;
  else
    cout << ":(" << 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 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
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;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

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;
string S, T;
ll ans = 0;

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

signed main() {
    INIT;
    cin >> N;
    vi a(N);
    cin >> a;
    int mx = 0;
    REP(i, N) {
        if (mx > a[i]) {
            ans += mx - a[i];
        }
        chmax(mx, a[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3960
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
typedef pair<int, ll> pii;
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forn1(i, n) for (int i = 1; i <= n; ++i)
#define pb push_back
#define fr first
#define sc second
#define int long long
const ll MOD = 998244353;

signed main() {
    FastIO
    ll n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<int> gg(n);
    forn(i, n) cin >> gg[i];
    sort(gg.begin(), gg.end());
    reverse(gg.begin(), gg.end());
    ll ans = p;
    if (v <= p) {
        for (int i = p; i < n; ++i) {
            if (gg[i] + m >= gg[p - 1])++ans;
            else break;
        }
    }
    else {
        ll k = (v - p) * m;
        ll l = p, r = n;
        ll c;
        while(l < r) {
            ll mid = (l + r) / 2;
            ll cur = gg[mid] + m;
            //cout << k << "\n";
            c = k;
            if (cur < gg[p - 1]) {
                r = mid;
                continue;
            }
            for (int i = n - 1; i >= p - 1 && c > 0; --i) {
                if (i == mid)continue;
                c -= min(m, max(0LL, cur - gg[i]));
            }
            if (c > 0) {
                r = mid;
            }
            else {
                l = mid + 1;
            }
            //cout << l << " " << r << "\n";
        }
        ans += l - p;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
#include <bitset>


using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

int pown(int n){
    int res = 1;
    REP(i, n){
        res *= 2;
    }
    return res;
}

int main(){
    string str;
    cin >> str;
    int n = str.length() - 1;
    bitset<9> bs;
    ll ans = 0;
    REP(i, pown(n)){
        bs = static_cast<bitset<9>>(i);
        ll sum = 0;
        ll tmp = str[0] - '0';
        REP(i, n){
            if(bs[i]){
                sum += tmp;
                tmp = str[i + 1] - '0';
            }else{
                tmp *= 10;
                tmp += str[i + 1] - '0';
            }
        }
        ans += sum + tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
l=[list() for i in range(N)]
for i in range(N-1):
    a,b,c=map(int,input().split())
    l[a-1].append((b-1,c))
    l[b-1].append((a-1,c))
Q,K=map(int,input().split())
L=[None]*N
L[K-1]=0
t=1
s={K-1}
while t<N:
    g=set()
    for i in s:
        for j in l[i]:
            if L[j[0]]==None:
                L[j[0]]=L[i]+j[1]
                g.add(j[0])
                t+=1
    s=g
for _ in range(Q):
    x,y=map(int,input().split())
    print(L[x-1]+L[y-1])

Measured memory_bytes: 75564
#include <bits/stdc++.h>
using namespace std;
int H, N, i, ans=0; vector<int> A(1001), B(1001);
int memo[10001]={};
int mons(int h){
if(h<=0){ return 0; }
if(memo[h]){ return memo[h]; }
int j, m=1e9;
for(j=0; j<N; j++){ m=min(m, mons(h-A[j])+B[j]); } 
return memo[h]=m;
}
int main(){
cin >> H >> N; 
for(i=0; i<N; i++){ cin >> A[i] >> B[i]; }
cout << mons(H) << "\n";
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define maxn 200010
using namespace std;
typedef long long LL;
LL c[maxn], a[maxn], b[maxn];
int n, k, tot;
int lowbit(int x) { return x & (-x); }
LL query(int x) { LL ret=0; while (x) ret += c[x], x -= lowbit(x); return ret; }
void add(int x) { while (x <= tot) ++c[x], x += lowbit(x); }
int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]), a[i] -= k;
    for (int i = 1; i <= n; ++i) b[i] = (a[i] += a[i-1]);
    b[n+1] = 0;
    sort(b+1, b+2+n);
    tot = unique(b+1, b+2+n) - (b+1);

    LL ans=0;
    a[0] = 0;
    for (int i = 0; i <= n; ++i) {
        int p = lower_bound(b+1, b+1+tot, a[i]) - b;
        ans += query(p);
        add(p);
    }
    printf("%lld\n", ans);
    return 0;
}


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

int getCount(int n, int x){
    int count = 0;
    for(int i = 1; i <= n; i++){
        for(int j = i + 1; j <= n; j++){
            for(int k = j + 1; k <= n; k++){
                int sum = 0;
                sum = i + j + k;
                if(sum == x) count += 1;
            }
        }
    }
    return count;
}

int main(){
    int n, x;
    
    while(1){
        cin >> n >> x;
        if(n == 0 && x == 0) break;
        cout << getCount(n, x) << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
int main(){
  /*long long N;
  cin>>N;
  string answer;
  long long k=1;
  while(k*26<=N) k=k*26;
  while(k>0){
    long long x=((N/k)%26)-1;
    if(x==0) answer+='a';
    if(x==1) answer+='b';
    if(x==2) answer+='c';
    if(x==3) answer+='d';
    if(x==4) answer+='e';
    if(x==5) answer+='f';
    if(x==6) answer+='g';
    if(x==7) answer+='h';
    if(x==8) answer+='i';
    if(x==9) answer+='j';
    if(x==10) answer+='k';
    if(x==11) answer+='l';
    if(x==12) answer+='m';
    if(x==13) answer+="n";
    if(x==14) answer+='o';
    if(x==15) answer+='p';
    if(x==16) answer+='q';
    if(x==17) answer+='r';
    if(x==18) answer+='s';
    if(x==19) answer+='t';
    if(x==20) answer+='u';
    if(x==21) answer+='v';
    if(x==22) answer+='w';
    if(x==23) answer+='x';
    if(x==24) answer+='y';
    if(x==25) answer+='z';
    k=k/26;
  }
  cout<<answer<<endl;*/
  
  int N,Q;
  cin>>N;
  long long answer=0;
  int A[100000],B[100000],C[100000],D[100001];
  for(int i=0;i<=100000;i++) D[i]=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    D[A[i]]++;
    answer+=A[i];
  }
  cin>>Q;
  for(int i=0;i<Q;i++){
    cin>>B[i]>>C[i];
    answer=answer-D[B[i]]*B[i]+D[B[i]]*C[i];
    D[C[i]]+=D[B[i]];
    D[B[i]]=0;
    cout<<answer<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 4736
# coding: utf-8
import math
import itertools
N = int(input())
R  =[]
for i in range(N):
    x, y = map(int,input().split())
    R.append([x, y])
#print(R[0][0])
#L = copy.deepcopy(R)
l = [i for i in range(N)]
p = list(itertools.permutations(l,N))
S = 0
#print(p)
for v in p:
    for i in range(N-1):
        S += math.sqrt((R[v[i]][0]-R[v[i+1]][0])**2+(R[v[i]][1]-R[v[i+1]][1])**2)

ans = S / len(p)
print(ans)

Measured memory_bytes: 13988
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int f(int n) {
  int res = 0;
  while (0 < n) {
    res += n % 10;
    n /= 10;
  }
  return res;
}

int main() {
  int N;
  cin >> N;
  if (N % f(N) == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Control.Arrow
import Data.List
import Data.Maybe
import Data.Char
import qualified Data.ByteString.Char8 as B
import Text.Printf

readInt = ( readLn :: IO Int )
readInts = map ( read :: String -> Int ) . words <$> getLine

getList = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

main = getLine >> getLine >>= putStrLn . which "Four" "Three" . ( 'Y' `elem`  )


Measured memory_bytes: 508
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
//        System.out.println(N);
        long p = N;
        List<Integer> primes = new ArrayList<Integer>();
//        long a = 0;
        long b = 0;
        long num = 0;
        long minNum = (long) Math.pow(10, 12);
        for (long a = 1; a <= Math.sqrt(N); a++){
            if (N % a != 0){
                continue;
            } else {
                b = N / a;
            }
            num = a + b - 2;
            if (num < minNum){
                minNum = num;
            }
        }
        System.out.println(minNum);



//        for (long i = Math.sqrt(N); i >= 1; i--){
//            while (p % i == 0){
//                p = p / i;
//                primes.add(i);
//            }
//        }
//        int a = 1; int b = 1;
//        for (int i = 0; i < primes.size(); i++){
//            if (a <= b) {
//                a *= primes.get(i);
//            } else {
//                b*=
//            }
//        }


    }
}


Measured memory_bytes: 35828
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
void yes(bool expr) {
  cout << (expr ? "Yes" : "No") << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lint N;
    cin >> N;
    lint ans = 0;
    for(lint a=2; a*a<=N; a++) {
        lint po = 1;
        while(true) {
            lint div = pow(a, po);
            if(N%div == 0) {
                N /= div;
                ans++;
                po++;
            } else {
                break;
            }
        }
        while(true) {
            if(N%a == 0) {
                N /= a;
            } else {
                break;
            }
        }
    }
    if(N > 1) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 4116
#include <bits/stdc++.h>
#define rep(i, n) for (rint i = 1; i <= int(n); i ++)
#define re0(i, n) for (rint i = 0; i < (int) n; i ++)
#define travel(i, u) for (rint i = head[u]; i; i = e[i].nxt)
#define rint register int
using namespace std;

typedef long long lo;

template<typename tp> inline void read(tp &x) {
    x = 0; char c = getchar(); int f = 0;
    for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
    for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
    if (f) x = -x;
}
const int N = 3e5 + 2333;
const int mo = 1e9 + 7;
inline void U(int &x, int y) { x += y; if (x >= mo) x -= mo; }

char str[N];
int n, sum[N], la[3], nxt[N][3], same[N], dp[N];

int main(void) {
	scanf("%s", str + 1); 
	n = strlen(str + 1);
	rep (i, n) {
		str[i] = str[i] == 'b' ? 2 : 1;
		sum[i] = (sum[i - 1] + str[i]) % 3;
	}
	la[0] = la[1] = la[2] = n + 1; same[n + 1] = n + 1;
	for (int i = n; i >= 1; i--) {
		for (int k = 0; k < 3; k++) nxt[i][k] = la[k];
		la[sum[i]] = i;
		if (str[i] == str[i + 1]) same[i] = i + 1;
		else same[i] = same[i + 1];
	}
	if (same[1] > n) return puts("1"), 0;
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		U(dp[i + 1], dp[i]);
		int v = 3 - str[i + 1];
		int val = (v + sum[i]) % 3;
		int nxtpos = nxt[i][val];
		int lb = same[i + 1];
		if (nxtpos <= n) {
			if (nxtpos < lb) nxtpos = nxt[lb - 1][val];
			if (nxtpos <= n) U(dp[nxtpos], dp[i]);
		}
	}
	int ans = 0;
	rep (i, n) if (sum[i] == sum[n]) U(ans, dp[i]);
	cout << ans << "\n";
}


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

int main(){
    int k;cin >> k;
    int a, b; cin >> a >> b;
    
    for (int i = a; i < b+1; i++)
    {
        if(i%k==0){
            cout<< "OK"<<endl;
            return 0;
        }
    }
    cout << "NG"<<endl;
    return 0;
}

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

int main() {
  int64_t N, L0, L1, L;
  cin >> N;
  
  L0=2;
  L1=1;
  
  for(int i=0;i<N;i++){
    if(i==0){
      L=1;
    }else{
      L=L1+L0;
      L0=L1;
      L1=L;
    }
  }
  
  cout << L << endl;
}


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

using namespace std;

#define MAX 50100
  
int prime[MAX];
  
void make()
{
    for (int i = 0; i < MAX; i++) {
        prime[i] = 0;
    }
    prime[0] = prime[1] = 1;
    for (int i = 4; i < MAX; i += 2) {
        prime[i] = 1;
    }
    for (int i = 3; i*i < MAX; i++) {
        if (prime[i]) continue;
        for (int j = i*2; j < MAX; j+= i) {
            prime[j] = 1;
        }
    }
}
  
int main()
{
    int n;          
    make();  
    while (cin >> n, n) {              
	int cnt = 0;
	for (int i = 2; i <= n/2; i++) {
	    if(!prime[i] && !prime[n-i]) cnt++;
	}
	cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int n;
   cin >> n;
   vector<int> P(n), Q(n);
   rep(i, n) cin >> P[i];
   rep(i, n) cin >> Q[i];
   vector<int> p(n);
   rep(i, n) p[i] = i + 1;
   map<vector<int>, int> mp;
   do {
      mp[p] = mp.size();
   } while (next_permutation(p.begin(), p.end()));
   int ans = abs(mp[P] - mp[Q]);
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(x)					(x).begin(),(x).end()
#define REP(i, n)				for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF						(int)2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	ll N, C;
	cin >> N >> C;
	vector<ll> x(N), v(N);
	REP(i, N) cin >> x[i] >> v[i];

	vector<ll> rvMax(N, 0);
	ll nowPos = 0;
	ll calTotal = 0;
	ll ans1 = 0;
	REP(i, N) {
		ll calOne = v[i] - (x[i] - nowPos);
		calTotal += calOne;
		ans1 = max(calTotal, ans1);
		rvMax[i] = max(rvMax[i], ans1);
		nowPos = x[i];
	}

	vector<ll> lvMax(N, 0);
	nowPos = C;
	calTotal = 0;
	ll ans2 = 0;
	for (int i = N - 1; i >= 0; i--) {
		ll calOne = v[i] - (nowPos - x[i]);
		calTotal += calOne;
		ans2 = max(calTotal, ans2);
		lvMax[i] = max(lvMax[i], ans2);
		nowPos = x[i];
	}

	ll ans3 = rvMax[N - 1];
	for (int i = 0; i < N - 1; i++) {
		ll calOne = rvMax[i] + lvMax[i + 1] - x[i];
		ans3 = max(ans3, calOne);
	}
	
	ll ans4 = lvMax[0];
	for (int i = 0; i < N - 1; i++) {
		ll calOne = rvMax[i] + lvMax[i + 1] - (C - x[i + 1]);
		ans4 = max(ans4, calOne);
	}

 	cout << max(ans3, ans4) << endl;
	return 0;
}


Measured memory_bytes: 3328
#include <cstdio>
int n;
int a[100005];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n-1;i++){
		if(a[i]-a[i+1]>=1){
//			printf("No");
//			return 0;
			a[i]--;
			for(int j=i+1;j<=n;j++){
				if(a[j]<a[i]){
					printf("No");
					return 0;
				}
//				else a[i]++;
			}
		}
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

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

    ll x = (n % k);
    ll y = abs(k - x);

    cout << min(x, y) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define sz size

using namespace std;

ll n,x,tmp;

vector<ll>v;

ll pow(ll a,ll b)
{
    ll ret=a;
    for (int i=0;i<b;i++)
    {
        ret*=3;
    }
    return ret;
}

ll f(ll a)
{
    ll ret=0;
    while(1)
    {
        if (a==0||a%2!=0)break;
        ret++;
        a/=2;
    }
    return ret;
}

int main()
{
    cin >> n;
    for (int i=0;i<n;i++)
    {
        cin >> x;
        if (x%2==0)v.pb(x);
    }
    if (v.sz()==0)
    {
        cout << 0 << endl;
    }
    else
    {
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        for (auto X:v)
        {
            ll y=pow(X,tmp);
            tmp+=f(y);
        }
        cout << tmp << endl;
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VII;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()

int main(){
	int K;
	cin>>K;
	vector<ll> A(K),B(K+1),C(K+1);
	for(int i=0;i<K;i++) cin>>A[i];
	B[K]=2,C[K]=2;
	for(int i=0;i<K;i++){
		B[K-1-i]=(B[K-i]+A[K-1-i]-1)/A[K-1-i]*A[K-1-i];
		C[K-1-i]=C[K-i]/A[K-1-i]*A[K-1-i]+A[K-1-i]-1;
	}
	ll BB=B[0],CC=C[0];
	for(int i=0;i<K;i++){
		BB=BB-BB%A[i];
		CC=CC-CC%A[i];
	}
	if(BB==2&&CC==2) cout<<B[0]<<" "<<C[0]<<endl;
	else cout<<-1<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i = n;i >= 0;--i)
#define FOR(i,m,n) for(int i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

int main(void)
{
    int n,m;
    cin >> n >> m;
    priority_queue<int> q;
    REP(i,n){
        int tmp;
        cin >> tmp;
        q.push(tmp);
    }

    REP(i,m){
        int max = q.top();
        q.pop();
        q.push(max / 2);
    }

    ll sum = 0;
    REP(i,n){
        sum += q.top();
        q.pop();
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 892
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try(Scanner scanner = new Scanner(System.in)) {
			String T = scanner.next();
			 T = T.replace("?", "D");

			char[] cs = T.toCharArray();
			int count = 0;
			for (int i = 0, len = cs.length; i < len; i++) {
				char c = cs[i];
				if (i != len - 1 && c == 'P' && cs[i + 1] == 'D') {
					count++;
				} else if (c == 'D') {
					count++;
				}
			}

			System.out.print(T);
		}
	}
}

Measured memory_bytes: 41384
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	string s;
	cin>>s;
	if(s[2] == s[3] && s[4] == s[5]){
		cout<<"Yes";
	}	
	else{
		cout<<"No";
	}

	return 0;
}

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

using namespace std;

typedef long long ll;

const int MAXN = 200010;
const int mod = 1e9 + 7;

int n;
int res, All;
int pw[MAXN];
int sz[MAXN];
vector<int>to[MAXN];

inline void dfs(int x, int la) {
	sz[x] = 1;
	int sum = 0;
	for(auto u : to[x]) {
		if(u == la) continue;
		dfs(u, x), sz[x] += sz[u];
		sum = (sum + pw[sz[u]] - 1) % mod;
	}
	sum = (sum + pw[n - sz[x]] - 1) % mod;
	sum = (All - 1 + mod - sum) % mod;
	res = (res + sum) % mod;
}

int main() {
    int prd = (mod + 1) >> 1, inv = 1;
    scanf("%d", &n);
    pw[0] = 1;
    for(int i = 1; i <= n; i++) {
    	pw[i] = (pw[i - 1] << 1) % mod;
		inv = 1LL * inv * prd % mod;
	} All = pw[n - 1];
	for(int i = 1; i < n; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		to[u].push_back(v);
		to[v].push_back(u);
	} dfs(1, 0);
	cout << 1LL * res * inv % mod << endl;
    return 0;
}

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

int main() {
	string s;
	cin >> s;
	map<int, int> suffix;
	++suffix[0];
	int power = 1, cur = 0, m = 2019, n = s.size();
	long long answer = 0;
	for(int i = n - 1; ~i; --i) {
		cur = (cur + (s[i] - '0') * power) % m;
		answer += suffix[cur];
		++suffix[cur];
		power = power * 10 % m;
	}
	cout << answer;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll b,r,g,c,s,t;
  while(cin >> b >> r >> g >> c >> s >> t){
    if(b+r+g+c+s+t == 0) break;
    ll ans = 100;
//     ll X = t - (b + r + g + c + s +(b+r) * 5);
    ans += b*15;
    ans += r * 15;
    ans += g * 7;
    ans += c * 2;
    ans += 15 * (b * 5 + r * 3);
    ll a = 3 *( t - s - b * 5 -r * 3) ;
    ll c = 2 * (b * 5 + r*3);
    ans -= a+c;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3148
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

int main() {
  int n, h[100000];
  ll dp[100010]; 
  
  scanf("%d", &n);
  for(int i=0;i<n;i++) scanf("%d", &h[i]);
  for(int i=0;i<n;i++) dp[i] = 2000000000;
  
  dp[0]=0; dp[1]=abs(h[0]-h[1]);
  for(int i=2;i<n;i++) {
    dp[i] = min(dp[i], dp[i-1]+abs(h[i]-h[i-1]));
    dp[i] = min(dp[i], dp[i-2]+abs(h[i]-h[i-2]));
  }
  
  printf("%d", dp[n-1]);
  
  return 0;
}

Measured memory_bytes: 1280