akhauriyash/Code-Regression huggingface dataset:
// vim: foldmethod=marker
#include <iostream> // cout, endl, cin{{{
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
typedef long long ll;/*}}}*/

int main(int argc, char *argv[])
{
  int n;
  ll A[200000];
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> A[i];

  int ans = 0;
  int c = 1;

  for (int i = 0; i < n; ++i) {
    if (A[i] != c) {
      ans++;
    } else {
      c++;
    }
  }

  if (c == 1 && n != 1) {
    ans = -1;
  }

  cout << ans << endl;
}


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

int main(void) {
    ll N; cin >> N;
    string S; cin >> S;
    ll r=0,g=0,b=0;
    for(int i=0; i<N; i++) {
        if(S[i]=='R') r++;
        if(S[i]=='G') g++;
        if(S[i]=='B') b++;
    }
    ll sum = r*g*b;
    ll count = 0;
    for(ll i=0; i<N; i++) {
        for(ll j=i+1; j<N; j++) {
                ll k=2*j-i;
                if(k<N) {
                    if(S[i]!=S[j] && S[i]!=S[k] && S[j]!=S[k]) {
                    //cout << " i:" << i << " j:" << j << " k:" << k << endl; 
                    count++;
                    }
                }
            }
        }
    cout << sum-count << endl;
}

Measured memory_bytes: 3592
while True:
	m,f,r = map(int,input().split())
	s=m+f
	if r >= 50:
		print('C')
	elif (m == -1) or (f == -1) :
		if(m+f+r == -3):
			break
		else:
			print('F')
	elif s >= 80 :
		print('A')
	elif ((s>=65)&(s<80)):
		print('B')
	elif (s>=50 and s<65):
		print('C')
	elif (s>=30 and s<50):
		print('D')
	elif (s<30):
		print('F')



Measured memory_bytes: 5596
from collections import*
q=deque([(1,1)])
k=int(input())
m={}
while q:
 n,s=q.pop()
 if(n in m)-1:m[n]=s;q+=(n*10%k,s),;q.appendleft((-~n%k,s+1))
print(m[0])

Measured memory_bytes: 24316
import itertools
def ABC123B():
    T = [int(input()) for _ in range(5)]
    templist = itertools.permutations(T)
    mint = 644
    for l in templist:
        time = 0

        for t in l:
            if time % 10 !=0:
                time += 10 - time % 10
            time += t
        mint = min(mint, time)
    print(mint)


ABC123B()


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

int main(){
  ll MOD = 1000000007;
  ll n,m;
  cin >> n >> m;
  vector<ll> a(m+2);
  a[m+1] = n+1, a[0] = -1;
  rep(i,m) cin >> a[i+1];
  rep(i,m){
    if(a[i] + 1 == a[i+1]){
      cout << 0 << endl;
      return 0;
    }
  }
  vector<ll> b(n+1);
  b[1] = 1, b[2] = 2;
  for(ll i=3; i<=n; i++){
    b[i] = (b[i-1] + b[i-2]) % MOD;
  }
  ll ans = 1;
  rep(i,m+1){
    if(a[i+1] == 1 || a[i] == n-1 || a[i+1] - a[i] -2 == 0) continue;
    else{
      ans *= b[a[i+1] - a[i] -2];
      ans %= MOD;
      //cout << a[i+1] - a[i] -2 << endl;
    }
  }
  cout << ans << endl;
}


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

int main() {
	
	int n, x;
	cin >> n >> x;
	vector<int> l(n);
	rep(i, n) cin >> l[i];
	
	int d = 0;
	int i;
	for(i=0; i<n; i++){
		if(d + l[i] <= x){
			d = d + l[i];
		}else{
			break;
		}
	}
	cout << i+1 << endl;
	return 0;
}

Measured memory_bytes: 256
a = [list(map(int, s.split())) for s in open(0)] [0]
for i in range(1, 1009):
    if (i * 0.08 >= a[0]) and (i * 0.08 < a[0] + 1) and (i * 0.1 >= a[1]) and (i * 0.1 < a[1] + 1):
        print(i)
        break
else:
    print(-1)

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

int i,j,n;
int ans=100000;

int main(){
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		ans*=1.05;
		if(ans%1000!=0)ans-=ans%1000,ans+=1000;
	}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define ld long double
const ll MOD = 998244353;
const ll INF = 1e18;
using namespace std;

vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define deb(...) 42
#endif


int32_t main(){    
	#ifdef XOX
		freopen("Input.txt", "r", stdin);
		freopen("Output.txt", "w", stdout);
	#endif
 
	ios::sync_with_stdio(!cin.tie(NULL));

	int n;
	cin >> n;

	int arr[n];
	for(int i = 0; i < n;i++)	cin >> arr[i];
	sort(arr, arr + n);

	priority_queue<int> pq;
	pq.push(arr[n - 1]);
	int ans = 0;
	for(int i = n - 2; i >= 0; i--) {
		ans += pq.top();
		pq.pop();
		pq.push(arr[i]);
		pq.push(arr[i]);
	}

	cout << ans;
}

Measured memory_bytes: 6900
#include<stdio.h>
#include<iostream>
#include<cstdlib>
using namespace std;

int N;
int main (){
    cin >> N;
    int mina = 1000000009;
    int maxa = 0;
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        if( a < mina ) mina = a;
        if( a > maxa ) maxa = a;
    }
    cout << maxa - mina << endl;
    return 0;
}


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

int main() {
  int N,cnt=0,x=1;
  cin >> N;
  vector<int> a(N);
  
  for(int i=0;i<N;i++)
    cin >> a.at(i);

  while(x){
    for(int i=0;i<N;i++){
      if(a.at(i)%2 != 0){
        x=0;
        break;
      }else
        a.at(i) /= 2;
    }
    if(x)
      cnt++;
  }
  cout << cnt << endl;
}


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

using namespace std;

int main(void){
    int N;
    string S;
    cin >> N >> S;
    int count=0;
    int res;
    for (int i=1;i<N;i++){
        if(S.at(i)=='E'){count++;}
    }
    res=count;
    for(int i=1;i<N;i++){
        if(S.at(i)=='E'){count--;}
        if(S.at(i-1)=='W'){count++;}
        if(count<=res){res=count;}
        // cout << "i: " << i <<" count: " << count <<endl;
    }
    cout << res <<endl;
    return 0;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define rrep(i,m,n) for(int i = m; i >= n; i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;
ll N,M;
ll x[100010], y[100010];
vector<ll> tree[100010];
// ll h[100010] = {}; 
ll dp[100010] = {};
ll dfs(ll cur){
    if(dp[cur] != -1) return dp[cur];
    ll val = 0;
    for(auto &e: tree[cur]){
        val = max(val, dfs(e) + 1);
    }
    dp[cur] = val;
    return val;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    rep(i,0,M){
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
        tree[x[i]].push_back(y[i]);
    }
    memset(dp, -1, sizeof(dp));
    ll ans = 0;
    rep(i,0,N){
        ans = max(ans, dfs(i));
    }
    print(ans);
    // printa(dp,N);
    // print(ans);
    // rep(i,0,M){
    //     cin >> x[i] >> y[i];
    //     x[i]--; y[i]--;
    //     tree[x[i]].push_back(y[i]);
    //     h[y[i]]++;
    // }
    // stack<ll> st;
    // rep(i,0,N){
    //     if(h[i] == 0){
    //         st.push(i);
    //     }
    // }
    // vector<ll> ans;
    // while(st.size()){
    //     ll k = st.top();
    //     st.pop();
    //     ans.push_back(k);
    //     for(auto &e: tree[k]){
    //         h[e]--;
    //         if(h[e] == 0) st.push(e);
    //     }
    // }
    // rep(i,0,N){
    //     ll v = ans[i];
    //     for(auto &e : tree[v]){
    //         d[e] = max(d[e], d[v] + 1);
    //     }
    // }
    // ll val = 0;
    // rep(i,0,N){
    //     val = max(val, d[i]);
    // }
    // print(val);

}


Measured memory_bytes: 10112
#include<stdio.h>
#define N 200000

int a[N];

int bin_search(int start,int last,int key){
	int mid=(last-start)/2+start;
	
	if(start > last)return 0;
	
	if(a[mid]==key)return 1;
	
	if(key > a[mid])return bin_search(mid+1,last,key);
	else return bin_search(0,mid-1,key);
	
}



int main(){
	int n,m,q,i,x;
	int flg=1;
	
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	
	scanf("%d",&m);
	for(i=0;i<m;i++){
		scanf("%d",&x);
		if(!bin_search(0,n-1,x))flg=0;
	}
	
	printf("%d\n",flg);
	
	return 0;
	
}


Measured memory_bytes: 2636
fn main() {
    let stdin = std::io::stdin();
    let mut rd = ProconReader::new(stdin.lock());

    let k: usize = rd.get();
    println!("{}", "ACL".repeat(k));
}

pub struct ProconReader<R: std::io::Read> {
    reader: R,
}

impl<R: std::io::Read> ProconReader<R> {
    pub fn new(reader: R) -> Self {
        Self { reader }
    }
    pub fn get<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&byte| byte == b' ' || byte == b'\n' || byte == b'\r')
            .take_while(|&byte| byte != b' ' && byte != b'\n' && byte != b'\r')
            .collect::<Vec<_>>();
        std::str::from_utf8(&buf)
            .unwrap()
            .parse()
            .ok()
            .expect("Parse Error.")
    }
}

Measured memory_bytes: 2108
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll a, b, c; cin >> a >> b >> c;
  if (a==5&&b==5&&c==7) cout << "YES" << endl;
  else if (a==5&&b==7&&c==5) cout << "YES" << endl;
  else if (a==7&&b==5&&c==5) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

int main() {
  int n; cin >> n;
  int Min = INT_MAX;
  int def = INT_MAX;
  int sum1 = 0, sum2 = 0;
  vector<int> w(n);
  for (int i=0; i<n; i++) {
    cin >> w[i];
  }
  for(int i=0; i<n; i++) {
    for(int j=0; j<i+1; j++) {
      sum1 += w[j];
      
    }
    for(int k=i+1; k<n; k++) {
      sum2 += w[k];
      
    }
    if(def > abs(sum1-sum2)) {
    def = abs(sum1-sum2);
    }
    sum1 = 0; sum2 = 0;
  }
  cout << def << endl;
  
}

Measured memory_bytes: 256
#pragma region header
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define ts to_string
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector <string>
#define vvs vector <vector<string>>
#define pq  priority_queue<int>
using ll = long long;
/* ----------------よく使う数字や配列----------------- */
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 2000000000;
const int MINF=-2000000000;
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */
/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
bool isprime(ll a)//素数判定、primeならtrue,違うならfalse
{
    if (a < 2) return false;
    else if (a == 2) return true;
    else if (a % 2 == 0) return false;
    double m = sqrt(a);
    for (int i = 3; i <= m; i += 2)
    {
        if (a % i == 0)
        {
            return false;
        }
    }
    // 素数である
    return true;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
ll kind(vi SYURUI) {//vector<int>型の配列の要素の種類数
    int size = SYURUI.size();
    sort(all(SYURUI));
    int cnt = 1;
    rep(i, size-1) {
        if (SYURUI[i] != SYURUI[i + 1])cnt++;
    }
    return cnt;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int N; cin >> N;
    int A = N - 1;
    int sum = 0;
    for (int i = 1; i <= A; i++) {
        sum += A / i;
    }
    cout << sum << endl;
}





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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int N;
int cnt[9];

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

  cin >> N;
  REP(i, N) {
    CIN(a);
    int tmp = min(a / 400, 8);
    
    cnt[tmp]++;
  }

  int mn = 0;
  int mx = 0;
  REP(i, 8) {
    if (cnt[i] > 0) mn++;
  }
  if (mn == 0) {
    mn = 1;
    mx = cnt[8];
  } else {
    mx = mn + cnt[8];
  }

  cout << mn << " " << mx << endl;

  return 0;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << endl;
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << endl;
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

bool compare(string str1, string str2){
  ll compare_value = strcmp(str1.c_str(), str2.c_str());
  //strcmp は小文字比較だけ
  return (compare_value < 0);
};

bool compare(string str1, string str2, string str3){
  return compare(str1, str2) && compare(str2, str3);
};

int main(){
  string s;
  int K;

  cin >> s;
  cin >> K;

  vector<string> s_set(K);
  rep(i, 0, K){
    s_set[i] = "zzzzz";
  }

  ll s_size = s.size();

  int count = 0;

  rep(s_initial, 0, s_size){
    ll s_length_max = min((int)(s_size+1-s_initial), K+1);
    rep(s_length, 1, s_length_max){
      string s_sub = s.substr(s_initial, s_length);

      if(compare(s_sub, s_set[0])){
        s_set.insert(s_set.begin(), s_sub);
        count++;
      }else{
        ll min_count = min(K-1, count);
        rep(i, 0, min_count){
          if(compare(s_set[i], s_sub, s_set[i+1])){
            s_set.insert(s_set.begin()+i+1, s_sub);
            count++;
            break;
          }
        }
      }
    }
  }

  cout << s_set[K-1] << endl;

  return 0;
}


Measured memory_bytes: 384
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    static class Task {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            long c = in.nextLong();
            long k = in.nextLong();

            long[] arr = new long[] {a, b, c};
            int[] valueArr = new int[]{1, 0, -1};
            long ans = 0;
            for (int i = 0; i < 3 && k > 0; i++) {
                if (arr[i] <= k) {
                    ans += arr[i] * valueArr[i];
                } else {
                    ans += k * valueArr[i];
                }
                k -= arr[i];
            }

            out.println(ans);
        }
    }

    private static void sort(double[] arr) {
        Double[] objArr = Arrays.stream(arr).boxed().toArray(Double[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(int[] arr) {
        Integer[] objArr = Arrays.stream(arr).boxed().toArray(Integer[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void sort(long[] arr) {
        Long[] objArr = Arrays.stream(arr).boxed().toArray(Long[]::new);
        Arrays.sort(objArr);
        for (int i = 0; i < arr.length; i++) {
            arr[i] = objArr[i];
        }
    }

    private static void solve() {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        task.solve(1, in, out);
        out.close();
    }

    public static void main(String[] args) {
        new Thread(null, () -> solve(), "1", 1 << 26).start();
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }

}


Measured memory_bytes: 34028
#include <cstdio>
#include <cstring>
#include <algorithm>
#define LL long long
#define MAXN 200010
using namespace std;

int n;
int pre[MAXN],ch[MAXN][2];
int size[MAXN],sf[MAXN];
LL v[MAXN],lim;
pair<LL,LL> *f[MAXN];

void dfs(int x){
	if(ch[x][0]){
		dfs(ch[x][0]);
		dfs(ch[x][1]);
		if(size[ch[x][0]]>size[ch[x][1]]) swap(ch[x][0],ch[x][1]);
		size[x]=size[ch[x][0]]<<1;
	}else{
		size[x]=1;
	}
	f[x]=new pair<LL,LL>[size[x]+1];
}

int join(pair<LL,LL> *fs,pair<LL,LL> *f0,pair<LL,LL> *f1,int sf0,int sf1){
	int now0=1,now1=1;
	int sfs=0;
	while(now0<=sf0 || now1<=sf1){
		if(now1>sf1){
			if(!sfs || fs[sfs].second>f0[now0].second)
				fs[++sfs]=f0[now0];
			now0++;
		}else if(now0>sf0){
			if(!sfs || fs[sfs].second>f1[now1].second)
				fs[++sfs]=f1[now1];
			now1++;
		}else if(f0[now0].first<f1[now1].first){
			if(!sfs || fs[sfs].second>f0[now0].second)
				fs[++sfs]=f0[now0];
			now0++;
		}else{
			if(!sfs || fs[sfs].second>f1[now1].second)
				fs[++sfs]=f1[now1];
			now1++;
		}
	}
	return sfs;
}

bool gao(int x){
	if(!ch[x][0]){
		sf[x]=1;
		f[x][1]=make_pair(0,0);
		return 1;
	}
	int c0=ch[x][0],c1=ch[x][1];
	if(!gao(c0)) return 0; 
	if(!gao(c1)) return 0;
	LL delta=v[c0]+v[c1];
	static pair<LL,LL> f0[MAXN],f1[MAXN];
	int sf0=0,sf1=0;
	int now=sf[c1];
	for(int i=sf[c0];i>=1;i--){
		while(now && f[c0][i].second+f[c1][now].first+delta>lim) now--;
		if(!now) break;
		f0[++sf0]=make_pair(f[c0][i].first+v[c0],f[c1][now].second+v[c1]);
	}
	for(int i=1;i<=sf0;i++)
		if(i<sf0-i+1)
			swap(f0[i],f0[sf0-i+1]);
	now=1;
	for(int i=1;i<=sf[c0];i++){
		while(now<=sf[c1] && f[c0][i].first+f[c1][now].second+delta>lim) now++;
		if(now>sf[c1]) break;
		f1[++sf1]=make_pair(f[c1][now].first+v[c1],f[c0][i].second+v[c0]);
	}
	sf[x]=join(f[x],f0,f1,sf0,sf1);
	return sf[x];
}

bool check(LL _lim){
	lim=_lim;
	return gao(1);
}

int main(){
#ifdef DEBUG
	freopen("E.in","r",stdin);
#endif
	scanf("%d",&n);
	for(int i=2;i<=n;i++){
		scanf("%d%lld",pre+i,v+i);
		if(!ch[pre[i]][0]) ch[pre[i]][0]=i;
		else ch[pre[i]][1]=i;
	}
	dfs(1);
	LL l=0,r=131072LL*131072LL;
	while(l<r){
		LL mid=(l+r)>>1;
		if(check(mid)) r=mid;
		else l=mid+1;
	}
	printf("%lld\n",l);
	return 0;
}


Measured memory_bytes: 33536
#include <bits/stdc++.h>
#define boost_io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define num(a) a-'0'
#define rep(i,a,b) for(int i=a;i<b;i++)
#define maxs(a,b) if(b>a)a=b
#define mins(a,b) if(b<a)a=b
#define debug(x) cerr<<#x<<":"<<x<<" "
#define all(a) (a).begin(), (a).end()
#define vi vector<int>
#define vl vector<long long int>
#define v vector
#define p pair
#define pb push_back
#define mk make_pair
#define f first
#define s second
#define ln "\n"
typedef long long int ll;
typedef long double ld;
typedef double d;
using namespace std;
ll modF=1e9+7;
ll INF=1e11;

void solve(){
	ll a,b;
	cin>>a>>b;
	cout<<(a*b)/__gcd(a,b)<<ln;
}	

int main(){
	boost_io;
	cout<<setprecision(10);
	solve();
	return 0;
}


Measured memory_bytes: 3608
#!/usr/bin/perl
                                                                                                      
$num = <STDIN>;
chomp($num);
$num =~ s/\s+//g;
                                                                                                      
for ($i = 1; $i < $num; $i++) {
    if ($i * $i == $num) {
        print "Yes\n";
        last;
    } elsif ($i * $i > $num) {
        print "No\n";
        last;
    }                                                                                                 
}              

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n, l;
  cin >> n >> l;
  multiset<string> se;
  rep(i, n) {
    string s;
    cin >> s;
    se.insert(s);
  }
  string ans;
  each(s, se) ans += s;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    int m;
    cin >> m;
    s64 d, c;
    s64 ans = 0;
    s64 num = 0;
    rep (i, m)
    {
        cin >> d >> c;
        num += d * c;
        ans += c;
    }
    --ans;
    s64 u = num / 10;
    d = num % 10;

    while (u >= 10)
    {
        ans += u / 10 * 10;
        u = u % 10 + u / 10;
    }

    while (u > 0)
    {
        ans += u;
        s64 temp = u + d;
        u = temp / 10;
        d = temp % 10;
    }

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



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

using namespace std;
int main()
{
    int cnt=0;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++)
    {
        if(i != 0)
        if( s[i-1] == s[i])
        {
            if( s[i] == '0' )
                s[i] = '1';
            else
                s[i] = '0';
                cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


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

#define REP(i,n) for(int i=0;i<n;++i)

const int MAX_N = 100;

int main() {
  int n, u, k, v, G[MAX_N][MAX_N] = {0};
  cin >> n;
  REP(i, n) {
    cin >> u >> k;
    REP(j, k) {
      cin >> v;
      G[u - 1][v - 1] = 1;
    }
  }
  REP(i, n) {
    REP(j, n) {
    if(j) cout << ' ';
    cout << G[i][j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3148
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
typedef pair<int , string> pis;
int n , l , r , q = 20;
string s , t;
int32_t main()
{
	IOS
	cin >> n , cout << 0 << endl , cin >> s;
	if(s == "Vacant")
		return 0;
	t = s , r = n - 1;
	while(q --)
	{
		int mid = l + abs(r - l) / 2;
		cout << mid << endl , cin >> s;
		if(s == "Vacant")
			return 0;
		if((s == t and !(mid & 1)) || (s != t and mid & 1))
			l = mid + 1;
		else
			r = mid - 1;
	}
	return 0;
}


Measured memory_bytes: 852
#include <stdio.h>

int main(){
	int sum = 0;
	char ch;

	while(true)
	{
		while((ch = getchar()) != '\n'){
			sum += ch - '0';
		}
		if(sum == 0)
			break;
		else{
			printf("%d\n",sum);
			sum = 0;
		}
	}
}



Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin >> S;
  if(S[5]=='0' && (S[6]=='1' || S[6]=='2' || S[6]=='3' || S[6]=='4')){
    cout << "Heisei" << endl;
  }
  else {
    cout << "TBD" << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
void print(int);
int rec(int ,int);
#define Max 100000
#define NIL -1
int A[Max];
struct Node{
  int p;
  int l;
  int r;
    };

struct Node T[Max];
int n;
int main()
{ 
  int child,h,i,v,e,depth,l,r;

  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].p=T[i].l=T[i].r=NIL;

  for(i=0;i<n;i++)
    {
      scanf("%d%d",&v,&depth);
      
      for(h=0;h<depth;h++)
	{
	  scanf("%d",&child);
	  if(h==0)T[v].l=child;
	  else T[l].r=child;
	  l=child;
	  T[child].p=v;
	}
    }
  for(i=0;i<n;i++)
    {
      if(T[i].p==NIL) r=i;
    }

  rec(r,0);

  for(i=0;i<n;i++) print(i);

  return 0;
}

int rec(int u, int p)
{
  A[u]=p;
  if(T[u].r!=NIL) rec(T[u].r,p);
  if(T[u].l!=NIL) rec(T[u].l,p+1);
}

void print(int u)
{
  int i,child;
  printf("node %d: ",u);
  printf("parent = %d, ",T[u]);
  printf("depth = %d, ",A[u]);

  if(T[u].p==NIL) printf("root, ");
  else if(T[u].l==NIL)  printf("leaf, ");
  else printf("internal node, ");

  printf("[");

  child=T[u].l;
  for(i=0;child!=NIL;i++){
    if(i) printf(", ");
    printf("%d",child);
    child=T[child].r;
  }
  printf("]\n");
}

Measured memory_bytes: 5300
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String t[];
		int count = 0;
		boolean flag=true;
		try {
			String w = br.readLine();
			while(flag){
				t = br.readLine().split(" ");
				for (String string : t) {
					if(string.equals("END_OF_TEXT")){
						flag = false;
						break;
					}
					if(string.equalsIgnoreCase(w)){
						count++;
					}
				}
			}
			System.out.println(count);
		} catch (IOException e) {
			e.printStackTrace();
		}

	}
}

Measured memory_bytes: 24296
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
const int MAXN=55;
const int mod=1e9+7;
int f[MAXN][MAXN][MAXN*MAXN];
int n,K;
void ad(int &x,int y){x+=y;if(x>=mod)x-=mod;}
void dl(int &x,int y){x-=y;if(x<0)x+=mod;}
int main()
{
	n=read();K=read();
	f[1][0][0]=f[1][1][2]=1;
	for(int i=1;i<n;i++)for(int j=0;j<=i;j++)for(int k=0;k<=n*n;k++)if(f[i][j][k])
	{
		ad(f[i+1][j+1][k+2*(j+1)],f[i][j][k]);//两个都不匹配 
		if(j)ad(f[i+1][j][k+2*j],2LL*f[i][j][k]*j%mod);//只一个匹配 
		if(j)ad(f[i+1][j-1][k+2*(j-1)],1LL*f[i][j][k]*j%mod*j%mod);//两匹配
		ad(f[i+1][j][k+2*j],f[i][j][k]);//互相匹配 
	}
	pr2(f[n][0][K]);
	return 0;
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))

#define MOD 1000000007
#define INF 1000000000

int A, B, C;

int main()
{
    cin >> A >> B >> C;
    int ans;
    if(A == C) { ans = B; }
    else if(B == C) { ans = A; }
    else if(A == B) { ans = C; }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    int a[n];
    int sum = 0;
    F0R(i,n) {cin >> a[i]; sum +=a[i];}
    int t = 0;
    int tSum = 0;
    int minDiff = abs(sum - 2*tSum);

    F0R(i,n){
      tSum += a[i];
      if(abs(sum - 2*tSum) < minDiff) minDiff = abs(sum - 2*tSum);
    }
    

    cout << minDiff << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

int main() {
    int d, g;
    cin >> d >> g;
    vector<int> p(d), c(d);
    for(int i = 0; i < d; i++){
        cin >> p[i] >> c[i];
    }

    int ans = 1e9;
    for(int bit = 0; bit < (1 << d); bit++){
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < d; i++){
            if(bit & (1 << i)){
                s += (i + 1) * 100 * p[i] + c[i];
                num += p[i];
            }else{
                rest_max = i;
            }
        }
        if(s < g){
            int ss = (rest_max + 1) * 100;
            int need = ((g - s) + (ss - 1)) / ss;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

int c(int a, int b) {
  int count = 0;
  for (;;) {
    if (a >= b) {
      break;
    }
    a *= 2;
    count++;
  }
  return count;
}

int main() {
  std::cout << std::fixed << std::setprecision(20);

  int n, k;
  scanf("%d %d", &n, &k);

  double p = 0.0;

  for (int i = 1; i <= n; i++) {
    int num = 0;
    int count = c(i, k);
    p += pow(0.5, count);

    // cout << count << endl;
    // cout << pow(0.5, count) << endl;
  }

  cout << p / n << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl              "\n"
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
    fast;
    long long i,j,c=1,d=1,n,h,sum=0;
    cin>>h;
    while(h>=2)
    {
        h=h/2;
        d=pow(2,c);
        sum=sum+d;
        c++;
    }
    cout<<(sum+1);




}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); }
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int V = 1e5+10;
ll dp[V];
int n, w;

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> n >> w;
  memset(dp, INF, sizeof dp);
  dp[0] = 0;
  for (int i = 0; i < n; ++i) {
    int a, v; cin >> a >> v;
    for (int to = V; to--;) {
      int from = to - v;
      if (from < 0 || dp[from] >= w) continue;
      dp[to] = min(dp[to], dp[from] + a);
    }
  }
  ll ans = 0;
  for (int i = V; i--;) {
    if (dp[i] <= w) {
      ans = i;
      break;
    }
  }
  cout << ans << nl;

  return 0;
}



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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define pb push_back

using namespace std;

const int N = 1e5 + 10;

int ans, n, k;
vector<int> G[N];

int dep[N], dis[N];

void DFS(int o){
	dis[o] = 0;
	for(int v : G[o]){
		dep[v] = dep[o] + 1;
		DFS(v);
		dis[o] = max(dis[o], dis[v] + 1);
	}
	if(dis[o] == k - 1 && dep[o] > 1) dis[o] = -1, ++ans;
}

int main(){
	int x;
	scanf("%d%d%d", &n, &k, &x);
	ans = x != 1;
	For(i, 2, n){
		int v;
		scanf("%d", &v);
		G[v].pb(i);
	}
	DFS(1);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 11136
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int r,m=-1e9,min;
	int N;
	cin >> N;
	cin >> min;
	for(int j=0;j<N-1;j++){
		cin >> r;
		if(r-min>m)m=r-min;
		if(min>r)min=r;
	}
	cout << m << "\n";
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
using UL = unsigned int;
using ULL = unsigned long long;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {
public:

	void Solve() {
		UL T; cin >> T;
		while (T--) {
			ULL N; cin >> N;
			priority_queue<pair<ULL, ULL>, vector<pair<ULL, ULL>>, greater<pair<ULL, ULL>>> Q;
			set<ULL> S;
			Q.push({ 0, N });
			ULL A, B, C, D; cin >> A >> B >> C >> D;
			ULL ans;
			while (Q.size()) {
				ULL p = Q.top().second;
				ULL d = Q.top().first;
				Q.pop();
				if (S.count(p)) continue;
				S.insert(p);
				if (p == 0) { ans = d; break; }
				switch (p % 2) {
				case 0:
					Q.push({ d + A, p / 2 }); break;
				case 1:
					Q.push({ d + A + D, p / 2 });
					Q.push({ d + A + D, (p + 1) / 2 }); break;
				}
				switch (p % 3) {
				case 0: Q.push({ d + B, p / 3 }); break;
				case 1: Q.push({ d + B + D, p / 3 }); break;
				case 2: Q.push({ d + B + D, p / 3 + 1 }); break;
				}
				switch (p % 5) {
				case 0: Q.push({ d + C, p / 5 }); break;
				case 1: Q.push({ d + C + D, p / 5 }); break;
				case 2: Q.push({ d + C + D + D, p / 5 }); break;
				case 3: Q.push({ d + C + D + D, p / 5 + 1 }); break;
				case 4: Q.push({ d + C + D, p / 5 + 1 }); break;
				}
				if ((ULL)1e18 / p > D) Q.push({ d + D * p, 0 });
			}
			cout << ans << endl;
		}
	}
};

int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}


Measured memory_bytes: 4092
#include<stdio.h>
int main(void){
	int N = 1;
	static int k[10000];
	int i;
	int a, b;

	for (;;){
		scanf("%d", &N);

		if (N == 0)
			break;

		for (i = 0; i < N; i++)
			scanf("%d", &k[i]);

		a = 0, b = 0;
		for (i = 0; i < N; i++){
			if (k[i] == 0)
				a++;
			if (k[i] < 2)
				b++;
		}

		if (b == N)
			printf("NA\n");
		else{
			N = N - a + 1;
			printf("%d\n", N);
		}
	}
}


Measured memory_bytes: 2740
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  vector<long> C(N-1), S(N-1), F(N-1);
  rep (i, N-1) cin >> C[i] >> S[i] >> F[i];

  rep (aaa, N - 1) {
    long current = 0;
    for (long i = aaa; i < N - 1; i++) {
      if (current < S[i]) current = S[i];
      if (current % F[i]) current = (current / F[i] + 1) * F[i];
      current += C[i];
    }
    cout << current << endl;
  }
  cout << 0 << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int a, b;
	cin >> a >> b;

	int ans = a - b * 2;
	if (ans < 0) {
		out(0);
	}
	else {
		out(ans);
	}

	return 0;
}

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

int main() {
  int N, X, T;
  cin >> N >> X >> T;
  if(N % X != 0)
  cout << (N / X + 1) * T;
  else cout << ( N / X ) * T;
 return 0;
}



Measured memory_bytes: 3600
#include<stdio.h>
main(){

  int value,data,i;

  while(1){

    scanf("%d",&value);
    
    if(!value) break;
    
    for(i=0;i<9;i++){
      scanf("%d",&data);
      value-=data;
    }
    
    printf("%d\n",value);
    
  }
  
  return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int n,a,b,c,d,s[100]={};
    cin>>n;
    while(cin>>a>>b>>c>>d){
        if(c==d)
            s[--a]++,s[--b]++;
        else if(c>d)
            s[--a]+=3;
        else
            s[--b]+=3;
    }
    for(int i=0;i<n;i++){
        int ans=1;
        for(int j=0;j<n;j++)
            if(s[j]>s[i])
                ans++;
        cout<<ans<<endl;
    }
}



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

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for (int i = 0; i + 2 < N; i++) {
        if (S.substr(i, 3) == "ABC") {
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  int ans = 0;
  REP(i,n){
    cin >> a[i];
    if(i != 0){
      ans = gcd(gcd(a[i],a[i-1]),ans);
    }
  }
                
  cout << ans << endl;           
  
}


Measured memory_bytes: 3752
def find_prime_factor(num):
    if num & 1 == 0:
        return 2
    for i in range(3, int(num ** (1 / 2)) + 1):
        if num % i == 0:
            return i
    return num


def prime_factorization(num):
    subtract = num
    result = []
    while subtract > 1:
        factor = find_prime_factor(subtract)
        result.append(factor)
        subtract //= factor
    return result


n = int(input())

# prime and prime's power.
power = {}
for i in range(1, n + 1):
    for prime in prime_factorization(i):
        if prime in power:
            power[prime] += 1
        else:
            power[prime] = 1

count75 = 0
count25 = 0
count15 = 0
count5 = 0
count3 = 0
for count in power.values():
    if count >= 74:
        count75 += 1
    elif count >= 24:
        count25 += 1
    elif count >= 14:
        count15 += 1
    elif count >= 4:
        count5 += 1
    elif count >= 2:
        count3 += 1

sum25 = count75 + count25
sum15 = count75 + count25 + count15
sum5 = count75 + count25 + count15 + count5
sum3 = count75 + count25 + count15 + count5 + count3
ans = count75 + sum25 * (sum3 - 1) + sum15 * (sum5 - 1) + (sum5 * (sum5 - 1) * (sum3 - 2)) // 2

print(ans)

Measured memory_bytes: 3188
n = int(input())
raw = []
for _ in range(n):
  a,b = input().split()
  b = int(b)
  raw.append([a,b])
t = input()
ans = 0
att = 0
for i in range(n):
  ans += att * raw[i][1]
  if raw[i][0] == t:
    att = 1
print(ans)

Measured memory_bytes: 3316
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author TM
 */


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <numeric>
#include <iterator>
#include <fstream>

#define SIZE 100005
#define MOD 1000000007
#define INF 1000000
long long fac[INF], finv[INF], inv[INF];

using namespace std;

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

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

    void solve(std::istream &cin, std::ostream &cout) {
        int64_t x, y;
        cin >> x >> y;
        if ((x + y) % 3 != 0) {
            cout << 0 << endl;
        } else {
            int64_t x_cnt = (2 * x - y) / 3;
            int64_t y_cnt = (2 * y - x) / 3;
            int64_t ans = 1;
            COMinit();
            cout << COM(x_cnt + y_cnt, x_cnt) << endl;
        }
    }
};


int main() {
    DKnight solver;
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 23680