akhauriyash/Code-Regression huggingface dataset:
#include<queue>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include <cstring>
#include <string.h>
#include <cmath>
#include <math.h>
#include <time.h>
#define ll long long
#define N 500003
#define M 103
#define db double
#define P putchar
#define G getchar
#define inf 998244353
using namespace std;
char ch;
void read(int &n)
{
	n=0;
	ch=G();
	while((ch<'0' || ch>'9') && ch!='-')ch=G();
	ll w=1;
	if(ch=='-')w=-1,ch=G();
	while('0'<=ch && ch<='9')n=(n<<3)+(n<<1)+ch-'0',ch=G();
	n*=w;
}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
ll abs(ll x){return x<0?-x:x;}
ll sqr(ll x){return x*x;}
void write(ll x){if(x>9) write(x/10);P(x%10+'0');}

int d[N],pos[N],f[N],q,n,m,x,y;

int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	
	read(n);read(m);
	
	pos[0]=m;
	for(int i=1;i<=n;i++)
		read(d[i]),pos[i]=min(pos[i-1],abs(pos[i-1]-d[i]));
	
	f[n+1]=1;
	for(int i=n;i;i--)
	{
		f[i]=f[i+1];
		if(d[i]<(f[i+1]<<1))f[i]+=d[i];
	}
	
	read(q);
	for(int i=1;i<=q;i++)
	{
		read(x);
		if(pos[x-1]>=f[x+1])puts("YES");
			else puts("NO");
	}
	
	return 0;
}


Measured memory_bytes: 7808
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
  int n, x[50], y[50], p, q, ans = 50;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &x[i], &y[i]);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j) {
        p = x[i] - x[j];
        q = y[i] - y[j];
      }
      int cnt = 0;
      for (int k = 0; k < n; k++) {
        for (int l = 0; l < n; l++) {
          if (k != l && x[k] - x[l] == p && y[k] - y[l] == q) {
            cnt++;
          }
        }
      }
      ans = min(ans, n - cnt);
    }
  }
  printf("%d\n", max(1, ans));
}

Measured memory_bytes: 128
#include <iostream>
#include <string>

using namespace std;

int k;
string str;


int main()
{
	cin >> str >> k;
	int seg_count = 0;
	int seg_length = 0;
	char start_char = '\0';
	int start_length = 0;
	char prev_char = '\0';
	long long total_length = 0LL;
	long long last_length = 0LL;
	int last_addition = 0LL;
	for (char c : str)
	{
		if (c != prev_char)
		{
			seg_count++;
			
			if (seg_count == 2)
			{
				start_char = prev_char;
				start_length = seg_length;
			}
			prev_char = c;
			last_length = total_length;
			total_length += seg_length / 2;
			last_addition = seg_length / 2;
			seg_length = 1;
			continue;
		}
		seg_length++;
	}
	last_length = total_length;
	total_length += seg_length / 2;
	last_addition = seg_length / 2;
	if (seg_count == 1)
	{
		total_length = str.length() * k / 2;
		cout << total_length << endl;
		return 0;
	}
	if (prev_char == start_char)
	{
		total_length = last_length + ((seg_length + start_length) / 2 + (last_length - start_length / 2)) * (k - 1) + last_addition;
		cout << total_length << endl;
		return 0;
	}
	total_length *= k;
	cout << total_length << endl;
	return 0;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>

#define in std::cin
#define out std::cout

int64_t N, MAX, MIN;
int32_t count[5] = {};
int64_t item[5][500][2] = {};
int32_t hash[5] = {0,1,2,3,4};

std::pair<int64_t, int64_t> patt_A[200 * 200 * 200];
auto patt_A_end = patt_A;
std::pair<int64_t, int64_t> patt_B[500*500];
auto patt_B_end = patt_B;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N>>MIN>>MAX;
	for (size_t t = 0; t < 5; t++)
	{
		item[t][count[t]][0] = 0;
		item[t][count[t]][1] = 0;
		++count[t];
	}
	for (int32_t i = 0; i < N; i++)
	{
		int64_t t, x, y;
		in >> t >> x >> y; --t;
		item[t][count[t]][0] = x;
		item[t][count[t]][1] = y;
		++count[t];
	}
	std::sort(hash, hash + 5, [](int i, int j) {return count[i] < count[j]; });

	for (int i = 0; i < count[hash[0]]; i++)
		for (int j = 0; j < count[hash[1]]; j++)
			for (int k = 0; k < count[hash[2]]; k++)
	{
		(*patt_A_end).first  = item[hash[0]][i][0] + item[hash[1]][j][0] + item[hash[2]][k][0];
		(*patt_A_end).second = item[hash[0]][i][1] + item[hash[1]][j][1] + item[hash[2]][k][1];
		++patt_A_end;
	}
	std::sort(patt_A, patt_A_end, std::greater<>{});
	for (int i = 0; i < count[hash[3]]; i++)
		for (int j = 0; j < count[hash[4]]; j++)
	{
		(*patt_B_end).first  = item[hash[3]][i][0] + item[hash[4]][j][0];
		(*patt_B_end).second = item[hash[3]][i][1] + item[hash[4]][j][1];
		++patt_B_end;
	}
	std::sort(patt_B, patt_B_end);

	std::multiset<int64_t> sets;
	auto B_beg_iter = patt_B, B_end_iter = patt_B;
	for (auto iter = patt_A; iter != patt_A_end; ++iter)
	{
		//push
		while (B_end_iter != patt_B_end && B_end_iter->first <= MAX - iter->first) {
			sets.insert(B_end_iter->second);
			++B_end_iter;
		}
		//pop
		while (B_beg_iter != B_end_iter &&B_beg_iter->first < MIN - iter->first) {
			sets.erase(sets.find(B_beg_iter->second));
			++B_beg_iter;
		}

		auto iter1 = sets.lower_bound(MIN - iter->second);
		if (iter1 != sets.end() && *iter1 + iter->second <= MAX) {
			out << "Yes" << endl;
			return 0;
		}
	}
	out << "No" << endl;

	return 0;
}
#endif

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

int calc_digit(ll n) {
  int digit = 0;
  // 120 --> 12
  // 12 --> 1
  // 1 --> 0
  while (n > 0) {
    n = n / 10;
    digit++;
  }
  return digit;
}

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

  ll lim = ll(sqrt(n));
  for (ll i = lim; i >= 1; i--) {
    if (n % i == 0) {
      int a = calc_digit(i);
      int b = calc_digit(n/i);
      cout << max(a, b) << endl;
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 3648
#include "iostream"
#include "string"
#include "algorithm"
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if ((a+b) % 2 == 0) {
		cout << (a + b) / 2;
	}
	else {
		cout << "IMPOSSIBLE";
	}
	cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String S = scanner.next();
    int o1 = 0;
    int e1 = 0;
    for (int i = 0; i < S.length(); i += 2) {
      if (S.charAt(i) == '1') {
        o1++;
      }
    }
    for (int i = 1; i < S.length(); i += 2) {
      if (S.charAt(i) == '1') {
        e1++;
      }
    }
    int o0 = (S.length() + 1) / 2 - o1;
    int e0 = S.length() / 2 - e1;
    int ans = Math.min(o0 + e1, o1 + e0);
    System.out.println(ans);
  }

}


Measured memory_bytes: 24088
#include<stdio.h>

int main(void){
    int a[5];
    int k;
    for(register int i = 0;i < 5;i++)scanf("%d",&a[i]);
    scanf("%d",&k);
    int c = 0;
    puts(a[4] - a[0] > k ? ":(":"Yay!");
}

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


int main() {
  int A, B, C;
  cin >> A >> B >> C;
  int count5 = 0;
  int count7 = 0;
  vector<int> array = {A, B, C};
  for (int i = 0; i < array.size(); i ++) {
  	if (array[i] == 5) {
    	count5 ++;
    } else if (array[i] == 7) {
    	count7 ++;
    }
  }
  string result = "NO";
  if (count5 == 2 && count7 == 1) {
  	result = "YES";
  }
  cout << result << endl; 
}


Measured memory_bytes: 256
N, M = map(int, input().split())
v = [[] for _ in range(N)]
u = [[] for _ in range(N)]
for _ in range(N + M - 1) :
    A, B = map(int, input().split())
    v[A-1].append(B-1)
    u[B-1].append(A-1)

for i in range(N) :
    if len(u[i]) == 0 :
        s = i
        break
        
dist = [0] * N
par = [-1] * N
cnt = [0] * N

par[s] = -1
q = [s]
while q :
    cur = q.pop()
    cnt[cur] += 1
    if cur != s and cnt[cur] != len(u[cur]) :
        continue
        
    for nex in v[cur] :
        if dist[cur] + 1 > dist[nex] :
            dist[nex] = dist[cur] + 1
            par[nex] = cur
            q.append((nex))

for i in range(N) :
    print(par[i] + 1)

Measured memory_bytes: 80852
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b;
    cin >> a >> b;
    int ans=a;
    if(a>b){
        cout << ans-1;
    }
    else{
        cout << ans;
    }


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main() {
	int R[MAX], n;

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> R[i];
	}
	int maxv = -2000000000;
	int minv = R[0];

	for (int i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}

	cout << maxv << endl;

	return 0;
}

Measured memory_bytes: 3840
from sys import stdin


def main() -> None:
    s = next_str()
    print(("WA", "AC")[judge(s)])


def judge(s: str) -> bool:
    flg = False
    n = len(s)

    for i in range(n):
        if i == 0:
            if s[i] != 'A':
                return False
        elif 2 <= i < n - 1 and s[i] == 'C' and not flg:
            flg = True
        elif s[i] != s[i].lower():
            return False

    if not flg:
        return False
    return True


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

def rl():
    return list(map(int, input().split()))

def T(n):
    return n * (n + 1) // 2

def S(a, b):
    return T(b) - T(a - 1)

def solve():
    n, k = rl()
    ans = 1
    for i in range(k, n + 1):
        lo = T(i - 1)
        hi = S(n - i + 1, n)
        ans += hi - lo + 1
        ans %= (10**9 + 7)
        # print (ans)

    print (ans)






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


Measured memory_bytes: 68836
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll long long
#define ull unsigned long long
#define dd double
#define oo 1001007000
#define ff float
#define ooo 4223352036854775007
#define iii pair<ll,ll>
#define vii vector<ll>
#define viii vector<iii>
#define sss pair<str,str>
#define str string
#define sii set<ll>
#define siii set<iii>
#define r0 return 0
#define pb push_back
#define sz size
using namespace std;

const char E='\n';
const int N=1000005;
const int NN=2005;
const ll md=998244353;


int main(){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
    ll ans=0;
    int n,m,s;
    cin >> n;
    for (int i=1;i<n;i++){
        for (int j=i;j<n;j+=i){
            ans++;
        }
    }
    cout << ans << endl;
    r0;
}
/*








*/


Measured memory_bytes: 3664
package main
 
import "fmt"
 
func main() {
        var a, b, c int
        fmt.Scan(&a, &b, &c)
        if a != b && b != c && a != c {
                fmt.Println("No")
        } else if a == b && b == c {
                fmt.Println("No")
        } else {
                fmt.Println("Yes")
        }
}

Measured memory_bytes: 512
from collections import deque
H,W=map(int,input().split())
maze=[list(input()) for i in range(H)]
count=-1

#-------------------------------------------------------------------------
#幅優先探索,再帰関数

def search() :
    flag=[[0]*W for i in range(H)]
    count=[[-1]*W for i in range(H)]
    flag[0][0]=1                               #通った場所はflagを0から1に変更していく
    count[0][0]=0                              #こちらで通る時間を数える
    pos=deque([])
    pos.append([0,0])

    while len(pos)>0 :
        y,x=pos.popleft()
        if y==H-1 and x==W-1 :
            return count[H-1][W-1]
            break

        for p,q in [[1,0],[-1,0],[0,1],[0,-1]] :
            if 0<=y+p<H and 0<=x+q<W and maze[y+p][x+q]=="." and flag[y+p][x+q]==0 :
                flag[y+p][x+q]=1     
                pos.append([y+p,x+q])
                count[y+p][x+q]=count[y][x]+1    

    if y!=H-1 and x!=W-1 :
        print(-1)
        exit()         

#-------------------------------------------------------------------------
#スコア求める,始めに白の個数を数えて、後で通った白の数だけ引く

for i in range(H) :
    for j in range(W) :
        if maze[i][j]=="." :    
            count+=1

ans=count-search()

print(ans)


Measured memory_bytes: 9464
using System;
using System.Collections.Generic;
using static System.Math;

namespace abc136_a
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            int A = cin.ReadInt;
            int B = cin.ReadInt;
            int C = cin.ReadInt;

            Console.WriteLine(Max(C-(A-B), 0));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) 
                {
                    return inputStream.Dequeue();
                }

                string[] tmp = _stream.ReadLine().Split(_separator);
                
                for (int i = 0; i < tmp.Length; ++i)
                {
                    inputStream.Enqueue(tmp[i]);
                }
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int n, p;
string s;
long long ans;
long long sum;
map <int, int> mp;

int main() { 

  scanf("%d %d\n", &n, &p);
  getline(cin, s);

  if (p == 2 || p == 5) {
    for (int i = 0; i < sz(s); i++) {
      if ((s[i] - '0') % p == 0) {
        ans += i + 1;
      }
    }
    cout << ans << endl;
    return 0;
  }

  reverse(all(s));
  mp[0] = 1;
  long long pt = 1;
  for (int i = 0; i < sz(s); i++) {
    sum = (sum + (s[i] - '0') * pt)  % p;
    ans += mp[sum];
    mp[sum]++;
    pt = pt * 10 % p;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 900
import sys
l,r=(int(x) for x in input().split())
s=2020
for i in range(l, min(l+2021,r+1)):
  for j in range(i+1, min(l+2021, r+1)):
    n=i%2019*j%2019%2019
    if n<s:
      s=n
    if s==0:
      print(s)
      sys.exit()
print(s)

Measured memory_bytes: 3060
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10000000)
input = sys.stdin.readline
INF = float("inf")


def dfs(G, visited, v, cnt):
    visited[v] = True

    for nv in G[v]:
        if visited[nv]:
            continue
        cnt = dfs(G, visited, nv, cnt + 1)
    
    return cnt


# 処理内容
def main():
    N, M = map(int, input().split())

    if M == 0:
        print(1)
        return

    P = set()
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1; b -= 1
        if a > b:
            a, b = b, a
        P.add((a, b))

    G = [[] for _ in range(N)]
    for pair in P:
        a, b = pair
        G[a].append(b)
        G[b].append(a)

    visited = [False] * N
    ans = 1
    for i in range(N):
        if visited[i]:
            continue
        tmp = dfs(G, visited, i, 1)
        ans = max(ans, tmp)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 250308
/*input
BBW
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int, int>
#define f first
#define s second 
#define mp make_pair
string st;
int conv()
{
	int ret=0;int pos=-1;
	for(int i=0;i<st.size();i++)
	{
		if(st[i]=='B')
		{
			pos=i;break;
		}
	}
	if(pos==-1) return 0;
	int ct=0;
	for(int i=pos+1;i<st.size();i++){
		if(st[i]=='W') ret+=i-(pos + ct++);
	}
	return ret;
}
signed main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>st;
	int ans=conv();cout<<ans;
}

Measured memory_bytes: 720
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<climits>
using namespace std;

int main() {
  int r, D, x;
  int ans=0;

  cin >> r >> D >> x;

  for(int i=0; i < 10; i++){
    x = r*x -D;
    cout << x << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;
const double PI = acos(-1.0);

int G[210][210];
int N, M, R;
int r[8];
int dist[210];
int mindist[8][8];

void dijkstra(int start){
    int done[210];
    mem(done, 0);
    REP(i, N){
        dist[i] = INF;
    }
    dist[start] = 0;
    int st = start, nextst = -1;
    int minCost = 0;
    int donecount = 0;
    while(donecount < N){
        done[st] = 1;
        donecount++;
        minCost = INF;
        REP(i, N){
            if(!done[i]){
                if(G[st][i] != INF && dist[st] + G[st][i] < dist[i]){
                    dist[i] = dist[st] + G[st][i];
                }
                if(dist[i] <= minCost){
                    nextst = i;
                    minCost = dist[i];
                }
            }
        }
        st = nextst;
    }
    /*
    REP(i, N){
        cout << done[i];
    }
    cout << "\n";
    */
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> R;
    REP(i, R){
        cin >> r[i];
        r[i]--;
    }
    REP(i, N){
        REP(j, N){
            if(i == j) G[i][j] = 0;
            else G[i][j] = INF;
        }
    }
    REP(i, M){
        int a,b,c;
        cin >> a >> b >> c;
        a--;
        b--;
        G[a][b] = c;
        G[b][a] = c;
    }
    REP(i, R){
        dijkstra(r[i]);
        REP(j, R){
            mindist[i][j] = dist[r[j]];
            // cout << mindist[i][j] << " ";
        }
    // cout << "\n";
    }

    int v[8];
    REP(i, R){
        v[i] = i;
    }

    int ans = INF;
    do {
        int tmp = 0;
        int s = v[0];
        FOR(j, 1, R){
            int g = v[j];
            tmp += mindist[s][g];
            s = g;
        }
        if(tmp < ans) ans = tmp;
    } while( next_permutation(v, v+R));

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
#define all(vec) vec.begin(),vec.end()
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n) for (int i = n; 0<i;i--)
#define print(out) cout<< out  << "\n";
#define mod 1000000007
const int INF = 1e8;
typedef pair<int,int> P;

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

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

int main(){
  ll A,B,C,D;cin>>A>>B>>C>>D;
  A--;
  ll CD=lcm(C,D);
  ll ans;
  ans=B-A;
  ans+=A/C-B/C+A/D-B/D+B/CD-A/CD;
  print(ans)
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        n: usize,
        k: usize,
        s: usize,
    }
    let mut ans = vec![s; k];
    if s < 1_000_000_000 {
        let mut add = vec![s + 1; n - k];
        ans.append(&mut add);
    } else {
        let mut add = vec![1; n - k];
        ans.append(&mut add);
    }
    for i in 0..n {
        print!("{} ", ans[i]);
    }
}


Measured memory_bytes: 3656
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>

int main() {
  int H, W, M;
  std::cin >> H >> W >> M;
  std::set<std::tuple<int, int>> targets;
  std::map<int, int> horizontal_counts, vertical_counts;
  int max_horizontal = 0;
  int max_vertical = 0;
  for (int i = 0; i < M; ++i) {
    int h, w;
    std::cin >> h >> w;
    targets.emplace(h, w);
    max_horizontal = std::max(max_horizontal, ++horizontal_counts[h]);
    max_vertical = std::max(max_vertical, ++vertical_counts[w]);
  }
  std::vector<int> horizontal, vertical;
  for (const auto [h, count] : horizontal_counts) {
    if (count == max_horizontal) {
      horizontal.push_back(h);
    }
  }
  for (const auto [w, count] : vertical_counts) {
    if (count == max_vertical) {
      vertical.push_back(w);
    }
  }
  if (horizontal.size() * vertical.size() > static_cast<std::size_t>(M)) {
    std::cout << max_horizontal + max_vertical << std::endl;
    return 0;
  }
  for (const auto h : horizontal) {
    for (const auto w : vertical) {
      if (targets.count(std::make_pair(h, w)) == 0) {
        std::cout << max_horizontal + max_vertical << std::endl;
        return 0;
      }
    }
  }
  std::cout << max_horizontal + max_vertical - 1 << std::endl;
  return 0;
}


Measured memory_bytes: 49476
def Base_10_to_n(X, n):#10進数をbit_base進数に変換
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

def main():
  s = str(input())
  ans = 0
  for i in range(2**(len(s)-1)):
    bits = Base_10_to_n(i, 2)
    bits = bits.zfill(len(s)-1)
    now = 0
    for j, bit in enumerate(bits):
      if bit == '1':
        ans += int(s[now:j+1])
        now = j + 1
      if j == len(s)-2:
        ans += int(s[now:])
  if ans == 0:
    ans += int(s)
  print(ans)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 9204
import java.util.*;

class Main {
	  static int mod=1_000_000_007;
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
      long P = sc.nextLong();
      long Q = sc.nextLong();
      long R = sc.nextLong();
 
      
      
	  System.out.println(P+Q+R-Math.max(P, Math.max(Q, R)));
  }
  
 
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
int a[100005];
vector<int> edge[100005];
int main(){
    int n,m,ans=0;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    for(int i=1;i<=m;i++){
        int u,v;
        cin>>u>>v;
        edge[u].push_back(v);
        edge[v].push_back(u);
    }
    for(int i=1;i<=n;i++){
        int tag=1;
        for(auto j:edge[i]){
            if(a[j]>=a[i]){
                tag=0;break;
            }
        }
        ans+=tag;
    }
    cout<<ans<<endl;
}

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

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

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, t, a;
  cin >> n >> t >> a;
  VLL h(n);
  VLL hh(n);
  ll ans = 1LL << 60;
  rep(i, n) cin >> h[i];
  rep(i, n) { hh[i] = (t * 1000LL) - (h[i] * 6LL); }
  rep(i, n) { ans = min(ans, abs(a * 1000LL - hh[i])); }
  rep(i, n) {
    // cerr << abs(a - h[i]) << endl;
    if(ans == abs(a * 1000LL - hh[i])) {
      cout << i + 1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
const int N = 1e5;  // limit for array size
ll n;  // array size

int main(){
	int n;cin>>n;
	
	ll a[n+1];
	
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	
	unordered_map<int,int>m1;
	unordered_map<int,int>m2;
	
	for(int i=1;i<=n;i+=2){
		m1[a[i]]++;
	}
	for(int i=2;i<=n;i+=2){
		m2[a[i]]++;
	}
	
	unordered_map<int,int> ::iterator it=m1.begin();
	
	int max1=-1,max2=-1;
	int no1=-1,no2=-1;
	
	for(;it!=m1.end();it++){
		if((*it).SS>=max1){
			max2=max1;
			max1=(*it).SS;
			no2=no1;
			no1=(*it).FF;
		}
		else if((*it).SS>max2){
			max2=(*it).SS;
			no2=(*it).FF;
		}
	}
	
	int max3=-1,max4=-1;
	int no3=-1,no4=-1;
	
	for(it=m2.begin();it!=m2.end();it++){
		if((*it).SS>=max3){
			max4=max3;
			max3=(*it).SS;
			no4=no3;
			no3=(*it).FF;
		}
		else if((*it).SS>max4){
			max4=(*it).SS;
			no4=(*it).FF;
		}
	}
	
	if(no1==no3&&max2==-1&&max4==-1){
		cout<<n/2<<endl;return 0;
	}
	
	
	if(no1!=no3){
		cout<<n-(max1)-max3<<endl;
	}
	else{
		if(max1>max3){
			cout<<n-max1-max4<<endl;
		}
		else if(max1<max3){
			cout<<n-max2-max3<<endl;
		}
		else if(max1==max3){
		   if(max4>=max2){
		   	  cout<<n-max4-max1<<endl;
		   }
		   else{
		   	  cout<<n-max3-max2<<endl;
		   }
		}
	}
	
	return 0;
}

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

int main(){
    int n,a,b;
    cin>>n>>a>>b;

    int total = 0;
    for(int i=1;i<=n;i++){
        string s = to_string(i);
        int s_sum = 0;
        for(int j=0;j<s.length();j++){
            s_sum += (int)s[j] - 48;
        }
        if (a <= s_sum && s_sum <= b){
            total += stoi(s);
        }
    }
    cout<<total<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>

using namespace std;

int S, W;

void solve()
{
    if(S <= W){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
}

int main()
{
    cin >> S >> W;
    solve();


    return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<iostream>
using namespace std;
int H, W; int c[1405][1405], dp[1405][1405];

void solve()
{
  int maxv = 0;
  for(int h=1; h<=H; h++)
  {
    for(int w=1; w<=W; w++)
    {
      if(c[h][w] == 1) dp[h][w] = 0;
      else
      {
        dp[h][w] = min(dp[h-1][w], min(dp[h-1][w-1], dp[h][w-1])) + 1;
        maxv = max(dp[h][w], maxv);
      }
    }
  }
  printf("%d\n", maxv*maxv);
}
int main()
{
  scanf("%d%d", &H, &W);
  for(int i=1; i<=H; i++)
  {
    for(int j=1; j<=W; j++)
      scanf("%d", &c[i][j]);
  }
  for(int i=0; i<=H; i++) dp[i][0] = 0;
  for(int j=0; j<=W; j++) dp[0][j] = 0;
  solve();
  return 0;
}



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

int main(void) {
    int count = 0;

    int n;
    std::cin >> n;
    std::vector<int> s(n, 0);
    for (int i = 0; i < n; i++) {
        std::cin >> s[i];
    }

    int q;
    std::cin >> q;
    std::vector<int> t(q, 0);
    for (int i = 0; i < q; i++) {
        std::cin >> t[i];
    }

    for (int i = 0; i < q; i++) {
        for (int j = 0; j < n; j++) {
            if (t[i] == s[j]) {
                count++;
                break;
            }
        }
    }
    std::cout << count << std::endl;
    return 0;
}

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

int main(){
  int n, w, h, len;
  char m[21][21];
  int dx[] = {0, 1, 0, -1};
  int dy[] = {-1, 0, 1, 0};
  char d[] = "^>v<";
  cin >> n;
  while(n--){
    int cx, cy, cd, bx, by;
    cin >> h >> w;
    getchar();
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	m[j][i] = getchar();
	if(m[j][i] == '^'){ cx = j; cy = i; cd = 0; m[j][i] = '.'; }
	if(m[j][i] == '>'){ cx = j; cy = i; cd = 1; m[j][i] = '.'; }
	if(m[j][i] == 'v'){ cx = j; cy = i; cd = 2; m[j][i] = '.'; }
	if(m[j][i] == '<'){ cx = j; cy = i; cd = 3; m[j][i] = '.'; }
      }
      getchar();
    }
    cin >> len;
    getchar();
    for(int c = 0; c < len; c++){
      switch(getchar()){
      case 'U':
	cd = 0;
	if(cy > 0 && m[cx][cy - 1] == '.') cy--;
	break;
      case 'R':
	cd = 1;
	if(cx < w-1 && m[cx + 1][cy] == '.') cx++;
	break;
      case 'D':
	cd = 2;
	if(cy < h-1 && m[cx][cy + 1] == '.') cy++;
	break;
      case 'L':
	cd = 3;
	if(cx > 0 && m[cx - 1][cy] == '.') cx--;
	break;
      case 'S':
	bx = cx; by = cy;
	while(m[bx][by] == '.' || m[bx][by] == '-'){
	  bx += dx[cd];
	  by += dy[cd];
	  if(m[bx][by] == '*'){
	    m[bx][by] = '.';
	    break;
	  }
	}
      }
    }
    getchar();
    for(int i = 0; i < h; i++){
      for(int j = 0; j < w; j++){
	if(i == cy && j == cx) cout << d[cd];
	else cout << m[j][i];
      }
      cout << endl;
    }
    if(n) cout << endl;
  }
}

Measured memory_bytes: 0
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair




int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    a=min(a,b);
    c=min(c,d);
    cout<<a+c<<endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
/*
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <iomanip>
#include <numeric>
*/

using namespace std;

typedef long long LL;

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

	cin.tie(0);
	ios::sync_with_stdio(false);

	int X;

	cin >> X;

	cout << X / 3600 << ":" << (X % 3600) / 60 << ":" << X % 60 << endl;

	return 0;
}


Measured memory_bytes: 3224
#include<iostream>
#include<string>
#include<ctype.h>
using namespace std;

int main()
{
	string str;

	getline(cin,str);

	for(int i=0;i<str.size();i++)
	{
		if(isupper(str[i])==0)
		{
			str[i] = toupper(str[i]);
			cout << str[i] ;
			continue;
		}

		else
		{
			str[i] = tolower(str[i]);
			cout << str[i] ;
		}
	} 

	cout << endl;

	return 0;
}

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

int arr[200010], n, two, four, odd;


int main()
{

        cin >> n;

        for(int i = 1; i <= n; i ++){
                cin >> arr[i];
                if(arr[i] % 4 == 0) four ++;
                else if(arr[i] % 2 == 0) two ++;
                else odd ++;

        }
        if(odd <= four) cout << "Yes\n";
        else if(four + 1 == odd && !two && four) cout << "Yes\n";
        else cout << "No\n";



        return 0;
}


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

int main()
{
	int N;
	int L[10];
	cin >> N;
	int max_L=0, iofmax,sum_L=0;
	for (int i = 0; i < N; i++) {
		cin >> L[i];
		sum_L += L[i];
		if (max_L < L[i]) {
			max_L = L[i];
			iofmax == i;
		}
	}
	if ((sum_L - max_L) > max_L ) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>

using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=1e9+1000;
const int mod=1e9+7;
ll infi=1e18+100;

//x=10111;
//x<<2 = 1011100 (右シフト),x>>2 = 101 (左シフト)
//(x>>2)&1 = 101 & 001 = 1
//iビット目は、(x>>i) & 1 でわかる(x>>i)%2 でもよい


ll N,A;
ll x[55];
ll dp[55][55][3000]={};


int main(){
	cin>>N>>A;
	rep(i,N) cin>>x[i];
  Rep(i,N){
    dp[i][0][0]=1;
  }
  rep(i,N){
    rep(j,N){
      rep(k,N*50){
        if(k>=x[i]) dp[i][j][k]=dp[i-1][j-1][k-x[i]]+dp[i-1][j][k];
        else dp[i][j][k]=dp[i-1][j][k];
      }
    }
  }
  
	ll ans=0;
  rep(j,N){
      ans+=dp[N][j][j*A];
  }
	cout<<ans<<endl;
	
	
	return 0;
}

Measured memory_bytes: 66560
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>

using namespace std;
int main( )
{
	int A,B,C;
	cin>>A>>B>>C;
	if(A==5&&B==7&&C==5)
	{
		cout<<"YES"<<endl;
	}
	else if(A==5&&B==5&&C==7)
	{
		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;
using ll = long long;

constexpr int nax = 5e5;

int n, a, b, c, d;

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

    cin >> n >> a >> b >> c >> d;

    for (int i = 0; i <= n - 1; ++i)
    {
        ll x = -(ll)c * i + (ll)c * (n - 1 - i);
        ll lo = x - ((ll)(d - c) * i);
        ll hi = x + ((ll)(d - c) * (n - 1 - i));
        if (lo <= (b - a) and (b - a) <= hi)
            return cout << "YES" << '\n', 0;
    }
    cout << "NO" << '\n';
}
 

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int X;
	cin >> X;
	int lim = floor(sqrt(X));
	int ret = 1;
	FOR(i,2,lim){
		int cur = i;
		while(cur <= X){
			ret = max(cur,ret);
			cur *= i;
		}
	}
	println(ret);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in cnt(in dc, const VI& ddg, bool fst){
  if(dc==0){
    if(sz(ddg)==0)
      return 1;
    return 0;
  }
  if(dc==1){
    if(sz(ddg)==0)
      return 10;
    return 0;
  }
  in gl=0;
  if(sz(ddg)>0){
    gl=ddg[0];
    gl%=10;
    gl+=10;
    gl%=10;
  }
  in wy=0;
  VI cn;
  for(in c=-9;c<=9;++c){
    if((9*c%10+10)%10==gl)
      cn.PB(-c);
  }
  if(cn.empty())
    return 0;
  in cw;
  forv(z,cn){
    in df=cn[z];
    cw=0;
    for(in v1=(fst?1:0);v1<=9;++v1){
      if(v1+df>=0 && v1+df<=9 &&(!fst || v1+df>0))
	++cw;
    }
    VI td=ddg;
    while(sz(td)<dc)
      td.PB(0);
    forn(i,dc-1){
      td[i]+=df*9;
    }
    td.PB(0);
    in cc;
    forn(i,sz(td)-1){
      cc=td[i]/10;
      td[i]-=cc*10;
      td[i+1]+=cc;
      if(td[i]<0){
	td[i]+=10;
	td[i+1]-=1;
      }
    }
    assert(td[0]==0);
    forn(i,sz(td)-1){
      td[i]=td[i+1];
    }
    td.back()=0;
    while(sz(td)>0 && td.back()==0)
      td.pop_back();
    cw*=cnt(dc-2,td,0);
    wy+=cw;
  }
  return min(wy,in(1e12));
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in d;
  cin>>d;
  in sm=0;
  VI dd;
  while(d){
    dd.PB(d%10);
    d/=10;
  }
  for(in dc=2;dc<=50;++dc){
    sm+=cnt(dc,dd,1);
  }
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoderMake.ABC173
{
    class ABC173B
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            int ac = 0;
            int wa = 0;
            int lte = 0;
            int re = 0;
            
            for(int i = 0; i < n; i++)
            {
                string s = Console.ReadLine();
                if (s == "AC")
                {
                    ac++;
                }
                else if(s=="WA")
                {
                    wa++;
                }
                else if (s == "TLE")
                {
                    lte++;
                }
                else
                {
                    re++;
                }
            }
            Console.WriteLine("AC x " + ac);
            Console.WriteLine("WA x " + wa);
            Console.WriteLine("TLE x " + lte);
            Console.WriteLine("RE x " + re);
        }
    }
}


Measured memory_bytes: 30688
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <math.h>
#include <algorithm>

using namespace std;

int main()
{
	int N;
	cin >> N;
	int B = 0, A = 0, BA = 0;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		string str;
		cin >> str;
		int len = str.length();
		if (str[len - 1] == 'A' && str[0] == 'B') BA++;
		else if (str[len - 1] == 'A') A++;
		else if (str[0] == 'B') B++;
		for (int j = 1; j < len; j++) {
			if (str[j - 1] == 'A' && str[j] == 'B') ans++;
		}
	}
	if (BA) {
		ans += BA - 1;
		if (A) { ans++; A--; }
		if (B) { ans++; B--; }
	}
	ans += min(B, A);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k,d,a,count=0;
	cin>>n>>k;
	bool check[n+1];
	memset(check,0,sizeof(check));
	while(k--){
		cin>>d;
	for(int i=1;i<=d;i++){
		cin>>a;
		check[a]=1;
	}
	}
	for(int i=1;i<=n;i++){
		if(check[i]==0){
			count++;
		}
		else{
			continue;
		}
	}
	cout<<count;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

ll A, B, C, D;
unordered_map<ll, ll> dp;
const ll MAXN = 1e18;

ll dfs(ll n)
{
    if (n <= 0) return 0;
    if (n == 1) return D;
    // メモ済みならそのまま返す
    if (dp[n] > 0)
    {
        return dp[n];
    }

    ll res = MAXN;
    if (n < res / D)
    {
        res = n * D;
    }
    ll minus, plus;
    if (n % 2 == 0)
    {
        // そのまま割る
        res = min(res, dfs(n / 2) + A);
    }
    else
    {
        // 引いて2で割る
        minus = n % 2;
        res = min(res, dfs((n - minus) / 2) + A + minus * D);
        // 足して2で割る
        plus = 2 - n % 2;
        res = min(res, dfs((n + plus) / 2) + A + plus * D);
    }

    if (n % 3 == 0)
    {
        // そのまま割る
        res = min(res, dfs(n / 3) + B);
    }
    else
    {
        // 引いて3で割る
        minus = n % 3;
        res = min(res, dfs((n - minus) / 3) + B + minus * D);
        // 足して3で割る
        plus = 3 - n % 3;
        res = min(res, dfs((n + plus) / 3) + B + plus * D);
    }
    if (n % 5 == 0)
    {
        // そのまま割る
        res = min(res, dfs(n / 5) + C);
    }
    else
    {
        // 引いて5で割る
        minus = n % 5;
        res = min(res, dfs((n - minus) / 5) + C + minus * D);
        // 足して5で割る
        plus = 5 - n % 5;
        res = min(res, dfs((n + plus) / 5) + C + plus * D);
    }

    // メモする
    dp[n] = res;

    return res;
}

int main()
{
    ll T;
    cin >> T;
    REP(i, T)
    {
        ll N;
        cin >> N >> A >> B >> C >> D;
        dp.clear();
        ll ans = dfs(N);
        cout << ans << endl;
    }
}


Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;
    long long n = 0 , candies = 0 , mod = 1000000007 ;
    cin >> n >> candies ;
    long long a[n+1] , temp[candies+1] , ways[n+1][candies+1] , ptr = 0 ;
    for(long long i = 1 ; i <= n ; i++)
        cin >> a[i] ;
    for(long long i = 0 ; i <= n ; i++)
        for(long long j = 0 ; j <= candies ; j++)
            ways[i][j] = 0 , temp[j] = 0 ;
    ways[0][0] = 1 ;
    for(long long i = 1 ; i <= n ; i++){
        temp[0] = ways[i-1][0] ;
        for(long long j = 1 ; j <= candies ; j++)
            temp[j] = (temp[j-1] % mod + ways[i-1][j] % mod) % mod ;
        for(long long j = 0 ; j <= candies ; j++){
            ways[i][j] = temp[j] ;
            if(j-a[i]-1 >= 0) ways[i][j] = (temp[j] - temp[j-a[i]-1] + mod) % mod ;
        }
    }
    cout << ways[n][candies] ;
}


Measured memory_bytes: 83180
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>

using namespace std;

#define ll long long
#define db double
#define clr(a, b) memset(a, b, sizeof(a))
#define vi vector<int>


const int maxn = 5e5 + 10;

ll n, t;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    cout << n * n << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N;
	cin>>N;
	int sum = 0;
	int n = N;
	while(n!=0){
		int r = n % 10;
		sum += r;
		n /= 10;
	}
	if(N % sum == 0){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


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

Dict={}

for i,Num in enumerate(A):
    Dict[i]=Num

List = sorted(Dict.items(), key=lambda x:x[1])
S=List[(N//2)-1][1]
B=List[(N//2)][1]
for i in range(N):
    if(Dict[i]<=S):
        print(B)
    else:
        print(S)



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

int rev(int A) {
    int ans = 0;
    while(A != 0) {
        ans *= 10;
        ans += A%10;
        A /= 10;
    }
    return ans;
}

int main()
{
    int A, B;
    cin >> A >> B;
    int cnt = 0;
    for(int i = A; i <= B; ++i) {
        if(i == rev(i)) {
            //cout << i << endl;
            ++cnt;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(){
  int N, h[100], count = 0, k;
  cin >> N;
  for(int i = 0; i<N; i++){
    cin >> h[i];
  }
  
  for(int j = 0; j<N; j++){
    while(h[j] > 0){
      count++;
      k = j;
      while(h[k] > 0 && k < N){
        h[k]--;
        k++;
      }
    }  
  }
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 3552
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main {
	static Map<Integer,Integer> map = new HashMap<>();
	static Set<Integer> set = new HashSet<>();
	static int count = 0;
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i < n; i++) {
			map.put(i + 1, sc.nextInt());
		}
		solve(1);
	}
	 static void solve(int i) {
		if(i == 2) {
			System.out.println(count);
			System.exit(0);
		}
		if(set.contains(i)) {
			System.out.println(-1);
			System.exit(0);
		} else {
			set.add(i);
			count++;
		}
		int a = map.get(i);
		solve(a);
	 }
}

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

int main(){
  string s;
  cin>>s;
  
  string ans = "Good";
  
  for(int i =0;i<s.length()-1;i++){
    if(s[i] == s[i+1])
    {
      ans = "Bad";
      break;
    }
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
  int x[101] = {0};
  int n;
  int i = 0, max = 0;

  while(scanf("%d", &n) != EOF)
    x[n]++;

  for(i = 1; i < 101; i++) {
    if(max < x[i])
      max = x[i];
  }

  for(i = 1; i < 101; i++) {
    if(max == x[i])
      printf("%d\n", i);
  }

  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
	
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define per(i , j , n) for(ll i = j ; i >= n ; i--)
 
 
 
int main(){
	double r;
    cin >> r;
    cout << setprecision(10) << 2*M_PI*r;
    
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    vector<ll>v(9,0);
    for(int i=0;i<n;i++)
    {
        ll x;
        cin>>x;
        if(x>=1 and x<=399)
        {
            v[0]=1;
        }
        else if(x>=400 and x<=799)
        {
            v[1]=1;
        }
        else if(x>=800 and x<=1199)
        {
            v[2]=1;
        }
        else if(x>=1200 and x<=1599)
        {
            v[3]=1;
        }
        else if(x>=1600 and x<=1999)
        {
            v[4]=1;
        }
        else if(x>=2000 and x<=2399)
        {
            v[5]=1;
        }
        else if(x>=2400 and x<=2799)
        {
            v[6]=1;
        }
        else if(x>=2800 and x<=3199)
        {
            v[7]=1;
        }
        else{
            v[8]++;
        }
    }
    ll mx=accumulate(v.begin(),v.end(),0);
    ll mn=0;
    for(int i=0;i<=7;i++)
    {
        mn+=v[i];
    }
    if(v[8]==n)
    {
        cout<<"1"<<" "<<n<<endl;
    }
    else
    {
       cout<<mn<<" "<<mx<<endl;
    }


}



Measured memory_bytes: 3588
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

typedef long long int64;

using namespace std;

vector<int64> a;
vector<int64> f;
int64 n;
int64 k;

bool ok(int64 N) {
	int64 cnt = 0;
	for (int i = 0; i < n; ++i) {
	    int64 target = N / f[i];
		if (a[i] > target) {
		    cnt += a[i] - target;
		}
	}
	
	return cnt <= k;
}

int main() {
	ios_base::sync_with_stdio(0);
    cin >> n;
	cin >> k;
	a.resize(n);
	f.resize(n);
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) cin >> f[i];
	sort(all(f));
	reverse(all(f));
	sort(all(a));
	int64 l = 0;
	int64 r = 3000000;
	r *= r;
	while (r - 3 > l) {
	    int64 m = (l + r) / 2;
		if (ok(m)) {
		    r = m;
		} else {
		    l = m;
		}
	}
	for (int64 i = l; i <= r; ++i) {
	    if (ok(i)) {
		    cout << i << endl;
			return 0;
		}
	}
    return 0;
}


Measured memory_bytes: 3456