akhauriyash/Code-Regression huggingface dataset:
n=int(input())

a=list(map(int, input().split()))

count=0
flag=True
while(flag):
    for i in range(len(a)):
        if a[i]%2==0:
            a[i]/=2
        else:
            flag=False
            break
    count+=1
       
print(count-1)
    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          163577857
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -1e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

 typedef tree<pii, null_type, less<pii>, rb_tree_tag,  
            tree_order_statistics_node_update>  odst; 


void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   
    #endif
}


void solve()
{
 
 int k;
 string s;
 cin >> k >> s;

 if(sz(s)>k)
 {
   
   string an ;
   forf(j,0,k) an += s[j];
   an+="...";
   cout<<an<<endl;
 }else
 {
  cout<<s<<endl;
 }
 
}

int32_t main()
{
 pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    // cout << "Time taken by function: "
    //      << duration.count() << " microseconds" << endl; 

 }

Measured memory_bytes: 3652
// Some Sums

#include <iostream>

using namespace std;

int SumDigits(int n){
	if (n / 10 == 0)
		return n;

	return SumDigits(n/10) + n%10;
}

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

	int res = 0;

	for (int i = 1; i <= N; ++i){
		int d = SumDigits(i);
		if (d >= A && d <= B)
			res += i;
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		while(true){
			
			int n = sc.nextInt();
			if(n==0) {
				sc.close();
				break;
			}
			
			String[] cnv1 = new String[n];
			String[] cnv2 = new String[n];
						
			for(int i=0; i<n; i++){
				cnv1[i] = sc.next();
				cnv2[i] = sc.next();
			}
			
			int m = sc.nextInt();
		
			for(int i=0; i<m; i++){
				int flg=0;
				String p = sc.next();
				for(int j=0; j<n; j++){
					if(p.equals(cnv1[j])){
						System.out.print(cnv2[j]);
						flg=1;
					}
					
				}
				if(flg==0) System.out.print(p);
			}
			System.out.println();
			
		}
		
	}
}

Measured memory_bytes: 70008
#include<bits/stdc++.h>
#define oo 0x3fffffff
#define N 505
using namespace std;


int n,k,m,d[N][N];

int main(void){
    int i,j,x,y;
    //freopen("in.txt","r",stdin);
    scanf("%d %d",&n,&k);


    x=n%2==1?((n+1)/2):n/2;
    printf("%s",x>=k?"YES":"NO");
    return 0;
}


Measured memory_bytes: 256
/*
[arc100] C - Linear Approximation
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 200000;

int N;
int B[MAX_N];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        B[i] = a - i + 1;
    }
    sort(B, B + N);

    int b = B[N / 2];
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += abs(B[i] - b);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
class InputLine
  def self.to_s
    gets.chomp
  end

  def self.to_i
    InputLine.to_s.to_i
  end
  
  def self.to_f
    InputLine.to_s.to_f
  end

  def self.to_sa
    InputLine.to_s.split(' ')
  end

  def self.to_ia
    InputLine.to_sa.map(&:to_i)
  end
  
  def self.to_fa
    InputLine.to_sa.map(&:to_f)
  end
end

def main(argv)
  n = InputLine.to_i

  if n.to_s.split('').map(&:to_i).include?(7) then
    puts 'Yes'
  else
    puts 'No'
  end
end

if self.to_s == 'main' then
  main(ARGV)
end

Measured memory_bytes: 14248
#include <cstdio>
#include <iostream>
#include <cassert>
#include <algorithm>    
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cmath>
#include <bitset>
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
// #define int long long
using namespace std;
	
typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef unsigned long long ull; 
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const int M = 1e9 + 7;
//__int128


signed main()
{
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n;
  cin >> n;
  std::vector<int> d(n);
  for(int i = 0; i < n; ++i) {
  	cin >> d[i];
  }
  long long res = 0;
  for(int i = 0; i < n; ++i) {
  	for(int j = i + 1; j < n; ++j) {
  		res += d[i] * d[j];
  	}
  }
  cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque

def merge(A,B):
    ans = [0]*(len(A)+len(B))
    count=i=j=0
    A+=[10**9+1]
    B+=[10**9+1]
    for k in range(len(ans)):
        if A[i]<B[j]:
            ans[k]=A[i]
            i+=1
        else:
            ans[k]=B[j]
            j+=1
        count+=1
    return (ans,count)

n = int(input())
S = [int(i) for i in input().split()]
div = deque([S])
mer = deque()
count = 0
while(len(div)>0):
    d = div.popleft()
    if(len(d)>2):
        mid = len(d)//2
        div.append(d[:mid])
        div.append(d[mid:])
    elif(len(d)==2):
        if d[0] > d[1]:
            mer.append(d[::-1])
        else:
            mer.append(d)
        count+=2
    else:
        mer.append(d)
        
while(len(mer)>1):
    A = mer.pop()
    B = mer.pop()
    ret = merge(A,B)
    mer.appendleft(ret[0])
    count+=ret[1]
    
ans = ""
for i in ret[0]:
    ans += str(i) + " "
print(ans[:-1])
print(count)


Measured memory_bytes: 65964
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
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; }
const int INF = 1<<30;

int main(){
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	s[k-1] = tolower(s[k-1]);
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 764
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let n = get!(usize);
    let mut ab = get!(usize, usize; n);

    ab.sort_by_key(|e| e.1);
    let mut before = 0;
    for (a,b) in ab {
        if before + a > b {
            println!("No");
            return;
        }
        before += a;
    }
    println!("Yes");
}


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

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)

#define endl "\n"

int main()
{
	faster;
	
	int n;
	double d;
	cin >> n >> d;

	int cnt = 0;

	for(int i= 0; i < n; i++){
		double x1,y1;
		cin >> x1 >> y1;
		double di = sqrt(x1 * x1 + y1 * y1);

		if(di <= d) cnt++;
	}

	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 3880
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Problem D: Distorted Love
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		Comparator<int[]> cmp = new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				if (o1[0] != o2[0]) {
					return Integer.compare(o1[0], o2[0]);
				} else {
					return Integer.compare(o1[1], o2[1]);
				}
			}
		};

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			int n = parseInt(line);
			if (n == 0) break;

			//????????¨??????
			br.readLine();

			Map<String, Map<int[], String>> pages = new HashMap<>();
			Deque<String> stackF, stackB;
			stackF = new ArrayDeque<>();
			stackB = new ArrayDeque<>();

			for (int i = 0; i < n; i++) {
				words = br.readLine().split(" ");

				String name = words[0];
				int b = parseInt(words[1]);

				pages.put(name, new TreeMap<>(cmp));

				for (int j = 0; j < b; j++) {
					words = br.readLine().split(" ");
					int[] pos = new int[4];
					for (int k = 0; k < 4; k++) {
						pos[k] = parseInt(words[k]);
					}
					pages.get(name).put(pos, words[4]);
				}
				if (i == 0) {
					stackF.push(name);
				}
			}

			int m = parseInt(br.readLine());

			for (int i = 0; i < m; i++) {
				words = br.readLine().split(" ");

				String op = words[0];

				switch (op) {
					case "click":
						int x = parseInt(words[1]);
						int y = parseInt(words[2]);
						String page = stackF.peek();
						Map<int[], String> btns = pages.get(page);
						for (int[] btn : btns.keySet()) {
							if (btn[0] <= x && x <= btn[2]
									&& btn[1] <= y && y <= btn[3]) {
								stackF.push(btns.get(btn));
								stackB.clear();
							}
						}
						break;
					case "back":
						if (stackF.size() > 1) {
							stackB.push(stackF.pop());
						}
						break;
					case "forward":
						if (!stackB.isEmpty()) {
							stackF.push(stackB.pop());
						} break;
					case "show":
						System.out.println(stackF.peek());
						break;
				}
			}
		}
	}
}

Measured memory_bytes: 28964
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int red = sc.nextInt();
		int green = sc.nextInt();
		int blue = sc.nextInt();
		int k = sc.nextInt();
		sc.close();

		while(red >= green){
			if(k > 0){
				green *= 2;
				k--;
			}else{
				System.out.println("No");
				return;
			}
		}
		while(green >= blue){
			if(k > 0){
				blue *= 2;
				k--;
			}else{
				System.out.println("No");
				return;
			}
		}

		if((red < green) && (green < blue)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}


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

using namespace std;

template <typename T>
ostream &operator<<(ostream &os, const std::vector<T> &vec) {
  for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
  return os;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  vector<vector<int>> G(N);
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i]--, B[i]--;
    G[A[i]].emplace_back(B[i]);
    G[B[i]].emplace_back(A[i]);
  }

  int res = 0;
  queue<int> que;
  vector<bool> used(N);

  for (int i = 0; i < M; i++) {
    que.push(0);

    used.assign(N, false);
    used[0] = true;

    while (!que.empty()) {
      int u = que.front();
      que.pop();

      for (int v : G[u]) {
        if (used[v] || (A[i] == u && B[i] == v) || (A[i] == v && B[i] == u))
          continue;
        que.push(v);
        used[v] = true;
      }
    }

    auto check = [used, N]() -> bool {
      for (int i = 0; i < N; i++) {
        if (!used[i]) return false;
      }
      return true;
    };

    if (!check()) res++;
  }

  cout << res << '\n';

  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		M, T, P, R := io.NextInt(), io.NextInt(), io.NextInt(), io.NextInt()
		if M == 0 {
			break
		}
		score := make([]struct{ num, time, index int }, T)
		submit := make([][]int, T)
		for i := 0; i < T; i++ {
			score[i].index = i + 1
			submit[i] = make([]int, P)
		}

		for i := 0; i < R; i++ {
			m, t, p, j := io.NextInt(), io.NextInt()-1, io.NextInt()-1, io.NextInt()
			if j == 0 {
				score[t].num++
				score[t].time += submit[t][p]*20 + m
			} else {
				submit[t][p]++
			}
		}
		sort.SliceStable(score, func(i, j int) bool {
			return score[i].num < score[j].num || score[i].num == score[j].num && score[i].time > score[j].time
		})

		for i := T - 1; i > 0; i-- {
			io.Printf("%d", score[i].index)
			if score[i].num == score[i-1].num && score[i].time == score[i-1].time {
				io.Printf("=")
			} else {
				io.Printf(",")
			}
		}
		io.Println(score[0].index)
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}



Measured memory_bytes: 2492
long M=1e9+7,D[1<<20],P[1<<20],s=5e8+4;i,x,p;c[1<<20];
main(a)
{
for(gets(D);i<1<<20;)D[i++]=1;
for(;~scanf("%d",&a);c[x]=p)P[x^=a]=(P[x]+(D[x]=(D[x]+P[x]*(p-c[x]))%M))%M,x||(p++,s=s*2%M);
for(;--i;)s+=P[i];
printf("%d",x?D[x]:s%M);
}


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

int main(){   
    int n;
    cin>>n;
    int a[n];
    map<int,int> m1,m2;
    for(int i=0;i<n;i++) {cin>>a[i]; m1[i+a[i]]++,m2[i-a[i]]++;}
    ll ans=0;
    for(int i=0;i<n;i++){
        int x=i+a[i];
        if(m2.find(x)!=m2.end()) {
            ans+=m2[x];
        }
    }
    cout<<ans<<endl;
}   


Measured memory_bytes: 21656
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    ll A, B, K;
    cin>>A>>B>>K;
    if(A>=K) cout<<A-K<<" "<<B<<endl;
    else cout<<0<<" "<<max((ll)0, B-(K-A))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define all(x) begin(x), end(x)

using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int x, y; cin >> x >> y;
    int a[300] = {0};
    a[0] = 300000; a[1] = 200000; a[2] = 100000;
    cout << a[x-1] + a[y-1] + (x == 1 and y == 1 ? 400000 : 0);
}

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

#define rep(i, a) REP(i, 0, a)
#define REP(i, a, b) for(int i = a; i < b; ++i)

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int, int> P;
typedef std::pair<P, int> PP;
struct edge{ int to, time, cost; };
const double esp = 1e-9;
const int inf = (int)1e+9;

int n, c;
int a[31], b[31];
int dp[31][(1 << 16)];

int countPop(int x){
	int cnt = 0;
	while (x != 0){
		if (x & 1)++cnt;
		x >>= 1;
	}
	return cnt;
}

int main(){
	while (true){
		std::cin >> n >> c;
		if (n == 0 && c == 0)break;

		rep(i, 31)rep(j, (1 << 16))dp[i][j] = -1;
		dp[0][0] = 0;
		rep(i, 31)a[i] = b[i] = 0;

		rep(i, n){
			int x;
			rep(j, 16)std::cin >> x, a[i] |= (x << j);
		}
		rep(i, c){
			int x;
			rep(j, 16)std::cin >> x, b[i] |= (x << j);
		}

		rep(i, n){
			rep(j, (1 << 16)){
				if (dp[i][j] == -1)continue;
				int table = (j | a[i]);
				int cnt = countPop(table);
				rep(k, c){
					int cal = (table & b[k]);
					dp[i + 1][table - cal] = std::max(dp[i + 1][table - cal], dp[i][j] + countPop(cal));
				}
			}
		}

		int ans = 0;
		rep(i, (1 << 16))ans = std::max(ans, dp[n][i]);
		std::cout << ans << std::endl;
	}
	return 0;
}

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

int main()
{
    int sum = 0, num = 0, k = 0, p = 0;
    string s;
    cin >> s;
    for(int i = s.size()-1; i >= 0; i--)
    {
        k = s[i] - '0';
        sum += k;
        num += (k * (pow(10.0, p)));
        p++;
    }
    if(num % sum == 0) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 3896
// https://yukicoder.me/submissions/326354

#include <cstdio>
#include <cstdint>
#include <vector>
#include <string>
#include <algorithm>

int main() {
  uintmax_t N;
  scanf("%ju", &N);
  --N;  //

  std::string res;

  do {
    res += 'a' + (N % 26);  //
    N /= 26;
  } while (N-- != 0);

  std::reverse(res.begin(), res.end());
  printf("%s\n", res.c_str());
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define INF 10000000000000009
#define INF 9223372036854775807
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define ORREP(i,n) for(int i=(n);i>=1;--i)
#define ZREP(i,n) for(int i=1;i<(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define rollcall cout<<"I'm Sucu."<<endl;
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define out(s,t,u) s?cout << t << endl:cout << u << endl
#define int ll
#define Endl endl

signed main(){
    int r[3];
    cin >> r[0] >> r[1] >> r[2];
    sort(r,r+3);
    cout << r[0]+r[1]+r[2]*10 << endl;
    return 0;
}   


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
const ll INF=1000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};


ll dp[100005];
ll h[100005];
int main() {

	int n,k;

	cin>>n>>k;

	rep(i,n){
		cin>>h[i+1];
		dp[i+1]=INF;
	}
	dp[0]=0;
	dp[1]=0;
	for(int i=1; i<n; i++){
		for(int j=i-1; j>=i-k; j--){
			if(j>=0)dp[i+1]=min(dp[i+1],dp[j+1]+labs(h[i+1]-h[j+1]));
			if(j<0)break;
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}


Measured memory_bytes: 1792
w,h,n=map(int,input().split())
temphu=h
temphd=0
tempwu=w
tempwd=0
for i in range(n):
  x,y,a=map(int,input().split())
  if a==1:
    tempwd=max(tempwd,x)
  if a==2:
    tempwu=min(tempwu,x)
  if a==3:
    temphd=max(temphd,y)
  if a==4:
    temphu=min(temphu,y)
print(max(0,temphu-temphd)*max(0,tempwu-tempwd))


Measured memory_bytes: 3064
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    cnt = 0
    for i in range(n):
        if B[i] < A[i]:
            cnt += A[i] - B[i]
            B[i] = A[i]

    for i in range(n):
        if B[i] > A[i]:
            cnt -= (B[i] - A[i]) // 2

    if cnt <= 0:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 4596
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
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=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  int cnt = 0;
  rep(i,n){
    int a;
    cin >> a;
    if(i%2==0 && a%2==1)cnt++;
  }
  cout << cnt << endl;
  return 0;
}


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

int main ()
{
	int n, cost, t;
	string name;
	queue< pair<string, int>  > Q;
	cin >> n >> cost;
	for(int i = 0; i < n; i++)
	{
		cin >> name >> t;
		Q.push(make_pair(name, t)); 
	}
	
	pair<string, int> u;
	
	int min_c, time = 0;
	
	while(!Q.empty())
	{
		u = Q.front();
		Q.pop(); 
		min_c = min(u.second, cost);
		u.second -= min_c;
		time += min_c;
		if(u.second > 0)
			Q.push(u);
		else
			cout <<  u.first << " " << time << endl;
	}
	return 0; 
	
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
using namespace std;
const int MAXN=200005;
int n,Pre;
long long a[MAXN],t,ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&t);
		a[i]=a[i-1]+t;
	}
	sort(a,a+n+1);
	for(int i=0;i<=n;i++){
		if(i==0||a[i]>a[i-1])Pre=i;
		ans+=i-Pre;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int main(){
  int i,n,j,a[100000];
  scanf("%d",&n);
  i=j=0;
  while(i*i+i<n<<1)i++;
  while(i){
    if(n>=i){
      a[j++]=i;
      n-=i;
    }
    --i;
  }
  while(j){
    printf("%d\n",a[j-1]);
    --j;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <vector>
#include <algorithm>
#define abs(a) ((a) < 0 ? - (a) : (a))
using namespace std;
int main() {
  long long int s;
  cin >> s;
  
  long long int x1, y1, x2, y2, x3, y3;
  x1 = 0;
  y1 = 0;
  x2 = 0;
  for (int i = 1; x2*x2 < s; i++) {
    x2++;
  }
  y3 = x2;
  y2 = 1;  
  x3 = x2 * y3 - s;
  
  cout << x1 << " " << y1 << " " << x2 << " " << y2 << " " << x3 << " " << y3 << endl;
  return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}



vector<ll> divisors(ll n) {
  vector<ll> ds;
  for(ll d = 1; d * d <= n; d++) {
    if (n % d == 0) {
      ds.push_back(d);
      if (d * d != n) ds.push_back(n/d);
    }
  }
  sort(ds.begin(), ds.end());
  return ds;
}

ll f(ll N, ll k) {
  if (k == 1) return -1;
  while (N >= k) {
    if (N % k == 0) N = N / k;
    else N = N % k;
  }
  return N;
}

int main2() {
  ll N = nextLong();

  set<ll> cand;

  vector<ll> ds = divisors(N);
  cand.insert(ALL(ds));
  vector<ll> ds2 = divisors(N - 1);
  cand.insert(ALL(ds2));
  int ans = 0;
  for (ll k : cand) {
    if (f(N, k) == 1) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

int main() {
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> b(n);
  vector<vector<int>> ans(h, vector<int>(w));
  rep(i, n) cin >> b[i];
  vector<int> a;
  rep(i,n){
    rep(j, b[i]){
      a.push_back(i+1);
    }
  }
  int flag = 1;
  for (int i = 0; i < h; i++){
    if(flag){
      for (int j = 0; j < w; j++){
        ans[i][j] = a[w * i + j];
      }
      flag = 0;
    }else {
      for (int j = 0; j < w; j++){
        ans[i][w - 1 - j] = a[w * i + j];
      }
      flag = 1;
    }
  }
  rep(i,h){
    rep(j,w){
      cout << ans[i][j] << (j == w - 1 ? "\n" : " ");
    }
  }
}

Measured memory_bytes: 512
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	int a, b;
	int ans[50];
	for (int i = 0; i < 50; i++)
		ans[i] = 0;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		ans[a - 1]++;
		ans[b - 1]++;
	}
	for (int i = 0; i < n; i++)
		cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <map>
#include <fstream>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define INF 1e9 
typedef long long ll;
typedef long double ld;
int main(){
    int x;cin>>x;
    cout<<((x==1?0:1))<<endl;
    return 0;
}


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

typedef long long LL;

const int N=300,mod=998244353;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

char s[N+9];
int n;

void into(){
  scanf("%s",s+1);
  n=strlen(s+1);
}

int dp[N+9][N+9][N+9];

void Get_dp(){
  dp[n][0][0]=1;
  for (int i=n;i>=1;--i)
	for (int j=0;j<i;++j)
	  for (int k=0;j+k<i;++k){
		dp[i-1][j][k]=dp[i][j][k];
		s[i]=='0'?sadd(dp[i][j][k+1],dp[i][j][k]):sadd(dp[i][j+1][k],dp[i][j][k]);
	  }
}

int f[N+9][N+9][N+9];

void Get_f(){
  for (int i=0;i<=n;++i)
	for (int j=0;j<=n+1;++j)
	  for (int k=0;k<=n+1;++k) f[i][j][k]=-1;
  f[0][0][0]=0;
  for (int i=0;i<n;++i)
	for (int j=0;j<=i>>1;++j)
	  for (int k=0;j+k<=i>>1;++k){
		if (f[i][j][k]==-1) continue;
		s[i+1]=='0'?f[i+1][j+1][k]=max(f[i+1][j+1][k],f[i][j][k]-1):f[i+1][j][k+1]=max(f[i+1][j][k+1],f[i][j][k]-1);
		if (i+2>n) continue;
		f[i+2][j][k]=max(f[i+2][j][k],f[i][j][k]+1);
		if (s[i+1]=='0'||s[i+2]=='0') f[i+2][j+1][k]=max(f[i+2][j+1][k],f[i][j][k]);
		if (s[i+1]=='1'||s[i+2]=='1') f[i+2][j][k+1]=max(f[i+2][j][k+1],f[i][j][k]);
	  }
  for (int i=0;i<=n;++i)
	for (int j=n;j>=0;--j)
	  for (int k=n;k>=0;--k){
		f[i][j][k]=max(f[i][j][k],max(f[i][j][k+1],f[i][j+1][k]));
		if (i) f[i][j][k]=max(f[i][j][k],f[i-1][j][k]);
	  }
}

int ans;

void Get_ans(){
  for (int i=0;i<=n;++i)
	for (int j=0;j<=i;++j)
	  for (int k=0;j+k<=i;++k)
		if (f[i][j][k]>=0) sadd(ans,dp[i][j][k]);
}

void work(){
  Get_dp();
  Get_f();
  Get_ans();
}

void outo(){
  printf("%d\n",sub(ans,1));
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 170428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <typename _Tp>
struct LazySegmentTree {
  _Tp n;
  vector<_Tp> node, lazy;

  LazySegmentTree(vector<_Tp> const& v) {
    _Tp sz = v.size();
    n = 1;
    while (sz > n) n *= 2;
    node.resize(2*n-1);
    lazy.resize(2*n-1, -1);

    for (int i = 0; i < sz; ++i) {
      node[i+n-1] = v[i];
    }
/*
    for (int i = n-2; i >= 0; --i) {
      node[i] = node[i*2+1] + node[i*2+2];
    }
    */
  }

  void eval(int k, int l, int r) {
    if (lazy[k] != -1) {
      node[k] = lazy[k]; // 自分自身に遅延評価を反映

      // 最下段でないならば評価を伝搬させる。
      if (r - l > 1) {
        lazy[2*k+1] = lazy[k];
        lazy[2*k+2] = lazy[k];
      }

      lazy[k] = -1;
    }
  }

  void update(int a, int b, _Tp value, int k = 0, int l = 0, int r = -1) {
    if (r < 0) r = n;
    eval(k,l,r);

    // 範囲外ならば切る。
    if (b <= l || r <= a) {
      // cout << 1 << endl;
      return;
    }

    if (a <= l && r <= b) {
      lazy[k] = value;
      eval(k,l,r);
      return;
    } else {
      update(a,b,value,2*k+1,l,(r+l)/2);
      update(a,b,value,2*k+2,(l+r)/2,r);
      node[k] = value;
    }
  }

  _Tp get(int idx, int k = 0, int l = 0, int r = -1) {
    int a = idx, b = idx+1;
    if (r < 0) {
      r = n;
    }

    eval(k,l,r);

    // cout << a << " "<< b << " " << l << " " << r << endl;

    if (a <= l && r <= b) {
      return node[k];
    }

    if (b <= l || r <= a) return -1;
    else {
      auto lv = get(idx, 2*k+1, l, (l+r)/2);
      auto rv = get(idx, 2*k+2, (l+r)/2, r);
      return max(lv, rv);
    }
  }
};

ll fi = (1L << 31) - 1;

int main() {
  int n, q;
  cin >> n >> q;
  vector<ll> v(n, fi);
  LazySegmentTree<ll> seg_tree(v);
  rep(i, q) {
    int com;
    cin >> com;
    if (com == 0) {
      int s,t,n;
      cin >> s >> t >> n;
      seg_tree.update(s,t+1,n);
    } else {
      int idx;
      cin >> idx;
      cout << seg_tree.get(idx) << "\n";
    }
  }
}




Measured memory_bytes: 7856
N, M = map(int,input().split())
s, c = [0]*M, [0]*M
for i in range(M):
  s[i], c[i] = map(int,input().split())

keta = [10]*N
for i in range(M):
  if keta[s[i]-1] == 10:
    keta[s[i]-1] = c[i]
  else:
    if keta[s[i]-1] != c[i]:
      print(-1)
      exit()
ans = 0
for i in range(N):
  if keta[0] == 0 and N != 1:
    print(-1)
    exit()
  elif i == 0 and keta[0] == 10:
    if N != 1:
      ans += pow(10,N-1)
    else:
      ans = 0
  elif keta[i] != 10:
    ans += keta[i]*pow(10,N-i-1)
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0;i < n;i++)
#define REP(i,n,k) for(int i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;

void solve() {
  int n,k;
  vector<int> v;
  cin >> n >> k;
  rep(i,n){
    int a;
    cin >> a;
    v.pb(a);
  }
  int score = 1e9;
  for(int i = 0;i+k <= v.size();i++){
    int l = v[i];
    int r = v[i+k-1];
    score = min(score,min(abs(l)+abs(r-l),abs(r)+abs(r-l)));
  }
  P(score);
}

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


Measured memory_bytes: 892
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

const ll INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vector<ll> a(3*n);
  rep(i,3*n) cin >> a[i];
  
  priority_queue<ll,vector<ll>,greater<ll>> q;
  vector<ll> left(n+1);
  ll sum = 0;
  rep(i,n){
    sum += a[i];
    q.push(a[i]);
  }
  left[0] = sum;
  for(int i = n; i < 2*n; i++){
    sum += a[i];
    q.push(a[i]);
    sum -= q.top(); q.pop();
    left[i-n+1] = sum;
  }


  priority_queue<ll> q2;
  vector<ll> right(n+1);
  ll sum2 = 0;
  for(int i = n*3-1; i >= n*2; i--){
    sum2 += a[i];
    q2.push(a[i]);
  }
  right[n] = sum2;
  for(int i = n*2-1; i >= n; i--){
    sum2 += a[i];
    q2.push(a[i]);
    sum2 -= q2.top(); q2.pop();
    right[i-n] = sum2;
  }
  
/*  rep(i,n+1){
    printf("left=%lld, right=%lld\n",left[i],right[i]);
  }
*/
  ll ans = INF * -1;
  rep(i,n+1) chmax(ans, left[i]-right[i]); 
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 6516
from collections import Counter
def main(s, t):
    s_c = sorted(Counter(s).items(), key=lambda x: -x[1])
    t_c = Counter(t)
    tmp = 0
    for k, v in s_c:
        minus = t_c[k] if k in t_c.keys() else 0
        tmp = max(tmp, v - minus)
    print(tmp)

if __name__ == '__main__':
    N = int(input().strip())
    s = [input().strip() for _ in range(N)]
    M = int(input().strip())
    t = [input().strip() for _ in range(M)]
    main(s, t)

Measured memory_bytes: 3316
from heapq import heappop, heappush
N, K = map(int, input().split())
A = list(map(int, input().split()))
F = list(map(int, input().split()))

def ok(x):
    cnt = 0
    for i in range(N):
        current = A[i] * F[i]
        if current > x:
            cnt += -(-(current - x) // F[i])
            
    return cnt <= K

A.sort()
F.sort(reverse=True)
lb = 0
ub = 10 ** 12 + 1

while ub - lb > 1:
    mid = (lb + ub) // 2
    
    if ok(mid):
        ub = mid
    else:
        lb = mid
        
if sum(A) <= K:
    print(0)
else:
    print(ub)




Measured memory_bytes: 119500
n = int(input())
b = 1
a = list(map(int,input().split()))
if 0 in a:
    print(0)
else:
    for i in range(n):
        b *= a[i]
        if b > 10**18:
            print(-1)
            break
    if b <=10**18:
        print(b)    


Measured memory_bytes: 21468
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
//using namespace atcoder;
map<ll,ll>mp;
ll n,A,B,C,D;

ll rec(ll num){
	if(num==0)return 0LL;
	if(num==1)return D;
	if(mp.find(num)!=mp.end())return mp[num];

	ll res;
	if(log10(num)+log10(D)>log10(INF))res=INF;
	else res=num*D;
	if(num%2==0){
		chmin(res,rec(num/2)+A);
	}
	else{
		chmin(res,min(rec(num/2),rec(num/2+1))+A+D);
	}
	if(num%3==0){
		chmin(res,rec(num/3)+B);
	}
	else{
		chmin(res,min(rec(num/3)+B+D*(num%3),rec(num/3+1)+B+D*(3-num%3)));
	}
	if(num%5==0){
		chmin(res,rec(num/5)+C);
	}
	else{
		chmin(res,min(rec(num/5)+C+D*(num%5),rec(num/5+1)+C+D*(5-num%5)));
	}
	return mp[num]=res;
}


void solve(){
	int t;
	cin>>t;
	while(t--){
		cin>>n>>A>>B>>C>>D;
		mp.clear();
		ll ans=rec(n);
		cout<<ans<<"\n";
	}
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 4612
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {
	

	//cout << int('a') << endl; 97
	//cout << int('b') << endl;

	long N; cin >> N;

	
	map<string,long> MAP;
	long cnt = 0;
	for (int i = 0; i < N; i++) {
		string str; cin >> str;	
		sort(str.begin(), str.end());
		MAP[str]++;
	}


	//for (const auto& [key, value] : MAP) {
	for(auto value : MAP) {
		if (value.second > 1) {
			cnt += value.second  * (value.second - 1) / 2;
		}
	}
	cout << cnt << endl;




	return 0;
}


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

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

    vector<int> p(n);
    for(int i=0; i<n; i++){
        cin >> p[i];
    }

    int counter = 0;
    for(int i=0; i<n; i++){
        if(p[i] != i + 1){
            counter += 1;
        }
    }
    if(counter <= 2) cout << "YES" << endl;
    if(counter > 2) cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <iomanip>
using ll = long long;
using namespace std;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r) { return l.second < r.second; }
bool greaterPair(const ipair& l, const ipair& r) { return l.second > r.second; }

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define irep(i, n) for (int i = 0; i <= (n); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rirep(i, n) for (int i = n; i >= 0; --i)
int factorical(int n) {
	int sum = 1;
	for (int i = 1; i <= n; ++i)
	{
		sum *= i;
	}
	return sum;
}

vector<int> divisors(int n) {
	vector<int> res;
	for (int i = 1; i * i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}
vector<ll> divisors_ll(ll n) {
	vector<ll> res;
	for (ll i = 1; i * i <= n; ++i) {
		if (n % i != 0) continue;
		res.push_back(i);
		if (n / i == i) continue; // 上の行で追加済み。
		res.push_back(n / i);
	}
	return res;
}


void printVector(const vector<int>& vec) {
	for (int value : vec) {
		cout << value << " ";
	}
	cout << endl;
}

bool pal(string s) {
	int n = s.length() / 2;
			rep(i, n) {
			if (s[i] != s[s.length() - 1 - i]) return false;
		}
			return true;
}

int euclidean_gcd(int a, int b) {
	if (a < b) return euclidean_gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

vector <string> vec_sort_and_del(vector<string> s) {
	std::sort(s.begin(), s.end());
	s.erase(std::unique(s.begin(), s.end()), s.end());
	return s;
}

int GetDigit(int num) {
	int digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}

int main() {
	double s;
	double PI = 3.14159265358979323846;
	cin >> s;
	cout << s * 2 * PI;

	return 0;
}




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

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

  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  map<int, int> Map;
  for (int i = 0; i < N; i++) {
    Map[A.at(i)]++;
  }

  int ans = 0;
  for (auto p : Map) {
    auto key = p.first;
    auto value = p.second;
    if (value != key) {
      if (key < value)
        ans += value - key;
      else
        ans += value;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 5120
import scala.collection.mutable._
import io.StdIn.readLine

object Main extends App {
  val map = new HashMap[String,Int]
  val s = readLine.split(" ")
  s.foreach(e => {
    if(!map.contains(e)) map.put(e,1)
    else map.put(e,map(e)+1)
  })
  val maxF = map.maxBy(_._2)._1
  val maxL = s.map(e => (e.length, e)).max._2

  println(maxF + " " + maxL)
}


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

int main(void) 
{
    ll n,m;
    cin >> n >> m;
    vector<ll> a(m);

    rep(i,m) cin >> a[i];

    ll num =0;
    rep(i,m) num += a[i];

    if(n < num) cout << -1 << endl;
    else cout << n -num << endl;
    return 0;
}

Measured memory_bytes: 3672
#include <stdio.h>
#include <math.h>

int main(void){
  int n,a[100005],d[100005];
  long long ans;
  scanf("%d",&n);
  for(int i=0;i<=n+1;i++){
    if(i==n+1||i==0){
      a[i]==0;
      continue;
    }
    scanf("%d",&a[i]);

  }

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

    d[i]=fabs(a[i+1]-a[i]);
    ans+=d[i];
  }

  long long ans1[100005]={ans};

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

    ans1[i]=ans-d[i]-d[i+1]+fabs(a[i+2]-a[i]);
      printf("%lld\n",ans1[i]);
     }



  return 0;
}


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

int main() {
    int N;
    int a[1010];
    cin >> N;
  for (int i = 0; i < N; ++i) a[i] = -1;
  for (int i = 0; i < N; ++i) cin >> a[i];
    int max_counter = -1;
    int min_counter = 1001;
    for (int i = 0; i < N; ++i)if (a[i] != -1)if (a[i] > max_counter) max_counter = a[i];
    for (int i = 0; i < N; ++i)if (a[i] != -1)if (a[i] < min_counter) min_counter = a[i];
    int result = 0;
    if(min_counter <= max_counter)result = max_counter - min_counter;
    cout << result << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int BinarySearch(int );
int S[1000000],n;
int main(){

  int j,i,q,T[1000000],count=0,flag;
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
    }
  scanf("%d",&q);
   for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }
  
    for(j=0;j<q;j++){
      flag=BinarySearch(T[j]);
      if(flag==1) count++;
    }
 
  printf("%d\n",count);
  return 0;


}

int BinarySearch(int key){
  int i,left=0,right,mid;
  right=n;
  while(left<right){
    mid=(left+right)/2;
    if(S[mid]==key)return 1;
    else if(key< S[mid]) right=mid;
    else left=mid+1;
  }
  return 0;
}

Measured memory_bytes: 1188
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;


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

Measured memory_bytes: 1168
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
    int H, W, D;
    cin >> H >> W >> D;
    vector<vector<int>> A;
    A = vector<vector<int>>(H * W, vector<int>(2, 0));

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            int temp;
            cin >> temp;
            temp--;
            A[temp][0] = i;
            A[temp][1] = j;
        }
    }

    vector<int> pow_list(H * W, 0);
    for (int i = H * W - D - 1; i >= 0; i--)
        pow_list[i] = pow_list[i + D] + abs(A[i][0] - A[i + D][0]) + abs(A[i][1] - A[i + D][1]);

    int Q;
    cin >> Q;
    int L, R;
    vector<int> pow(Q, 0);
    for (int i = 0; i < Q; i++)
    {
        cin >> L >> R;
        L--;
        R--;
        pow[i] = pow_list[L] - pow_list[R];
    }
    for (int i = 0; i < Q; i++)
        cout << pow[i] << endl;
}

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

const ll mod = 1e18;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  __int128 ans = 1;
  rep(i, n) {
    ans *= a[i];
    if (ans > mod) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ll(ans) << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n, s) for (int i = s; i < (int)(n); i++)

ll calcNumOfCombination(ll n, ll r) {
    ll num = 1;
    for (ll i = 1; i <= r; i++) {
        num = num * (n - i + 1) / i;
    }
    return num;
}

int gcd(int x, int y) { return (x % y) ? gcd(y, x % y) : y; }

int findSumDigits(int s) {
    int num = 0;
    int temp = 0;
    while (s) {
        temp = s % 10;
        num += temp;
        s = s / 10;
    }
    return num;
}

int main() {
    ll n, k;
    cin >> n >> k;
    ll sum = 0;
    ll low = 0, high = 0;
    int flag = 0;

    for (ll i = k; i <= n + 1; i++) {
        if (flag == 0) {
            for (ll j = 0; j < i; j++) {
                low += j;
                high += (n - j);
            }
            flag = 1;
        }
        sum += (high - low + 1);
        low += i;
        high += (n - i);
    }

    ll ans = sum % (1000000007);

    cout << ans << endl;


    return 0;
}

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

int main() {
  int k,n;cin>>k>>n;
  vector<int> position(n);
  vector<int> distance(n);
  for (int i = 0; i < n; i++) cin >> position.at(i);

  // 各家の間の距離を出す
  for (int i = 0; i < n-1; i++) {
    distance.at(i) = position.at(i+1) - position.at(i);
  }
  distance.at(n-1) = k - position.at(n-1) + position.at(0);

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

  // 最も離れている区間は避ける
  cout << k - distance.at(n-1) << endl;
}

Measured memory_bytes: 1920