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

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

vector<ll> factmemo, factmemoInv;
ll factmemoMod = -1;

ll factorial(int n, int M) {
  if (factmemoMod == M) return factmemo[n];
  if (n <= 1) return 1;

  ll res = 1;
  for (int i = 1; i <= n; i++) res = res * i % M;
  return res;
}

ll power(ll k, ll n, int M) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * k % M;
    k = k * k % M;
    n /= 2;
  }
  return res;
}

void initFactorial(int n, int M) {
  factmemo.assign(n + 1, 0);
  factmemoInv.assign(n + 1, 0);
  factmemoMod = M;
  factmemo[0] = 1;
  for (int i = 1; i <= n; i++) factmemo[i] = factmemo[i - 1] * i % M;
  factmemoInv[n] = power(factmemo[n], M - 2, M);
  for (int i = n; i > 0; i--) factmemoInv[i - 1] = factmemoInv[i] * i % M;
}

//nCm nPm nHm (mod M)

/*Combination*/
ll C(int n, int m, int M) {
  if (n < m) return 0;
  if (m == 0 || n == m) return 1;

  if (factmemoMod == M)
    return factmemo[n] * factmemoInv[m] % M * factmemoInv[n - m] % M;

  ll numer = factorial(n, M);
  ll denom = factorial(m, M) * factorial(n - m, M) % M;

  denom = power((int)denom, M - 2, M);

  return numer * denom % M;
}
/*Permutation*/
ll P(int n, int m, int M) {
  if (n < m) return 0;
  if (m == 0) return 1;

  if (factmemoMod == M)
    return factmemo[n] * factmemoInv[n - m] % M;

  ll numer = factorial(n, M);
  ll denom = factorial(n - m, M);

  denom = power((int)denom, M - 2, M);

  return numer * denom % M;
}
/*Combination with Repetitions*/
ll H(int n, int m, int M) {
  if (n == 0 && m == 0) return 1;
  return C(n + m - 1, m, M);
}


int main() {
  int N, K;

  cin >> N >> K;

  initFactorial(N, mod);

  for (int i=1; i<=K; i++) {
    int B = K - i;
    int R = N - K - (i - 1);
    ll ans = 0;

    if (B >= 0 && R >= 0) {
      ans = H(i, B, mod) * H(i+1, R, mod) % mod;
    }

    printf("%lld\n", ans);
  }


  return 0;
}


Measured memory_bytes: 256
mod=10**9+7
import math
import sys
from collections import deque
import heapq
import copy
import itertools
from itertools import permutations
from itertools import combinations
import bisect
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
a=ii()
lst=[[0,0,0]]
for i in range(a):
  x,y,z=mi()
  lst.append([max(lst[i][1],lst[i][2])+x,max(lst[i][0],lst[i][2])+y,max(lst[i][1],lst[i][0])+z])
print(max(lst[-1]))

Measured memory_bytes: 86688
import numpy as np
N = int(input())
H = [int(x) for x in input().split()]

cost = np.full(N, float('inf'))
cost[0] = int(0)
cost[1] = abs(H[0]-H[1])
for i in range(2, N):
    cost[i] = min(abs(H[i]-H[i-1]) + cost[i-1], abs(H[i]-H[i-2]) + cost[i-2])

print(int(cost[N-1]))
    

Measured memory_bytes: 23088
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long A, B;
    scan(A, B);
    lcm(A, B).writeln();

}

T lcm(T)(T a, T b)
{
    return (a * b) / gcd(a, b);
}


Measured memory_bytes: 256
#include <stdio.h>
#define mod 1000000007
#define large 100050

int main()
{
	char s[large];
	scanf("%s", &s);
	int dp[large][13] = {};
	int length = 0;
	for (int i = 0;; i++)
	{
		if (s[i] == '\0')
		{
			length = i;
			break;
		}
	}

	for (int i = 0; i < length; i++)
	{
		if (i == 0) {
			if (s[i] == '?')
			{
				for (int j = 0; j < 10; j++)
					dp[i][j]++;
			}
			else
			{
				dp[i][s[i] - '0']++;
			}

		}
		else
		{
			for (int j = 0; j < 13; j++)
			{
				if (dp[i - 1][j] > 0)
				{
					if (s[i] == '?')
					{
						for (int k = 0; k <10; k++)
						{
							dp[i][(j * 10 + (k)) % 13] += dp[i - 1][j];
							dp[i][(j * 10 + (k)) % 13] %= mod;
						}
					}
					else
					{
						dp[i][(j * 10 + (s[i] - '0')) % 13] += dp[i - 1][j];
						dp[i][(j * 10 + (s[i] - '0')) % 13] %= mod;
					}

				}
			}
		}
	}
	printf("%d\n", dp[length - 1][5]);
}

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


template<typename T>
class Deque{
public:
  T *val;
  int sz;
  int length;
  int head, tail;
  
  Deque(){sz = 0, length = 0, val = new T[0];}
  Deque(int size, T init = T()){
    length = 1;
    while(length < size) length *= 2;
    val = new T[length];
    sz = size;
    head = 0;
    tail = 0;
    for(int i=0;i<size;i++) val[tail++] = init;
  }
  
  Deque(const Deque &t){
    sz = t.size();
    length = 1;
    while(length < sz) length *= 2;
    val = new T[length];
    head = 0;
    tail = 0;
    for(int i=0;i<sz;i++) val[tail++] = t[i];
  }

  ~Deque(){
    delete [] val;
  }
  
  T& operator [] (int i){assert(0 <= i && i < sz);return val[(head + i)%length];}
  T& operator [] (int i)const{assert(0 <= i && i < sz);return val[(head + i)%length];}
  int size()const{return sz;}
  int empty()const{return sz == 0;}

  void resize(int n, T v=T()){
    while(n < size()) pop_back();
    while(n > size()) push_back(v);
  }


  void increaseMemory(){
    int length_ = length;
    
    length = length * 2;
    if(length == 0) length = 1;
    T *val2 = new T[length];
    for(int i=0;i<sz;i++) val2[i] = val[(head + i)%length_];
    head = 0;
    tail = sz;
    delete [] val;
    val = val2;
  };
  
  void push_back(T v){
    if(sz == length) increaseMemory();
    sz++;
    val[tail++] = v;
    if(tail == length) tail = 0;
  }
  
  void push_front(int v){
    if(sz == length) increaseMemory();
    sz++;
    head--;
    if(head == -1) head = length - 1;
    val[head] = v;
  }

  void pop_back(){
    assert(sz > 0);
    sz--;
    tail--;
    if(tail == -1) tail = length - 1;
  }
  
  void pop_front(){
    assert(sz > 0);
    sz--;
    head++;
    if(head == length) head = 0;
  }
};
template <typename T>
using vector = Deque<T>;

int main(){
  int q;
  cin>>q;

  Deque<int> A;
  while(q--){
    int cmd;
    cin>>cmd;

    if(cmd == 0){
      int d, x;
      cin>>d>>x;
      d == 0? (A.push_front(x)): (A.push_back(x));
    }
    if(cmd == 1){
      int p;
      cin>>p;
      cout<<A[p]<<endl;
    }
    if(cmd == 2){
      int d;
      cin>>d;
      d == 0? (A.pop_front()): (A.pop_back()); 
    }
  }
  return 0;
}



Measured memory_bytes: 4804
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  vector<ll> l(n);
  for (int i = 0; i < n; ++i) {
    cin >> l[i];
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      for (int k = j + 1; k < n; ++k) {
        ll sum = l[i] + l[j] + l[k];
        ll mx = max(l[i], max(l[j], l[k]));
        if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i]) {
          if (mx < sum - mx) {
            ans++;
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
import java.util.Scanner;


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

		int N = sc.nextInt();

		int K = sc.nextInt();

		String S = sc.next();

		String[] str = new String[N];

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

			if(i==K-1) {
				if( String.valueOf(S.charAt(i)) .equals( "A")) str[i] = "a";
				else if( String.valueOf(S.charAt(i)).equals( "B"))  str[i] =  "b";
				else if( String.valueOf(S.charAt(i)) .equals( "C"))  str[i] =  "c";
			}
			else {
			str[i] = String.valueOf(S.charAt(i));

			}

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


		System.out.print(str[i]);
		}
	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
typedef pair<int, int> pint;
#define mp make_pair
const ll INF = 1001001001001001001;

int main() {
    int n;
    cin >> n;
    vector<vector<pint>> graph(n, vector<pint>(0));
    for (int i = 0; i < n - 1; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a; --b;
        graph[a].emplace_back(mp(c, b));
        graph[b].emplace_back(mp(c, a));
    }
    int q, k;
    cin >> q >> k;
    --k;
    vector<int> x(q), y(q);
    for (int i = 0; i < q; ++i) {
        cin >> x[i] >> y[i];
        --x[i]; --y[i];
    }
    
    priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> pq;
    vector<ll> dist(n, INF);
    pq.push(mp(0, k));
    dist[k] = 0;
    while (!pq.empty()) {
        pint v = pq.top();
        pq.pop();
        for (pint i : graph[v.second]) {
            if (dist[i.second] > dist[v.second] + i.first) {
                dist[i.second] = dist[v.second] + i.first;
                pq.push(mp(dist[i.second], i.second));
            }
        }
    }
    for (int i = 0; i < q; ++i) {
        cout << dist[x[i]] + dist[y[i]] << endl;
    }
}


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

int main() {
  int A,B;
  cin >> A >> B;
  
  if(A%3==0 || B%3==0 ||(A+B)%3==0){
    cout << "Possible" << endl;
  }
  else{
    cout << "Impossible" << endl;
  }
}


Measured memory_bytes: 256
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    let n = get!();
    let mut ans = 0.0;
    for _ in 0..n {
    	let m = get!(f64);
        let s = get();
        if s == "JPY" {
        	ans += m;
        } else {
        	ans += m * 380000.0;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
def resolve():
    a, b, c = map(int, input().split())
    if a == b and a != c:
        print("Yes")
    elif a == c and a != b:
        print("Yes")
    elif b == c and a != b:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 3060
import java.util.*;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[][] ab = new int[n][2];

		for (int i = 0; i < n; i++) {
			ab[i][0] = sc.nextInt();
			ab[i][1] = sc.nextInt();
		}
		Arrays.sort(ab, (x, y) -> x[0] - y[0]);
		PriorityQueue<Integer> q = new PriorityQueue<>((o1, o2) -> o2 - o1);

		int sum = 0;

		int index = 0;
		for (int i = 1; i <= m; i++) {
			while (index < n && ab[index][0] <= i) {
				q.add(ab[index][1]);
				index++;
			}

			if (q.size() != 0) {
				sum += (int) q.poll();
			}
		}

		System.out.println(sum);

		sc.close();

	}
}

Measured memory_bytes: 94712
#include<iostream>
using namespace std;
int main() {
	int n,k,x,y;
	x = 1;
	cin >> n >> k;
	for (y = 0; y < n - 1; y++) {
		x = x*(k - 1);
	}
	x = x*k;
	cout << x;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)
#define all(v) v.begin(), v.end()
#define rall(x) (x).rbegin(), (x).rend()
#define pll pair<long long, long long>
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define vc vector<char>
#define vvc vector<vc>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vvb = vector<vb>;
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;}
//snippets:tmp,cl,cvl,cs,co,coy,con,cov,setp

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin >> n;
  vll a(n);
  rep(i, n) cin >> a[i];
  vll b(n);
  rep(i, n) cin >> b[i];
  ll ind=-1;
  reverse(all(b));
  rep(i,n){
    if(a[i]==b[i]){
      ind=i;
      break;
    }
  }
  if(ind==-1){
    cout<<"Yes"<<endl;
    rep(i,n) cout<<b[i]<<" ";
    cout<<endl;
    return 0;
  }
  bool flag=false;
  ll count=0;
  ll mi,ma;
  ll start=100000;
  rep(i,n){
    if(a[i]==a[ind]||b[i]==b[ind]){
      if(!flag){
        mi=i;
        flag=true;
      }
      ma=i;
    }
    if(a[i]==a[ind]&&b[i]==b[ind]){
      count++;
    }
  }
  if(count>(n-(ma-mi+1))) cout<<"No"<<endl;
  else{
    rep(i,count){
      if(i<mi) swap(b[i],b[ind+i]);
      else swap(b[ma+1+i-mi],b[ind+i]);

    }
    cout<<"Yes"<<endl;
    rep(i,n) cout<<b[i]<<" ";
    cout<<endl;
  }
}


Measured memory_bytes: 6312
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	prices := scanIntSlice(n)
	sort.Ints(prices)

	sum := 0
	for i := 0; i < k; i++ {
		sum += prices[i]
	}

	fmt.Printf("%d\n", sum)
}

func scanIntSlice(size int) []int {
	input := []int{}
	for i := 0; i < size; i++ {
		var in int
		fmt.Scanf("%d", &in)
		input = append(input, in)
	}
	return input
}


Measured memory_bytes: 1928
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define itr(a) begin(a), end(a)
#define pb push_back
#define x first
#define y second
#define endl '\n'

#define FAST cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

#ifndef __LOCAL
#define FILES(namein, nameout) freopen(namein, "r", stdin); freopen(nameout, "w", stdout); FAST;
#else
#define FILES(namein, nameout) FAST;
#endif //__LOCAL

using namespace std;
using namespace __gnu_pbds;
using python = void;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned short uss;
typedef pair<ll, ll> pll;
typedef tree<ll, null_type> ordered_set;

const ll M = 1e9+7;
const ll N = 2e5+228;
constexpr ll inf = 0x3f3f3f3f3f3f3f3f;
pll a[N];
ll fwt[N];
void fwinc(ll pos, ll delta){
	for(;pos<N;pos+=pos&-pos) fwt[pos] += delta;
}
ll fwsum(ll r, ll s = 0){
	for(;r>0;r-=r&-r) s+=fwt[r]; 
	return s;
}

python solve(){
	FAST;
	ll n, d, sub;
	cin >> n >> d >> sub;
	for(ll i =0;i<n;i++) cin >> a[i].x >> a[i].y;
	sort(a, a+n);
	a[n] = {inf, inf};
	ll mlp = 0, sres = 0;
	while(mlp < n){
		while(a[mlp].y-fwsum(mlp+1) <= 0) ++mlp;
		if(mlp == n) continue;
		a[mlp].y-=fwsum(mlp+1);
		ll dd = a[mlp].y/sub + (a[mlp].y%sub ? 1 : 0);
		sres += dd;
		fwinc(mlp+1, dd*sub);
		ll l = 0, r = n-1;
		while(r-l>1){
			ll m = (l+r)>>1;
			if(a[m].x <= a[mlp].x+2*d) l = m;
			else r = m;
		}
		ll xrs = 0;
		for(ll m = l;m<=r;m++) if(a[m].x <= a[mlp].x+2*d) xrs = m;
		fwinc(xrs+2, -dd*sub);
		++mlp;
	}
	cout << sres << '\x0a';
}

signed main(){
	FAST;
	ll q = 1;
	//cin >> q;
	while(q--){
		solve();
	}
}

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

int main()
{

    long long int a,b,n;
    while(~scanf("%lld",&a))
    {
        if(a%2==0)
            printf("%lld\n",a);
        if(a%2!=0)
            printf("%lld\n",2*a);

    }
    return 0;
}


Measured memory_bytes: 128
"use strict";

function main(input) {
    const args = input.split(' ');
    const a = Number(args[0]);
    const b = Number(args[1])

    if ((a * b) % 2 === 0) {
        console.log('Even');
    } else {
        console.log('Odd');
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> v1,v2,u;
ll n,k,a,cnt1,cnt2,N,MOD=1000000007,ans=1;
int main(void){
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a;
        if(a<0){
            cnt2++;
            v2.push_back(-a);
        }
        else{
            cnt1++;
            v1.push_back(a);
        }
    }
    if(cnt2%2==1)N=cnt2-1;
    else N=cnt2;
    if(N+cnt1<k||((cnt1==0)&&(k%2==1))){
        for(int i=0;i<cnt2;i++){
            v1.push_back(v2[i]);
        }
        sort(v1.begin(),v1.end());
        for(int i=0;i<k;i++){
            ans*=v1[i];
            ans%=MOD;
        }
        ans=-ans;
        cout<<(ans+MOD)%MOD<<endl;
        return 0;
    }
    else{
        if(k%2==0){
            sort(v1.begin(),v1.end());
            sort(v2.begin(),v2.end());
            reverse(v1.begin(),v1.end());
            reverse(v2.begin(),v2.end());
            for(int i=0;i<cnt1/2;i++){
                u.push_back(v1[i*2]*v1[i*2+1]);
            }
            for(int i=0;i<cnt2/2;i++){
                u.push_back(v2[i*2]*v2[i*2+1]);
            }
            sort(u.begin(),u.end());
            reverse(u.begin(),u.end());
            for(int i=0;i<k/2;i++){
                ans*=(u[i]%MOD);
                ans%=MOD;
            }
            cout<<ans<<endl;
            return 0;
        }
        else{
            sort(v1.begin(),v1.end());
            sort(v2.begin(),v2.end());
            reverse(v1.begin(),v1.end());
            reverse(v2.begin(),v2.end());
            ans*=v1[0];
            for(int i=0;i<(cnt1-1)/2;i++){
                u.push_back(v1[i*2+1]*v1[i*2+2]);
            }
            
            for(int i=0;i<cnt2/2;i++){
                u.push_back(v2[i*2]*v2[i*2+1]);
            }
            sort(u.begin(),u.end());
            reverse(u.begin(),u.end());
            for(int i=0;i<k/2;i++){
                ans*=(u[i]%MOD);
                ans%=MOD;
            }
            cout<<ans<<endl;
            return 0;
        }
    }
    
}


Measured memory_bytes: 6576
from functools import reduce

n = int(input())

t = [int(input()) for _ in range(n)]

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

t.sort()

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list(t))


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

void Main() {
    // input
    int N;
    cin >> N;
    u_int64_t MAX = 1000000000000000000;

    u_int64_t ans = 1;
    bool flag = true;
    for (int i = 0; i < N; i++) {
        u_int64_t num;
        cin >> num;
        
        if (num == 0) {
            cout << 0 << endl;
            return ;
        }

        if (flag) {
            if (ans > MAX / num) {
                ans = 0;
                flag = false;
            }
            ans *= num;
        }
        
    }

    if (!flag) {
        cout << -1 << endl;
        return ;
    }
    cout << ans << endl;

    // translate


    // output

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<set>
#include<vector>
#include<map>
#include<queue>

#define N 300005
#define M 8000005

#define ls (t<<1)
#define rs ((t<<1)|1)
#define mid ((l+r)>>1)

#define mk make_pair
#define pb push_back
#define fi first
#define se second

using namespace std;

int i,j,m,n,p,k,Q,H,S,D;

int main()
{
		scanf("%d%d%d%d%d",&Q,&H,&S,&D,&n); 
		H=min(H,2*Q);
		S=min(S,2*H);
		D=min(D,2*S);
		cout<<1ll*(n/2)*D+(n%2)*S<<endl;
}


Measured memory_bytes: 768
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

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

	set<int> a;

	for (int i = 0; i < n; i++) {
		int buf; cin >> buf;

		if (a.find(buf) != a.end()) {
			a.erase(buf);
		}
		else {
			a.insert(buf);
		}
	}

	cout << a.size() << endl;
}

Measured memory_bytes: 4864
S = input()

mae = int(S[:2])
ato = int(S[2:])

mae_f = 0

if mae >= 1 and mae <=12:
    mae_f = 1

ato_f = 0

if ato >= 1 and ato <=12:
    ato_f = 1
    
if mae_f == 0 and ato_f == 0:
    print('NA')
elif mae_f == 1 and ato_f == 1:
    print('AMBIGUOUS')
elif mae_f == 0:
    print('YYMM')
else:
    print('MMYY')


Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
    // Your code here!
    char c[3];
    scanf("%s",c);
   
    if (c[0] == 'S'){
        if (c[1] == 'U'){printf("7");}
        if (c[1] == 'A'){printf("1");}
    }
    else if (c[0] == 'M'){
        printf("6");
    }
    else if (c[0] == 'T'){
        if (c[1] == 'U'){printf("5");}
        if (c[1] == 'H'){printf("3");}
    }
    else if (c[0] == 'W'){
        printf("4");
    }
   
    else if (c[0] == 'F'){
        printf("2");
    }
return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<vector>
#include<map>
#include<algorithm>
#include<functional>
#include<iterator>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


struct v_t
{
	int p;
	vi c;
};


using vvt=vector<v_t>;


void vmove(vvt&v, int a, int b)
{
	for(int mbc:v[b].c)
	{
		v[mbc].p=a;
	}
	copy(v[b].c.begin(), v[b].c.end(), back_inserter(v[a].c));
	v[b].c.clear();
}


ll uni(vvt&v, ll ans, int n, int a, int b)
{
	if(v[a].p==v[b].p) return ans;

	ll an=v[v[a].p].c.size();
	ll bn=v[v[b].p].c.size();

	if(an<bn) swap(a, b);
	vmove(v, v[a].p, v[b].p);
	return ans-an*(n-an)-bn*(n-bn)+(an+bn)*(n-(an+bn));
}


int main(void)
{
	int n, m;

	while(scanf("%d%d", &n, &m)==2)
	{
		vi a(m), b(m);
		vector<v_t> v(n+1);
		vll ans(m+1);

		for(int i=1;i<=n;i++)
		{
			v[i].p=i;
			v[i].c.push_back(i);
		}

		for(int i=0;i<m;i++)
		{
			scanf("%d%d", &a[i], &b[i]);
		}

		ans[m]=(ll)n*(n-1);
		for(int i=m-1;i>=0;i--)
		{
			ans[i]=ans[i+1];
			ans[i]=uni(v, ans[i+1], n, a[i], b[i]);
		}
		for(int i=1;i<=m;i++)
		{
			printf("%lld\n", ans[i]/2);
		}
	}

	return 0;
}


Measured memory_bytes: 12920
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int A[100001];

int main() {
  int n;
  S(n);
  int mx = 0;
  rep(i,0,n) {
    S(A[i]);
    mx = max(mx, A[i]);
  }
  double tmp = mx * 0.5;
  int num2 = mx;
  rep(i,0,n) if(A[i] != mx) {
    if(abs(A[i] - tmp) <= abs(num2 - tmp)) {
      num2 = A[i];
    }
  }
  printf("%d %d\n",mx,num2);
  return 0;
}


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

long long fastpow(long long x, long long y, long long m) {
    if(!y) return 1;
    long long ret = fastpow(x, y/2, m);
    if(y&1) return (x * ret * ret)%m;
    else return (ret * ret)%m;
}

long long solve(long long mid, vector<int> &vec) {
    long long ret = 0;
    for(int i = 0; i < (int) vec.size(); i++) ret += abs(vec[i] - (mid + i + 1));
    return ret;
}

long long ts(vector<int> &vec) {
    long long lo = -1e9-5, hi = 1e9+5, mid;
    while(lo < hi) {
        mid = (lo + hi) >> 1LL;
        if(solve(mid, vec) < solve(mid+1, vec)) {
            hi = mid;
        }
        else {
            lo = mid+1;
        }
    }
    return solve(lo, vec);
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    int n; cin >> n;
    vector<int> vec(n);
    for(int i = 0; i < n; i++) cin >> vec[i];
    cout << ts(vec);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define Rall(x) (x).rbegin(),(x).rend()
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
using namespace std;

ll gcd(ll a, ll b) {
  if(a==0) return b;
  if(a>b) return gcd(a%b, b);
  else return gcd(b%a, a);
}


int main(){
  ll N;
  cin >> N;
  vector<ll> a(N),l(N+2),r(N+2);
  rep(i,N){
    cin >> a[i];
  }
  l[0] = 1;
  l[1] = a[0];
  for(ll i=2;i<=N;i++){
    l[i] = gcd(l[i-1],a[i-1]);
  }

  r[N] = 1;
  r[N-1] = a[N-1];
  for(ll i=N-2;i>=0;i--){
    r[i] = gcd(r[i+1],a[i]);
  }
  ll max = r[0];
  for(ll i=0;i<N;i++){
    if(i==0){
      if(max<r[i+1]) max = r[i+1];
    }
    if(i==N-1){
      if(max<l[i]) max = l[i];
    }
    if(max<gcd(l[i],r[i+1])){
      max = gcd(l[i],r[i+1]);
    }
    //cout << l[i] << " " << r[i+1] << endl;
  }
  cout << max << endl;
}


Measured memory_bytes: 2560
#include <stdio.h>
 
int main (){
	char s[255];
	scanf("%[^\n]", s);
	for (int i= 0; s[i] != '\0'; i++){
		if (s[i] >='a' && s[i]<= 'z'){
			printf("%c", s[i]);
		}else{
			printf(" ");
		}
	}
	puts("");
 
	return 0;
}

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

double standard_deviation(int a[],double ave,int n){
    double ave_d = 0.0;
    for(int i=0;i<n;i++){
        ave_d += pow(a[i]-ave,2);//データの加算
    }
    return ave_d / n; //対象の分散を返す
}

double average(int a[],int n){
    double ave=0;
    for(int i=0;i<n;i++){
        ave += a[i];
    }
    return ave/n; //対象の平均値を返す
}

int main() {
    int tm = clock();
    int n;
    cin >> n;
    while(true){
        int score[n];
        for(int i=0;i<n;i++)
            cin >> score[i];
        cout << fixed << sqrt(standard_deviation(score,average(score,n),n)) <<endl;

        cin >> n;
        if(n == 0)
            break;
    }
    //printf("Execution Time: %.10lf sec\n", 1.0 * (clock() - tm) / CLOCKS_PER_SEC);
}



Measured memory_bytes: 3256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;



int main()
{
    fastInp;

    ll n;
    cin >> n;
    string s;
    cin >> s;

    ll ans = 0;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            for (int k = 0; k < 10; k++) {
                ll curPos = 0;
                for (int t = 0; t < s.size(); t++) {
                    if (curPos == 3) continue;

                    if (curPos == 0) {
                        if (s[t] - '0' == i) curPos++;
                    } else if (curPos == 1) {
                        if (s[t] - '0' == j) curPos++;
                    } else {
                        if (s[t] - '0' == k) curPos++;
                    }
                }

                if (curPos == 3) ans++;
            }
        }
    }

    cout << ans;

    return 0;
}

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

int main() {
  int a,b,c; cin>>a>>b>>c;
  bool ka=false;
  if (a==b && a!=c) ka=true;
  if (b==c && a!=c) ka=true;
  if (a==c && a!=b) ka=true;
  if (ka) cout<<"Yes"<<endl;
  else cout<<"No"<<endl; 
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, L;
  cin >> n >> L;
  int yo = 0, ans = INT_MAX, prin = 0;
  for (int i = 1; i <= n; i++) {
    int tmp = i + L - 1;
    yo += tmp;
  }
  for (int i = 1; i <= n; i++) {
    int bo = 0;
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      int tmp = j + L - 1;
      bo += tmp;
    }
    if (abs(yo - bo) < ans) {
      prin = bo;
      ans = abs(yo - bo);
    }
  }
  cout << prin;
  return 0;
}


Measured memory_bytes: 256
h, w = map(int, input().split())

if h == 1 and w == 1:
    ans = 1
elif h == 2 or w == 2:
    ans = 0
elif h == 1 or w == 1:
        if h == 1:
            ans = w - 2
        else:
            ans = h - 2
else:
    ans = (h - 2) * (w - 2)
            
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
#define INF __INT32_MAX__

int main() {
    int N;
    cin >> N;
    vl A(N);
    vl sum(N);
    rep(i, N) {
        cin >> A[i];
        sum[i] = A[i];
    }
    for (int i = 1; i < N; i++) {
        sum[i] += sum[i - 1];
    }

    // +-+-+-...のパターン
    ll div1 = 0;
    ll cnt1 = 0;
    for (int i = 0; i < N; i++) {
        ll x = sum[i] + div1;
        // +
        if (i % 2 == 0) {
            if (x <= 0) {
                div1 += (1 - x);
                cnt1 += (1 - x);
            }
        }
        // -
        else {
            if (x >= 0) {
                div1 -= (1 + x);
                cnt1 += (1 + x);
            }
        }
    }

    // -+-+-+...のパターン
    ll div2 = 0;
    ll cnt2 = 0;
    for (int i = 0; i < N; i++) {
        ll x = sum[i] + div2;
        // +
        if (i % 2 == 1) {
            if (x <= 0) {
                div2 += (1 - x);
                cnt2 += (1 - x);
            }
        }
        // -
        else {
            if (x >= 0) {
                div2 -= (1 + x);
                cnt2 += (1 + x);
            }
        }
    }

    cout << min(cnt1, cnt2) << endl;
}

Measured memory_bytes: 4816
import * as fs from 'fs';

const readString = (() => {
  const input = fs.readFileSync(0).toString();
  const words = input.split(/[ \n]/);
  let i = 0;
  return () => words[i++] || '';
})();
const readInt = () => parseInt(readString(), 10);

(function main() {
  const N = readInt();
  const M = readInt();
  const routes: { [n: number]: number[] } = {}
  const pairs = Array.from({ length: M }, () => {
    const A = readInt();
    const B = readInt();
    routes[A] = routes[A] || [];
    routes[A].push(B);
    routes[B] = routes[B] || [];
    routes[B].push(A);
  });
  const depth: { [n: number]: number } = { 1: 1 };
  const parent: { [n: number]: number } = {};
  const paths: number[] = [1];
  while (true) {
    const n = paths.pop();
    if (n == null) break;

    const rs = routes[n];
    for (const r of rs) {
      if (depth[r] == null) {
        depth[r] = depth[n] + 1;
        parent[r] = n;
        paths.unshift(r);
      }
    }
  }

  console.log('Yes');
  for (let i = 2; i <= N; i++) {
    console.log(parent[i]);
  }
})();


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

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

  int ans = s.size();

  for (int i = 0; i < 2; i++) {
    int cnt = 0;
    for (int j = 0; j < s.size(); j++) {
      if (j % 2 == 0 && s[j] != (char)(i + '0')) cnt++;
      if (j % 2 == 1 && s[j] == (char)(i + '0')) cnt++;
    }

    ans = min(ans, cnt);
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    int x, y, a, b, c, tmp;
    ll ans = 0;
    sc(x), sc(y), sc(a), sc(b), sc(c);
    vector<P> v(a+b+c);
    rep(i, 0, a) sc(v[i].first), v[i].second = 0;
    rep(i, a, a+b) sc(v[i].first), v[i].second = 1;
    rep(i, a+b, a+b+c) sc(v[i].first), v[i].second = 2;
    sort(v.begin(), v.end(), greater<P>());
    int cx = 0, cy = 0, cz = 0;
    rep(i, 0, a+b+c){
        if (v[i].second==0){
            if (cx==x) continue;
            cx++;
        }else if (v[i].second==1){
            if (cy==y) continue;
            cy++;
        }else cz++;
        ans += v[i].first;
        if (cx+cy+cz == x+y) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
import sys
import copy
import math
import itertools
import numpy as np
l = [int(c) for c in input().split()]
a = l[0]
b = l[1]
if a*b <= 0:
    print("Zero")
elif a > 0 and b > 0:
    print("Positive")
else:
    if abs(b-a)%2==1:
        print("Positive")
    else:
        print("Negative")


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

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

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define ll long long
#define ld long double
#define endl "\n"
#define ff first
#define ss second

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}

template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}

void _print() {cerr << "]\n";}

template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...) 20
#endif

ll power(ll a,ll b,ll m=1e9+7)
{
    a%=m;
    if(b==1)
    return a;
    if(b==0)
    return 1;
    ll ret=power(a,b/2);
    ret=(ret%m*ret%m)%m;
    if(b&1)
    ret=(ret%m*a%m)%m;
    return ret;
}

ll lcm(ll a,ll b)
{
    return (a*b)/(__gcd(a,b));
}

const int N=2e5;
ll dp[N],vis[N];
vector<ll> e[N];

ll dfs(ll u)
{
    vis[u]=1;
    for(auto k:e[u])
    {
        if(dp[k])
        {
            dp[u]=max(dp[u],dp[k]+1);
            continue;
        }
        ll ans=0;
        ans=dfs(k);
        dp[u]=max(dp[u],ans+1);
    }
    return dp[u];
}

void solve()
{
    ll n,m,i;
    cin>>n>>m;
    memset(dp,0,sizeof(dp));
    memset(vis,0,sizeof(vis));
    for(i=0;i<m;i++)
    {
        ll u,v;
        cin>>u>>v;
        e[u].pb(v);
    }
    for(i=1;i<=n;i++)
    {
        if(!vis[i])
        dfs(i);
    }
    ll ans=-1;
    for(i=1;i<=n;i++)
    {
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
}

int main()
{
    make_it_fast;
    int TEST_CASES=1;
    // cin>>TEST_CASES;
    while(TEST_CASES--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 16548
package main

import (
	"bufio"
	"container/heap"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	h, _ := sc.NextInt()
	w, _ := sc.NextInt()
	k, _ := sc.NextInt()
	x1, _ := sc.NextInt()
	y1, _ := sc.NextInt()
	x2, _ := sc.NextInt()
	y2, _ := sc.NextInt()
	stage := make([]string, h)
	for i := 0; i < h; i++ {
		sc.Scan()
		stage[i] = sc.Text()
	}
	ans := solve(h, w, k, x1-1, y1-1, x2-1, y2-1, stage)
	fmt.Println(ans)
}

type state struct {
	x, y, dist int
}

type priorityQueue []*state

func (p priorityQueue) Len() int            { return len(p) }
func (p priorityQueue) Less(i, j int) bool  { return p[i].dist < p[j].dist }
func (p priorityQueue) Swap(i, j int)       { p[i], p[j] = p[j], p[i] }
func (p *priorityQueue) Push(x interface{}) { *p = append(*p, x.(*state)) }
func (p *priorityQueue) Pop() interface{} {
	x := (*p)[len(*p)-1]
	*p = (*p)[:len(*p)-1]
	return x
}

var inf = math.MaxInt64
var dxs, dys = []int{0, 0, -1, 1}, []int{-1, 1, 0, 0}

func solve(h, w, k, x1, y1, x2, y2 int, stage []string) int {
	dists := make([][]int, h)
	for x := range dists {
		dists[x] = make([]int, w)
		for y := range dists[x] {
			dists[x][y] = inf
		}
	}

	dists[x1][y1] = 0
	q := priorityQueue{}
	s := &state{x1, y1, 0}
	heap.Push(&q, s)
	for len(q) > 0 {
		p := heap.Pop(&q).(*state)
		if p.x == x2 && p.y == y2 {
			return p.dist
		}
		for d := range dxs {
			for i := 1; i <= k; i++ {
				x, y := p.x+i*dxs[d], p.y+i*dys[d]
				if x < 0 || h <= x || y < 0 || w <= y {
					break
				}
				if stage[x][y] == '@' {
					break
				}
				dist := p.dist + 1
				if dist > dists[x][y] {
					break
				}
				if dist == dists[x][y] {
					continue
				}
				dists[x][y] = dist
				s := &state{x, y, dist}
				heap.Push(&q, s)
			}

		}
	}
	if dists[x2][y2] == inf {
		return -1
	}
	return dists[x2][y2]
}

// Scanner is a wrapper of bufio.Scanner which is customized for competitive programing.
type Scanner struct {
	bufio.Scanner
}

// NewScanner is a constructor for Scanner.
func NewScanner(r io.Reader) *Scanner {
	sc := Scanner{*bufio.NewScanner(r)}
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)
	return &sc
}

// NextInt reads a integer from io stream.
func (sc *Scanner) NextInt() (int, error) {
	if !sc.Scan() {
		return -1, errors.New("failed to scan")
	}
	return strconv.Atoi(sc.Text())
}


Measured memory_bytes: 27772
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;

int main(){

    int N;
    long long mul = 1;
    vector<long long> A;
    bool hasZero = false;

    cin >> N;
    A.resize(N);
    for (int i = 0; i < N; i++){
        long long n;
        cin >> n;
        if(n == 0){
            hasZero = true;
        }
        A[i] = n;
    }

    if(hasZero){
        cout << 0 << endl;
        return 0;
    }else{
        for (int i = 0; i < N; i++){
            if(A[i] > (1000000000000000000/mul)){
                cout << -1 << endl;
                return 0;
            }
            mul *= A[i];
        }
        cout << mul << endl;
    }
}

Measured memory_bytes: 3928
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); 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; }

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, Q;
    cin >> N >> Q;
    vvc<ll> E(N);
    rep(i,N-1){
        ll a,b;
        cin>>a>>b;
        a--, b--;
        E[a].eb(b);
        E[b].eb(a);
    }
    vl cnt(N);
    rep(i,Q){
        ll p, x;
        cin >> p >> x;
        p--;
        cnt[p] += x;
    }

    queue<ll> q;
    q.emplace(0);
    vc<bool> used(N);
    while(!q.empty()){
        ll v = q.front();
        q.pop();
        used[v] = true;
        for(auto to:E[v]){
            if (used[to]) continue;
            cnt[to] += cnt[v];
            q.emplace(to);
        }
    }
    rep(i, N) cout << cnt[i] << " ";
    cout << endl;

}

Measured memory_bytes: 17904
#ABC094-C
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
n=I()
X=IL()
Y=sorted(X)
for i in range(n):
    if X[i]<=Y[n//2-1]:
        print(Y[n//2])
    else:
        print(Y[n//2-1])

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

int two = 0, four = 0;

int main()
{
  int n, a;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a;
    if(a % 4 == 0) four++;
    else if(a % 2 == 0) two++;
  }

  int cnt = two / 2;
  cnt *= 2;
  cnt += four * 2;
  if(four) cnt++;

  cout << (cnt >= n ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int main(){
  int n,m,k,ans=0;
  int i,j,l;
  vector <int> v;
  
  cin>>n>>m;
  
  for(i=0;i<m+1;i++)
    v.push_back(0);
  
  for(i=0;i<n;i++){
    cin>>k;
    for(j=0;j<k;j++){
      cin>>l;
      v[l]+=1;
    }
  }
  
  for(i=1;i<m+1;i++){
    if(v[i]==n)
      ans++;
  }
  cout<<ans<<endl;
  return 0;
  
}

Measured memory_bytes: 256
def solve2 s,t,ss
  
  ss.times do |i|
    
    return "GREATER" if s[i] > t[i]
    return "LESS" if s[i] < t[i]
  end
  return "EQUAL"
end

def solve s,t
  
  ss = s.size
  ts = t.size
  
  if ss == ts
    return solve2 s,t,ss
  elsif  ss > ts
    return "GREATER"
  else 
    return "LESS"
  end
end

A = gets.chomp
B = gets.chomp

puts solve A, B


Measured memory_bytes: 1788
// problem.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

//#include "stdafx.h"

#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
using namespace std;
typedef pair<int, int> P;

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

ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

int main()
{
    ll N, M; cin >> N >> M;
    string S, T; cin >> S >> T;
    ll L = lcm(N, M);
    bool ok = true;
    ll g = gcd(N, M);
    ll n = N / g;
    ll m = M / g;
    for (ll i = 0; i < g; i++) {
        ll a = n * i; ll b = m * i;
        if (S[a] != T[b]) {
            ok = false; 
            break;
        }
    }

    ll ans = ok ? L : -1;
    cout << ans << endl;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int solve(){
  ll K,A,B;
  cin >> K >> A >> B;
  if(A >= B){
    cout << K + 1 << endl;
    return 0;
  }
  if(K < A || B - A == 1){
    cout << K + 1 << endl;
    return 0;
  }
  ll now_B = A;
  K -= A - 1;
  if(K % 2 == 0){
    cout << now_B + (K / 2) * (B - A) << endl;
  }
  else{
    K--;
    cout << now_B + (K / 2) * (B - A) + 1<< endl;
  }
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
} 

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cmath>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <numeric>

using namespace std;

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

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

int n;
ll k;
const int Maxn = 100010;
ll a[Maxn];

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

    bool flag = false;
    ll digits = 0;
    for (int i = 50; i >= 0; --i) {
        ll mask = 1LL << i;
        if ((k & mask) || flag) {
            int num = 0;
            for (int j = 0; j < n; ++j) {
                if (!(mask & a[j])) ++num;
            }
            if (num > n - num) digits += mask;
            else flag = true;

        }
    }

    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += digits ^ a[i];
    }
    cout << ans << endl;
}

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

int main() {
	int n;
	vector<int> d;
	cin >> n;

	for(int i = 0;i<n;i++){
		int a;
		cin >> a;
		d.push_back(a);
	}

	sort(d.begin(),d.end());
	int h = d.size()/2;
	int v=d[h]-d[h-1];
	int ans=v;

	cout << ans;
}

Measured memory_bytes: 892
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String BallPlace = "A";
        while (sc.hasNext()){
            String Ball[] = sc.nextLine().split(",");
            if (Ball[0].equals(BallPlace)) {
                BallPlace = Ball[1];
            }else if (Ball[1].equals(BallPlace)){
                BallPlace = Ball[0];

            }

        }
        System.out.println(BallPlace);
    }
}

Measured memory_bytes: 17160
#include <stdio.h>

int main()
{
	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	int ans = 0;
	for(int i = 1; i <= n; i++) 
	{
		int temp = i;
		int total = 0;
 
		while(temp > 0) 
		{
			total += temp % 10;
			temp /= 10;
		}
 
		if(total >= a && total <= b) 
		{
			ans += i;
		}
	}
 
	printf("%d\n", ans);
	return 0;
} 

Measured memory_bytes: 1712
#include <bits/stdc++.h>
#define endl '\n'
#define _USE_MATH_DEFINES
using namespace std;

int main() {
	
	ios::sync_with_stdio(false);
    cin.tie(0);
    
    double ans = 0;
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    int bd = m*6;
    double ad = h*30 + m*0.5;
    double d;
    if(ad>bd) d = ad - bd;
    else d = bd - ad;
    if(d>180) d = 360 - d;
//    cout<<d;
    if(d == 180) ans = a+b;
    else {
    	ans = a*a+b*b - 2*a*b*cos(d*(M_PI/180));
    	//cout<<"123";
    	ans = pow(ans,0.5);
	}
    
    cout<<setprecision(21)<<ans;
    
    
	return 0;
}

Measured memory_bytes: 4316