akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<queue>
#define PI 3.141592653589793238
#define INF -1
#define ll long long
using namespace std;

int main()
{
	int n, k;
	int tmp;
	double e;
	double* max;
	double height;
	cin >> n >> k;
	max = (double*)malloc(sizeof(double) * n);
	height = 0;
	//printf("E[6] = %f\n", kitai(6));


	for (int i = 0; i < n; i++) {
		cin >> tmp;
		e = (1.0 + (double)tmp) / 2.0;
		if (i == 0) {
			max[i] = e;
		} else {
			max[i] = e + max[i - 1];
		}
		
	}

	height = max[k - 1];

	for (int i = k; i < n; i++) {
		//printf("%f\n", max[i] - max[i - k]);
		if (height < max[i] - max[i - k]) {
			height = max[i] - max[i - k];
		}
	}

	printf("%9f", height);
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a,b;
int main(){
cin>>a>>b;
if(a>0)cout<<"Positive";
else if(a==0||(a<0&&b>0)) cout<<"Zero";
else if((abs(b)-abs(a))%2!=0) cout<<"Positive";
else cout<<"Negative";}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

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

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

const int MAX = 2e5+5;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    COMinit();
    ll N,M,K;
    cin >> N >> M >> K;
    ll sum = 0;
    for(int i=0;i<=N-1;i++){
        for(int j=0;j<=M-1;j++){
            ll tmp = (N-i) * (M-j) * (i+j);
            if(i!=0 && j!=0)tmp *= 2;
            (sum += tmp)%=mod;
        }
    }
    cout << (sum%mod * COM(N*M-2,K-2)%mod)%mod << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 5e5 + 10;

int bit[N], prv[N], n;

void update(int idx, int val) {
	while(idx <= n) {
		bit[idx] += val;
		idx += idx & -idx;
	}
}

int pref(int idx) {
	int ans = 0;
	while(idx > 0) {
		ans += bit[idx];
		idx -= idx & -idx;
	}
	return ans;
}

int rsum(int l, int r) {
	return pref(r) - pref(l - 1);
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int q;
	cin >> n >> q;
	int c[n + 1];
	for(int i = 1; i <= n; i++) {
		cin >> c[i];
	}
	vector<pair<pii, int>> v;
	for(int i = 0; i < q; i++) {
		int l, r;
		cin >> l >> r;
		v.pb({{r, l}, i});
	}
	sort(all(v));
	int ans[q], j = 0;
	for(int i = 1; i <= n; i++) {
		if(!prv[c[i]]) {
			prv[c[i]] = i;
			update(i, 1);
		}
		else {
			update(prv[c[i]], -1);
			update(i, 1);
			prv[c[i]] = i;
		}
		while(j < q && v[j].fi.fi == i) {
			ans[v[j].se] = rsum(v[j].fi.se, v[j].fi.fi);
			j++;
		}
	}
	for(int i = 0; i < q; i++) {
		cout << ans[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 31232
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int d, n;
  cin >> d >> n;

  int ans = n;
  if (n == 100) ans++;
  rep(i, d) ans *= 100;
  cout << ans << endl;




  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
        int N, ans = 0, i;
        int l[1000], r[1000];

        scanf("%d", &N);
        getchar();
        for(i = 0; i < N; i++) {
                scanf("%d %d", &l[i], &r[i]);
                getchar();
        }
        for(i = 0; i < N; i++) {
                ans += r[i] - l[i] + 1;
        }
        printf("%d", ans);

        return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include<numeric>
using namespace std;
using P = pair<int, int>;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;


int main(){
    int a[3][3]={};
    rep(i,3) {
        rep(j,3){
            cin >> a[i][j];
        }
    }
    int n; cin >> n;
    vector<int> b(n);
    rep(i,n) cin >> b[i];
    bool check[4][4] = {false};
    rep(i,3){
        rep(j,3){
            rep(k,n){
                if(a[i][j]==b[k]){
                    check[i][j] = true;
                }
            }
        }
    }

    int column=false;
    rep(i,3){
        if(check[0][i] && check[1][i] && check[2][i]) column=true;
    }
    int row=false;
    rep(i,3){
        if(check[i][0] && check[i][1] && check[i][2]) row=true;
    }
    bool naname = false;
    if(check[0][0] && check[1][1] && check[2][2]) naname=true;
    if(check[0][2] && check[1][1] && check[0][2]) naname=true;

    if(row || column || naname) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll fun(ll ele,vector<ll>income[],ll dist[])
{ ll i;
  if(dist[ele]!=0)
    return dist[ele];
  if(income[ele].size()==0)
    return 0;
  else 
  {
    for(i=0;i<income[ele].size();i++)
      dist[ele]=max(dist[ele],fun(income[ele][i],income,dist)+1);
  }
  return dist[ele];
}
int main()
{
  ll n,m,i;
  cin>>n>>m;
  vector<ll>income[n+1];
  vector<ll>outgo[n+1];
  ll a,b;
  while(m--)
  {
	cin>>a>>b;
    income[b].push_back(a);
    outgo[a].push_back(b);
  }
  ll dist[1000001]={0};
  ll ans=0;
  for(i=1;i<=n;i++)
  {
    if(outgo[i].size()==0)
    {
      dist[i]=max(dist[i],fun(i,income,dist));
      ans=max(ans,dist[i]);
    }
  }
  cout<<ans<<endl;
  
  
}
  


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

using namespace std;

int main(){
	int a,b,d,r;
	cin>>a>>b;
	r=1;
	if(a<b){
		swap(a,b);
	}
	while (r!=0){
	r= a % b;
	d= a / b;
	a=b;
	b=r;
	}
	cout<<a<<endl;
} 


Measured memory_bytes: 3092
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	r,c,k=MI()
	G=[[0]*(c+1) for _ in range(r+1)]
	dp=[[0]*(c+1) for j in range(4)]
	for _ in range(k):
		rrr,ccc,v=MI()
		G[rrr][ccc]=v
	#print(G)

	#print(dp)

	for rr in range(1,r+1):
		for cc in range(1,c+1):
			if G[rr][cc]==0:
				for i in range(4):
					dp[i][cc]=max(dp[i][cc-1],dp[3][cc])
			else:
				dp[0][cc]=max(dp[3][cc],dp[0][cc-1])
				dp[1][cc]=max(dp[0][cc]+G[rr][cc],dp[1][cc-1])
				dp[2][cc]=max(dp[1][cc-1]+G[rr][cc],dp[2][cc-1],dp[1][cc])
				dp[3][cc]=max(dp[2][cc-1]+G[rr][cc],dp[3][cc-1],dp[2][cc])
	#print(dp)
	print(dp[-1][-1])















if __name__ == "__main__":
	main()


Measured memory_bytes: 145536
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int N, Even = 0;
    cin >> N;
    for (int i = 0; i < N; i++){
        int a;
        cin >> a;
        if (a % 2 == 0){
            Even++;
        }
    }
    cout << int(pow(3, N)) - int(pow(2, Even)) << endl;

}




Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;

const int MAX_N = (int)1e5 + 5;
lint A[MAX_N];

int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr);
    int N; cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];

    lint ans = 0, cur = 0;
    for(int i=0;i<N;i++){
        if(A[i]<=cur+1) cur = max(cur, A[i]);
        else{
            ans += (A[i]-1) / (cur+1);
            cur = max(cur, 1LL);
        }
    }
    cout << ans << endl;
    return 0;
}

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


int main() {
	
	int x1, x2, x3, x4, y1, y2, y3, y4;
	cin >> x1 >> y1 >> x2 >> y2;
	cout << x2-(y2-y1) << ' ' << y2+(x2-x1) << ' ';
	cout << x1-(y2-y1) << ' ' << y1+(x2-x1) << endl; 
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>

using namespace std;

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)

ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;
int const N_MAX = 1e5;

// nCr
ll po[POW_MAX + 2];
ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
ll mod_inv (ll x) {
  return mod_pow(x, MOD - 2) % MOD;
}
ll comb(int n, int r) {
  if (!po[n]) {
    po[0] = 1;
    FOR(i, 1, n + 1) po[i] = po[i - 1] * i % MOD;
  }
  return (((po[n] * mod_inv(po[r])) % MOD) * mod_inv(po[n - r])) % MOD;
}
// greatest common divisor
ll gcd(ll a, ll b) {
  while (a % b != 0) {
    ll tmp = a;
    a = b;
    b = tmp % b;
  }
  return b;
}

int N, K;
int len[101][101];
vector<P> p;
vector<P> edges;

int main() {
  scanf("%d %d", &N, &K);

  int s = 0;
  for (int i = 1; i < N - 1; i++) s += i;
  if (K > s) {
    printf("%d\n", -1);
    return 0;
  }
  rep(i, N - 1) edges.push_back(P(1, i + 2));

  int idx = 0;
  int ts = N - 2;
  while (s > K) {
    int st = edges[idx].second;
    rep(j, ts) {
      edges.push_back(P(st, st + j + 1));
      s--;
      if (s == K) break;
    }
    idx++;
    ts--;
  }
  printf("%ld\n", edges.size());
  for (P p : edges) {
    printf("%d %d\n", p.first, p.second);
  }
}


Measured memory_bytes: 384
N, X = map(int, input().split())
a,p = [1],[1]
for i in range(N):
    a.append(a[i] *2 +3)
    p.append(p[i] *2 +1)
def f(N,X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N-1]:
        return f(N-1,X-1)
    else:
        return 1 + p[N-1] + f(N-1,X-2-a[N-1])
print(f(N,X))

Measured memory_bytes: 3064
trial = int(input())
numlist = [str(n) for n in range(2,10)]

cases = []
for t in range(trial):
    cases.append(input().split(" "))
for case in range(len(cases)):
    num = 0
    for ba in range(2):
        #print(num)
        for n in range(len(cases[case][ba])):
                if cases[case][ba][n] == "m":
                    if n - 1 == 0:
                        num += int(cases[case][ba][n-1]) * 1000
                    else:
                        num += 1000
                elif cases[case][ba][n] == "c":
                    if (n - 1 == 0 and cases[case][ba][n-1] != "m") or cases[case][ba][n-1] in numlist:
                        num += int(cases[case][ba][n-1]) * 100
                    else:
                        num += 100
                elif cases[case][ba][n] == "x":
                    if (n - 1 == 0 and cases[case][ba][n-1] not in ["m","c"]) or cases[case][ba][n-1] in numlist:
                        num += int(cases[case][ba][n-1]) * 10
                    else:
                        num += 10
                elif cases[case][ba][n] == "i":
                    if (n - 1 == 0 and cases[case][ba][n-1] not in ["m","c","x"]) or cases[case][ba][n-1] in numlist:
                        num += int(cases[case][ba][n-1]) * 1
                    else:
                        num += 1
    else:
        num = str(num)
        answer = ""
        for n in range(len(num)):
            if len(num) - 1 - n == 3:
                if num[n] == "1":
                    answer += "m"
                elif num[n] == "0":
                    pass
                else:
                    answer += str(num[n]) + "m"
            if len(num) - 1 - n == 2:
                if num[n] == "1":
                    answer += "c"
                elif num[n] == "0":
                    pass
                else:
                    answer += str(num[n]) + "c"
            if len(num) - 1 - n == 1:
                if num[n] == "1":
                    answer += "x"
                elif num[n] == "0":
                    pass
                else:
                    answer += str(num[n]) + "x"
            if len(num) - 1 - n == 0:
                if num[n] == "1":
                    answer += "i"
                elif num[n] == "0":
                    pass
                else:
                    answer += str(num[n]) + "i"
        else:
            print(answer)

Measured memory_bytes: 8368
<?php
// C
fscanf(STDIN, '%d', $n);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
$c = $a[-1] = $a[$n] = 0;
for ($i = 0; $i <= $n; $i++) $c += abs($a[$i] - $a[$i - 1]);
for ($i = 0; $i < $n; $i++) $ans[] = $c + abs($a[$i + 1]  - $a[$i - 1]) - (abs($a[$i] - $a[$i - 1]) + abs($a[$i + 1] - $a[$i]));
echo implode(PHP_EOL, $ans);

Measured memory_bytes: 19952
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<char>	vc;
typedef vector<bool>	vb;
#define br "\n"

void solve(){
    ll n,k;
    cin >> n >> k;
    vll v(n);
    rep(i,0,n) cin >> v[i];
    double ans = 0;
    rep(i,0,k){
        ans += log10(v[i]);
    }
    rep(i,k,n){
        double ans1 = ans - log10(v[i - k]) + log10(v[i]);
        if(ans1 <= ans){
            cout << "No" << br;
        }
        else{
            cout << "Yes" << br;
        }
        ans = ans1;
    }

}
 
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 

	ll t = 1;
	// cin >> t;
	rep(i,0,t){
		solve();
	}
 
}

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

int s[8];
char a[10][10]={"........","........","........","........","........","........","........","........"};
void dfs(int n,int k);
void dfs(int n,int k)
{
   int s1[8],b[10][10];
   for(int i=0;i<8;i++)
      s1[i]=s[i];
      for(int i=0;i<10;i++)
         for(int j=0;j<10;j++)
         b[i][j]=a[i][j];
   if(n==8)
   {
      for(int i=0;i<8;i++)
         puts(a[i]);
         return;
   }
   if(s[k]>=0)
   {
      dfs(n,k+1);
      return;
   }
   for(int i=0;i<8;i++)
   {
      int f=1;
      for(int j=0;j<8;j++)
      {
         if(s[j]==i||(s[j]>=0&&fabs(s[j]-i)==fabs(j-k)))
         {
            f=0;break;
         }
      }
      if(f)
      {
         s[k]=i;
         a[k][i]='Q';
         dfs(n+1,k+1);
         for(int i=0;i<8;i++)
            s[i]=s1[i];
             for(int i=0;i<10;i++)
         for(int j=0;j<10;j++)
         a[i][j]=b[i][j];
      }
   }
}
int main()
{
    int x,y,t;
    cin>>t;
    memset(s,-1,sizeof(s));
    for(int i=0;i<t;i++)
    {
       cin>>y>>x;
       a[y][x]='Q';
       s[y]=x;
    }
    dfs(t,0);
    return 0;
}



Measured memory_bytes: 3096
////////////////////////// Author
////////////////////////// Nasim Hossain Rabbi
////////////////////////// JU-CSE28
////////////////////////// CF - imnasim3.1415
////////////////////////// UVA - imnasim3.1415
////////////////////////// Mail - imnasim3.1415@gmail.com
#include<bits/stdc++.h>
using namespace std;
#define sz size()
#define mk make_pair
#define clr clear()
#define B begin()
#define E end()
#define EM empty()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(i,n) for(i=0;i<n;i++)
#define Rep(i,n) for(i=1;i<=n;i++)
#define all(cont) cont.begin(),cont.end()
#define pb push_back
string en="\n";
string t="hello";
#define sqr(a) ((a) * (a))
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL)
#define pi 3.1415926535897932384626433832795
#define vi vector<int>
#define vl vector<long long>
#define vs vector<string>
#define vp(vi,x) cin>>x; vi.pb(x);
#define LB(a,x) (lower_bound(aov(a),x)-a.begin())
#define UB(a,x) (upper_bound(aov(a),x)-a.begin())
typedef long long LL;
typedef unsigned long long ULL;
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
int toInt(string s){int sm;stringstream ss(s);ss>>sm;return sm;}
template<typename T>inline T gcd(T a,T b){if(a<0)return gcd(-a,b);if(b<0)return gcd(a,-b);return (b==0)?a:gcd(b,a%b);}
template<typename T>inline T lcm(T a,T b) {if(a<0)return lcm(-a,b);if(b<0)return lcm(a,-b);return a*(b/gcd(a,b));}
int main()
{
//    fast;
    LL i,j,k,n,m,l,s=0,x,y,tc=1,c=0;
    while(cin>>n>>m)
    {
        if(n==2 && m==2) cout<<0<<en;
        else if(n==1 && m==1) cout<<1<<en;
        else
        {
            if(n==1) cout<<m-2<<en;
            else if(m==1) cout<<n-2<<en;
            else
            {
                c=(n-2)*(m-2);
                cout<<c<<en;
            }
        }
    }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;

vector<int> pa;
int root(int n) {
	if (pa[n] == n) return n;
	else return pa[n] = root(pa[n]);
}

void unite(int a, int b) {
	int art = root(a), brt = root(b);
	if (art == brt) return;
	pa[brt] = art;
}

int main() {
	int N, M; cin >> N >> M;
	pa = vector<int>(N);
	vector<ll> a(N);
	priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;
	for (int i = 0; i < N; i++) {
		pa[i] = i;
		cin >> a[i];
		pq.emplace(a[i], i);
	}

	for (int i = 0; i < M; i++) {
		int x, y; cin >> x >> y;
		unite(x, y);
	}

	if (N > 2 * M + 2) cout << "Impossible" << endl;
	else {
		vector< priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>> co(N);
		for (int i = 0; i < N; i++) {
			int rt = root(i);
			co[rt].emplace(a[i], i);
		}

		ll ans = 0, cnt = 0;
		vector<bool> used(N);
		for (int i = 0; i < N; i++) {
			if (co[i].size() > 0) {
				ans += co[i].top().first;
				used[co[i].top().second] = true;
				cnt++;
			}
		}

		while (cnt < 2 * (N - M - 1)) {
			if (!used[pq.top().second]) {
				ans += pq.top().first;
				used[pq.top().second] = true;		
				cnt++;
			}
			pq.pop();
		}

		if (M == N - 1) cout << 0 << endl;
		else cout << ans << endl;
	}

}

Measured memory_bytes: 12324
# 2019-11-18 23:58:23(JST)
import sys
import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    n, *l = [int(x) for x in sys.stdin.read().split()]
    l.sort()

    c = collections.defaultdict(int)
    for i in range(n):
        c[l[i]] += 1
    
    # cumsum: count of {l[j]|l[j] <= l[i]}
    s = [0 for _ in range(l[-3] + l[-2] + 1)] # a+bの最大値以下まで
    for i in range(l[-3] + l[-2]):
        s[i+1] = s[i] + c[i+1]

    count = 0
    # a <= b <= c
    for i in range(n-2):
        a = l[i]
        for j in range(i+1, n-1):
            b = l[j]
            # cの候補の数: a+b > cを満たし、c = l[k]となるkがjより大きい棒の数
            count += s[a+b-1] - (j + 1) # b は j+1番目

    print(count)




    

if __name__ == "__main__":
    main()


Measured memory_bytes: 3692
#include<stdio.h>

int M[101][101];
int Q[101];
int n,HEAD=0,TAIL=0;
int VERT[101],d[101];

void Enqueue(int);
int Dequeue();

int Dequeue()
{
  int x;
  x=Q[HEAD];
  if(HEAD+1 == 100)HEAD=0;
  else HEAD=HEAD+1;
  return x;
}

void Enqueue(int a)
{
  Q[TAIL]=a;
  if(TAIL+1 == 100)TAIL=0;
  else TAIL=TAIL+1;
}

int main()
{
  int i,j,v,vv,m,u,k;

  scanf("%d",&n);
  for(i=0 ; i < n ; i++)
  {
    VERT[i]=0;
    for(j=0 ; j < n ; j++)
    {
      M[i][j]=0;
    }
  }
  for(i=0 ; i < n ; i++)
  {
    scanf("%d%d",&v,&m);
    for(j=0 ; j < m ; j++)
    {
      scanf("%d",&vv);
      M[v-1][vv-1]=1;
    }
  }

  for(j=0 ; j < n ; j++)
  {
    if(M[0][j] == 1)
    {
      VERT[j]=0;
    }
  }
  VERT[0]=1;
  d[0]=0;
  Enqueue(0);
  while(HEAD!=TAIL)
  {
    u=Dequeue();
    for(k=0 ; k < n ; k++)
    {
      if(M[u][k] == 1 && VERT[k] == 0)
      {
        VERT[k]=1;
        d[k]=d[u]+1;
        Enqueue(k);
      }
      VERT[u]=2;
    }
  }

  for(i=0 ; i < n ; i++)
  {
    if(VERT[i] == 2)printf("%d %d\n",i+1,d[i]);
    else printf("%d -1\n",i+1);
  }
  return 0;
}



Measured memory_bytes: 2148
import java.util.*;

public class Main {

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

        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long c = scanner.nextLong();
        long k = scanner.nextLong();

        long sum = 0;

        long calc = k;
        if (calc < a) {
            System.out.println(calc);
            System.exit(0);
        } else {
            sum += a;
            calc = calc - a;
        }
        if (calc <= 0) {
            System.out.println(sum);
            System.exit(0);
        }

        if (calc < b) {
            System.out.println(sum);
            System.exit(0);
        } else {
            calc = calc - b;
        }
        if (calc <= 0) {
            System.out.println(sum);
            System.exit(0);
        }

        if (calc < c) {
            System.out.print(sum - calc);
            System.exit(0);
        } else {
            System.out.println(sum - c);
            System.exit(0);
        }
    }
}

Measured memory_bytes: 35756
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

def main():
    A,B=map(int,input().split())
    if B%A==0:
        print(A+B)
    else:
        print(B-A)

if __name__ == '__main__':
    main()


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

    ll N,W;
    string S;
    cin >> N>>W;
    vector<ll> w(N),v(N);

    REP(i, N)
        cin >> w.at(i) >> v.at(i);

    ll dp[N+10][W+10];



    for (ll i = 0; i <=W; i++) {
        if (i >= w.at(0))
        {
            dp[0][i] = v.at(0);
        }
        else
        {
            dp[0][i] = 0;
        }
        //cout << dp[0][i] << endl;
    }

    REPS(i,N-1){
        REPS(j,W){
            if(j<w.at(i)){
                dp[i][j] = dp[i-1][j];
            }
            else{
                dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w.at(i)] + v.at(i));
            }
        }
    }

    cout << dp[N - 1][W] << endl;



}


Measured memory_bytes: 79872
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Control.Monad.ST (runST)
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.Vector.Unboxed as V
import Data.STRef.Strict



readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as = let
    (fo, la) = span f as
    las = case la of
        [] -> []
        xs -> split f $ tail xs
    in
        case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> [Int] -> [Int] -> Int
solve n as bs = runST $ do
    av <- V.thaw $  V.fromList as
    bv <- V.thaw $  V.fromList bs
    ans <- newSTRef 0
    forM_ [0..n-1] $ \i -> 
        do
            b <- MV.read bv i
            a <- MV.read av i 
            a' <- MV.read av (i  + 1)
            let kill = min a b
            let remainB = b - kill
            modifySTRef ans (+kill)
            MV.write av i (a - kill)
            let kill' = min a' remainB
            modifySTRef ans (+kill')
            MV.write av (i + 1) (a' - kill')
    readSTRef ans


main = do
    n <- readInt
    as <- readInts
    bs <- readInts
    print $ solve n as bs


Measured memory_bytes: 22396
inp = input().split()
a = int(inp[0])
b = int(inp[1])
c = int(inp[2])

def move(a, b, c):
    ava = a-b
    wat = b
    # 5-3 2
    if(ava >= c):
        ava -= c
        wat += c
        c = 0
    elif(ava < c):
        c = c - ava
        wat += ava
        ava = 0

    print(c)
move(a, b, c)


Measured memory_bytes: 38384
#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#define rep(i, n) for(int i=0; i<n; ++i)

int main() {
  int n;
  std::string s;
  std::cin >> n >> s;
  int max;
  int x = 0;

  max = 0;

  rep(i, n) {
    if(s[i]=='I') {
      x += 1;
    }else if(s[i]=='D') {
      x -= 1;
    }

    if(max < x) max = x;
  }

  std::cout << max << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)

int main()
{
    string S, T;
    cin >> S >> T;

    vector<int> Rs(26, -1), Rt(26, -1);
    bool flag = true;

    rep(i, S.size())
    {
        char s = S[i] - 'a', t = T[i] - 'a';
        if (Rs[s] >= 0 && Rs[s] != t) flag = false;
        else Rs[s] = t;

        if (Rt[t] >= 0 && Rt[t] != s) flag = false;
        else Rt[t] = s;
    }

    if (flag) cout << "Yes";
    else cout << "No";
    cout << endl;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique(x).begin(),(x).end()),(x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

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

  int n, ans = 0;
  cin >> n;
  vector<int> a(n), x(n, 0);
  arep(i, a) cin >> i;
  reps(i, n - 1, -1) {
    int sum = 0;
    for (int j = i; j < n; j += i + 1) sum += x[j];
    if (sum % 2 != a[i] % 2) x[i] = 1, ++ans;
  }

  cout << ans << '\n';
  rep(i, 0, n) {
    if (x[i] != 0) cout << i + 1 << ' ';
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 3968
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			long[] a = new long[n];

			for (int i = 0; i < n; i++) {
				a[i] = sc.nextLong();
				if (a[i] == 0) {
					System.out.println(0);
					return;
				}
			}

			BigInteger result = BigInteger.ONE;
			BigInteger max = new BigInteger("1000000000000000000");
			for (long i : a) {
				result = result.multiply(BigInteger.valueOf(i));
				if (max.compareTo(result) < 0) {
					System.out.println(-1);
					return;
				}
			}
			System.out.println(result);
		}
	}
}


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


int semi[51][51];
int dp[51][51];

int main(){
	int h,w;
	cin>>h>>w;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			char c;
			cin>>c;
			semi[i][j]=c-'0';
		}
	}
	fill((int*)dp,(int*)(dp+50),1<<30);
	dp[0][0]=0;
	for(int i=0;i<=h;i++){
		for(int j=0;j<=w;j++){
			dp[i+1][j]=min(dp[i+1][j],dp[i][j]+semi[i+1][j]);
			dp[i][j+1]=min(dp[i][j+1],dp[i][j]+semi[i][j+1]);
		}
	}
	cout<<dp[h-1][w-1]<<endl;
	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

	ll r;
	cin >> r;
	cout << r * pi * 2 << endl;
}


Measured memory_bytes: 3792
#include<iostream>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define fr first
#define sc second
typedef pair<int,int> Pi;/*Pair int って意味だって！*/
typedef pair<Pi,int> Pii;
struct edge{
  int to,cost;
};
typedef vector< vector < edge > > Graph;

int dijkstr(Graph& info,int s ,int g){
  vector<int> min_cost[info.size()];
  priority_queue<Pii,vector<Pii>,greater<Pii> > que;
  //min_cost.resize(info.size(),-1);
  for(int i=0;i<info.size();i++){
    min_cost[i].resize(3,-1);
  }
  que.push( Pii( Pi(0,s) ,2/*チケット残数*/));
  while(!que.empty()){
    Pii p = que.top();
    que.pop();
    if(p.fr.sc == g && p.sc != 1) return p.fr.fr;
    if(p.fr.fr > min_cost[p.fr.sc][p.sc]){ //出してきた場所が更新され、小さくなっていた場合。
      if(p.sc == 0) continue;
    }
    for(int i=0;i<info[p.fr.sc].size();i++){
      edge& e = info[p.fr.sc][i];

      if(min_cost[e.to][p.sc] == -1 || p.fr.fr+e.cost < min_cost[e.to][p.sc]){
	if(p.sc!=1){
	  min_cost[e.to][p.sc] = p.fr.fr + e.cost;
	  que.push(Pii(Pi(min_cost[e.to][p.sc],e.to),p.sc));
	}
      }
      if(p.sc != 0 && (p.fr.fr < min_cost[e.to][p.sc - 1] || min_cost[e.to][p.sc - 1]==-1) ){
	min_cost[e.to][p.sc - 1] = p.fr.fr;
	que.push(Pii(Pi(min_cost[e.to][p.sc - 1],e.to),p.sc-1));
      }

    }
  }

  return -1;
}

int main(){
  Graph g;
  int n, m;
  while(1){
    g.clear(); //Graph初期化。
    cin >> n >> m;
    if(n==0 && m==0) break;
    g.resize(n + 1); //nでは足りない。
    for(int i=0;i<m;i++){
      int a, b, c;
      cin >> a >> b >> c; 
      g[a].push_back((edge){b,c});
      g[b].push_back((edge){a,c});
    }

    cout << dijkstr(g,1,n) << endl;
  }
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#include <stdlib.h>
#include <fstream>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

ll mod(ll a, ll b){
  ll ret=a%b;
  if(ret<0) ret+=b;
  return ret;
}

ll modpow(ll a,ll b,ll c){
  ll res=1;
  while(b>0){
    if(b&1) res=mod(res*a,c);
    a=mod(a*a,c);
    b>>=1;
  }
  return res;
}

int main() {
  int n;
  cin>>n;
  int temp=n;
  int sum=0;
  while(temp>0){
    sum+=temp%10;
    temp/=10;
  }
  if(n%sum==0) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    long long int m,k;
    cin>>m>>k;
    if(k>=(long long int)pow(2,m)){
        cout << "-1" << endl;
        return 0;
    }else if(m==0){
        if(k==0){
            cout << "0 0" << endl;
        }else{
            cout << "-1" << endl;
        }
        return 0;
    }else if(m==1){
        if(k==0){
            cout << "0 0 1 1" << endl;
        }else{
            cout << "-1" << endl;
        }
        return 0;
    }else{
        REP(i,(long long int)pow(2,m)){
            if(i!=k){
                cout << i << " ";
            }
            
        }
        cout << k << " ";
        DEFOR(i,(long long int)pow(2,m),0){
            if(i!=k){
                cout << i << " ";
            }
        }
        cout << k << endl;
    }

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template< typename T > using matrix = vector< vector< T > >;

//FUNCTION  


void solve(void)
{
  int N,K;
  cin>>N>>K;
  vector<pair<int,int> > DATA(N);
  for (int i = 0; i < N; i++)
  {
    cin>>DATA[i].first >> DATA[i].second;
  }
  sort(ALL(DATA));
  int ANS = I64_MAX;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < N; j++)
    {
      int X1,X2,Y1,Y2;

      for (int k = 0; k < N; k++)
      {
        for(int m = 0; m < N; m ++)
        {
          X1 = min(min(DATA[i].first,DATA[j].first),min(DATA[k].first,DATA[m].first));
          Y1 = min(min(DATA[i].second,DATA[j].second),min(DATA[k].second,DATA[m].second));
          X2 = max(max(DATA[i].first,DATA[j].first),max(DATA[k].first,DATA[m].first));
          Y2 = max(max(DATA[i].second,DATA[j].second),max(DATA[k].second,DATA[m].second));
          int COUNT = 0;
          for (int l = 0; l < N; l++)
          {
            if(DATA[l].first >= X1 && DATA[l].first <= X2 && DATA[l].second >= Y1 && DATA[l].second <= Y2)
            {
              COUNT++;
            }
            
          }
          if(COUNT >= K)
          {
            chmin(ANS,(X2 - X1)*(Y2 - Y1));

          }
          
        }
      }
      
    }

    
  }

      cout<<ANS<<endl;
  
  return;
}
int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define inputv(a) forall(i,0,a.size()) cin>>a[i]
#define outputv(a) for(auto i:a) cout<<i<<" ";br;
#define fs first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define minv(a) *min_element(all(a))
#define maxv(a) *max_element(all(a))
#define br cout<<"\n"
using namespace std;
int dr[]={1,-1,0,0};
int dc[]={0,0,1,-1};
ll mod=1000000007;
ll po(ll x,ll n){
    ll res = 1;
    while(n>0){
        if(n%2==1)
            res = ((res)%mod*(x)%mod);
        x = (x*x)%mod;
        n = n/2;
    }
    return res%mod;
}
ll ceil(ll x,ll y)
{
    if(x%y==0)
        return x/y;
    else
        return(x/y)+1;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n];
    rep(i,0,n) cin>>a[i];
    sort(a,a+n,greater<ll>());
    ll ans=a[0];
    ll cnt=1;
    for(ll i=1;i<n-1;i++)
    {
        if(cnt==n-1)break;
        if(cnt==n-2)
            {ans=ans+a[i]; cnt++;}
        else
            {ans=ans+2*a[i]; cnt=cnt+2;}

    }
    cout<<ans;
	return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long

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

	int a,b,c,k;
	cin >> a >> b >> c >> k;
	while(b <= a){
		b *= 2;
		k--;
	}
	while(c <= b){
		c *= 2;
		k--;
	}
	if(k < 0) cout << "No";
	else cout << "Yes";
	return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>

int main()
{
	int i, n, tmp, status, preStatus, count;
	char action[200];
	
	while(1)
	{
		status = preStatus = 0x00;
		count = 0;
		
		scanf("%d", &n);
		
		if(n == 0) break;
		
		for(i = 0; i < n; i++)
		{
			scanf("%s", &action[i * 2]);
		}
		
		for(i = 0; i < n; i++)
		{
			if(action[i * 2] == 'l'){
				tmp = 0x10;
			} else {
				tmp = 0x01;
			}
			
			if(action[i * 2 + 1] == 'u'){
				status |= tmp;
			} else {
				status &= ~tmp;
			}
			
			if(preStatus == (~status & 0x11))
			{
				preStatus = status;
				count++;
			}
		}
		
		printf("%d\n", count);
	}
	
	return 0;
}

Measured memory_bytes: 604
#include <iostream>

int main() {
  unsigned int N, D;
  std::cin >> N >> D;

  const unsigned int x = 2 * D + 1;
  const unsigned int amari = N % x;
  if (amari == 0) {
    std::cout << N / x << std::endl;
  } else {
    std::cout << N / x + 1 << std::endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  int i,j,k;
  int build[4][3][10]={{{}}};
  cin >> n;
  int b,f,r,v;
  for(i=0;i<n;i++){
    cin >> b >> f >> r >> v;
    build[b-1][f-1][r-1]+=v;
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	cout << " ";
	cout << build[i][j][k];
      }
      cout << endl;
    }
    if(i<3)cout << "####################" << endl;
  }
  return 0;
}


Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	int N;
	cin >> N;
	vector<int>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	vector<int>S(N+1);
	S[0] = abs(A[0]);
	S[N] = abs(A[N - 1]);
	for (int i = 1; i < N; i++) {
		S[i] = abs(A[i-1]-A[i]);
	}
	/*for (int i = 0; i < N+1; i++) {
		cout << S[i] << endl;
	}*/
	int sum = 0;
	for (int i = 0; i < N+1; i++) {
		sum += S[i];
	}
	//cout << sum << endl;
	vector<int>AA(N + 2);
	AA[0] = 0;
	AA[N] = 0;
	for (int i = 1; i < N + 1; i++) {
		AA[i]=A[i-1];
	}
	/*for (int i = 0; i < N + 2; i++) {
		cout << AA[i] << endl;
	}*/
	for (int i = 0; i < N; i++) {
		cout << sum - (S[i] + S[i + 1]) + abs(AA[i + 2] - AA[i]) << endl;
	}
	/*for (int i = 0; i < N; i++) {
		cout << (S[i] + S[i + 1]) << ' ' << abs(AA[i + 2] - AA[i]) << endl;
	}*/
}

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

int main() {
  int k; cin>>k ;
  string s; cin>>s;
  
  int n=s.size();
  if(n<=k)cout<<s;
  else{
    string s_=s.substr(0,k);
    cout<<s_+"...";
  }
}
      

Measured memory_bytes: 3576
#include <iostream>
using namespace std;
long long n, s, mn, mi, a[5], b[5], c[5]={1,2,4,8};
int main() {
	int i;
	for(i=0; i<4; i++) cin>>a[i], b[i]=a[i];
	cin>>n, n*=4;
	b[0]*=8, b[1]*=4, b[2]*=2;
	while(n) {
		mn = 1e9;
		for(i=0; i<4; i++) if(b[i]<mn) mn=b[i], mi=i;
		s += n/c[mi]*a[mi], n %= c[mi], b[mi] = 1e9;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  double x1,y1,x2,y2,x3,y3,x4,y4;
  double m1,m2;
  int x, i;
  scanf("%d", &x);
  for(i= 0; i < x;i++){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
    m1 = (y2-y1)/(x2-x1);
    m2 = (y4-y3)/(x4-x3);
    if(m1 == m2){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
  }
  return 0;
}

Measured memory_bytes: 620
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>

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

int main( void ){
	int n;
	if (!scanf( "%d", &n ))
		return -1;
	int* array = new int[ n ];
	rep( i, 0, n - 1 ){
		if (!scanf( "%d", array + i ))
			return -1;
	}
	int* ans = new int [ n ];
	int sum = array[ 0 ] + array[ n - 2 ];
	rep( i, 1, n-1 ){
		sum+= std::min(array[i-1], array[i]);
	}
	printf("%d\n", sum);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
const int MOD = 1000000007;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
   fac[0] = fac[1] = 1;
   finv[0] = finv[1] = 1;
   inv[1] = 1;
   for (int i = 2; i < MAX; i++){
       fac[i] = fac[i - 1] * i % MOD;
       inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
       finv[i] = finv[i - 1] * inv[i] % MOD;
   }
}
// 二項係数計算
long long COM(int n, int k){
   if (n < k) return 0;
   if (n < 0 || k < 0) return 0;
   return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    COMinit();
    int N,M,count=0;
    cin>>N>>M;
    vector<int>numofdiv;
    for(int i=2;M!=1;i++){
        if(M%i==0){
            count=0;
            for(int j=0;M%i==0;j++){
                M/=i;
                count++;
            }
            numofdiv.pb(count);
        }
    }
    ll sub=1;
    for(int i=0;i<numofdiv.size();i++){
        sub*=COM(N+numofdiv[i]-1,numofdiv[i]);
        sub%=MOD;
    }
    cout<<sub<<endl;
}

Measured memory_bytes: 12288
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


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

	int N;
	cin >> N;
	int cnt3 = min(5000, 2*((N - 1) / 2));
	int cnt2 = N - cnt3;

	if (N == 3) {
		cout << 2 << " " << 5 << " " << 63 << endl;
	}
	else {
		if (cnt2 % 3 == 0 || cnt2 % 3 == 2) {
			for (int i = 1; i <= cnt2; i++) {
				cout << 2 * i << " ";
			}
			for (int i = 1; i <= cnt3; i++) {
				cout << 6 * i - 3 << " ";
			}
			cout << endl;
		}
		else {
			cnt3 -= 2;
			cnt2 += 2;
			for (int i = 1; i <= cnt2; i++) {
				cout << 2 * i << " ";
			}
			for (int i = 1; i <= cnt3; i++) {
				cout << 6 * i - 3 << " ";
			}
			cout << endl;
		}
	}

	return 0;
}

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

a =[]
for i in range(1, N):
  if A[i-1] -A[i] > 0:
    add = A[i-1] -A[i]
    a.append(add)
    A[i] += add
print(sum(a))
  

Measured memory_bytes: 32332
N = int(input())
memo = [0]*N
C = [0]*N
S = [0]*N
F = [0]*N



for i in range(N-1):
    Ci, Si, Fi = map(int, input().split())
    C[i], S[i], F[i] = Ci, Si, Fi

for i in range(N):
    t = 0
    for j in range(i, N-1):
        if t < S[j]:
            t = S[j]
        else:
            if t % F[j] == 0:
                pass
            else:
                t = t+F[j]-(t%F[j])
        t += C[j]

    print(t)


Measured memory_bytes: 3188