akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int  ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(H); sll(W);
	sll(h); sll(w);
	LL cells = H * W - h * W - H * w + h * w;
	pll(cells); nl;
}


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

using namespace std;

#define run_forrest_run ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define vi vector <int>
#define pii pair <int, int>
#define sz(a) (int)a.size()
#define F first
#define S second
#define si set <int>
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int gcd(int a,int b){if(b==0)return a;else return gcd(b,a%b);}
int lcm(int a,int b){return abs(a*b)/gcd(a,b);} 

const int inf = 1e8+1-1;	
const int mod = inf + 7;

const int N = 1e5+500;
int a[N];

int main()
{                   
	run_forrest_run;
	int n,a,b;
	cin >> n >> a >> b;
	cout << min(n*a, b);
	
	return 0;
}

Measured memory_bytes: 256
import math

def resolve():
    N, D = map(int, input().split())

    ans = 0
    for _ in range(N):
        x, y = map(int, input().split())
        dist = math.sqrt(x*x + y*y)
        if dist <= D:
            ans += 1
    print(ans)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9188
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#define pb push_back
#define INF 1000000000
using namespace std;
typedef pair<int,int> P;
int n;

struct edge{
	int to,cost;
	edge(int to,int cost):to(to),cost(cost){}
};
vector<vector<edge> > G1,G2;


int dijkstra1(int s,int t){
	priority_queue<P,vector<P> , greater<P> > que;
	vector<int> d(n,INF);
	d[s]=0;
	que.push(P(0,s));
	while(!que.empty()){
		P q=que.top();
		que.pop();
		int now=q.second,dist=q.first;
		if(now==t){
			return dist;
		}
		
		if(d[now]<dist)
			continue;
		
		for(int i=0;i<(int)G1[now].size();i++){
			if(G1[now][i].cost+dist<d[G1[now][i].to]){
				que.push(P(G1[now][i].cost+dist,G1[now][i].to));
				d[G1[now][i].to]=G1[now][i].cost+dist;
			}
		}
	}
	return -1;
	
}
int dijkstra2(int s,int t){
	priority_queue<P,vector<P> , greater<P> > que;
	vector<int> d(n,INF);
	d[s]=0;
	que.push(P(0,s));
	while(!que.empty()){
		P q=que.top();
		que.pop();
		int now=q.second,dist=q.first;
		if(now==t){
			return dist;
		}
		
		if(d[now]<dist)
			continue;
		
		for(int i=0;i<(int)G2[now].size();i++){
			if(G2[now][i].cost+dist<d[G2[now][i].to]){
				que.push(P(G2[now][i].cost+dist,G2[now][i].to));
				d[G2[now][i].to]=G2[now][i].cost+dist;
			}
		}
	}
	return -1;
}
int main(){
	int m;
	while(cin>>m>>n,n||m){
		G1.resize(n);
		G2.resize(n);
		G1.clear();
		G2.clear();
		for(int i=0;i<m;i++){
			int a,b,c,t;
			cin>>a>>b>>c>>t;a--;b--;
			G1[a].pb(edge(b,c));
			G1[b].pb(edge(a,c));
			G2[a].pb(edge(b,t));
			G2[b].pb(edge(a,t));
		}

		
		int k;
		cin>>k;
		for(int i=0;i<k;i++){
			int p,q,r;
			cin>>p>>q>>r;p--,q--;
			if(r==0){
				cout<<dijkstra1(p,q)<<endl;
			}else
				cout<<dijkstra2(p,q)<<endl;
			
			
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 2932
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <fstream>
#include <set>
#include <stack>
#include <queue>
#include <list>
using namespace std;
typedef long long int64;
typedef vector<int> vec;
typedef vector<int64> vec64;
#define db(x) cout << "> " << #x << ": " << x << "\n";
#define ss cout << " ";
#define ct(x) cout << x;
#define nn cout << "\n";
#define cts(x) cout << x << " ";
#define ctn(x) cout << x << "\n";
// // // // // // // // // // // // // // // // // // // // // // 
/*                  TEMPLATE - VANILLA                         */
// // // // // // // // // // // // // // // // // // // // // //
int64 q, n;

void solve(){

    return;
}


int main(){
    long double a,b;
    cin >> a >> b;
    cout << (int64) floor(a*b);
    return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (ll i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
long long GCD(long long x, long long y) { return y ? GCD(y, x%y) : x; }

int main(){
    int N;
    cin >> N;
    int max_a = 0;
    vector<int> cnt(1000000);
    rep(i, N){
        int a;
        cin >> a;
        cnt[a]++;
        cnt[a+1]++;
        cnt[a+2]++;
    }
    for(auto aaa: cnt){
        max_a = max(max_a, aaa);
    }
    cout << max_a << endl;
    return 0;
}


Measured memory_bytes: 7144
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int INF = 1e12;

int p[21], q[21][51], r[21][51];
int costTable[21][100010];
int d[21][110][110];

signed main(){
    int n, m, c, s, g;
    while(cin >> n >> m >> c >> s >> g, n){
        s--; g--;
        rep(i, 0, c + 1){
            rep(j, 0, n){
                rep(k, 0, n){
                    d[i][j][k] = INF;
                }
                d[i][j][j] = 0;
            }
        }
        rep(i, 0, m){
            int x, y, di, ci;
            cin >> x >> y >> di >> ci;
            x--; y--; ci--;
            d[ci][x][y] = min(d[ci][x][y], di);
            d[ci][y][x] = min(d[ci][y][x], di);
        }
        rep(i, 0, c){
            cin >> p[i];
        }
        rep(i, 0, c){
            rep(j, 0, p[i] - 1) cin >> q[i][j];
            q[i][p[i] - 1] = 100000;
            rep(j, 0, p[i]) cin >> r[i][j];
        }
        rep(i, 0, c){
            int idx = 0;
            costTable[i][0] = 0;
            rep(j, 1, 100010){
                costTable[i][j] = costTable[i][j - 1] + r[i][idx];
                // if(j <= 10) cout << i << ' ' << j << ' ' << costTable[i][j] << endl;
                if(j == q[i][idx]) idx++;
            }
        }
        rep(l, 0, c){
            rep(k, 0, n){
                rep(i, 0, n){
                    rep(j, 0, n){
                        d[l][i][j] = min(d[l][i][j], d[l][i][k] + d[l][k][j]);
                    }
                }
            }
        }
        rep(i, 0, n){
            rep(j, 0, n){
                rep(k, 0, c){
                    if(d[k][i][j] >= 100010) continue;
                    int tmp = costTable[k][d[k][i][j]];
                    d[c][i][j] = min(d[c][i][j], tmp);
                }
                // cout << i << ' ' << j << ' ' << d[c][i][j] << endl;
            }
        }
        rep(k, 0, n){
            rep(i, 0, n){
                rep(j, 0, n){
                    d[c][i][j] = min(d[c][i][j], d[c][i][k] + d[c][k][j]);
                }
            }
        }
        if(d[c][s][g] >= INF) cout << -1 << endl;
        else cout << d[c][s][g] << endl;
    }
}


Measured memory_bytes: 20612
/*****TEMPLATE*****/
      

#include <algorithm>
#include <array>
#include <bitset>
#include <cctype> 
#include <chrono>
#include <climits>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cstring>
#include <cstdio>
#include <stdio.h>
//INCLUDES
using namespace std;

#define lld long long int
#define ulld unsigned long long int
#define mod 1000000007
#define pb push_back
#define umap unordered_map
#define mp make_pair
#define fi first
#define se second 
#define rep(n) for(int i=0;i<n;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//DEFINES

lld gcd(lld a,lld b){ if(a<b) { a=a+b; b=a-b; a=a-b;}while(b!=0){lld r=a%b; a=b; b=r;} return a;}
lld bs(lld arr[], lld l, lld r, lld x) { if (r >= l) {  lld mid = l + (r - l) / 2;  if (arr[mid] == x)  return mid; if (arr[mid] > x)  return bs(arr, l, mid - 1, x);  return bs(arr, mid + 1, r, x);  }  return -1; }
lld mypower(lld x, lld n){	if (n == 0)	return 1;	if (n & 1) 	return (((x * mypower(x, n / 2))%mod) * (mypower(x, n / 2)%mod)%mod);return (((mypower(x, n / 2))%mod) * (mypower(x, n / 2)%mod))%mod;}
lld modinv(lld a) { lld g = gcd(a, mod); if (g != 1) return -1;else{  return mypower(a, mod-2)%mod; } } 

//FUNCTIONS
void solve()
{
    lld n;
    cin>>n;
    double a[n+1];
    for (int i = 1; i <=n; i++) {
        cin>>a[i];
    }
    
    double dp[n+1][n+1]={};
    dp[1][1]=a[1];
    dp[1][0]=(1.0-a[1]);
    for (int i = 2; i <=n; i++) 
    {
        for( int j =0; j<=i;j++)
        {
            if(j==0)
            dp[i][j]=(1.0-a[i])*dp[i-1][j];
            else
            dp[i][j]=(1.0-a[i])*dp[i-1][j]+a[i]*dp[i-1][j-1];
        }
    }
    double ans=0.0;
    for (int i = (n+1)/2; i <=n; i++) {
        ans+=dp[n][i];
    }
    cout<<fixed<<setprecision(10);
    cout<<ans;
    return;
}
int main() 
{
    fast
    solve();
    return 0;
}



Measured memory_bytes: 74080
<?php
$xy = explode(" ", trim(fgets(STDIN)));
$x1 = $xy[0];
$y1 = $xy[1];
$x2 = $xy[2];
$y2 = $xy[3];
$disx = $x2 - $x1;
$disy = $y2 - $y1;

$x3 = $x2 - $disy;
$y3 = $y2 + $disx;
$x4 = $x3 - $disx;
$y4 = $y3 - $disy;

printf("%d %d %d %d", $x3, $y3, $x4, $y4);
?>

Measured memory_bytes: 3576
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

// #define DEBUG_MODE
#ifdef DEBUG_MODE
#define dump(x) cout << #x << " : " << x << endl
#define LINE cout << "line : " << __LINE__ << endl
#define dumpV(v) cout << #v << " : ["; for(auto& t : v) cout << t << ", "; cout<<"]" << endl;
#define STOP assert(false);
#else
#define dump(x) ;
#define LINE 	;
#define dumpV(v);
#define STOP 	;
#endif

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fi<<", "<<a.se<<')';
    return out;
  }
}


int f(string s, char c) {
	int ret = 0LL;
	auto check = [&] {
		rep(i, s.size()) if(s[i] != c) return false;
		return true;
	};
	while(1) {
		if(check() || s.size() == 1) return ret;
		ret++;
		string t;
		rep(i, s.size()-1) {
			if(s[i+1] == c) t += s[i+1];
			else t += s[i];
		}
		dump(t.size());
		s = t;
	}
	return -1;
}

int main(){
	string s;
	cin >> s;
	int ans = 1e9;
	REP(c, 'a', 'z'+1) ans = min(ans, f(s, c));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
const int N = 55;
typedef long long ll;
const ll INF = 1e18; 
using namespace std;

int n;
ll a[N], ans = INF; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int lowbit(int x) { return x & (-x); }

bool check(ll k)
{
	ll res = 0; 
	for(int i = 1; i <= n; i++)
		res += (k + a[i] + 1) / (n + 1); 
	return res <= k; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	n = read <int> ();
	for(int i = 1; i <= n; i++) a[i] = read <ll> ();
	if(check(0)) { puts("0"); return 0; }
	for(int x = 0; x <= n; x++)
	{
		ll l = 0, r = (50ll * 10000000000000000 - x) / n, mid, tmp = 0; 
		while(l <= r)
		{
			mid = (l + r) >> 1; 
			if(check(mid * n + x)) tmp = mid, r = mid - 1; 
			else l = mid + 1; 
		}
		ans = min(ans, tmp * n + x); 
	}
	printf("%lld\n", ans); 
	return 0; 
}


Measured memory_bytes: 3768
#include <iostream>
#include <functional>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
	int n,a[100];
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	sort(a,a+n, greater<int>());
	int sum[2];
	sum[0] = 0;
	sum[1] = 0;
	for (int i = 0;i < n;i++) {
		sum[i % 2] += a[i];
	}
	cout << sum[0] - sum[1];
	return 0;
}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
# list(map(int, input().split()))

V, E, r = map(int, input().split())

adj = [[] for _ in range(V)]
for i in range(E):
    s, t, d = map(int, input().split())
    adj[s].append((d, t))

n = V
import heapq

INF = float("INF")
dist = [INF for _ in range(n)]
visited = [False for _ in range(n)] 

q = [(0, r)]
dist[r] = 0
path = [0 for _ in range(n)]
def dijkstra():
    while len(q) > 0:
        v = heapq.heappop(q)
        a = v[1]
        if visited[a]:
            continue
        visited[a] = True
        for u in adj[a]:
            w = u[0]
            b = u[1]
            if dist[a] + w < dist[b]: 
                dist[b] = dist[a] + w
                heapq.heappush(q, (dist[b], b))

dijkstra()
for i in range(V):
    if dist[i] == float("inf"):
        print("INF")
    else:
        print(dist[i])


Measured memory_bytes: 91216
{-# LANGUAGE FlexibleContexts #-}

import Control.Monad
import Data.List

main = sol <$> get <*> get >>= print

get = map read . words <$> getLine

sol [n,t] (a:as)
  | max n t<3 = 1
  | otherwise = length $ elemIndices (maximum ds) ds
  where
  ds = map (uncurry subtract) . filter ((>0) . snd) . uncurry (:)
    $ foldl' f ((a,0),[]) as

f ((l,r),d) a
  | a<l && r==0 = ((a,r),d)
  | a<l         = ((a,0),(l,r):d)
  | a>r         = ((l,a),d)
  | otherwise   = ((l,r),d)


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

long long gcm(long long a, long long b){
    if(a > b) return gcm(b,a);
    if(b%a  == 0) return a;
    return gcm(b%a, a);
}

int main()
{
    int n, x;
    cin >> n >> x;
    vector<long long> v;
    v.push_back(x);
    for(int i=0; i<n; i++){
        long long a;
        cin >> a;
        v.push_back(a);
    }
    sort(v.begin(), v.end());
    
    long long ans = 1e15;
    for(int i=0; i<v.size()-1; i++){
        if(i == 0){ 
            ans = v[i+1] - v[i];
        }else{
            // cout << i << ", "<< ans << endl;
            ans = gcm(ans, v[i+1] - v[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
import sys
input = sys.stdin.readline

def sumN(n,N,f):
	total = 0
	i = n
	while i < N:
		total += f[i]
		i += n+1

	if total % 2:
		return 1
	else:
		return 0

def main():
	N = int(input())
	a = list(map(int,input().split()))
	ball = []
	ballNum = 0
	f = [0]*N

	for i in reversed(range(1,N)):
		if sumN(i,N,f) != (a[i] % 2):
			f[i] = 1
			ball.append(i+1)
			ballNum +=1

	if (sum(f) % 2) != (a[0] % 2):
		f[0] = 1
		ball.append(1)
		ballNum +=1

	print(ballNum)
	print(*ball)

if __name__ == "__main__":
	main()


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

using namespace std;

int n;

int main() {
	cin >> n;
	vector<int> dp(3);
	for (int i = 0; i < n; i++) {
		vector<int> new_dp(3), c(3);
		for (int j = 0; j < 3; j++) cin >> c[j];
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (j != k) new_dp[k] = max(new_dp[k], dp[j] + c[k]);
			}
		}
		dp = new_dp;
	}
	cout << max({dp[0], dp[1], dp[2]}) << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a=0, b=101, x=0;
  int c=0;
  cin >> a >> b;
  if(a<1||100<b) cout << "入力エラー(制約 : 1≦a, b≦100)" << endl;
  else{
    c = (a+b)%2;
    x = (a+b)/2;
    if(0<c) x = x+1;
    cout << x << endl;
  }
}


Measured memory_bytes: 3632
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  sequence_ . map (putStrLn . map toLEL) . f n $ 0

f :: Int -> Int -> [[Int]]
f 0 _ = [[]]
f l m = [0..m] >>= map <$> (:) <*> f (pred l) . max m . succ

toLEL :: Int -> Char
toLEL = toEnum . (fromEnum 'a' +)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 3708
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int t = sc.nextInt();
        int a = sc.nextInt();
        Double[] h = new Double[n];
        int x = 0;
        for(int i = 0 ; i < n ; i++ ){
            h[i] = sc.nextDouble();
            h[i] = Math.abs(a - t + h[i] * 0.006);
            if(h[x] > h[i]){
                x = i;
            }
        }
        System.out.println(x + 1);
        sc.close();
    }
}

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


int main() {
	int n;
	cin >> n;
	int D[10000][2];
	bool ok =0;
	for(int i =0;i<n;i++) {
		for(int j =0;j<2;j++) {
			cin >> D[i][j];
		}
		if(i >= 2 && D[i][0] == D[i][1]) {
			if(D[i-2][0] == D[i-2][1] && D[i-1][0] == D[i-1][1]) ok =1;
		}
	}
	cout << ((ok) ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 3648
let rec s = function
  | 0 -> 0
  | n -> n mod 10 + s (n / 10)

let p x y = x * s y <= y * s x

let bases = Array.to_list @@ Array.init 16 (fun d -> int_of_float (10. ** float_of_int d))

let solutions =
  Array.init 1000 (fun i ->
    List.filter (fun r ->
      p ((i + 1) * r - 1) ((i - i mod 10 + 10) * r - 1) &&
      p ((i + 1) * r - 1) ((i - i mod 100 + 100) * r - 1) &&
      p ((i + 1) * r - 1) ((i - i mod 1000 + 1000) * r - 1)) bases
    |> List.map (fun r -> (i + 1) * r - 1))
  |> Array.to_list
  |> List.concat
  |> List.sort_uniq compare
  |> List.tl
  |> Array.of_list

let () = Scanf.scanf "%d" @@ fun k ->
  for i = 1 to k do
    Printf.printf "%d\n" solutions.(i - 1)
  done


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

class Program
{
    static void Main(string[] args)
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private string A = Console.ReadLine();
    public void Solve()
    {
        long[]count = new long[256];
        foreach(char c in A)
        {
            count[c]++;
        }
        long length = A.Length;
        long anser = (length-1)*(length)/2+1;
        foreach(long i in count)
        {
            anser-=(i-1)*(i)/2;
        }
        Console.WriteLine(anser);
    }
}

Measured memory_bytes: 11744
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int main() {
    string s;
    stack<int> st;

    while (cin >> s) {
        if (s == "+") {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a + b);
        } else if (s == "-") {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(b - a);
        } else if (s == "*") {
            int a = st.top();
            st.pop();
            int b = st.top();
            st.pop();
            st.push(a * b);
        } else {
            // ?????????????????°????????????
            st.push(stoi(s));
        }
    }
    cout << st.top() << endl;

    return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define mod 1000000007
#define mem(a,val) memset(a,val,sizeof(a))

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	int *arr = new int[n];
	int sum = 0;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		sum+=arr[i];
	}
	sort(arr,arr+n,std::greater<int>());
	if(arr[m-1]*4*m >= sum){
		cout<<"Yes";
	}	
	else{
		cout<<"No";
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        //入力
        Scanner scn=new Scanner(System.in);
        int sound=scn.nextInt();
        int hand=scn.nextInt();
        int fin=scn.nextInt();
        int answer=0;
        //処理
       if(hand/sound>=fin){
           answer = fin;
       }else{
           answer = hand/sound;
       }
       //出力
       System.out.println(answer);
    }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>a(n);
    map<int,int>mp;
    rep(i,n){
        cin>>a[i];
        mp[a[i]]++;
    }
    int ans=0;
    for(auto& p:mp){
        int x=p.second;
        if(x%2==1)ans++;
    }
    cout<<ans<<endl;
}

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

int main(){
	int K;
	string S;
	cin >> K >>  S;
	int n = S.length();
	if (n<=K) cout<< S << endl;
	else{
		for(int i=0;i<K;i++){
			cout << S[i];
		}
		cout << "..." << endl;
	} 
}



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

int main() {
  string s; cin  >> s;
  int cnt = 0;
  int n = (int)s.size();
  char prv = s[0];
  for (int i = 1; i < n; i++) {
    if (s[i] != prv) {
      cnt++;
      prv = s[i];
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  long long a[100001], broken[100001] = {0}, dp[100001];
  for (int i = 0; i < m; i++) cin >> a[i];
  for (int i = 0; i < m; i++) broken[a[i]] = 1;
  dp[0] = 1;
  if (!broken[1]) dp[1] = 1;
  for (int i = 2; i <= n; i++) {
    dp[i] = dp[i-2] * (1-broken[i-2]) + dp[i-1] * (1-broken[i-1]);
    dp[i] %= 1000000007;
  }
  cout << dp[n];
  return 0;
}

Measured memory_bytes: 5864
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,D,X;
    cin >> N >> D >> X;
    vector<int> days(N);
    int count=0;
    for(int i=0;i<N;i++){
        cin >> days.at(i);
        if(days.at(i)>D){
        	count++;
        }else if(D%days.at(i)!=0){
        	count+=D/days.at(i)+1;
        }else{
        	count+=D/days.at(i);
        }
    }
    cout << count+X << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF = float("inf")
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    S = input()
    T = input()
    m = len(S)
    n = len(T)
    dp = [[-INF] * (n + 1) for _ in range(m + 1)]
    prev = [[(-1, -1)] * (n + 1) for _ in range(m + 1)]

    for i in range(m):
        dp[i][0] = 0
    for j in range(n):
        dp[0][j] = 0

    for i in range(m):
        for j in range(n):
            if S[i] == T[j]:
                if dp[i + 1][j + 1] < dp[i][j] + 1:
                    dp[i + 1][j + 1] = dp[i][j] + 1
                    prev[i + 1][j + 1] = (i, j)
            else:
                if dp[i + 1][j + 1] < dp[i + 1][j]:
                    dp[i + 1][j + 1] = dp[i + 1][j]
                    prev[i + 1][j + 1] = (i + 1, j)
                if dp[i + 1][j + 1] < dp[i][j + 1]:
                    dp[i + 1][j + 1] = dp[i][j + 1]
                    prev[i + 1][j + 1] = (i, j + 1)

    i, j = m, n
    res = []
    cnt = 0
    while 1:
        pi, pj = prev[i][j]
        if (pi, pj) == (-1, -1):
            break
        if i - pi == 1 and j - pj == 1:
            res.append(S[pi])
        i, j = pi, pj

    print(''.join(reversed(res)))
resolve()

Measured memory_bytes: 641276
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
#define endl "\n"
using namespace std;

//constexpr int inf = 2147483647;
//constexpr int64_t inf64 = 9223372036854775807;
//constexpr int mod = 1e9+7;
const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy[8] = {-1, 1, 0, -1, 1, -1, 0, 1};

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

  int h, w;
  cin >> h >> w;

  vector<string> grid(h);
  rep(i,h) cin >> grid[i];

  rep(i,h) {
    rep(j,w) {
      if (grid[i][j] == '#') continue;

      int cnt = 0;
      rep(dir, 8) {
        int nh = i + dy[dir];
        int nw = j + dx[dir];

        if(nh < 0) continue;
        if(nw < 0) continue;
        if(nh >= h) continue;
        if(nw >= w) continue;

        if(grid[nh][nw] == '#') cnt++;
      }
      grid[i][j] = (char)(cnt+'0');
    }
  }

  rep(i,h) cout << grid[i] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX_N 30
#define NIL -1
 
typedef struct node_ {
    int parent;
    int left;
    int right;
} Node;
 
Node T[MAX_N];
 
void preorder(int u) {
    if (u == NIL) return;
 
    printf(" %d", u);
    preorder(T[u].left);
    preorder(T[u].right);
}
 
void inorder(int u) {
    if (u == NIL) return;
 
    inorder(T[u].left);
    printf(" %d", u);
    inorder(T[u].right);
}
 
void postorder(int u) {
    if (u == NIL) return;
 
    postorder(T[u].left);
    postorder(T[u].right);
    printf(" %d", u);
}
 
int main(void) {
    int i, n;
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        T[i].parent = NIL;
        T[i].left = NIL;
        T[i].right = NIL;
    }
 
    for (i = 0; i < n; i++) {
        int id, left, right;
        scanf("%d %d %d", &id, &left, &right);
        T[id].left = left;
        T[id].right = right;
        if (left != NIL) T[left].parent = id;
        if (right != NIL) T[right].parent = id;
    }
 
    int r;
    for (i = 0; i < n; i++) {
        if (T[i].parent == NIL) r = i;
    }
 
    puts("Preorder");
    preorder(r); putchar('\n');
    puts("Inorder");
    inorder(r); putchar('\n');
    puts("Postorder");
    postorder(r); putchar('\n');
 
    return 0;
}

Measured memory_bytes: 616
def main():    
    S = raw_input()

    A = ["R", "U", "D"]
    B = ["L", "U", "D"]

    for i,c in enumerate(S):
        if i%2 ==0:
            if c in A:
                continue
        else:
            if c in B:
                continue
            
        print "No"
        return
    
    print "Yes"

main()

Measured memory_bytes: 27884
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()
alphabets = string.ascii_lowercase

N = int(input())
ans = [["a", 0]]
for i in range(1, N):
    ans2 = copy.deepcopy(ans)
    ans = []
    for l in ans2:
        for k in range(int(l[1]) + 2):
            ans.append([l[0] + alphabets[k], max(l[1], k)])
for i in ans:
    print(i[0])





Measured memory_bytes: 29936
#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 H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> c(H, vector<char>(W));
    rep(i,H) {
        rep(j,W) {
            cin >> c.at(i).at(j);
        }
    }
    int ans = 0;
    for (int bit = 0; bit < (1<<H+W); bit++) {
        int black = 0;
        rep(i,H) {
            rep(j,W) {
                if (c.at(i).at(j) == '#') {
                    if ((bit & (1<<i)) == 0 && (bit & (1<<H+j)) == 0) {
                        ++black;
                    }
                }
            }
        }
        if (black == K) ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const ll N = 1e5+9;

ll n;
ll a[N];
ll b[N];

int main() {
    cin >> n;
    for(int i = 1; i <= n+1; i++)  cin >> a[i];
    for(int i = 1; i <= n; i++)  cin >> b[i];

    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ll d1 = min(a[i], b[i]);
        a[i] -= d1;
        b[i] -= d1;
        ans += d1;

        ll d2 = min(a[i+1], b[i]);
        a[i+1] -= d2;
        b[i] -= d2;
        ans += d2;
    }

    cout << ans << endl;
}

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

int main(){
	while(1){
		int n;
		double ave = 0.0;
		double sum = 0.0;
		cin >> n;
		vector<int> data(n);
		if(n == 0) break;
		for(auto &a:data){
			cin >> a;
		}
		for(auto a:data){
			ave += a;
		}
		ave /= n;
		for(auto a:data){
			sum += (ave - a) * (ave - a);
		}
		printf("%.10lf\n",sqrt(sum/n));
	}
	return 0;
}	

Measured memory_bytes: 3204
#include <stdio.h>
#include <stdlib.h>

typedef struct{
    char c;
    int n;
}Card;

void merge(Card a[],int left,int mid,int right){
    int n1,n2,i,j,k;
    Card *l,*r;
    n1 = mid-left; n2 = right-mid;
    l = (Card*)malloc(sizeof(Card)*(n1+1));
    r = (Card*)malloc(sizeof(Card)*(n2+1));
    for(i=0;i<n1;i++){
        l[i].n =a[i+left].n;
        l[i].c =a[i+left].c;
    }
    for(i=0;i<n2;i++){
        r[i].n =a[i+mid].n;
        r[i].c =a[i+mid].c;
    }
    l[n1].n=1000000001;r[n2].n=1000000001;
    i=0;j=0;
    for(k=left;k<right;k++){
        if(l[i].n<=r[j].n){
            a[k].n = l[i].n;
            a[k].c = l[i].c;
            i++;
        }else{
        	a[k].n = r[j].n;
            a[k].c = r[j].c;
            j++;
        }
    }
    free(l);
    free(r);
}

void mergesort(Card a[],int left,int right){
    int mid;
    if(left+1<right){
        mid = (left+right)/2;
        mergesort(a,left,mid);
        mergesort(a,mid,right);
        merge(a,left,mid,right);
    }
}

void chenge(Card a[],int i,int j){
    int n; char c;
    n = a[i].n; c = a[i].c;
    a[i].n = a[j].n; a[i].c = a[j].c;
    a[j].n = n; a[j].c = c;
}

int pertition(Card a[],int left,int right){
    int i,j,k;
    k=left-1;
    for(i=left;i<right-1;i++){
        if(a[i].n<=a[right-1].n){
            k++;
            chenge(a,i,k);
        }
    }
    chenge(a,k+1,right-1);
    return k+1;
}

void quicksort(Card a[],int left,int right){
    int mid;
    if(left+1<right){
        mid = pertition(a,left,right);
        quicksort(a,left,mid);
        quicksort(a,mid+1,right);
    }
}

int main(void){
    int n,i,flg;
    char aaaa;
    Card *c1;
    Card *c2;
    scanf("%d",&n);
    c1 = (Card*)malloc(sizeof(Card)*n);
    c2 = (Card*)malloc(sizeof(Card)*n);
    for(i=0;i<n;i++){
        c1[i].c = '\0';
    	while(!('A'<=c1[i].c&&c1[i].c<='Z')){
    		scanf("%c",&c1[i].c);
    	}
        scanf("%d",&c1[i].n);
        c2[i].c = c1[i].c; c2[i].n = c1[i].n;
    }
    quicksort(c1,0,n);
    mergesort(c2,0,n);
    flg = 0;
    for(i=0;i<n;i++){
        if(c1[i].c!=c2[i].c){
            flg = 1;
            break;
        }
    }
    if(flg==0){
        printf("Stable\n");
    }else{
        printf("Not stable\n");
    }
    for(i=0;i<n;i++){
        printf("%c %d\n",c1[i].c,c1[i].n);
    }
    
    free(c1);
    free(c2);
    return 0;
}


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

int main() {
	int n;
	string s, t;
	cin >> n >> s >> t;
	int same = 0;
	for (int i = 0; i < n; i++)
	{
		if(s.substr(i) == t.substr(0, n - i)) {
			same = n - i;
			break;
		}
	}
	cout << 2 * n - same << endl;
	return 0;
}


Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);

		int N = scanner.nextInt();


		double number = 0;
		for (int i = 0; i < N; i++) {
			double A = scanner.nextDouble();
			number = number + ( 1 / A);
		}

		log(1 / number);

	}

	private static void log(String str) {
		System.out.println(str);
	}

	private static void log(int str) {
		System.out.println(str);
	}

	private static void log(double str) {
		System.out.println(str);
	}

}

Measured memory_bytes: 23124
p = []
while True:
    s = input()
    if s == "0,0":
        break
    p.append([int(i) for i in s.split(",")])

p.sort(key = lambda x : x[1], reverse = True)

while True:
    try:
        n = int(input())
    except:
        break
    ans = 1
    for i in range(len(p)):
        if i != 0 and p[i][1] != p[i - 1][1]:
            ans += 1
        if p[i][0] == n:
            print(ans)
            break

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

#define int long long
#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 rap(i,a,n) for (int i = a; i < (n); i++) 
#define rrap(i,n,a) for (int i = (n)-1; i >= a; i--) 
#define LL_MAX 9223372036854775807

typedef vector<int> vi;  
typedef pair<int,int> ii;  
typedef vector<ii> vii;  
typedef list<int> li;  
typedef unordered_map<int,int> mii;

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

    int n,a, count=1, broken=0;
    cin >> n;
    rep(i,n) {
        cin >> a;
        if (a != count) broken++;
        else count++;
    }
    if (broken > 0 && count > 1) cout << broken << '\n';
    else if (count > 1) cout << 0 << '\n';
    else cout << -1 << '\n';

    return 0;
    //compile: g++ -std=c++14 -O2 -Wall NAME.cpp -o NAME
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    int[][] A;
    long[] memo;
    int N;
    long calc(int v, int F)
    {
        if (memo[F] >= 0)
        {
            return memo[F];
        }


        if (v == N - 1)
        {
            for (int i = 0; i < N; i++)
            {
                if ((F >> i & 1) == 0)
                {
                    return memo[F] = A[v][i];
                }
            }
        }

        var ret = 0L;
        for (int i = 0; i < N; i++)
        {
            if ((F >> i & 1) == 0)
            {
                ret += A[v][i] * calc(v + 1, F | 1 << i);
                ret %= mod;
            }

        }

        return memo[F] = ret;

    }
    void solve()
    {
        N = cin.nextint;
        A = Enumerable.Range(0, N).Select(i => cin.scanint).ToArray();
        memo = Enumerable.Repeat(-1L, 1 << N).ToArray();
        WriteLine(calc(0, 0));
    }

}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
    public void join<T>(IEnumerable<T> values) { WriteLine(string.Join(" ", values)); }
}

Measured memory_bytes: 41900
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

template <typename T>
vector<T> divisor(T x) {
	vector<T> ret;
	for (T i = 1; i * i <= x; ++i) {
		if (x % i == 0) {
			ret.push_back(i);
			if (i * i != x) { ret.push_back(x / i); }
		}
	}
	sort(ret.rbegin(), ret.rend());
	return ret;
}

int main() {
	Int N, K;
	cin >> N >> K;
	vector<Int> A(N);
	for (int i = 0; i < N; ++i) { cin >> A[i]; }

	vector<Int> v = divisor(accumulate(A.begin(), A.end(), (Int)0));
	for (auto x : v) {
		vector<Int> a(N);
		for (int i = 0; i < N; ++i) { a[i] = A[i] % x; }
		Int sum = accumulate(a.begin(), a.end(), (Int)0);
		Int wl = min(N, N - sum / x);
		if ((sum % x != 0) || (wl < 0)) { continue; }

		sort(a.begin(), a.end());
		Int k = 0;
		for (int i = 0; i < wl; ++i) { k += a[i]; }

		if (k <= K) {
			cout << x << endl;
			return 0;
		}
	}
	cout << 1 << endl;

	return 0;
}


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

using namespace std;
long long a[100005];
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main(){
	int n;
	scanf("%d",&n);
	long long ans=0;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(a[i]==0)ans=a[i];
		else ans=gcd(ans,a[i]);
	} 
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define endl '\n'
#define ll long long
#define mod 1000000007
#define inf 1000000000000000000
bool func(pair<ll,ll> a,pair<ll,ll> b)
{
	return a.second<b.second;
}
int main()
{
	fastio;
	#ifdef APNA_IO
		freopen("input.txt" , "rt" ,stdin);
		freopen("output.txt" , "wt" ,stdout);
	#endif
	ll n,a,b,i;
	cin>>n;
	pair<ll,ll> arr[n];
	for(i=0;i<n;i++)
	{
		cin>>a>>b;
		arr[i].first=a;
		arr[i].second=b;
	}
	sort(arr,arr+n,func);
	for(i=1;i<n;i++)
	{
		arr[i].first=arr[i].first+arr[i-1].first;
	}
	bool x=true;
	for(i=0;i<n;i++)
	{
		if(arr[i].first>arr[i].second)
			x=false;
	}
	if(x)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}





Measured memory_bytes: 3328
#include <stdio.h>

#define MAX 50000000

int parent(int i) {return i / 2;}
int left(int i) {return 2*i;}
int right(int i){return 2*i + 1;}
int H;
int A[MAX];

void maxHeap(int idx){
    int l = left(idx);
    int r = right(idx);
    int large;
    if(l <= H && A[idx] < A[l]){
        large = l;
    } else {
        large = idx;
    }

    if(r <= H && A[large] < A[r]){
        large = r;
    }

    if(large != idx){
        int tmp = A[idx];
        A[idx] = A[large];
        A[large] = tmp;
        maxHeap(large);
    }

}

void exec(){
    for(int i = H/2; i >= 1; i--) maxHeap(i);
}

int main(){
    int i;
    scanf("%d", &H);
    for(i = 1; i <= H; i++){
        scanf("%d", &A[i]);
    }

    exec();

    for(i = 1; i <= H; i++){
        printf(" %d", A[i]);
    }

    printf("\n");

    return 0;
}



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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i, m, n) for(int i = (int)m; i < (int)n; i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;

/*FUNCs=================================================*/



/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    int h,w,i,j; cin >>h>>w;
    vs s(h+2);
    rep(j,w+2) s[0][j] = '.';
    for(int i = 1; i <= h; i++){
        cin >> s[i];
        s[i].push_back('.');
        reverse(s[i].begin(), s[i].end());
        s[i].push_back('.');
        reverse(s[i].begin(), s[i].end());
    }
    rep(j,w+2) s[h+1][j] = '.';

    rep2(i,1,h+1){
        rep2(j,1,w+1){
            if(s[i][j] == '.'){
                int cnt = 0;
                for(int k=i-1; k<=i+1; k++){
                    for(int l=j-1; l<=j+1; l++){
                        if(s[k][l]=='#') cnt++;
                    }
                }
              	if(cnt==0) s[i][j] = '0';
                else s[i][j] = '0'+cnt;
            }
        }
    }  
    rep2(i, 1, h+1){
        rep2(j, 1, w+1){
            cout << s[i][j];
            if(j ==w) cout <<'\n';
        }
    }    
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int x, n;
	cin >> x >> n;
	vi p(n);
	map<int, int> vis;
	rep(i, n) cin >> p[i], vis[p[i]] = 1;
	int mn = 1e9, bst = -1;
	repn(i, -200, 200) if(!vis[i]){
		int cr = abs(i - x);
		if(cr < mn){
			mn = cr;
			bst = i;
		}
	}
	cout << bst << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <queue>
#include <deque>
#include <complex>
#include <cstdio>
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define REP(i,a) FOR(i,0,a)
#define X real() 
#define Y imag()
using namespace std;
typedef long long ll;
typedef int useType;
typedef pair<useType,useType> pr;
typedef vector<useType> VI;
const int INF=1<<30;
int DP[2][2][10002];
int main(){
	int n,p;
	cin >> n;
		REP(i,2)
			REP(j,10002){
				DP[0][i][j]=INF;
				DP[1][i][j]=INF;
			}

		DP[0][0][1]=0;
		DP[0][1][0]=0;
		REP(i,n-1){
			cin >> p;
			FOR(k,1,n+1)
				DP[(i+1)&1][0][k]=min(DP[i&1][0][k-1],DP[i&1][1][k-1]+p);
			REP(k,n+1)
				DP[(i+1)&1][1][k]=min(DP[i&1][0][k]+p,DP[i&1][1][k]);
		}
		cout << min(DP[(n-1)&1][0][n/2],DP[(n-1)&1][1][n/2]) << endl;
	return 0;
}

Measured memory_bytes: 1320
#include<stdio.h>
typedef long long int lli;
int main() {
  int n,ans;
  int i=1;
  scanf("%d", &n);
  while(1){
      if((1000*i)>=n){
          ans = (1000*i) - n;
          break;
      }
      else{
        i++;
      }
  }
  
  printf("%d\n", ans);

  return 0;
}



Measured memory_bytes: 1708
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Spreadsheet
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split(' ');

            int row = int.Parse(line[0]);
            int col = int.Parse(line[1]);

            List<int> data = new List<int>();

            for (int i = 0; i < row; i++)
            {
                string[] temp = Console.ReadLine().Split(' ');
                foreach (string item in temp)
                {
                    data.Add(int.Parse(item));
                }
            }

            List<int> rowTotal = new List<int>();

            for (int i = 0; i < col; i++)
            {
                int colSum = 0;
                for (int j = i; j < row * col; j += col)
                {
                    colSum += data[j];
                }
                data.Add(colSum);
            }

            for (int i = 0; i < (row+1) * col; i += col)
            {
                int rowSum = 0;
                for (int j = i; j < col + i; j++)
                {
                    rowSum += data[j];
                }
                rowTotal.Add(rowSum);
            }

            int count = 1;
            
            foreach (int item in rowTotal)
            {
                data.Insert(count * col + count -1, item);
                ++count;
            }

            int count2 = -1;
            foreach (int item in data)
            {
                count2++;
                Console.Write(item);

                if (count2 % (col + 1) == col)
                {
                    Console.WriteLine();
                }
                else
                {
                    Console.Write(" ");
                }
            }
        }
    }
}



Measured memory_bytes: 15992
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n;
	cin >> n;
	vector<ll> a(n), b(n);
	rep(i,n) cin >> a[i];
	rep(i,n) cin >> b[i];
	vector<ll> mns;
	vector<ll> pls;
	rep(i,n) {
		int x = a[i] - b[i];
		if (x < 0) mns.push_back(x);
		else if (x > 0) pls.push_back(x);
	}
	ll p = 0;
	rep(i,mns.size()) p += mns[i];
	sort(ALL(pls), greater<>());
	vector<ll> sum(pls.size()+1);
	rep(i,pls.size()) sum[i+1] = sum[i] + pls[i];
	p = abs(p);
	if (p > sum[pls.size()]) {
		cout << -1 << endl;
		return;
	}
	if (mns.size() == 0) {
		cout << 0 << endl;
		return;
	}
	int ans = mns.size() + upper_bound(ALL(sum), p) - sum.begin(); 
	cout << ans << endl;

}

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

Measured memory_bytes: 6184
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            int ans = 0;
            for (int i = 0; i < s.Length; i++)
            {
                int val = int.Parse(s[i]);
                while (0 ==(val % 2))
                {
                    ans++;
                    val /= 2;
                }
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13792