akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

int i,j;

vector<string> v;
string s,t="";

int pt(char c){
  return (c=='#')?1:0;
}

int main(){
  LL h,w;
  cin >>h>>w;
  REP(i,w+2)
    t+='.';
  v.push_back(t);
  REP(i,h){
    cin >> s;
    v.push_back('.'+s+'.');
  }
  v.push_back(t);
  REP(i,h){
    REP(j,w){
      if(v[i+1][j+1]=='#')
	cout<<'#';
      else
	cout<<pt(v[i][j])+pt(v[i][j+1])+pt(v[i][j+2])+pt(v[i+1][j])+pt(v[i+1][j+2])+pt(v[i+2][j])+pt(v[i+2][j+1])+pt(v[i+2][j+2]);
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
 

public class Main {
    public static void main(String[] args) {   
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int H = 0;
        int A = N; 

        if(N<=10){
            System.out.println("Yes");
            return;
        }

        while(N>10){      
        H += N%10;
        N /= 10;
        if(N<=10)
        H +=N; 
        }

        if(A%H==0){
        System.out.println("Yes");
        }else{
        System.out.println("No");
        }          
    
    }    
}




Measured memory_bytes: 23124
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <type_traits>
#include <limits>
#include <random>
#include <iomanip>

using namespace std;

using ll = long long;

typedef pair<int, int> P;

#define rep(i,N) for(long long i = 0;i < (long long)N; ++i)

static int mod = 1000000007;
static int large = 1000000000;

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


int N;
int h[100000];

int note[1000000];

int f(int x) {
	if (note[x] != -1) return note[x];
	if (x == 1) {
		return 0;
	}
	if (x == 2) {
		return abs(h[0] - h[1]);
	}
	return note[x] = min(f(x - 1) + abs(h[x - 1]- h[x - 2]), f(x - 2) + abs(h[x - 1] - h[x - 3]));
}

int main() {
	cin >> N;
	rep(i, N) {
		cin >> h[i];
	}
	for (int i = 0; i < 100001; i++) {
		note[i] = -1;
	}
	cout << f(N) << endl;
	return 0;
}



Measured memory_bytes: 5248
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define Rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;

////////////////////////////////////////////////////////////////////


int main() {
int h,w;
cin>>h>>w;

int grid[h+1][w+1];
for(int k=0;k<=1;k++){
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
if(k==0){
cin>>grid[i][j];
continue;}
int p;
cin>>p;
grid[i][j]=abs(grid[i][j]-p);
	
}
}
}

int dp[h+1][w+1][6482];

for(int i=1;i<=h;i++){
	for(int j=1;j<=w;j++){
	for(int k=0;k<=6481;k++){
dp[i][j][k]=0;
	}
	}
}

int ans=1000000;
dp[1][1][grid[1][1]]=1;

for(int i=1;i<=h;i++){
	for(int j=1;j<=w;j++){
	for(int k=0;k<=6481;k++){
int l=grid[i][j];
	if(i>=2){
		if(dp[i-1][j][k]==1 ){
			if(k+l<=6481){
		dp[i][j][k+l]=1;}
	    dp[i][j][abs(k-l)]=1;}
	}
if(j>=2){
		if(dp[i][j-1][k]==1 ){
			if(k+l<=6481){
		dp[i][j][k+l]=1;}
	    dp[i][j][abs(k-l)]=1;}
	}
		}
	}
}





for(int i=0;i<=6481;i++){
	if(dp[h][w][i]==1){
		cout<<i<<endl;
		return 0;
	}
}







}



Measured memory_bytes: 164352
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function main()
    s=chomp(readline())
    ans=0
    for i in 1:trunc(Int,ceil(length(s)/2))
        if s[i]!=s[length(s)-i+1]
            ans+=1
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 109804
#pragma GCC optimize ("Ofast", "unroll-loops", "loop-nest-optimize")

#include <bits/stdc++.h>

#define REP(i, n) REPI(i, 0, n)
#define REP1(i, n) REPI(i, 1, n)
#define REPI(i, init, n) for(int i = init; i < n; i++)
#define MS(arr, val) memset(arr, val, sizeof(arr))
#define SZ(x) (x).size()
#define ALL(x) (x).begin(), (x).end()
#define EB emplace_back
#define UB upper_bound
#define LB lower_bound
#define FS first
#define SC second

#ifdef __WIN32__
inline size_t fread_unlocked(void *_buf, int _sz, int _cnt, FILE *_stream)
{
	return fread(_buf, _sz, _cnt, _stream);
}//fread_unlocked
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef double DB;
typedef long double LDB;
//typedef pair<int, int> P;

char buf[100000];

inline char gc()
{
	static char *st = buf, *ed = buf;

	if (st >= ed)
	{
		st = buf;
		ed = st + fread_unlocked(buf, 1, sizeof(buf), stdin);

		if (st == ed) return EOF;
	}//if

	return *(st++);
}//gc

template<class T>
inline bool rit(T &_a)
{
	char _c = gc();
	bool neg = false;
	for (; _c < '0' || _c > '9'; _c = gc())
	{
		if (_c == EOF) return false;
		if (_c == '-') neg = true;
	}//for

	for (_a = 0; _c >= '0' && _c <= '9'; _c = gc())
		_a = _a * 10 + _c - '0';

	if (neg) _a = -_a;

	return true;
}//rit

template<class S, class ...T>
inline bool rit(S &_a, T&... _b)
{
	if (!rit(_a)) return false;
	return rit(_b...);
}//rit

//============================================================================//

const int MAX_N = 0 + 10;
//const int INF8 = 0x3f;
//const int INF32 = 0x3f3f3f3f;
//const int MOD = 1e9 + 7;
//const int MOD = 46337; //maximum prime int for multiplying
//const LL MOD = 2999999929; //maximum prime LL for multiplying
//const LL INF64 = 0x3f3f3f3f3f3f3f3f;
//const DB PI = acos(-1);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int N, A;
	bool flag = true;
	
	rit(N);
	while (N--)
	{
		rit(A);
		
		if ((A & 1) == 0 && A % 3 != 0 && A % 5 != 0)
		{
			flag = false;
			break;
		}//if
	}//while
	
	if (flag) cout << "APPROVED\n";
	else cout << "DENIED\n";
	
	return 0;
}//main


Measured memory_bytes: 256
N = int(input())
ABs = []
for i in range(N):
  a, b = map(int, input().split())
  ABs.append((a, b))
CDs = []
for i in range(N):
  c, d = map(int, input().split())
  CDs.append((c, d))
ABs.sort()
CDs.sort()
r = 0
s = set()
for c, d in CDs:
  ma, mb = -1, -1
  for a, b in ABs:
    if a < c and b < d and b > mb and (a, b) not in s:
      ma, mb = a, b
  if not ma < 0:
    r += 1
    s.add((ma, mb))
    #print(ma, mb)
print(r)


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

using namespace std;

vector<int> A;
int N;

bool isEnable()
{
	int i = 0;
	if (N % 2 != 0)
	{
		if (A[0] != 0)
			return false;
		else
			i++;
	}

	for (; i < N; i += 2)
	{
		if (!(A[i] == i + 1 && A[i + 1] == i + 1))
			return false;
	}

	return true;
}

int main()
{
	cin >> N;
	long long ans = 1;
	const int mod = 1000000007;

	A.resize(N);

	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	sort(A.begin(), A.end());

	if (isEnable())
	{
		for (int i = 0; i < N / 2; i++)
			ans = (ans * 2) % mod;
	}
	else
		ans = 0;

	cout << (ans % mod) << endl;

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdin);
    int k,n;
    while(cin>>k>>n){
        int arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];

        }
       int mn=arr[n-1]-arr[0];
       for(int i=1;i<n;i++){
            mn=min(mn,k-(arr[i]-arr[i-1]));
       }
        cout<<mn<<endl;
    }
    return 0;
}


Measured memory_bytes: 1152
import sys
inputs = sys.stdin.readlines()

import heapq
from heapq import heapify, heappush, heappop, _heapify_max
def _heappush_max(heap, item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappop_max(heap):
    lastelt = heap.pop()
    if heap:
        returnitem = heap[0]
        heap[0] = lastelt
        heapq._siftup_max(heap, 0)
        return returnitem
    return lastelt

N, M = map(int, inputs[0].split())
A = list(map(int, inputs[1].split()))
_heapify_max(A)
for _ in range(M):
    _heappush_max(A, _heappop_max(A) // 2)
print(sum(A))

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

int main(void) {
    int64_t N, B, C;
    int64_t sum = 0;
    cin >> N;

    vector<int64_t> A(N);
    vector<int64_t> chk(N,0);
    for(int i=0;i<N;i++) {
        cin >> A[i];
        if(i) {
            if((A[i-1] +1) == A[i]) {
                chk[A[i-1]-1] = 1;
            }
        }
    }
    
    for(int i=0;i<N;i++) {
        cin >> B;
        sum += B;
    }
    for(int i=1;i<N;i++) {
        cin >> C;
        if(chk[i-1]) sum+=C;
    }

    cout << sum << "\n";
    return 0;
}


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

using namespace std;

int main(int argc, char const *argv[]) {
	int n,m,x;
	cin >> n >> m >> x;
	vector<int> c(n);
	vector<vector<int>> a(n, vector<int> (m, 0));
	for (size_t i = 0; i < n; i++) {
		cin >> c.at(i);
		for (size_t j = 0; j < m; j++) {
			cin >> a.at(i).at(j);
		}
	}

	int minval = 1300000;
	for (size_t bits = 0; bits < 1 << n; bits++) {
		bool isAchieve = true;
		for (size_t j = 0; j < m; j++) {
			int rikaido = 0;
			for (size_t i = 0; i < n; i++) {
				if ((bits >> i) & 1) {
					rikaido += a.at(i).at(j);
				}
			}
			if (rikaido < x) {
				isAchieve = false;
				break;
			}
		}
		if (isAchieve) {
			int val = 0;
			for (size_t i = 0; i < n; i++) {
				if ((bits >> i) & 1) {
					val += c.at(i);
				}
			}
			minval = min(minval, val);
		}
	}

	if (minval == 1300000) {
		cout << -1 << endl;
	} else {
		cout << minval << endl;
	}
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
//using
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;

//関数マクロ
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl

//定数マクロ
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>

//定数
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);

//テンプレート関数
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
//intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); } //c++17からある
//intl lcm(intl a,intl b){ return a / gcd(a, b) * b; } //c++17からある

//自作テンプレート関数
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}//Yes,Noの出力を楽にするよう
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}//上の関数のYes,Noを任意の文字列でできるようにしたもの
intl fact(intl k){ intl a = 1; for(int i = 2; i <= k; i++){ a *= i; } return a; }//k!を求める関数,O(N)
intl digit10(intl a){ intl b = 0; do{ a /= 10; b++; }while(a); return b; }//aを10進数で表したときの桁数を求める関数,O(logN)



//--------------入力受け取る場所----------------------------------------------------
intl n,m;
intl a,b,c,d;
string s,t;

void input_var(){
    cin >> n;
}
//-------------------------------------------------------------------------------

signed main(){
    cout << fixed << setprecision(10);
    input_var();
    fp(n >= 30);
    return 0;
}


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

int n,k,a[11],ans;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;++i)
	{
		int x;
		scanf("%d",&x);
		a[x]=1;
	}
	ans=n;
	while(1)
	{		
		int qwq=ans,pd=0;
		while(qwq)
		{
			if(a[qwq%10])
			{
				pd=1;
				break;
			}
			qwq/=10;
		}
		if(pd==0)
		{
			printf("%d\n",ans);
			break;
		}
		ans++;
	}
	return 0;
}

Measured memory_bytes: 256
#![allow(dead_code, unused_variables)]
use proconio::{fastout, input};
use std::cmp::max;

#[fastout]
fn main() {
    input! {
        n: usize,
        W:usize,
    }
    let mut w = Vec::new();
    let mut v = Vec::new();
    for i in 0..n{
        input!{x:usize,y:usize}
        w.push(x);
        v.push(y);
    }

    let mut dp = vec![0;W+10];

    for i in 0..n{
        for j in 0..=W{
            let jj = W-j;
            if jj >= w[i]{
                dp[jj] = max(dp[jj],dp[jj-w[i]] + v[i]);
            }
        }
    }

    println!("{}",dp[W]);
}


Measured memory_bytes: 2868
N, K = map(int, input().split())
H = list(map(int, input().split()))

if N < K:
    print(abs(H[N-1]-H[0]))
else:
    C = [0] * N
    for i in range(K):
        C[i] = abs(H[i]-H[0])
    for i in range(K, N):
        C[i] = min([C[i-k] + abs(H[i]-H[i-k]) for k in range(K, 0, -1)])
    print(C[N-1])

Measured memory_bytes: 52448
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
	int n;
	while(cin >>n){
		if(n == -1){break;}
		double x = 0, y = 0, angle = 0;
		if(n>0){x = 1;n--;}
		while(n--){
			double xp = x,yp = y;
			x-=yp/sqrt(xp*xp+yp*yp);
			y+=xp/sqrt(xp*xp+yp*yp);
		}
		printf("%.2lf\n%.2lf\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld  = long double;
using pll = pair<ll, ll> ;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=1LL<<60 ;
const ll MOD=998244353 ; //10e9+7から今回は998244353に
const ld PI=acos(-1);
const ld EPS = 1e-9; //微調整用（EPSより小さいと0と判定など）
 
#define gcd __gcd //llは受け取ってくれない
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define ALL(a) a.begin(),a.end() //sort(ALL(vec));
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define PB push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに
 
//最大値、最小値を更新する。aよりbのが大きい（小さい）か等しければaを更新してtrueを返す。そうでなければ何もせずfalseを返す chmax(nowmax,x);
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
// ----- template end ---- //
 
// ------- library ------- //


//nCk(mod MOD)の計算　n!(mod MOD)とk!^{MOD-2}を前計算して求める
//nの最大値を設定すること
ll maxN = 300000; // n, kの最大値を代入(0 < n <= maxN)
vector<ll> fac(maxN+1); //n!(mod MOD) を格納。
vector<ll> ifac(maxN+1); //k!^{MOD-2} (mod MOD)
//a,bの範囲的にこれだけ配列を用意していけば十分

ll mpow(ll x, ll n){ //x^n(mod MOD) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

// ----- library end ----- //



int main() {
  
  ll N, A, B, K;
  cin >> N >> A >> B >> K;

  //大した量ではないので，先にfax[i]とifax[i]を全て計算しておく
  fac[0] = 1;
  ifac[0] = 1;
  for(ll i = 0; i<maxN; i++){
      fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod MOD)
      ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD; // k!^{MOD-2} (mod MOD) ←累乗にmpowを採用
  }

  vector<pair<ll, ll> > colorlist;
  ll restK;
  REP(r, 0, min(N, K/A) + 1){ //r:0～K/R ただしrがNを超えてはならない
    restK = K - r * A;
    if (restK==0){
      colorlist.PB(make_pair(r, 0));
      break;
    }
    else if (restK % B == 0){
      if(N >= restK/B){
        colorlist.PB(make_pair(r,restK/B));
      }
    }
  }

  ll ans = 0;
  ll tmpans = 0;
  for (auto eacht : colorlist){
    ll rr, gg;
    tie(rr, gg) = eacht;
    tmpans = comb(N, rr) * comb(N, gg) % MOD;
    ans += tmpans;
    ans %= MOD;
//    cout << ans << ' ' << rr << ' ' << gg << ' ' << bb << ' ' << ww << endl;
  }

  cout << ans << endl;


// -- main() end -- //
}


 

Measured memory_bytes: 11120
#include<stdio.h>

int main(void)
{
	int x,y;
	int d,i;
	
	scanf("%d %d",&x,&y);
	
	for(i=1;;i++)
	{
		d=x%y;
		if(d!=0)
		{
			x=y;
			y=d;
		}
		if(d==0)break;
	}
	
	printf("%d\n",y);
	
	return 0;
}



Measured memory_bytes: 2088
#include <bits/stdc++.h>
using namespace std;
using lli=long long int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vi=vector<int>;  using vs=vector<string>; using gi=greater<int>;
#define soao(c) sort((c).begin(),(c).end()) //昇順
#define sodo(c) sort((c).begin(),(c).end(),gi()) //降順
#define rev(c) reverse((c).begin(), (c).end())

int main() {
  int keta,M; cin>>keta>>M;

    vi ans(keta,0);
    vi s(M),c(M); rep(i,M) cin>>s.at(i)>>c.at(i);
    
    rep(i,M){
      if(s.at(i)==1&&c.at(i)==0&&keta!=1){
        cout<<"-1"<<endl;
        goto end;
      }
    }

    rep(i,M){
      rep(j,M){
        if(s.at(i)==s.at(j)&&i!=j){
          if(c.at(i)!=c.at(j)){
            cout<<"-1"<<endl;
            goto end;
          }
        }
      }
    }

    rep(i,M) ans.at(s.at(i)-1)=c.at(i);
    
    if(keta==3){
      if(ans.at(0)==0) cout<<"1"<<ans.at(1)<<ans.at(2)<<endl;
      else cout<<ans.at(0)<<ans.at(1)<<ans.at(2)<<endl;
    }else if(keta==2){
      if(ans.at(0)==0) cout<<"1"<<ans.at(1)<<endl;
      else cout<<ans.at(0)<<ans.at(1)<<endl;
    }else cout<<ans.at(0)<<endl;
  
  end:;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int N, X;
        N = scan.nextInt();
        X = scan.nextInt();
        int[] x = new int[N];
        for (int i = 0; i < N; i++) {
            x[i] = scan.nextInt();
        }
        int [] dif = new int[N];
        for (int i = 0; i < N; i++) {
            dif[i] = Math.abs(x[i] - X);
        }
        Arrays.sort(dif);
        
        int ans = N == 1 ? dif[0] : gcd(dif[1], dif[0]);
        for (int i = 2; i < N; i++) {
            ans = gcd(dif[i], ans);
        }
        System.out.println(ans);
    }
    
    public static int gcd(int a, int b) {
        if (b > 0) {
            return gcd(b, a % b);
        }
        else {
            return a;
        }
    }
}

Measured memory_bytes: 48316
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct Node Node;

struct Node{
    int id;
    int degree;
    int height;
    Node* parent;
    Node* left;
    Node* right;
    Node* sibling;
};

void initNode(Node*);
int max(int,int);
int getDepth(Node*);
int getHeight(Node*);
void printTree(int,Node[]);

int main(int argc, char** argv) {
    int size;
    scanf("%d\n", &size);
    Node tree[size];
    for(int i = 0; i < size; i++)
        initNode(&tree[i]);
    
    int loc, left, right, root;
    for(int i = 0; i < size; i++){
        scanf("%d %d %d", &loc, &left, &right);
        tree[loc].id = loc;
        if(left >= 0){
            tree[loc].left = tree+left;
            tree[left].parent = tree+loc;
            tree[loc].degree++;
        }
        if(right >= 0){
            tree[loc].right = tree+right;
            tree[right].parent = tree+loc;
            tree[loc].degree++;
        }
        if(tree[loc].left != NULL && tree[loc].right != NULL){
            tree[loc].left->sibling = tree[loc].right;
            tree[loc].right->sibling = tree[loc].left;
        }
        else if(tree[loc].left == NULL && tree[loc].right == NULL)
            tree[loc].height = 0;
        if(tree[loc].parent == NULL)
            root = loc;
    }
    
    getHeight(&tree[0]);
    printTree(size,tree);
    
    return (EXIT_SUCCESS);
}

void initNode(Node *n){
    n->id = -1;
    n->degree = 0;
    n->height = -1;
    n->parent = NULL;
    n->left = NULL;
    n->right = NULL;
    n->sibling = NULL;
}

int max(int a, int b){
    if(a > b)
        return a;
    return b;
}

int getDepth(Node* target){
    int count = 0;
    if(target->parent != NULL){
        count++;
        count += getDepth(target->parent);
    }
    return count;
}

int getHeight(Node* target){
    int leftCount = 0;
    int rightCount = 0;
    if(target->height == -1){
        if(target->left != NULL){
            leftCount++;
            leftCount += getHeight(target->left);
        }
        if(target->right != NULL){
            rightCount++;
            rightCount += getHeight(target->right);
        }
         target->height = max(rightCount, leftCount);
    }
    return target->height;
}

void printTree(int size, Node tree[size]){
    int parent, sibling;
    char type[15];
    for(int i = 0; i < size; i++){
        parent = -1;
        sibling = -1;
        printf("node %d: ", i);
        if(tree[i].parent != NULL)
            parent = tree[i].parent->id;
        printf("parent = %d, ", parent);
        if(tree[i].sibling != NULL)
            sibling = tree[i].sibling->id;
        printf("sibling = %d, ", sibling);
        printf("degree = %d, ", tree[i].degree);
        printf("depth = %d, ", getDepth(&tree[i]));
        printf("height = %d, ", getHeight(&tree[i]));
        if(tree[i].parent == NULL)
            strcpy(type,"root");
        else{
            if(tree[i].degree != 0)
                strcpy(type,"internal node");
            else
                strcpy(type,"leaf");
        }
        printf("%s\n", type);
    }
}



Measured memory_bytes: 2104
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int ans = 0;
    if(n > 9) {
    ArrayList<Integer> prime = new ArrayList<Integer>();
    boolean[] is_prime = new boolean[n + 1];
    for(int i = 0; i <= n - 2; i++) is_prime[i] = true;
    is_prime[0] = false;
    if(n > 2) is_prime[1] = false;
    for(int i = 2; i <= n; i++) {
      if(is_prime[i]) {
        prime.add(i);
        for(int j = 2 * i; j <= n; j += i) is_prime[j] = false;
      }
    }
    int[] ord = new int[prime.size()];
    int[] m = new int[5];
    for(int i = 0; i < prime.size(); i++) {
      int p = prime.get(i);
      int t = 0;
      for(int j = 1; j <= 7; j++) {
        t += n / (int)Math.pow(p, j);
      }
      ord[i] = t;
      if(t >= 74) {
        m[0]++;
        m[1]++;
        m[2]++;
        m[3]++;
        m[4]++;
      } else if(t >= 24) {
        m[0]++;
        m[1]++;
        m[2]++;
        m[3]++;
      } else if(t >= 14) {
        m[0]++;
        m[1]++;
        m[2]++;
      } else if(t >= 4) {
        m[0]++;
        m[1]++;
      } else if(t >= 2) {
        m[0]++;
      }
    }
    ans += m[4];
    ans += (m[2] * (m[1] - 1));
    ans += (m[3] * (m[0] - 1));
    ans += (m[1] * (m[1] - 1) * (m[0] - 2) / 2);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007

signed main() 
{
	int n , q , temp , x , y , sum = 0;
	map<int,int> m;
	cin >> n;
	for(int i = 0 ; i < n ; i++)
		cin >> temp , m[temp]++ , sum += temp;
	cin >> q;
	while(q--)
	{
		cin >> x >> y;
		sum += (y-x)*m[x];
		m[y]+=m[x];
		m[x]=0;
		cout << sum << endl;
	}
}

Measured memory_bytes: 9540
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDigit(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  lol sum = 0;
  rep(i, s.size()){
    sum += s[i] - '0';
  }
  cout << (sum % 9 == 0 ? "Yes\n" : "No\n");
  return 0;
}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;

int n;
string s;
int a[200001];
int dp[200001][3];

int f(int k, int p)
{
    if (k == n)
        return 0;
    if (dp[k][p] != -1)
        return dp[k][p];

    int sol = 1e9;
    if (p != 1) sol = min(sol, (a[k] != 0) + f(k + 1, 0));
    sol = min(sol, (a[k] != 1) + f(k + 1, 1));
    return dp[k][p] = sol;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    cin >> s;
    for (int i = 0; i < n; ++i)
        a[i] = s[i] == '#';

    memset(dp, -1, sizeof dp);
    cout << f(0, 2);
}


Measured memory_bytes: 13076
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
using ll = long long;


int main() {
    lli A, B;
    cin >> A >> B;

    if (A + B > A - B) {
        if (A + B > A * B) {
            cout << A + B << endl;
        } else {
            cout << A * B << endl;
        }
    } else {
        if (A - B > A * B) {
            cout << A - B << endl;
        } else {
            cout << A * B << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
from operator import itemgetter

N = input()
N = int(N)

X = []
Y = []
for i in range(N):
    S_x,P_x = input().split()
    X.append(S_x)
    X.append(int(P_x))
    X.append(i+1)
    Y.append(X)
    X = []

Y = sorted(Y,key=itemgetter(1),reverse=True)
Y = sorted(Y,key=itemgetter(0))

for i in range(N):
    print(Y[i][2])


Measured memory_bytes: 3064
#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;

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

inline void fastio () {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
}

#define whats(x) cerr << #x << " = " << (x) << "\n"; 

using LL = long long;
using LD = long double;

const LL INF = LLONG_MAX;
const LL MOD = 998244353;
const LL N = 2e5+1;

LL powm (LL x, LL p, LL m) {
	LL res = 1;
	x %= m;
	while (p) {
		if (p & 1) {
			res = (res * x) % m;
		}
		x = (x * x) % m;
		p >>= 1;
	}
	return res;
}

LL fac[N], invfac[N];

int main() {
	fastio();

	fac[0] = 1;
	for (LL i = 1; i < N; ++i) {
		fac[i] = (fac[i-1] * i) % MOD;
	}

	invfac[N-1] = powm(fac[N-1], MOD-2, MOD);
	for (LL i = N-2; i >= 0; --i) {
		invfac[i] = (invfac[i+1] * (i+1)) % MOD;
	}

	auto binom = [] (const LL& n, const LL& r) -> LL {
		if (n < r) {
			return 0;
		}
		else {
			LL ans = (((fac[n] * invfac[r]) % MOD) * invfac[n-r]) % MOD;
			return ans;
		}
	};

	LL n, m, k;
	cin >> n >> m >> k;

	LL result = 0;
	for (LL j = 0; j <= k; ++j) {
		LL term = (binom(n-1, j) * m) % MOD;
		term = (term * powm(m-1, n-j-1, MOD)) % MOD;
		result = (result + term) % MOD;
	}
	cout << result << "\n";

}

Measured memory_bytes: 6744
$a = <>;
@b = glob<>;
@b = sort {$a <=> $b} @b;
$kati = ($b[0] + $b[1])/2;

for(my $i = 2; $i < $a; $i++){
	$kati = ($kati + $b[$i])/2;
}
print $kati;


Measured memory_bytes: 768
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdlib>  
#include <cmath>
using namespace std;


int main(){
    int n, k;
    string s;
    cin >> n >>k;
    if(n<k){
      cout << 1 <<endl;
    }else if(k == 1){
      cout << 0 << endl;
    }else{
      cout <<n-k <<endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		if(in.nextInt() * in.nextInt() % 2 == 1) {
			System.out.println("Odd");
		}
		else
			System.out.println("Even");
	}

}


Measured memory_bytes: 23764
#!/usr/bin/env python3
import sys

def solve(N: int, P: "List[int]"):
    M = [float('inf')]
    for p in P:
        if p < M[-1]:
            M.append(p)
        else:
            M.append(M[-1])
    return sum(m > p for m, p in zip(M, P))


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, P))

if __name__ == '__main__':
    main()


Measured memory_bytes: 27520
#include<bits/stdc++.h>
using namespace std;
int p[1010],b[10010],t,n;
void OUT(long long v,int i,int j){
	printf("%lld",v);putchar(' ');
}
int main(){
	p[0]=1;
	for(int i=2;i<=7919;++i){
		if(!b[i])p[++t]=i;
		if(t==500)p[++t]=1;
		for(int j=1;j<=t&&i*p[j]<=7919;++j)if(j^501){
			b[i*p[j]]=1;if(i%p[j]==0)break;
		}
	}p[t+1]=1;
	scanf("%d",&n);
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			if(i+j&1){
				OUT(1ll*p[i+j>>1]*p[i+j+1>>1]*p[501+(n+2-j+i>>1)]*p[501+(n-j+i>>1)]+1,i,j);
			}else{
				OUT(p[i+j>>1]*p[501+(n+1-j+i>>1)],i,j);
			}
		}
		putchar('\n');
	}
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;
vi a;

int main(){
	cin>>n>>m;
	a=vi(n);
	int A=0,B=0;
	for(int i=0;i<m;i++){
		int x;
		string s;
		cin>>x>>s;
		x--;
		if(s=="WA") a[x]++;
		else{
			if(a[x]>=0){
				A++;
				B+=a[x];
				a[x]=-inf;
			}
		}
	}
	cout<<A<<' '<<B<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main()
{
    int a,b,c,m,sum;
    scanf("%d%d%d",&a,&b,&c);
    if (a>b) m=a;
    else m=b;
    if (m<c) sum=a+b;
    else if (a>b) sum=b+c;
    else sum=a+c;
    printf("%d",sum);
    return 0;
}


Measured memory_bytes: 128
n,m = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
a = sum(ar)
for i in range(n-1):
    if ar[i] + ar[i+1] > m:
        b = (ar[i] + ar[i+1]) - m
        if ar[i+1] >= b:
            ar[i+1] -= b 
        else:
            ar[i] -= b - ar[i+1]
            ar[i+1] = 0
print(a - sum(ar))

Measured memory_bytes: 14132
// https://atcoder.jp/contests/abc054/tasks/abc054_b
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, n) for (int i = 0; i < n; i++)
#define EACH(i, n) for (auto &i: n)

void solv(int n, int m) {
  vector<string> a, b;

  FOR(i, n) {
    string s;
    getline(cin, s);
    a.push_back(s);
  }
  FOR(i, m) {
    string s;
    getline(cin, s);
    b.push_back(s);
  }

  FOR(i, a.size() - b.size() + 1) {
    FOR(j, a[i].size() - b[0].size() + 1) {
      if (a[i].substr(j, b[0].size()).compare(b[0]) == 0) {
        int k;
        for (k = 1; k < b.size(); k++) {
          if (a[i + k].substr(j, b[0].size()).compare(b[k]) != 0) {
            break;
          }
        }
        if (k == b.size()) {
          cout << "Yes" << endl;
          return;
        }
      }
    }
  }
  cout << "No" << endl;
}

int main() {
  int n, m;

  while (cin >> n >> m) {
    cin.ignore(1);
    solv(n, m);
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int dp[MAX_N];

signed main() {
  INIT;
	VAR(int,n,k);
	VEC(int,h,n);

	fill_n(dp,MAX_N,LINF);
	dp[0] = 0;
	REP(i,n){
		FOR(j,1,k+1){
			if(i-j>=0) {
				dp[i] = min(dp[i], dp[i-j] + abs(h[i]-h[i-j]));
				//debug(i);
				//debug(k);
			}
		}
	}

	REP(i,n){
		debug(dp[i]);
	}
	OUT(dp[n-1])BR;
	
  return 0;
}


Measured memory_bytes: 3456
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    char prev = '\0';
    REP(i, n) {
        if(s[i] != prev) ans++;
        prev = s[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
#include<stdio.h>
int main(void){

	int a,b,c,d;
	int e,f,g,h;
	int goa,gob;

	scanf("%d %d %d %d",&a,&b,&c,&d);
	scanf("%d %d %d %d",&e,&f,&g,&h);

	goa=a+b+c+d; gob=e+f+g+h;

	if(goa>gob) printf("%d\n",goa);
	else printf("%d\n",gob);

	return 0;
}

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

int main(){
    int a, b, c, min;
    cin >> a >> b >> c;
    min = abs(a-b)+abs(a-c);
    if((abs(a-b)+abs(b-c)<min)) min = (abs(a-b) + abs(b-c));
    if((abs(a-c)+abs(b-c)<min)) min = (abs(a-c) + abs(b-c));
    cout << min << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

/*
AC
*/

int main(void){
	ll n,a[100010],ans=0;
	cin>>n;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	if(n%2==0){//中央値２つ
		ll mid=(a[n/2]+a[n/2-1])/2;
		rep(i,n)a[i]-=mid;
		rep(i,n){
			if(i!=n/2&&i!=n/2-1){
				ans+=abs(a[i]);
			}
			ans+=abs(a[i]);
		}
	}else{//中央値１つ
		ll mid=a[n/2],second;
		rep(i,n)a[i]-=mid;
		second=min(abs(a[n/2-1]),abs(a[n/2+1]));
		rep(i,n)ans+=2*abs(a[i]);
		ans-=second;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<algorithm>
struct Query{
    int l,r;
    int id;
};
int a[500005];
Query b[500005];
int bit[500005];
int answer[500005];
std::vector<int>pos[500005];
int minn[500005];

void change(int p,int v,int n){
    while(p<=n){
        bit[p] += v;
        p += p&-p;
    }
}

int ask(int p){
    int res = 0;
    while(p!=0){
        res += bit[p];
        p -= p&-p;
    }
    return res;
}

int main(){
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i = 1; i <= n; i++) scanf("%d",&a[i]);
    for(int i = 1; i <= q; i++) scanf("%d%d",&b[i].l,&b[i].r), b[i].id = i;
    //tail is minn
    for(int i = n; i >= 1; i--){
        pos[a[i]].push_back(i);
    }
    for(int i = 1; i <= n; i++){
        if(pos[i].size()!=0){
            int first = pos[i][pos[i].size()-1];
            change(first,1,n);
        }
    }
    std::sort(b+1,b+1+q,[&](Query &u,Query &v){
        if(u.l!=v.l) return u.l<v.l;
        else return u.r<v.r;
    });
    int lastL = 1;
    int p = 1;
    while(p<=q){
        int np = p;
        while(np+1<=q && b[np+1].l==b[p].l) np++;
        int curL = b[p].l;
        for(int i = lastL; i < curL; i++){
            int c = a[i];
            int lastP = pos[c][pos[c].size()-1];
            pos[c].pop_back();
            change(lastP,-1,n);
            if(pos[c].size()!=0){
                int curP = pos[c][pos[c].size()-1];
                change(curP,1,n);
            }
        }
        lastL = curL;
        for(int i = p; i <= np; i++){
            int upper = b[i].r;
            int res = ask(upper);
            answer[b[i].id] = res;
        }
        p = np+1;
    }
    for(int i = 1; i <= q; i++) printf("%d\n",answer[i]);
    return 0;
}


Measured memory_bytes: 42808
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

int main() {
  string s; cin >> s;

  int result = 0;
  rep(i, s.length()) result += s[i]=='g' ? 1 : -1;
  result /=2;
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k,s;
  cin>>k>>s;
  int count=0;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      if((s-i-j)>=0&&(s-i-j)<=k){
        count++;
      }
    }
  }
  cout<<count;
}


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

int main(){
    int a, b, c, d, e, f;
    while(cin>>a>>b>>c>>d>>e>>f, a+b+c+d+e+f){
        a += d, b += e, c += f;
        int x = 0;
        for(int t = 0; t < 3; t++){
            if(a < t || b < t || c < t)   break;
            x = max(x, t + (a-t)/3 + (b-t)/3 + (c-t)/3);
        }
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 3080
import java.util.*;
public class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                long q = sc.nextLong();
                long h = sc.nextLong();
                long s = sc.nextLong();
                long d = sc.nextLong();
                long n = sc.nextLong();
                sc.close();
                long a = Math.min(q * 4 , Math.min(h * 2 , s));
                long b = Math.min(d , 2 * a);
                long yono = n / 2 * b + (n % 2) * a;
                System.out.println(yono);
        }
}
//にわとりになりたい

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n;
	cin>>n;
	vector<ll> a(n);
	rep(i,n)cin>>a[i];
	vector<ll> plus(n),minus(n);
	map<ll,ll> mp;
	rep(i,n){
		plus[i] = a[i]+(i+1);
		minus[i] = (i+1) - a[i];

		if(mp[plus[i]]==0)mp[plus[i]]=1;
		else mp[plus[i]] += 1;
	}

	ll ans=0;
	repr(i,n-1,0){
		ans += mp[minus[i]];
		mp[plus[i]] -= 1;
	}
	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 30532
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
using namespace std;

int main() {
  int N;
  long long K;
  cin >> N >> K;
  int a[N];
  for(int i=0;i<N;++i) cin >> a[i];
  
  set<int> set;
  vector<int> setV;
  int si;
  int bef=1;
  int bi;
  set.insert(1);
  setV.push_back(1);
  si = set.size();
  while(true){
    bef = a[bef-1];
    set.insert(bef);
    setV.push_back(bef);
    if( si==set.size() ) break;
    si = set.size();
    //cout<<si<<" "<<bef<<endl;
  }
  int i=0;
  while(true){
    if(setV[i]==bef) break;
    //cout<<setV[i]<<endl;
    i++;
  }
  
  if(K<=i) cout<<setV[K]<<endl;
  else{
    K = (K-i)%(si-i);
    cout<<setV[i+K]<<endl;
  }

 
}

Measured memory_bytes: 13892
#include <stdio.h>

int main() {
	
	int x;
	int i = 1;

	while (1) {
		scanf("%d", &x);

		if (x == 0) {
			break;
		}

		printf("Case %d: %d\n", i, x);
		i++;
	}

	return 0;
}



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

#include <boost/range/adaptors.hpp>
#include <boost/range/combine.hpp>
#include <boost/range/irange.hpp>

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

int main() {
    int64_t s, w;
    cin >> s >> w;

    if (w >= s) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
}

Measured memory_bytes: 3616
k = int(input())
from collections import deque
q = deque() # FIFOキューの作成
for i in range(1,10):
    q.append(str(i))


for i in range(k-1):
    a = q.popleft()
    last = int(a[-1:])
    if last == 0:
        q.append(a+"0")
        q.append(a + "1")
    elif last ==9:
        q.append(a+"8")
        q.append(a + "9")
    else:
        q.append(a + str(last - 1))
        q.append(a + str(last ))
        q.append(a + str(last + 1))

print(q.popleft())

Measured memory_bytes: 22524
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define X first
#define Y second
#define MAXN 100010

map<int, int> mp;
vector<int> lis;

ll Solve()
{
    int t = lis.size() - 1;
    while (t >= 0 && mp[lis[t]] == 1)
    	  --t;
    if (t < 0) 
       return 0;
    
    int a = lis[t];
    if (mp[a] >= 4) return 1ll * a * a;
    t--;
    while (t >= 0 && mp[lis[t]] == 1)
    	  --t;
    if (t < 0) 
       return 0;
    int b = lis[t];
    return 1ll * a * b;
}

int main()
{
	//freopen("input", "r", stdin);
	//freopen("output", "w", stdout);
	
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
	{
	    int x;
	    scanf("%d", &x);
	    mp[x]++;
	    lis.push_back(x);
    } 
    sort(lis.begin(), lis.end());
    lis.erase(unique(lis.begin(), lis.end()), lis.end());
    
    cout << Solve() << endl;
 

	
	return 0;
}

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

int main() {
    
    int A, B;
    
    cin >> A >> B;
    
    int result = A + B;
    
    int def = A - B;
    
    if(result < def) {
        result = def;
    }
    
    int kake = A * B;
    
    if(result < kake) {
        result = kake;
    }
    
    cout << result << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N , sum , a;
  cin >> N;
  sum = 0;
  a = 1;
  
  for(int i = 0; i< 9; i++){
    a = 1;
  	for(int j = 0; j< i; j++){
    	a *= 10;
    }
    sum += N % a * 10 / a;
  }
  
  if(N % sum == 0){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
}

Measured memory_bytes: 256
// 01/02/20 // 5:08 PM //

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MAXN = (int)1e2 + 10;
const int MAXK = (int)1e5 + 10;
const int MOD  = (int)1e9 + 7;

int n, k, a[MAXN];
int memo[MAXN][MAXK], prefix[MAXK];

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

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


    for(int i=0; i<=n; i++)            memo[i][0] = 1;
    for(int j=0; j<=k && j<=a[1]; j++) memo[1][j] = 1;

    // i = 1
    prefix[0] = memo[1][0];
    for(int j=1; j<=k; j++) prefix[j] = memo[1][j] + prefix[j-1];

    for(int i=2; i<=n; i++){

        for(int j=1; j<=k; j++){

            if(j<=a[i])
                memo[i][j] = prefix[j]%MOD;
            else
                memo[i][j] = (prefix[j] - prefix[j-a[i]-1] + MOD)%MOD;

            //memo[i][j] = (prefix[j] - prefix[j - min(a[i], j) - 1])%MOD;
        }

        prefix[0] = memo[i][0]%MOD;
        for(int j=1; j<=k; j++)
            prefix[j] = (memo[i][j]%MOD + prefix[j-1])%MOD;
    }

    cout << memo[n][k] << endl;

    return 0;
}


Measured memory_bytes: 79360
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30));
const long long linf = (1LL<<60);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long n;
    cin >> n;
    cout << (n-1)*n/2 << endl;
    return 0;
}



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

int main() {
    int n;
    cin >> n;
    int x[n], l[n];
    for (int i = 0; i < n; i++) cin >> x[i] >> l[i];
    vector<pair<int, int> > v;
    for (int i = 0; i < n; i++) v.push_back({x[i]-l[i], x[i]+l[i]});
    sort(v.begin(), v.end());
    
    int ans = n, e = v[0].second;
    for (int i = 1; i < n; i++) {
        if (e <= v[i].first) e = v[i].second;
        else { ans--; e = min(e, v[i].second); }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
#define ll long long

int main(){
  ll A, B;
  int K;
  cin >> A >> B >> K;
  if(A+K <= B-K+1){
    for(ll i=A; i<A+K; i++)
      cout << i << endl;
    for(ll i=B-K+1; i<=B; i++)
      cout << i << endl;
  } else {
    for(ll i=A; i<=B; i++)
      cout << i << endl;
  }
  return 0;
}


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int n;
int f[100][5][2] = {}, p[100][11] = {};

int solve(string s) {
  if(s.length() < 10) {
    return max(solve(s + '0'), solve(s + '1'));
  }
  rep(i, 0, 10) {
    if(s[i] == '1') break;
    if(i == 9) return -1145141919;
  }
  int ka = 0;
  rep(i, 0, n) {
    int sum = 0;
    rep(j, 0, 5) {
      rep(k, 0, 2) {
        if(s[j * 2 + k] == '1') {
          if(f[i][j][k]) sum++;
        }
      }
    }
    ka += p[i][sum];
  }
  return ka;
}

signed main() {
  cin >> n;
  rep(i, 0, n) rep(j, 0, 5) cin >> f[i][j][0] >> f[i][j][1];
  rep(i, 0, n) rep(j, 0, 11) cin >> p[i][j];
  int ans = 0;
  cout << solve("") << endl;
}


Measured memory_bytes: 256