akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds; 
using namespace std;
#define int long long
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define mii map<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,b) for(ll (i)=0;i<(b);i++)
#define all(c) (c).begin(), (c).end()
#define F first
#define S second
#define CLR(p) memset(p, 0, sizeof(p))
#define SET(p) memset(p, -1, sizeof(p))
#define DEBUG true
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
//typedef long long int ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
tree_order_statistics_node_update> new_data_set; 
const int MAX=1e6+5;
#define MOD 1000000007
/*std::cout << std::fixed;
std::cout << std::setprecision(6);*/
//(a%mod-b%mod+mod)%mod

// #define LOCAL 1

/************************************


 
*************************************/

vector<int>par,dep,tin,tout;
vector<vector<int>>v;
vector<int>deg;
vector<pll>req;
bool visited[MAX];






void solve(){
    int t=1;
    // cin>>t;
    while(t--){
        int n;
        cin>>n;
        int a[n+1];
        mll m;
        for(int i=2;i<=n;i++){
            cin>>a[i];
            m[a[i]]++;
        }
        for(int i=1;i<=n;i++){
            cout<<m[i]<<"\n";
        }

        
    }
}


signed main() 
{ 
    boost;

    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (cin.peek() != EOF) {
        solve();
        cout << endl << endl;
        string s;
        do getline(cin, s);
        while (!cin.eof() && !s.empty());
        while (isspace(cin.peek())) cin.get();
    }
    #else
        solve();
    #endif




    

    
	return 0; 
} 

Measured memory_bytes: 17716
import sys
n=int(input())
h=list(map(int,input().split()))
b=0
for i in reversed(range(1,n)):
  if h[i]>=h[i-1]:
    continue
  elif h[i]+1==h[i-1]:
    h[i-1]-=1
  else:
    print("No")
    break
else:
  print("Yes")

Measured memory_bytes: 14396
def edu_dp_a_frog2():
    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    dp = [0] * n
    dp[0] = 0
    dp[1] = abs(h[1]-h[0])
    for i in range(2, n):
        dp[i] = min([dp[i-j]+abs(h[i]-h[i-j]) for j in range(1, min(i+1, k+1))])
        # for j in range(1, min(i+1, k+1)):
        #     dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]))
    print(dp[n-1])

edu_dp_a_frog2()

Measured memory_bytes: 20528
pub fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn depth(pi: usize, p: &Vec<usize>) -> usize {
    if pi == 1 {
        return 1;
    }
    depth(p[pi-2], p) + 1
}

const INF: usize = 1000000;

fn main() {
    let n = read1::<usize>();
    if n == 1 {
        let _p = read1::<String>();
        let _x = read1::<String>();
        println!("POSSIBLE");
        return;
    }
    let p = readn::<usize>(" ");
    let x = readn::<usize>(" ");

    let mut c = vec![Vec::new(); n];
    for i in 0..n-1 {
        c[p[i]-1].push(i+1);
    }

    let mut d = Vec::with_capacity(n);
    d.push((0, 0));
    for i in 0..n-1 {
        d.push((depth(p[i], &p), i+1));
    }
    d.sort_by(|a, b| (b.0).cmp(&(a.0)));
    
    let mut dp = vec![INF; n];
    for i in 0..n {
        let v = d[i].1;
        if c[v].len() == 0 {
            dp[v] = 0;
        } else {
            let c_num = c[v].len();
            let mut x_max = 0;
            let mut x_min = 0;
            let mut x_delta = Vec::new();
            for j in 0..c_num {
                if dp[c[v][j]] < x[c[v][j]] {
                    x_min += dp[c[v][j]];
                    x_max += x[c[v][j]];
                    x_delta.push(x[c[v][j]] - dp[c[v][j]]);
                } else {
                    x_min += x[c[v][j]];
                    x_max += dp[c[v][j]];
                    x_delta.push(dp[c[v][j]] - x[c[v][j]]);
                }
            }
            if x_min > x[v] {
                println!("IMPOSSIBLE");
                return;
            }
            let rest = x[v] - x_min;
            let mut dp2 = vec![vec![x_max; rest+1]; c_num+1];

            for y in 0..c_num {
                for x in 0..rest {
                    dp2[y+1][x+1] = std::cmp::min(dp2[y][x+1], dp2[y+1][x]);
                    if x_delta[y] <= x + 1 {
                        dp2[y+1][x+1] = std::cmp::min(dp2[y+1][x+1], dp2[y][x+1-x_delta[y]] - x_delta[y]);
                    }
                }
            }
            dp[v] = dp2[c_num][rest];
        }
    }

    println!("POSSIBLE");
}

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

int main() {
  ll a,b; cin >> a >> b;
  if(a>=1 && a<=9 && b>=1 && b<=9) cout << a*b << endl;
  else cout << "-1" << endl;
  
  return 0;
}



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

int main()
{
  string S,T,U ;
  int A,B ;
  cin>>S>>T>>A>>B>>U ;
  
  if(S==U) cout<<A-1<<" "<<B<<endl ;
  else if(T==U) cout<<A<<" "<<B-1<<endl ;
  else cout<<A<<" "<<B<<endl ;
  
  return 0 ;
}

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

int main() {

	int N;
	cin >> N;

	vector<pair<int, int>> p(N);
	
	for (int i = 0; i < N; i++)
	{
		int A;
		cin >> A;

		pair<int, int> tmp;
		tmp.first = A;
		tmp.second = i + 1;

		p[i] = tmp;
	}
	sort(p.begin(),p.end());

	for (int i = 0; i < N; i++)
	{
		cout << p[i].second << " ";
	}
	cout << endl;
	

	
	return 0;
}

Measured memory_bytes: 1664
using System;
using System.Linq;
using System.Collections.Generic;

class B{
  static void Main(){
    string str = Console.ReadLine();
    string strT = string.Join("", str.Reverse());
    string str1 = str.Substring(0, str.Length / 2).ToString();
    string str2 = strT.Substring(0, str.Length / 2).ToString();    
    int ans = 0;
    for(int i = 0; i < str.Length / 2; i++){
      if (str1.Substring(i, 1) != str2.Substring(i ,1)) ans++;
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 26612
K, N = map(int, input().split())
# print(K, N)
A = list(map(int, input().split()))
# print(A)
l = []
for i in range(1, N):
    l.append(int(A[i] - A[i - 1]))
l.append(int(A[0] + (K - A[N - 1])))
# print(l)
ans = sum(l) - max(l)
print(ans)


Measured memory_bytes: 32324
x = 0.0
y = 0.0
dir = 90

while (line = gets)
  d, t = line.chop.split(",").map { |s| s.to_i }

  if (d == 0 && t == 0)
    break
  end

  rad = Math::PI * dir / 180
  x += d * Math.cos(rad)
  y += d * Math.sin(rad)

  dir = (dir + 360 - t) % 360
end

puts x.to_i, y.to_i

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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (n); i < (a); i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int a,b;cin>>a>>b;
  cout<<max(a+b,max(a-b,a*b))<<endl;
}


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

using namespace std;

int v[101010];

int main() {
    int N, M;

    cin >> N >> M;
    
    for (int i = 0; i < M; ++i) {
        int L, R;
        cin >> L >> R;
        v[L]++;
        v[R + 1]--;
    }

    int itr = 0;
    for (int i = 0; i <= N; i++) {
        itr += v[i];
        v[i] = itr;
    }
    int ans = 0;
    for (int i = 0; i <= N; i++) {
        if (v[i] == M) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] x = new int[5];
		for (int i = 0; i < x.length; ++i) {
			x[i] = sc.nextInt();
		}
		for (int i = 0; i < x.length; ++i) {
			if (x[i] == 0) {
				System.out.println(i + 1);
				return;
			}
		}
	}
}


Measured memory_bytes: 35632
using System;

namespace abc154A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            string S = str[0];
            string T = str[1];
            str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            string U = Console.ReadLine();
            if (U == S)
                Console.WriteLine(A - 1 + " " + B);
            else
                Console.WriteLine(A + " " + (B - 1));
        }
    }
}


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

using namespace std;

#define INF 1000000009
#define maxn 100005

int n,k;
int a[maxn],memo[maxn];

int call(int pos){
  if(pos == n - 1) return 0;
  if(memo[pos] != -1) return memo[pos];
  int maxi = INF;
  for(int i = 1; i <= k; i++){
    if(pos + i < n){
      maxi = min(maxi,abs(a[pos] - a[pos + i])+ call(pos + i));
    }
  }
  return memo[pos] = maxi;
}

int main(){
  cin >> n >> k;
  for(int i = 0; i < n; i++) cin >> a[i];
  memset(memo,-1,sizeof(memo));
  cout << call(0) << endl;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef pair<int,int> pii;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
template<class Type> void line(const Type &a){int cnt=0;for(auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n,m;
	cin>>n>>m;
	
	if(n==m) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#define SQR(x) ((x)*(x))
using namespace std;

double L[20],a[20],b[20];
double ans=0;
int N,M;

double Distance(int x,int y){
  return SQR(L[x]-L[y])+SQR(a[x]-a[y])+SQR(b[x]-b[y]);
}
void Dfs(int pos,int num,vector<int> vec){

  double sum=0;
  if(num == M){
    for(int i=0 ; i < (int)vec.size() ; i++){
      for(int j=0 ; j < (int)vec.size() ; j++){
	if(i == j)continue;
	sum+=Distance(vec[i],vec[j]);
      }
    }
    ans=max(ans,sum/2);
    return;
  }
  
  if(pos == N)return;
  Dfs(pos+1,num,vec);
  vec.push_back(pos);
  Dfs(pos+1,num+1,vec);
  
}

int main(){
  
  cin >>N>>M;
  
  for(int i=0 ; i < N ; i++){
    cin >>L[i]>>a[i]>>b[i];
  }
  
  vector<int> vec;
  
  Dfs(0,0,vec);
  
  printf("%.20f\n",ans);
  
  return 0;
}

Measured memory_bytes: 1268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, t;
  cin >> n >> t;
  ll ans = t, now = 0;
  rep(i, n) {
    ll a;
    cin >> a;
    ans += min(t, a - now);
    now = a;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
ab = []
cd = []
for i in range(n):
  ab.append(list(map(int, input().split())))
for i in range(m):
  cd.append(list(map(int, input().split())))

for i in range(n):
  ret = [0,10**11]
  for j in range(m):
    if abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1]) < ret[1]:
      ret = [j+1, abs(ab[i][0]-cd[j][0]) + abs(ab[i][1]-cd[j][1])]
  print(ret[0])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(2e5)+10;
int n,c1,c2;
ll ans;
char s[maxn];
int main() {
	//freopen("1.txt","r",stdin);
	scanf("%s",s+1); n=strlen(s+1);
	for (int i=1;i<=n;i++)
		if (s[i]=='W') c2++;
	for (int i=1;i<=n;i++) {
		if (s[i]=='W') c1++,ans+=abs(i-c1);
		else c2++,ans+=abs(i-c2);
	}
	printf("%lld\n",ans/2);
	return 0;
}

Measured memory_bytes: 384
# ABC112C - Pyramid
def main():
    N, *XYH = map(int, open(0).read().split())
    A = [(x, y, h) for x, y, h in zip(*[iter(XYH)] * 3)]
    A.sort(key=lambda x: x[2], reverse=1)
    for x in range(0, 101):
        for y in range(0, 101):
            i, j, k = A[0]
            h = k + abs(i - x) + abs(j - y)
            for i, j, k in A[1:]:
                if k != max(h - abs(i - x) - abs(j - y), 0):
                    break
            else:
                print(x, y, h)
                return


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long double a,r,b,x,y;
    long long int c=0;
    cin>>a>>b;
    while(a--)
    {
        cin>>x>>y;
        r=sqrt(x*x+y*y);
        if(r<=b)
            c++;
    }
    cout<<c<<endl;
    return 0;
}


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

int main() {
  int N, A;
  cin >> N >> A;
  int B = N % 500; 
    
  if (N < 500) {
    if (A < N) {
      cout << "No" << endl;
    }
    else {
      cout << "Yes" << endl;
    }
  }  
  else {
    if (A < B) { 
      cout << "No" << endl;
    }
    else {
      cout << "Yes" << endl;
    }
  }      
}

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


#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);++i)
bool x[500][500];
int main(){
	int n;
	bool all_black = true;
	bool all_white = true;
	char y;

	cin >> n;
	bool *col = (bool *)calloc((n), sizeof(bool));
	bool *row = (bool *)calloc((n), sizeof(bool));
	bool *row_black = (bool *)calloc((n), sizeof(bool));
	int *col_white_num = (int *)calloc((n), sizeof(int));
	REP(i, n){
		col[i] = true;
		col_white_num[i] = 0;
		row[i] = true;
	}

	REP(i, n){
		REP(j, n){
			cin >> y;
			if(y == '#'){
				x[i][j] = true;
				row_black[j] = true;
				all_white = false;
			}else{
				x[i][j] = false;
				all_black = false;
				col[i] = false;
				row[j] = false;
				col_white_num[i]++;
			}
		}
	}
	// all
	if(all_black){
		cout << 0 << endl;
		return 0;
	}
	if(all_white){
		cout << -1 << endl;
		return 0;
	}

	// line
	int row_max = 0;
	bool is_line = false;
	REP(i, n){
		if(col[i]){
			is_line = true;
		}if(row[i]){
			row_max++;
		}
	}
	if(is_line){
			cout << n - row_max << endl;
	 		return 0;
	}

	//create line
	int min_num = n;

	REP(i, n){
		int k = col_white_num[i];
		if(!row_black[i]) k++;
		if(k < min_num) min_num = k;
	}
	cout << n - row_max + min_num << endl;

	return 0;
}



Measured memory_bytes: 512
#
import sys
import math
import numpy as np
import itertools


# ひとつ入力
n = int(input())
# n行の数をリストに
a = [int(input()) for i in range(n)] 

ki=0

for i in a:
    if i % 2 == 1:
        ki += 1

if ki >= 1:
    print("first")
else:
    print("second")






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

int N;
int A[3][3];
int B[15];
vector<int> C;

bool contain(int a, int b, int c, vector<int> &C) {
  auto itr1 = find(C.begin(), C.end(), a);
  size_t index1 = distance(C.begin(), itr1);
  auto itr2 = find(C.begin(), C.end(), b);
  size_t index2 = distance(C.begin(), itr2);
  auto itr3 = find(C.begin(), C.end(), c);
  size_t index3 = distance(C.begin(), itr3);
  if (index1 != C.size() && index2 != C.size() &&
      index3 != C.size()) {  // 発見できたとき
    return true;
  } else {  // 発見できなかったとき
    return false;
  }
}

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

  cin >> N;
  for (int i = 0; i < N; i++) cin >> B[i];

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < N; k++) {
        if (A[i][j] == B[k]) {
          C.push_back((i + 1) * 10 + (j + 1));
        }
      }
    }
  }

  bool judge = (contain(11, 12, 13, C) || contain(21, 22, 23, C) ||
                contain(31, 32, 33, C) || contain(11, 22, 33, C) ||
                contain(13, 22, 31, C) || contain(11, 21, 31, C) ||
                contain(12, 22, 32, C) || contain(13, 23, 33, C));

  if (judge) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
a, b = gets.chomp.split(" ").map(&:to_i)

if a == b
  answer = "Draw"
else
  if a == 1
    answer = "Alice"
  elsif b == 1
    answer = "Bob"
  elsif a > b
    answer = "Alice"
  else
    answer = "Bob"
  end
end

puts answer

Measured memory_bytes: 1788
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	for (double V; cin >> V;) {
		int N; double T, Y;
		T = V / 9.8;
		Y = 4.9*T*T;
		N = ceil((Y + 5) / 5);
		cout << N << endl;
	}
	return 0;
}

Measured memory_bytes: 1232
n=int(input())
l=list(map(int,input().split()))
bitlist=[]
for i in range(n):
  bit=[]
  num=l[i]
  for j in range(20):
    bit.append(num%2)
    num//=2
  bitlist.append(bit)
left=0
right=0
b=True
ans=1
now={}
for i in range(20):
  if bitlist[0][i]==1:
    now[2**i]=1
  else:
    now[2**i]=0
b=1#b=1の時右を伸ばす
while right<n:
  if b==1:
    right+=1
    if right==n:
      break
    for i in range(20):
      if bitlist[right][i]==1:
        now[2**i]+=1
        if now[2**i]>=2:
          b=0
    if b==1:
      ans+=right-left+1
  else:
    b1=1
    for i in range(20):
      if bitlist[left][i]==1:
        now[2**i]-=1
      if now[2**i]>=2:
        b1=0      
    left+=1
    if b1==1:
      b=1
      ans+=right-left+1
print(ans)

Measured memory_bytes: 126540
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for (int i = 0; i < values.length; i++) {
			values[i] = i + 1;
		}
		for (int i = 0; i < n; i++) {
			String str = sc.next();
			String[] ab = str.split(",");
			int a = Integer.parseInt(ab[0]) - 1;
			int b = Integer.parseInt(ab[1]) - 1;
			int c;
			c = values[a];
			values[a] = values[b];
			values[b] = c;
		}
		for (int i = 0; i < values.length; i++) {
			System.out.println(values[i]);
		}
	}
}

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


int main(int argc, char const *argv[])
{
	int H,W;
	int i,j = 0;
	while(true){
		cin >> H >> W;
		if((H == 0)&&(W == 0))
		{
			break;
		}

		for(i = 0; i < W;i++){
			cout << '#';
		}
		cout << endl;

		for(i = 1;i<H-1;i++){
			cout << '#';
			for(j = 1;j<W-1;j++){
				cout << '.';
			}
			cout << '#' << endl;
		}

		for(i = 0; i < W;i++){
			cout << '#';
		}
		cout << endl << endl ;

	}
	return 0;
}


Measured memory_bytes: 3068
amari = [i for i in range(10)]
p = 10**9 + 7
s =  str(input())
n = len(s)
ans = [0]*13
ans[0] = 1
for i in reversed(s):
  dp = [0]*13
  if i == '?':
    for j in range(13):
      for k in amari:
        dp[(j + k)%13] += ans[j]
  else:
    for j in range(13):
      dp[(j + amari[int(i)])%13] += ans[j]
      
  for i in range(len(dp)):
    dp[i] %= p
  ans = dp
  for i in range(len(amari)):
    amari[i] = amari[i]*10%13
print(ans[5])

Measured memory_bytes: 43580
#include<iostream>
using namespace std;
int main(){
    bool S[13] = {}, H[13] = {}, C[13] = {}, D[13] = {};
    int n, number, i;
    char mark;
    
    cin >> n;
    
    for(i=0;i<n;i++){
        
        cin >> mark >> number;
        
        if(mark == 'S'){
            S[number-1] = true;
        }else if(mark == 'H'){
            H[number-1] = true;
        }else if(mark == 'C'){
            C[number-1] = true;
        }else{
            D[number-1] = true;
        }
    }
    
    for(i=0;i<13;i++){
        if(S[i] == false){
            cout << "S " << i+1 << endl;
        }
    }
    for(i=0;i<13;i++){
        if(H[i] == false){
            cout << "H " << i+1 << endl;
        }
    }
    for(i=0;i<13;i++){
        if(C[i] == false){
            cout << "C " << i+1 << endl;
        }
    }
    for(i=0;i<13;i++){
        if(D[i] == false){
            cout << "D " << i+1 << endl;
        }
    }
    
    return 0;
    
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
long long l[1000000],r[1000000],b[10000000];
using namespace std;
int main(){
	long long n,m,minn=100000,maxx=0,res=0;
	cin>>n>>m;
	for (int i=0;i<m;i++){
		cin>>l[i]>>r[i];
		maxx=max(maxx,l[i]);
		minn=min(minn,r[i]);
	}
	res=minn-maxx+1;
	if (res>0) cout<<res;
	else cout<<0;
	return 0;
}

Measured memory_bytes: 6400
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


s = S()
k = I()
L = []
for i in range(len(s)):
    for j in range(i + 1, i + 1 + k):
        L.append(s[i:j])



L = sorted(list(set(L)))
print(L[k - 1])


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

namespace abc086_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            Console.WriteLine(((x[0] * x[1]) % 2 == 0) ? "Even" : "Odd");
        }
    }
}


Measured memory_bytes: 13268
#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 n;
    cin >> n;
    long double ans=0.0;
    rep(i,n){
        long double m;
        string s;
        cin >> m >> s;
        if(s == "JPY"){
            ans += m;
        }
        else{
            ans += m*380000.0;
        }
    }
    cout << ans;

    return 0;
}

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


using namespace std;

#define MAX 2000000


void couting_sort(int A[], int B[], int n)
{
    int max_v = *max_element(A, A + n);
    vector<int> counter(10000, 0);

    for (int i = 0; i < n; i++)
        counter[A[i]]++;
    for (int i = 1; i <= max_v; i++) {
        counter[i] += counter[i - 1];
    }

    for (int i = 0; i < n; i++) {
        B[--counter[A[i]]] = A[i];
    }
}


int A[MAX];
int B[MAX];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> A[i];
    couting_sort(A, B, n);

    for (int i = 0; i < n - 1; i++)
        cout << B[i] << " ";
    cout << B[n - 1] << endl;

    return 0;
}



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

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

	int n, k;

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

	int l[n];
	int i;

	for(i=0;i<n;i++){
		scanf("%d", &l[i]);
	}

	int tmp;
	int sum = 0;

	for(k=k;k>0;k--,n--){

		//find max
		for(i=0;i<n-1;i++){
			if(l[i] > l[i+1]){
				//exchange
				tmp = l[i];
				l[i] = l[i+1];
				l[i+1] = tmp;
			}
		}
		sum += l[i];
	}

	printf("%d\n", sum);

	return 0;
}


Measured memory_bytes: 128
/*author - Aryan Mittal*/
#include<bits/stdc++.h>
using namespace std;

#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

#define pow2(x) ((x)*(x))
#define ll long long
#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front

#define mod 1000000007
#define clock (clock() * 1000.0 / CLOCKS_PER_SEC)

#define mp make_pair
#define ff first
#define ss second
#define null NULL

#define all(c) (c).begin(),(c).end()
#define nl "\n"

typedef vector<ll> vl;
typedef vector< vl > vvl;
typedef pair< ll,ll> pll;
typedef map< ll,ll> mll;

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

    ll n,k;
    cin>>n>>k;

    ll h[n+1];
    for(ll i=1;i<=n;i++){
        cin>>h[i];
    }

    ll dp[n+1]={0};
    dp[1]=0;

    for(ll i=2;i<=n;i++){
        ll min_val = INT_MAX;
        if(i-k<1){
            // go from 0 to i-1
            for(ll j=1;j<=i-1;j++){
                min_val = min(min_val,dp[j]+abs(h[i]-h[j]));
            }
        }else{
            // go from i-1 to i-k
            for(ll j=i-k;j<=i-1;j++){
                min_val = min(min_val,dp[j]+abs(h[i]-h[j]));
            }
        }
        dp[i] = min_val;
    }

    cout<<dp[n]<<"\n";

    return 0;
}

Measured memory_bytes: 1792
import sys
from collections import defaultdict, deque
import math

# import copy
# from bisect import bisect_left, bisect_right
# import heapq

# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7

def divide(k):
    return pow(k, MOD-2, MOD)


def make_nck(n):
    ret = [1]
    for i in range(1, n+1):
        ret.append((ret[-1] * (n + 1 - i) * divide(i)) % MOD)

    # print(ret)
    return ret

def make_nigojyo(n):
    ret = [1]

    for i in range(1, n+1):
        ret.append((ret[-1] * 25) % MOD)

    # print(ret)
    return ret


def solve():
    K = getN()
    S = getS()
    l = len(S)
    nck = make_nck(K + len(S))
    nigojyo = make_nigojyo(K + l)
    # ans = 1
    # for i in range(K):
    #     ans *= 2 * (l + 1) - l
    #     ans
    #     l += 1
    #     ans %= MOD
    ans = 0

    for i in range(l + K - l + 1):
        ans += (nigojyo[i]) * nck[i]
        ans %= MOD
        # print(ans)

    print(ans)



def main():
    n = getN()
    for _ in range(n):
        solve()


if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 415400
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <limits>
#include <iterator>
#include <cmath>
#include <numeric>
#include <stack>
#include <cassert>
#include <forward_list>
#include <chrono>
#include <deque>
#include <list>
#include <random>
#include <cstdio>
#include <sstream>

int main()
{
	int n, x;
	std::cin >> n >> x;
	std::vector<int> L(n+1);
	L[0] = 0;
	for (int i = 1; i < n+1; i++)
	{
		std::cin >> L[i];
	}
	
	int ans = 0;
	for (int i = 0; i < n+1; i++)
	{
		ans += L[i];

		if (ans > x)
		{
			std::cout << i << std::endl;
			break;
		}
		else if (i == n)
		{
			std::cout << i+1 << std::endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
using namespace std;
int x[51], y[51];
int main()
{
	int n, k=1;
	while (scanf("%d", &n), n) {
		for (int i=0; i<n; ++i) scanf("%d%d", x+i, y+i);
		double res = 0;
		for (int i=1; i<n-1; ++i) {
			double ax = x[0]-x[i];
			double bx = x[0]-x[i+1];
			double ay = y[0]-y[i];
			double by = y[0]-y[i+1];
			res += bx * ay - ax * by;
		}
		printf("%d %.1f\n", k++, res/2);
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

struct UnionFind {
    vector<int> par;
    vector<int> siz;

    UnionFind(int N) : par(N), siz(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i, siz[i] = 1;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        siz[ry] += siz[rx];
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
        return siz[root(x)];
    }
};

int main() {
    int N, M; cin >> N >> M;
    vector<int> L(M, -1);
    UnionFind G(N);
    rep(i, N) {
        int K; cin >> K;
        rep(j, K) {
            int l; cin >> l; --l;
            if(L[l] != -1) {
                G.unite(L[l], i);
            }
            L[l] = i;
        }
    }

    cout << ((G.size(0) == N) ? "YES" : "NO") << endl;
}


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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};



int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int g = __gcd(a,b);
    if(c%g==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}

Measured memory_bytes: 256
/**Bismillahir Rahmanir Rahim**/


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

#define pb push_back
#define io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define clr(v) v.clear()
vector<ll>v;
pair<ll,ll>p;
map<ll,ll>mp;
set<ll>st;
deque<ll>dq;
priority_queue<ll>pq;
#define f(i,b) for(i=0;i<b;i++)
#define f1(i,b) for(i=1;i<=b;i++)
#define fr(i,b)for(i=b-1;i>=0;i--)
ll mn=INT_MAX,mx=INT_MIN;
ll n,m,tc,i,j,tmp,sum,cn,ans,res,pos,flag,l,x,k,dif;

string s,str;


ll a[200007],b[200007];
int main()
{

   io;
ll a,b,c,d;
cin>>a>>b>>c>>d;
if(a+b-c>d)puts("Left");
else if(a+b-c<d)puts("Right");
else puts("Balanced");
return 0;
}





Measured memory_bytes: 3652
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w, a, b;
    cin >> w >> a >> b;
    if((a <= b && b <= a + w) || (b <= a && a <= b + w)){
        cout << 0 << "\n";
    }else{
        cout << min(abs(b - a - w), abs(a - b - w)) << "\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int gcd(int &a, int &b) {
  if(b == 0) return a;
  int d;
  a = a % b;
  swap(a, b);
  d = gcd(a, b);
  return d;
}

int X;

int main() {
  cin >> X;
  int Y = 360;
  int temp = 360;
  int d = gcd(X, temp);
  int K = Y / d;
  // cout << d << endl;
  cout << K << endl;
  return 0;
}

Measured memory_bytes: 3604
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		int H1 = input.nextInt();
		int M1 = input.nextInt();
		int H2 = input.nextInt();
		int M2 = input.nextInt();
		int K = input.nextInt();
		
		int remainder  = 0;
		int minutes = 0;
		int hours =0;
		
		if (M2 < M1) {
			remainder = 1;
			minutes = (M2+60)-M1;
		} else if( M1 < M2) {
			minutes = M2-M1;
		}
		
		hours = H2-remainder-H1;
		
		int totalMinutes = (hours*60)+minutes;
		
		System.out.println(totalMinutes-K);
		
		

	}

}


Measured memory_bytes: 35816
program main

  ! <module> to import
  use, intrinsic :: iso_fortran_env

  ! require all variables to be explicitly declared
  implicit none
    
    ! variables for this <program>
    integer(kind=INT8) :: A, B, C
    
    ! STEP.01
    ! read out the data
    read *, A, B, C
    
    ! STEP.02
    ! output the result
    print '(I0)', min (B/A, C)

end program main

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  cin>>A>>B;
  if(A>=13){
    cout<<B<<endl;
    return 0;
  }
  else if(A>=6&&A<13){
    cout<<B/2<<endl;
    return 0;
  }
  else{
    cout<<0<<endl;
    return 0;
  }
}

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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
}

int main()
{
  string S;
  cin >> S;
  ll begin = 0;
  char pre = S[0];
  S += '#';
  vector<ll> v(S.length());
  rep(i, S.length()-1) {
    if (S[i+1] != pre) {
      if (pre == '<') {
        rep(j, i+1-begin) {
          v[begin + j+1] = j+1; 
        }
      } else {
        rep(j, i+1-begin) {
          v[i+1 - j-1] = max(v[i+1 - j-1], j+1);
        }
      }
      begin = i+1;
      pre = S[i+1];
    }
  }
  ll ans = 0;
  rep(i, v.size()) ans += v[i];
  print(ans);
  return 0;
}

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

using namespace std;

int f(int x, int y, int z){
  return x*x + y*y + z*z + x*y + y*z + z*x;
}

int main(){
  int n;
  cin >> n;
  
  vector<int> Fs(n+1, 0);
  int tmp;
  for(int x = 1; x*x < n; x++){
    for(int y = 1; y*y < n; y++){
      for(int z = 1; z*z < n; z++){
        tmp = f(x,y,z);
        if(tmp <= n ){ Fs.at(tmp)++; }
      }
    }
  }
  
  for(int i = 1; i <=n;i++){
    cout << Fs.at(i) << endl;
  }
  return 0;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
using namespace std;
vector<pair<int,int> > a[1000000];
int n;
int col[1000000];
bool ex[1000000];
vector<pair<int,int> > s;
void dfs(int u,int p) {
    int v;
    for(auto w:a[u]) {
        v=w.second;
        if(col[v]!=0) ex[col[v]]=true;
    }
    int j=1;
    while(ex[j]) j++;
    for(auto w:a[u]) {
        v=w.second;
        if(col[v]==0) {
            ex[j]=true;
            col[v]=j;
        }
        while(ex[j]) j++;
    }
    for(auto w:a[u]) {
        v=w.second;
        ex[col[v]]=false;
    }
    for(int i=0;i<a[u].size();i++) {
        if(a[u][i].first!=p) dfs(a[u][i].first,u);
    }
}
int main() {
    int u,v;
    scanf("%d",&n);
    for(int i=0;i<n-1;i++) {
        scanf("%d %d",&u,&v);
        a[u].push_back({v,i});
        a[v].push_back({u,i});
    }
    int c=0;
    for(int i=1;i<=n;i++) {
        int l=a[i].size();
        c=max(c,l);
    }
    dfs(1,-1);
    printf("%d\n",c);
    for(int i=0;i<n-1;i++) printf("%d\n",col[i]);
    return 0;
}


Measured memory_bytes: 29440
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>

#include <numeric>
using namespace std;


int main(){
	long long N,X,time,dist;
	time = 1;
	dist = 0;
	cin >> X;
	int d;
	while (1){
		
		dist += time;
		if (dist >= X) break;
		time += 1;

	}
	cout << time << endl;
	

	
	return 0;
}

Measured memory_bytes: 256
/*input
6
2 7 1 8 2 8
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=500005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int a[maxn];
int cnt[3];
int main()
{
	IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];
	REP(i,n){
		if(a[i]%2) cnt[0]++;
		else if(a[i]%4) cnt[1]++;
		else cnt[2]++;
	}
	if(cnt[1]) cnt[0]++;
	if(cnt[0]>cnt[2]+1) cout<<"No\n";
	else cout<<"Yes\n";
	return 0;	
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
    int x, y, z;
    cin >> x >> y >> z;

    int temp1, temp2;
    temp1 = x;
    temp2 = y;

    y = temp1;
    x = z;
    z = temp2;

    cout << x << " " << y << " " << z << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, 0, n) cin >> a[i];

  vector<int> x(n + 1, 0);
  vector<int> ans;
  repr(i, 1, n + 1) {
    int c = 0;
    for (int j = 2 * i; j < n + 1; j += i)
      c += x[j];

    if (a[i - 1] % 2 == 0 && c % 2 == 1) {
      x[i] = 1;
      ans.push_back(i);
    }
    if (a[i - 1] % 2 == 1 && c % 2 == 0) {
      x[i] = 1;
      ans.push_back(i);
    }
  }

  int m = ans.size();
  cout << m << endl;
  repr(i, 0, m) {
    if (i < m-1)
      cout << " ";
    cout << ans[i];
  }
  cout << endl;
}


Measured memory_bytes: 5396
import bisect
A, B, Q = map(int, input().split())
ss = [int(input()) for i in range(A)]
ts = [int(input()) for i in range(B)]
xs = [int(input()) for i in range(Q)]
INF = 10**11

ss = [-INF] + ss + [INF]
ts = [-INF] + ts + [INF]
 
# s_e is index the nearest s on the east side of x
for x in xs:
  s_e_ix = bisect.bisect_left(ss, x)
  s_e = ss[s_e_ix]
  s_w = ss[s_e_ix - 1]
  
  t_e_ix = bisect.bisect_left(ts, x)
  t_e = ts[t_e_ix]
  t_w = ts[t_e_ix - 1]
  
  d = INF
  for s in [s_w, s_e]:
    for t in [t_w, t_e]:
      d0 = abs(s-x) + abs(t-s)
      d1 = abs(t-x) + abs(s-t)
      d = min(d0, d1, d)
  print(d)

Measured memory_bytes: 16780
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
const ll INF = 1e18;
const ll ALOT = 4e9;

ll n, a, b, c, d;

map<ll, ll> mm;

void solve() {
	ll ans = INF;
	cin >> n >> a >> b >> c >> d;
	mm.clear();
	mm[n] = 0;
	auto updmm = [](ll n, ll x) {
		if (mm.count(n)) {
			mm[n] = min(mm[n], x);
		} else {
			mm[n] = x;
		}
	};
	auto upd = [&updmm] (ll n, ll div, ll cost, ll add) {
		if (n % div == 0) {
			updmm(n / div, add + cost);
		} else {
			updmm(n / div, add + cost + d * (n % div));
			updmm(n / div + 1, add + cost + d * (div -  n % div));
		}
	};
	while (!mm.empty()) {
		ll n = mm.rbegin()->first;
		ll cost = mm.rbegin()->second;
		mm.erase(n);
		if (n <= ALOT && cost <= INF) {
			ans = min(ans, cost + n * d);
		}
		if (n > 1) {
			upd(n, 2, a, cost);
			upd(n, 3, b, cost);
			upd(n, 5, c, cost);
		}
	}
	cout << ans << "\n";
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	int tt;
	cin >> tt;
	for (int i = 0; i < tt; ++i) {
		solve();
	}
	return 0;
}




Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define trav(x, it) for(auto it = x.begin(); it != x.end(); it++)
#define pr(x) cout << #x << " = " << x << endl
#define fill(x,y) memset(x,y,sizeof(x))
#define endl "\n"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector< pii > vpii;
typedef vector< pll > vpll;
const ld eps = 1e-7;
const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, mod - 2);}

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	char ch;
	cin >> ch;
	if(ch >= 'A' && ch <='Z')
		cout << 'A' << endl;
	else
		cout << 'a' << endl;

}

Measured memory_bytes: 3648
#include<iostream>
using namespace std;
 
#define INF 10000000
#define NIL -1
 
struct Node{int parent,left,right;};
Node T[INF];
int n,D[INF];
 
void print(int u){
  int i,c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].parent << ", ";
  cout << "depth = " << D[u] << ", ";
 
  if(T[u].parent==NIL) cout << "root, ";
  else if(T[u].left == NIL) cout << "leaf, ";
  else cout << "internal node, ";
 
  cout << "[";
  for(i=0,c=T[u].left;c!=NIL;i++,c=T[c].right){
    if(i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}
 
void rec(int u,int p){
  D[u] = p;
  if(T[u].right != NIL) rec(T[u].right,p);
  if(T[u].left != NIL) rec(T[u].left,p+1);  
}
 
int main(void){
  int i,j,d,v,c,left,right;
 
  cin >> n;
  for(i=0;i<n;i++) T[i].parent = T[i].left = T[i].right = NIL;
 
  for(i=0;i<n;i++){
    cin >> v >> d;
    for(j=0;j<d;j++){
      cin >> c;
      if(j==0) T[v].left = c;
      else T[left].right = c;
      left = c;
      T[c].parent = v;
    }
  }
 
  for(i=0;i<n;i++) if(T[i].parent==NIL) right = i;
  rec(right,0);
 
  for(i=0;i<n;i++) print(i);
}

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

int main() {

  int N;
  cin >> N;

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

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

  int answer = 0;
  
  for (int i = 0; i < N; i++) {
    int answer_ = 0;
    for (int j = 0; j < N; j++) {
      if (i == j) {
        answer_ += A1[j] + A2[j];
      } else if (i < j) {
        answer_ += A2[j];
      } else {
        answer_ += A1[j];
      }
    }
    answer = max(answer, answer_);
  }

  cout << answer << endl;

  return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cctype>
using namespace std;
#define ARRAY_MAX 250

int main(void){

    char array[ARRAY_MAX];

    int i = 0;

    fgets(array,ARRAY_MAX,stdin);

    while(array[i] != '\0'){
        array[i] = toupper(array[i]);
        i++;
    }
    
    printf("%s",array);
    
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			if (i * j == N) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>

long double pi = acosl(-1.0L);

int main() {
  long double a, b, x;
  scanf("%Lf %Lf %Lf", &a, &b, &x);

  long double h = x / a / a;
  long double theta;
  if (x == a*a*b) {
    theta = 0.0;
  } else if (x*2 >= a*a*b) {
    long double y = std::max(0.0L, 2*(b-h));
    theta = std::acos(a / std::hypot(a, y));
  } else {
    long double y = 2*a*h / b;
    theta = std::acos(y / std::hypot(b, y));
  }

  theta *= 180.0L / pi;
  printf("%.20Lf\n", theta);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    string n;
    cin >> n;
    ll judge=0;
    for(ll i=0;i<n.size();i++){
        ll k=n[i]-'0';
        judge+=k;
    }
    if(judge%9==0){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3744
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;

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

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

  ll sum[n + 1], sp[n + 1];
  sum[0] = sp[0] = 0;
  for(int i = 1; i <= n; i++){
    sum[i] = sum[i - 1] + a[i - 1];
    if(a[i - 1] > 0){
      sp[i] = sp[i - 1] + a[i - 1];
    }
    else{
      sp[i] = sp[i - 1];
    }
  }

  ll ans = 0;
  for(int i = 0; i + k <= n; i++){
    ll tmp = sp[i] + (sp[n] - sp[i + k]);
    ans = max(ans, tmp);
    tmp += sum[i + k] - sum[i];
    ans = max(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2176
#include <cstdio>

typedef long long LL;

int main()
{
	LL X; scanf("%lld", &X);
	LL L = 0, R = X;
	while(L < R) {
		LL M = (L + R + 1) / 2;
		if(M * (M + 1) / 2 <= X) L = M;
		else R = M - 1;
	}

	if(L * (L + 1) / 2 == X) { printf("%lld\n", L); return 0; }
	printf("%lld\n", L + 1);

	return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string S;
    cin>>S;
    int cnt=0;
    int cur=0;
    while(cur<S.size()){
        int next=cur;
        while(next<S.size()&&S[cur]==S[next])next++;
        cnt++;
        cur=next;
    }
    cout<<cnt-1<<endl;
    return 0;
}


Measured memory_bytes: 512