akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

N = inp()
hh = inpl()
dp = [INF]*N
dp[0] = 0
dp[1] = abs(hh[1]-hh[0])

for i in range(2,N):
    dp[i] = min(dp[i-1]+abs(hh[i]-hh[i-1]),dp[i-2]+abs(hh[i]-hh[i-2]))

print(dp[-1])


Measured memory_bytes: 15248
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  auto v = readln.chomp.split.to!(int[]);
  auto c = readln.chomp.split.to!(int[]);
  auto d = new int[](n);
  foreach (i; 0..n) {
    d[i] = v[i] - c[i];
  }
  sort!((a,b)=>a > b)(d);
  int res;
  foreach (i; 0..n) {
    if (d[i] < 0) {
      break;
    }
    res += d[i];
  }
  res.writeln;
}


Measured memory_bytes: 256
def main():
    from collections import deque

    h, w = map(int, input().split())
    start = tuple(map(lambda x: int(x) - 1, input().split()))
    goal = tuple(map(lambda x: int(x) - 1, input().split()))

    maze = tuple([tuple(input()) for _ in range(h)])
    vis = [[False] * w for _ in range(h)]

    mw = [(1, 0), (0, 1), (-1, 0), (0, -1)]
    mj = list(set((i, j) for i in range(-2, 3) for j in range(-2, 3)) - set(mw) - {(0, 0)})

    q = deque()
    q.append((start[0], start[1], 0))
    while q:
        y, x, c = q.popleft()
        if vis[y][x]:
            continue
        vis[y][x] = True
        if (y, x) == goal:
            print(c)
            break
        for a, b in mw:
            if 0 <= y + a < h and 0 <= x + b < w:
                if maze[y + a][x + b] == '.':
                    q.appendleft((y + a, x + b, c))
        for a, b in mj:
            if 0 <= y + a < h and 0 <= x + b < w:
                if maze[y + a][x + b] == '.':
                    q.append((y + a, x + b, c + 1))
    else:
        print(-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 305316
def resolve():
    N = int(input())
    abc = []
    for i in range(N):
        abc.append([int(i) for i in input().split()])
        if i == 0:
            dp = [abc[0]]
        else:
            dp.append(
                [
                    abc[i][j] + max(dp[-1][k] for k in range(3) if j != k)
                    for j in range(3)
                ]
            )
    print(max(dp[-1]))


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 83548
#include <bits/stdc++.h>
using longlong=long long;

int main(){
    std::cin.tie(nullptr);std::cin.sync_with_stdio(false);
    int ans=0;
    for(int i=0;i<3;i++){
        char c;std::cin>>c;
        ans+=c=='1';
    }
    std::cout<<ans<<std::endl;
}

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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}


ll const mod = 1e9+7;
// べき乗
int64_t modpow(int64_t x, int64_t n) {
    x = x%mod;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%mod;  //nが奇数ならnを1ずらす
    }
    else return modpow((x*x)%mod, n/2)%mod;  //nが偶数ならnが半分になる
}

//逆元　a/b の modをとるとき -> a*modinv(b)%mod
long long modinv(long long a, long long m = 1e9+7) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m; 
  if (u < 0) u += m;
  return u;
}

int main() {
  int N,K,a,b;
  cin >> N >> K;
  vector<vector<int>> tree(N);
  rep(i,N-1){
    cin >> a >> b;
    a--;b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }

  ll res=K;
  vector<bool> vd(N,false);
  queue<int> q;
  q.push(0);
  vd[0]=true;
  while (!q.empty()) {
    auto t = q.front();
    q.pop();
    int cnt=2;
    if (t==0) cnt--;
    for (auto c:tree[t]) {
      if (vd[c]==false) {
        res *= K-cnt;
        res%=mod;
        cnt++;
        q.push(c);
        vd[c] = true;
      }
    }
  }
  cout << res << endl;
}

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

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define REP(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)((x).size()))

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e15+10;
const ll mod = 1e9+7;
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; }
#define print(x) cerr << #x << " is " << x << endl;


int V, E;
const int MAX_V = 1000;
using DD = ll;
#define INF 1e14+7
#define C_MAX 5010
DD d[50][C_MAX];
struct edge {int to; DD a, b; };
vector<edge> G[MAX_V];
int C[1000];
ll D[1000];
int S;
void add_edge(int from, int to, DD a, DD b) {
    G[from].push_back((edge){to, a, b}); 
    G[to].push_back((edge){from, a, b}); 
}
void dijkstra(int ss){
    priority_queue<P, vector<P>, greater<P> > que;
    
    rep(i, 50)rep(j, C_MAX)d[i][j] = INF;
    chmin(S, C_MAX - 1);
    d[ss][S] = 0;
    que.push(make_pair(0, make_pair(ss, S)));
    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second.first;
        int s = p.second.second;
        if (d[v][s] < p.first)continue;
        //fprintf(stderr, "%Ld, %d, %d\n", p.first, v, s);
        
        
        int new_s = min (s + C[v], C_MAX - 1);
        if (d[v][new_s] > p.first + D[v]){
            d[v][new_s] = p.first + D[v];
            que.push(make_pair(p.first + D[v], make_pair(v, new_s)));
       }
        for (int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if (s >= e.a && d[e.to][s - e.a] >  d[v][s] + e.b){
                d[e.to][s - e.a] =  d[v][s] + e.b;
                //if (d[e.to][s - e.a] < C_MAX)
                que.push(make_pair(d[e.to][s - e.a], make_pair(e.to, s - e.a)));
            }
        }
    }


    return;
}

int main() {
    cin >> V >> E >> S;
    rep(i, E){
        int u, v;
        ll a, b;
        cin >> u >> v >> a >> b;
        u--; v--;
        add_edge(u, v, a, b);
    }
    rep(i, V)cin >> C[i] >> D[i];
    
    dijkstra(0); // O(M log N)
    reps(i, 1, V){
        ll ans = INF;
        for (int j = 0; j < C_MAX; j++){
            chmin(ans, d[i][j]);
        }
        //cout << i << " " << ans << endl;
        cout <<  ans << endl;
    }
    
    return 0;
}


Measured memory_bytes: 11472
N, M = map(int, input().split())
A = list(map(int, input().split()))

for i in range(len(A)):
    A[i] *= -1

import heapq

heapq.heapify(A)


for _ in range(M):
    a = heapq.heappop(A)
    heapq.heappush(A, ((a*(-1))//2)*(-1))


result = -sum(A)
print(result)


Measured memory_bytes: 14224
minmp = 10000000
def dfs(depth, pt):

    if depth==n:
        mp_tmp = 0
        all_used = True
        for k in range(3):
            if pt.count(k) == 0:
                all_used = False
                break

            sum_tmp = 0
            mp_tmp += (pt.count(k) - 1)*10
            for l in range(n):
                if pt[l] == k:
                    sum_tmp += moto[l]
            
            mp_tmp += abs(sum_tmp-take[k])

        if all_used == True:
            global minmp
            minmp = min(minmp,mp_tmp)
            return
        else:
            return

    for i in range(4):
        pt[depth] = i
        dfs(depth+1, pt)

    return

#入力をとる
n,a,b,c = map(int,input().split())
moto = [int(input()) for i in range(n)]


take = []
take.append(a)
take.append(b)
take.append(c)

pt  = [3]*n
for i in range(n):
    dfs(i,pt)

print(minmp)

Measured memory_bytes: 3064
N, M = list(map(int, input().split()))

box = []
box.append([1, True])
for _ in range(N - 1):
    box.append([1, False])

for _ in range(M):
    x, y = list(map(int, input().split()))
    x -= 1
    y -= 1

    box[x][0] -= 1
    box[y][0] += 1

    if box[x][1]:
        box[y][1] = True

    if box[x][0] == 0:
        box[x][1] = False
    
ans = 0
for i in range(N):
    if box[i][1]:
        ans += 1
print(ans)

Measured memory_bytes: 17476
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    a, b, c, x, y =MI()
    ans = float('inf')
    for i in range(0, max(x*2, y*2)+1, 2):
        p = a*max(0, x-i//2) + b*max(0, y-i//2) + c*i
        ans = min(ans, p)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9172
#include <stdio.h>
int main(void){
    int a,b,x;
    scanf("%d %d",&a,&b);
    int i,tax_eight,tax_ten;
    for(i=1;i<1001;i++){
        tax_eight=(int)(i*0.08);
        tax_ten=(int)(i*0.1);
        if(tax_eight==a && tax_ten==b){
            printf("%d\n",i);
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}


Measured memory_bytes: 256
def main():
    N, *A = map(int, open(0).read().split())

    A = sorted(enumerate(A), reverse=True, key=lambda x: x[1])

    dp = [[0] * (N + 1) for _ in range(N + 1)]
    for i, (p, a) in enumerate(A):
        for j in range(i + 1):
            dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + a * (p - j))
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a * (N - (i - j) - 1 - p))

    print(max(dp[N]))

main()

Measured memory_bytes: 124612
fun main(args: Array<String>) {
	val (N, T) = readLine()!!.split(" ").map { it.toInt() }
	var ansC = Int.MAX_VALUE
	var ansT = Int.MAX_VALUE

	for (i in 0 until N) {
		val (c, t) = readLine()!!.split(" ").map { it.toInt() }
		if (t <= T && c < ansC) {
			ansC = c
			ansT = t
		}
	}
	if (ansT > T) {
		println("TLE")
	} else {
		println(ansC)
	}
}


Measured memory_bytes: 37868
n,k = list(map(int,input().split()))
d = [0] * k
a = [[] for _ in range(k)]

for i in range(k):
  d[i] = int(input())
  a[i] = list(map(int,input().split()))

s = [1] * n

for an in a:
  for j in an:
    s[j-1] = 0

print(sum(s))

Measured memory_bytes: 9136
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const int mod = 998244353;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<double>v;
	f(n){
		double add;
		cin >> add;
		v.pb(add);
	}
	sort(v.begin(),v.end());
	double ans = (v[0]+v[1])/2;
	fr(i,2,n){
		ans += v[i];
		ans /= 2.0;
	}
	cout <<fixed<<setprecision(10)<< ans << endl;
}

Measured memory_bytes: 256
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))


def main():
    n = ii()
    a = li()

    a.sort()
    ans = 0
    ans += (a[0]+a[1])/2
    for i in range(2,n):
        ans = (ans + a[i])/2
    print(ans)

main()


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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N, 0);

  for(int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int alice = 0, bob = 0;
  
  for(int j = 0; j < N; j++) {
    if(j % 2 == 0) {
      alice += vec[j];
    } else {
      bob += vec[j];
    }
  }
  
  cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;
#define pb push_back
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
const double PI=acos(-1);

void solve(){
    ll n; cin >> n;
    vector<ll> h(n);
    REP(i, n) cin >> h[i];

    bool flag = true;
    ll tmpmx = -1;
    REP(i, n){
        tmpmx = max(tmpmx, h[i]);
        if(tmpmx-2 >= h[i]){
            flag = false;
        }
    }
    if(flag) Yes();
    else No();
    
}

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

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ph push
#define ptc putchar
#define enter putchar('\n')
#define mod 998244353
using namespace std;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long lnt;
inline int read(){
	int x = 0;char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + c - '0' , c = getchar();
	return x;
}
inline void write(int x){
	if (!x){
       ptc('0');
       return;
	}
	int dg[20] , len = 0;
	while (x) dg[len++] = x % 10 , x /= 10;
	while (len--) ptc(dg[len]+'0');
}
inline void writeln(int x){
	write(x);
	ptc('\n');
}
inline int add(int x,int y){
	x += y;if (x >= mod) x -= mod;
	return x;
}
inline int sub(int x,int y){
	x -= y;if (x < 0) x += mod;
	return x;
}
inline int qpow(int x,int y){
	int res = 1;
	while (y){
		if (y & 1) res = 1ll * res * x % mod;
		x = 1ll * x * x % mod;y >>= 1;
	}
	return res;
}
lnt a , b , c , d , pd , pa;
int T;
int main(){
	cin >> T;
	while (T--){
		cin >> a >> b >> c >> d;
		if (a < b || d < b){
			puts("No");
			continue;
		}
		a %= b;
		d %= b;
		d = __gcd(d , b);
		ll smallest = ((c + 1 - a + d - 1) / d);
		
//		printf("%lld\n",smallest);
		if (smallest * d + a < b){
			puts("No");
			continue;
		}
		puts("Yes");
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <vector>
/*与えられた数列Sの中に含まれている数列Tの要素の数を出力する*/
using namespace std;
int main(){
	vector<int> s, t;
	int n, n2;
	cin >> n;
	for(int i = 0; i < n; i++){
		int tmp;
		cin >> tmp;
		s.push_back(tmp);
	}
	cin >> n2;
	for(int i = 0; i < n2; i++){
		int tmp;
		cin >> tmp;
		t.push_back(tmp);
	}
	int ans = 0;
	for(int t_i = 0; t_i < n2; t_i++){
		int first = 0, last = n, middle;
		while(first < last){
			middle = (first + last) / 2;
			if(s[middle] == t[t_i]){
				ans++;
				break;
			}else if(s[middle] > t[t_i]){
				last = middle;
			}else{
				first = middle + 1;
			}
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
using namespace std;

int main(void){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll n;
    cin>>n;
    vector<string> vs(n);
    ll ans = 0;
    rep(i,n){
        cin>>vs[i];
        sort(vs[i].begin(),vs[i].end());
    }
    sort(vs.begin(),vs.end());
    ll kosu = 1;
    for(ll i=1;i<n;++i){
        if(vs[i] != vs[i-1]){
            ans += (kosu*(kosu-1))/2;
            kosu = 1;
        }else{
            kosu++;
        }
    }
    ans += (kosu*(kosu-1))/2;
    cout<<ans<<endl;
    
}


Measured memory_bytes: 6016
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

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

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

fn calc_s1(i: usize, a: &Vec<usize>) -> usize {
    if a[i] == 0 {
        return 2;
    }
    if a[i] % 2 == 0 {
        return 0;
    }
    1
}

fn calc_s2(i: usize, a: &Vec<usize>) -> usize {
    if a[i] % 2 == 0 {
        return 1;
    }
    0
}

fn main() {
    let n: usize = read();
    let a = (0..n).map(|_| read::<usize>()).collect::<Vec<_>>();

    let mut dp = vec![vec![0; 5]; n];
    dp[0][0] = a[0];
    for i in 1..n {
        dp[i][0] = dp[i - 1][0] + a[i];
    }
    dp[0][1] = calc_s1(0, &a);
    for i in 1..n {
        dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]);
        dp[i][1] += calc_s1(i, &a);
    }
    dp[0][2] = calc_s2(0, &a);
    for i in 1..n {
        dp[i][2] = *dp[i - 1].iter().take(3).min().unwrap();
        dp[i][2] += calc_s2(i, &a);
    }
    dp[0][3] = calc_s1(0, &a);
    for i in 1..n {
        dp[i][3] = *dp[i - 1].iter().take(4).min().unwrap();
        dp[i][3] += calc_s1(i, &a);
    }
    dp[0][4] = a[0];
    for i in 1..n {
        dp[i][4] = *dp[i - 1].iter().take(5).min().unwrap();
        dp[i][4] += a[i];
    }
    // println!("{:?}", dp);
    println!("{}", (0..5).map(|i| dp[n - 1][i]).min().unwrap());
}


Measured memory_bytes: 20732
// B.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int max = 0;
    int l[100];
    int maxkey = 0;
    for (int i = 0; i < n; i++) {
        cin >> l[i];
        if (max < l[i]) {
            max = l[i];
            maxkey = i;
        }
    }

    int sum = 0;

    for (int i = 0; i < n; i++) {
        if (i == maxkey)continue;
        sum += l[i];
    }
    if (sum <= max) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }
    return 0;
    
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define mx 505
using namespace std;
int arr[mx][mx];
main(){
	int n,m,q;
	cin>>n>>m>>q;
	int a[n+1][n+1];
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		arr[a][b]++;
	}
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			arr[i][j] += arr[i][j-1];
		}
	}
	while(q--){
		int a,b;
		cin>>a>>b;
		int count = 0;
		for(int i=a;i<=b;i++){
			count += (arr[i][b] - arr[i][i-1]);
		}
		cout<<count<<endl;
	}
}

Measured memory_bytes: 1920
using System;
using System.Collections.Generic;

class Scanner {
    private string[] arr;
    private int count = 0;
    private int pointer = 0;
    public string next() {
        if(this.pointer >= this.count) {
            var str = Console.ReadLine();
            arr = str.Split(' ');
            count = arr.Length;
            pointer = 0;
        }
        var result = arr[pointer];
        pointer++;
        return result;
    }
    public bool hasNext() {
        return pointer < count;
    }
    public int nextInt() {
        return int.Parse(next());
    }
    public double nextDouble() {
        return double.Parse(next());
    }
}

class Run
{
  static void Main()
  {
    var scan = new Scanner();
    var A = scan.nextInt();
    var P = scan.nextInt();
    int answer = (A * 3 + P)/2;
    Console.Write(answer);
  }
}

Measured memory_bytes: 11092
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int K,S;
  cin >> K >> S;

  int ans = 0;
  for(int x=0;x<=K;x++){
    for(int y=0;y<=K;y++){
      int z = S - x - y;
      if(0 <= z && z <= K) ans++;
    }
  }

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

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

const ll INF = 1LL << 60;

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


int main() {
  int n;cin>>n;
  vector<ll> a(n),b(n);
  rep(i,n)cin>>a[i];
  rep(i,n)cin>>b[i];
  ll summ=0;
  ll sump=0;
  rep(i,n){
    ll x=(a[i]-b[i]);
    if(x>0)sump+=x;
    else summ+=-x/2;
  }
  if(sump<=summ)cout<<"Yes";
  else cout<<"No";
}


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

using namespace std;

int main()
{
    long long int X;
    long long int K;
    long long int D;
    cin >> X >> K >> D;
    if(X < 0)
        X = -X;

    long long int auxN = X/D;
    if(K <= auxN)
    {
        cout << X - K*D;
        return 0;
    }
    else
    {
        X -= D * auxN;
        K -= auxN;
    }

    if(K%2 == 0)
        cout << X;
    else
        cout << D-X;

    return 0;
}


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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
ll mod = 1000000007;

int main() {
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n) { cin >> a[i]; }
    sort(a, a + n, greater<ll>());
    ll ans = 0;
    ans += a[0];

    n -= 2;

    ll index = 1;
    while (n > 0) {
        if (n >= 2) {
            ans += a[index] * 2;
            n -= 2;
        } else {
            ans += a[index];
            n--;
        }
        index++;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 5200
# -*- coding: utf-8 -*-

N = int(input())
S = []
for i in range(N):
    t = input()
    l = []
    for a in t:
        l.append(ord(a)-ord('a'))
    l.sort()
    v = 0
    for a in l:
        v = v * 26 + a
    S.append(v)

S.sort()
S.append(-1)

P = -1
C = 0
Ans = 0
for v in S:
    if P != v:
       Ans += int(C * (C - 1) / 2)
       C = 1
    else:
        C += 1
    P = v

print(Ans)



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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int n,m;
	string temp;
	std::cin >> n;
	std::map<string, int> map;
	for (size_t i = 0; i < n; i++) {
		std::cin >> temp;
		auto x = map.find(temp);
		if (x != map.end()) {
			map[temp]++;
		}
		else {
			map.insert(make_pair(temp,1));
		}
	}
	std::cin >> m;
	for (size_t i = 0; i < m; i++) {
		std::cin >> temp;
		auto x = map.find(temp);
		if (x != map.end()) {
			map[temp]--;
		}
	}
	int ans = 0;
	for (auto itr = map.begin(); itr != map.end(); itr++) {
		ans = max(ans, itr->second);
	}

	std::cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()
    DD = ((1,0),(0,1),(-1,0),(0,-1))

    N = NI()

    ans = pow(10,N,MOD) - (pow(9,N,MOD) * 2 - pow(8,N,MOD))


    print(ans % MOD)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68840
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <math.h>
#include <cmath>
#include <set>   

using namespace std;


int main() {

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	if (abs(a - b) <= d && abs(b - c) <= d) {
		cout << "Yes" << endl;
	}
	else if(abs(a - c) <= d){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;

	}

}

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

L.sort()

ans = 0
for i in range(0, N):
    Li = L[i]
    for j in range(i + 1, N):
        Lj = L[j]
        if Li != Lj:
            for k in range(j + 1, N):
                Lk = L[k]
                if Lj != Lk:
                    if Li + Lj > Lk:
                        ans += 1
print(ans)

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
int main(){
	string S;
	cin >> S;
    int ans = 753;
    string T;
	for(int i = 0; i < S.size()-2; i++) {
		T=S.substr(i,3);
		ans = min(ans,abs(753-((T[0]-'0')*100+(T[1]-'0')*10+(T[2]-'0'))));
	}
	cout<< ans <<endl;
}


Measured memory_bytes: 256
a,b,c,x,y = map(int, input().split())
cand = []
cand.append(a*x + b*y)
cand.append(max(x,y)*2*c)
if x > y:
    cand.append(min(x,y)*2*c + abs(x-y)*a)
else:
    cand.append(min(x,y)*2*c + abs(x-y)*b)
print(min(cand))

Measured memory_bytes: 3064
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
//    ll x=maxx/2, y=sqrt(maxx)/2;
//    for(ll i=1;i<=y;i++){
//        if(vis[i]==0){
//            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
//                vis[j]=1;
//        }
//    }
//    prime.push_back(2);
//    for(ll i=3;i<maxx;i+=2)
//        if(vis[i/2]==0)
//        prime.push_back(i);
//}
//void generate_mobius()
//{
//    for(int i=0;i<maxx;i++)mobi[i]=1;
//    for(int i=2;i<maxx;i++){
//        if(!pr[i]){
//            mobi[i]*=-1;
//            for(int j=i+i;j<maxx;j+=i){
//                pr[j]=1;
//                mobi[j]*=(j%(i*i)?-1:0);
//            }
//        }
//    }
//}
//bool isprime(ll a)
//{
//    if(a==1)return false;
//    if(a==2)return true;
//    if(a%2==0)return false;
//    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
//        if(a%prime[i]==0)return false;
//    return true;
//}
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
    ll ret = 0 , cur = a % c ;
    while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
    return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
    ll ret = 1, cur = b % m;
    while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
    return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
    ll ret = 1 , cur = a%c ;
    while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
    return ret%c ;
}
inline ll power(ll b, ll p){
    ll ret = 1, cur = b;
    while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
    return ret;
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
void Dufaux()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a*b>=c*d){
        cout<<a*b<<endl;
    }
    else{
        cout<<c*d<<endl;
    }
}
int main()
{
    FastIO;
	///sieve();
	///generate_mobius();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}






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

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define sp cout << " ";
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';              

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;


int main(){

	ll a,p;
	cin >> a >> p;
	p += (3 * a);

	cout << p / 2 << '\n';

}


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

int main(){
    int n, tmp;
    long long ans=0;
    scanf("%d",&n);
    vector<int>a(n+1);
    vector<int>b(n);
    for(int i=0; i<n+1; i++){
        cin >> a[i];
    }
    for(int i=0; i<n; i++){
        cin >> b[i];
    }
    for(int i=0; i<n; i++){
        if(b[i]<=a[i]){
            ans += b[i];
        }else{
            ans += a[i];
            b[i] -= a[i];
            ans += min(b[i], a[i+1]);
            a[i+1] -= min(b[i],a[i+1]);
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4036
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define eps 1.0e-8
#define INF 1e50
#define g 4.9
using namespace std;
double X,Y;
int n;
struct G{
    double x;
    double y;
};
G d[1010];
double calc(double x)
{
    double ans=0;
    for(int i=0;i<n;i++){
        double t=(x*d[i].x/g+d[i].y/g)/2.0;
        if(t>0) ans+=t*d[i].x;
    }
    return ans;
}
double calcy(double x)
{
    double ans=0;
    for(int i=0;i<n;i++){
        double t=(x*d[i].x/g+d[i].y/g)/2.0;
        if(t>0) ans+=t*d[i].y-g*t*t;
    }
    return ans;
}
double cnt()
{
    double left=-1e4, right=1e4, mid;
    while(left+eps<right){
        mid=left+(right-left)/2.0;
        if(calc(mid)>=X) right=mid;
        else left=mid;
    }
    return calcy(left);
}
int main()
{
    int i,j;
    while(scanf("%d",&n),n)
    {
        for(i=0;i<n;i++) scanf("%lf%lf",&d[i].x,&d[i].y);
        scanf("%lf%lf",&X,&Y);
        //for(i=0;i<n;i++) printf("%lf %lf\n",d[i].x,d[i].y);
        double ymin=INF, ymax=-INF;
        for(i=0;i<n;i++){
            double t1=X/d[i].x, y=d[i].y*t1-g*t1*t1;
            ymin=min(y,ymin);
        }
        double tmp=cnt();
        ymax=max(ymax,tmp);
        //printf("%f %f\n",ymin,ymax);
        if(Y<=ymax+eps&&Y>=ymin-eps) puts("Yes");
        else puts("No");
    }
    return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int n=s.size(),cnt=0,i;
  for(i=0;i<n;i++){
    if(i%2==0){
      if(s[i]=='R' || s[i]=='U' || s[i]=='D'){
        cnt++;
      }
    }else{
      if(s[i]=='L' || s[i]=='U' || s[i]=='D'){
        cnt++;
      }
    }
  }
  if(cnt==n){
  	cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	int n,i,p,k,j,gokei,big=0,b ;
	while(1)
	{
	scanf("%d",&n);
	big=0 ;
	if(n==0)
	{
		break ;
	}
	for(i=1;i<n+1;i++)
	{
		scanf("%d %d %d",&p,&k,&j) ;
		gokei=k+j ;
		if(big<gokei)
		{
			b=p ;
			big=gokei ;
		}
	}
	printf("%d %d\n",b,big);
	}
return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
using namespace __gnu_pbds;
using namespace std;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST int testcase;cin>>testcase;while(testcase--)
#define FTEST int testcase;fin>>testcase;while(testcase--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
#define endl "\n"
#define plll pair<ll,pll>
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
FO
ll k;
ll power(ll a,ll p){
    ll ans=1;
    while(p){
        if(p&1) ans=(ans*a)%k;
        p/=2;
        a=(a*a)%k;
    }
    return(ans);
}
void solve(){


    cin>>k;
    if(k==7) {cout<<1;return;}
    if(k%2==0 || k%5==0) {cout<<-1;return;}
    int t=1;
    k*=9;
    if(k%7==0) k/=7;
    while(1){
        ll x=power(10,t)-1;
        if(x<0) x+=k;
        if(x==0) {cout<<t;return;}
        t++;
    }
    return;
}
int main(){
    IO
   // TEST
    solve();
    return(0);
}


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

using namespace std;



int main(int argc, char* argv[])
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int A, B;
  cin >> A >> B;
  cout << A * B - A - B + 1 << "\n";

  return 0;
}


Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		HashMap<String, Integer> m = new HashMap<>();

		int n = Integer.parseInt(sc.nextLine());

		for(int i = 0; i < n; i++)
		{
			String s = sc.nextLine();
			m.put(s, m.containsKey(s) ? m.get(s) + 1 : 1);
		}

		n = Integer.parseInt(sc.nextLine());

		for(int i = 0; i < n; i++)
		{
			String s = sc.nextLine();
			m.put(s, m.containsKey(s) ? m.get(s) - 1 : - 1);
		}

		int v = 0;
		for(Integer z : m.values())
		{
			v = Math.max(v, z);
		}
		System.out.println(v);
	}
}

Measured memory_bytes: 21844
import collections

N,K = map(int,input().split())
A = [0]*N
A = list(map(int,input().split()))
c = collections.Counter(A)
c_list = list(c.values())
c_list.sort()
c_list_inv = [i for i in c_list[::-1]]
c_list_sum = [i for i in c_list_inv[K::1]]
print(sum(c_list_sum))

Measured memory_bytes: 34180
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int a,b; cin >> a >> b;
    if(a>8||b>8) cout << ":("<<endl;
    else cout << "Yay!"<<endl;
}


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

class Node {
  public:
    Node() = default;
    int value;
    int cnt;
};

static constexpr int kMaxValue = 100000;

bool has_larger_cnt(const Node& a, const Node& b)
{
  return a.cnt > b.cnt;
}

int main()
{
  int n;
  cin >> n;
  assert(n % 2 == 0);
  vector<Node> odd(kMaxValue+1);
  vector<Node> even(kMaxValue+1);
  for (int i = 0; i <= kMaxValue; i++) {
    even.at(i).value = i;
    odd.at(i).value = i;
  }
  for (int i = 0; i < n; i++) {
    int value;
    cin >> value;
    if (i % 2 == 0) {
      even.at(value).cnt++;
    } else  {
      odd.at(value).cnt++;
    }
  }
  sort(odd.begin(), odd.end(), has_larger_cnt);
  sort(even.begin(), even.end(), has_larger_cnt);
  int result;
  if (odd.at(0).value != even.at(0).value) {
    result = n - odd.at(0).cnt - even.at(0).cnt;
  } else {
    result = n - max(odd.at(0).cnt + even.at(1).cnt, odd.at(1).cnt + odd.at(0).cnt);
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NK = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, K) = (NK[0], NK[1]);
        var H = ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();

        var ans = H.OrderByDescending(x => x).Skip(K).Sum();

        WriteLine(ans);
    }
}


Measured memory_bytes: 51532
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while(true){
        String a = sc.next();
        if(a.equals("-")){
                break;
            }
        int b = sc.nextInt();
        int i = 0;
        String a1, a2;
        
        
        for (i = 0; i < b; i++) {
            int c= sc.nextInt();

            
            
            a1=a.substring(0,c);
            a2=a.substring(c);
             a=a2+a1;
        }
        
        System.out.println(a);
    }
        sc.close();
    }

}


Measured memory_bytes: 26176
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		 BufferedReader br = new BufferedReader(new
		 InputStreamReader(System.in));
		//BufferedReader br = new BufferedReader(new FileReader("sample.txt"));

		int n = Integer.parseInt(br.readLine());
		int[] in = new int[n];
		int max = Integer.MIN_VALUE;
		int mini = 0;
		int maxj=0;
		boolean con=false;
		
		for (int i = 0; i < n; i++)
			in[i] = Integer.parseInt(br.readLine());
		

		for (int i = 0; i < n - 1; i++) {
			if (in[i] > in[mini])continue;
			for (int j = i + 1; j < n; j++){
				if(i!=0&&con&&i<maxj){
					mini=i;
					max=in[maxj]-in[i];
					break;}
				else if(max+in[i]<in[j]){
					max=in[j]-in[i];
					mini=i;
					maxj=j;
					con=false;
				}
			}con=true;
		}
		System.out.println(max);

	}

}

Measured memory_bytes: 37720
import java.util.*;
import java.util.Collections;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = Integer.parseInt(sc.next());
        int S = Integer.parseInt(sc.next());
        
        long count = 0;
        
        for(int x = 0; x <= K; x++) {
            if(x == S) {
                count++;
                break;
            }
            if(x > S) {
                break;
            }
            if(x+K+K < S) {
                continue;
            }
            for(int y = 0; y <= K; y++) {
                if(x + y == S) {
                    count++;
                    break;
                }
                if(x + y > S) {
                    break;
                }
                if(x+y+K < S) {
                    continue;
                }
                count++;
            }
            
        }
        
        System.out.println(count);
        
    }
}

Measured memory_bytes: 23380
#include<stdio.h>
#include<stdlib.h>
 
typedef struct node{
  int key;
  int priority;
  struct node *left;
  struct node *right;
}node;
 
 
node * Delete(node **,int);
node * _delete(node **,int);
 
int find(node *p,int x){
 
  while(p!=NULL){
    if(p->key == x)return 1;
    else if(p->key > x)p=p->left;
    else p=p->right;
  }
 
  return 0;
 
}
 
void inorder(node *p){
 
  if(p->left!=NULL)inorder(p->left);
 
  printf(" %d",p->key);
 
  if(p->right!=NULL)inorder(p->right);
 
  return;
 
}
 
void preorder(node *p){
 
  printf(" %d",p->key);
 
  if(p->left!=NULL)preorder(p->left);
 
  if(p->right!=NULL)preorder(p->right);
 
  return;
 
}
 
void print(node *p){
 
  inorder(p);
  printf("\n");
 
  preorder(p);
  printf("\n");
 
  return;
 
}
 
node * makenode(int x,int y){
  node *new=malloc(sizeof(node));
  new->key=x;
  new->priority=y;
  new->left=NULL;
  new->right=NULL;
  return new;
}
 
node *rightRotate(node *p){
  node *q=p->left;
  p->left=q->right;
  q->right=p;
  return q;
}
 
node *leftRotate(node *p){
  node *q=p->right;
  p->right=q->left;
  q->left=p;
  return q;
}
 
 
node* insert(node **t,int key,int priority){
  node *new;
 
  if((*t)==NULL)
  return new=makenode(key,priority);
  if ((*t)->key==key)
  return *t;
 
  if(key < (*t)->key){
    (*t)->left=insert(&(*t)->left,key,priority);
    if((*t)->priority < (*t)->left->priority)
    (*t)=rightRotate((*t));
  }
  else {
    (*t)->right=insert(&(*t)->right,key,priority);
    if((*t)->priority < (*t)->right->priority)
    (*t)=leftRotate((*t));
  }
 
  return *t;
}
 
 
node * Delete(node **t,int key){
  if((*t)==NULL)
  return NULL;
 
  if(key < (*t)->key)
  (*t)->left=Delete(&((*t)->left),key);
 
  else if(key > (*t)->key)
  (*t)->right=Delete(&((*t)->right),key);
 
  else return _delete(t,key);
 
  return *t;
}
 
node * _delete(node **t,int key){
  if((*t)->left==NULL && (*t)->right==NULL)
  return NULL;
  else if((*t)->left==NULL)
  (*t)=leftRotate(*t);
  else if((*t)->right==NULL)
  (*t)=rightRotate(*t);
  else {
    if((*t)->left->priority > (*t)->right->priority)
    (*t)=rightRotate(*t);
    else
    (*t)=leftRotate(*t);
  }
  return Delete(t,key);
}
 
 
int main(){
  int n,x,y;
  char com[8];
  node *root=NULL;
 
  scanf("%d",&n);
 
  for(int i=0;i<n;i++){
    scanf("%s",com);
 
    switch(com[0]){
 
      case 'i':scanf("%d %d",&x,&y);
      root=insert(&root,x,y);
      break;
 
      case 'd':scanf("%d",&x);
      root=Delete(&root,x);
      break;
 
 
      case 'f':scanf("%d",&x);
      if(find(root,x))printf("yes\n");
      else printf("no\n");
      break;
 
      case 'p':print(root);
      break;
 
    }
 
  }
 
  return 0;
 
}



Measured memory_bytes: 7940
import heapq
N,M = map(int,input().split())
A = list(map(lambda x: int(x)*(-1),input().split()))
heapq.heapify(A)
for _ in range(M):
    tmp_min = heapq.heappop(A)
    heapq.heappush(A, (-1)*(-tmp_min//2))
print(-sum(A))

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

bool inside(ll n,ll l,ll r,ll k){
  if(l<=r) return l<=k&&k<=r;
  else return inside(n,l,n-1,k)||inside(n,0,r,k);
}

int N;
ll l[2001],r[2001];

ll solve(string A,string B){
  //dbg(A);
  ll res=INF;

  memset(l,0,sizeof(l)); memset(r,0,sizeof(r));
  rep(i,N){
    ll j=i;
    while(B[j]!='1'){
      j=(j-1+N)%N;
      l[i]++;
    }
    j=i;
    while(B[j]!='1'){
      j=(j+1)%N;
      r[i]++;
    }
    //dbg(l[i]); dbg(r[i]);
  }

  rep(k,N){
    ll mis=0;
    multiset<P> ls;
    multiset<ll> rs;
    rep(i,N){
      ll j=(i+k)%N;
      if(A[i]!=B[j]){
        mis++;
        if(inside(N,i,j,(i+r[i])%N)||inside(N,i,j,(j-l[j]+N)%N))continue;
        ls.insert(P(l[i],r[j]));
      }
    }
    //dbg(k); dbg(mis); dbg(ls.size());
    if(ls.size()==0){
      minch(res,mis+k); continue;
    }
    ls.insert(P(0,0)); rs.insert(0);
    while(ls.size()){
      minch(res,mis+2*(ls.rbegin()->first)+2*(*rs.rbegin())+k);
      P p=*ls.rbegin();
      ls.erase(ls.find(p)); rs.insert(p.se);
    }
  }

  //dbg(res);
  return res;
}

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

  string A,B;
  cin>>A>>B;
  N=A.size();

  {
    bool a=false,b=false;
    rep(i,N){
      if(A[i]=='1')a=true;
      if(B[i]=='1')b=true;
    }
    if(!b){
      if(a)cout<<-1<<endl;
      else cout<<0<<endl;
      return 0;
    }
  }

  string rA=A,rB=B;
  reverse(all(rA)); reverse(all(rB));
  cout<<min(solve(A,B),solve(rA,rB))<<endl;

  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=500010;

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

    ll x;
    cin>>x;
    ll c=100;
    ll ans=0;
    while(c<x)
    {
        ++ans;
        c+=c/100;
    }
    cout<<ans;

    return (0);
}


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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< pair<int,int> > vpii;
typedef vector< pair<ll,ll> > vpll;
typedef vector< vector<int> > matrix;

#define SET(Ar,val) memset(Ar,val,sizeof(Ar))
#define rep(i,val,n)  for(int i=val;i<n;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define LMAX LONG_LONG_MAX
#define LMIN LONG_LONG_MIN
#define IMAX INT_MAX
#define IMIN INT_MIN
#define M 1000000007

/*--------------------------------------------------------------------------------------------------------------------------------*/

template <class T> T modpower(T a,T b,T MOD)
{
    T ans=1;
    while(b!=0)
    {
        if(b%2==1)
        ans=(ans*a)%MOD;
        a=(a*a)%MOD;
        b/=2;
    }
    return ans;
}

bool bp[102][102];

bool bpm(int N, int u, bool seen[], int matchR[])
{
    for (int v = 0; v < N; v++)
    {
        if (bp[u][v] && !seen[v])
        {
            seen[v] = true;
            if (matchR[v] < 0 || bpm(N, matchR[v], seen, matchR))
            {
                matchR[v] = u;
                return true;
            }
        }
    }
    return false;
}

int maxbpm(int N)
{
    int matchR[N];
    memset(matchR, -1, sizeof(matchR));
    int result = 0;
    for (int u = 0; u < N; u++)
    {
        bool seen[N];
        memset(seen, 0, sizeof(seen));
        if (bpm(N,u, seen, matchR))
            result++;
    }
    return result;
}

void init()
{
    int n,x,y;
    cin >> n ;
    vpii v1,v2;
    rep(i,0,n)
    {
        cin >> x >> y ;
        v1.pb({x,y});
    }
    rep(i,0,n)
    {
        cin >> x >> y ;
        v2.pb({x,y});
    }
    rep(i,0,n)
    {
        rep(j,0,n)
        {
            if((v1[i].fi < v2[j].fi) && (v1[i].se < v2[j].se))
                bp[i][j] = 1;
            else
                bp[i][j] = 0;
        }
    }
    cout << maxbpm(n);
}

int main()
{
    clock_t time1=clock();
	/*#ifndef ONLINE_JUDGE
	freopen("abc_091.in","r",stdin);
	#else
	//ONLINE_JUDGE
	#endif*/
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
    init();
    clock_t time2 = clock();
    cerr <<"Time: " <<(double)(time2-time1)/CLOCKS_PER_SEC <<" seconds" <<endl;
	return 0;
}


Measured memory_bytes: 256