akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    float n=N;
    float ans;
    if(N%2){
        ans=(N/2+1)/n;
    }else{
        ans=0.50000;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define all(a)                      a.begin(), a.end()
#define pb                          push_back
#define ll							long long
#define index(a)            		order_of_key(a)
#define value(a)					find_by_order(a)
#define count_1 					__builtin_popcount
#define mod(x, m)					((((x) % (m)) + (m)) % (m))
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

ll dp[101][100005],w[100005],c[100005];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout<<setprecision(12);
	
	ll n,C;
	cin>>n>>C;
	for(int i=1;i<=n;i++){
		cin>>w[i]>>c[i];
	}
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=C;j++){
			if(j < w[i])dp[i][j]=dp[i-1][j];
			else
			dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+c[i]);
		}
	}
	cout<<dp[n][C];
	return 0;
}

Measured memory_bytes: 78720
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define ll long long
#define MAX 200200
#define lson (now<<1)
#define rson (now<<1|1)
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,Q,A,B,a[MAX];ll f[MAX];
struct SegMentTree
{
	ll t[MAX<<2],tag[MAX<<2],a[MAX];
	void pushup(int now){t[now]=min(t[lson],t[rson]);}
	void Build(int now,int l,int r)
	{
		if(l==r){t[now]=f[l]+a[l];return;}
		int mid=(l+r)>>1;tag[now]=0;
		Build(lson,l,mid);Build(rson,mid+1,r);
		pushup(now);
	}
	void puttag(int now,ll w){t[now]+=w;tag[now]+=w;}
	void pushdown(int now)
	{
		if(!tag[now])return;
		puttag(lson,tag[now]);
		puttag(rson,tag[now]);
		tag[now]=0;
	}
	void Modify(int now,int l,int r,int p,ll w)
	{
		if(l==r){t[now]=min(t[now],w);return;}
		int mid=(l+r)>>1;pushdown(now);
		if(p<=mid)Modify(lson,l,mid,p,w);
		else Modify(rson,mid+1,r,p,w);
		pushup(now);
	}
	void Modify(int now,int l,int r,int L,int R,int w)
	{
		if(L<=l&&r<=R){puttag(now,w);return;}
		int mid=(l+r)>>1;pushdown(now);
		if(L<=mid)Modify(lson,l,mid,L,R,w);
		if(R>mid)Modify(rson,mid+1,r,L,R,w);
		pushup(now);
	}
	ll Query(int now,int l,int r,int L,int R)
	{
		if(L<=l&&r<=R)return t[now];
		int mid=(l+r)>>1;ll ret=4e18;pushdown(now);
		if(L<=mid)ret=min(ret,Query(lson,l,mid,L,R));
		if(R>mid)ret=min(ret,Query(rson,mid+1,r,L,R));
		return ret;
	}
}T1,T2;
ll Solve(int A,int B)
{
	memset(f,63,sizeof(f));f[B]=abs(A-a[1]);
	for(int i=1;i<=n;++i)T1.a[i]=-i,T2.a[i]=i;
	T1.Build(1,1,n);T2.Build(1,1,n);
	ll inf=f[0];f[B]=inf;f[1]=abs(A-a[1]);
	for(int i=2;i<=Q;++i)
	{
		ll ret=inf;
		ret=min(ret,T1.Query(1,1,n,1,a[i])+a[i]);
		ret=min(ret,T2.Query(1,1,n,a[i],n)-a[i]);
		T1.Modify(1,1,n,1,n,abs(a[i]-a[i-1]));
		T2.Modify(1,1,n,1,n,abs(a[i]-a[i-1]));
		T1.Modify(1,1,n,a[i-1],ret-a[i-1]);
		T2.Modify(1,1,n,a[i-1],ret+a[i-1]);
		ret=min(ret,f[i-1]+abs(a[i]-a[i-1]));
		f[i]=ret;
	}
	return f[Q];
}
int main()
{
	n=read();Q=read();A=read();B=read();
	for(int i=1;i<=Q;++i)a[i]=read();
	printf("%lld\n",min(Solve(A,B),Solve(B,A)));
	return 0;
}


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

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

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

    sort(d.begin(),d.end());
    
    int j = 0;
    int ans = 0;
    for(int i=0;i<N;i++) {
        if(d[i] > j) {
            ans += 1;
            j = d[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

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

        int a, b;
        a = scanner.nextInt();
        b = scanner.nextInt();
        if (a < b) {
            System.out.println("a < b");
        } else if (a > b) {
            System.out.println("a > b");
        } else {
            System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26168
n = int(input())
p = list(map(int, input().split()))
flag = False
for i in range(n):
    for j in range(n):
        p2 = p.copy()
        p2[i], p2[j] = p2[j], p2[i]
        if sorted(p) == p2:
            flag = True
print("YES") if flag else print("NO")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF (long long)1 << 61
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

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

int main() {
	int n,k; cin >> n >> k;
    int d,ans=0;
    vector<int> b(n,0);
    REP(i,k){
        cin >> d;
        vector<int> A(d);
        REP(j,d){
            cin >> A[j];
        }
        REP(j,d){
            b[A[j]-1]++;
        }
    }
    REP(i,n){
        if(b[i]==0)ans++;
    }
    cout << ans << endl;
    

    return 0;
}


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

int main()
{
    int K, X;

    cin >> K >> X;

    int st = X - K + 1;

    int tm = K*2 - 1;

    int i = st;
    while ( i < st+tm)
    {
        cout << i << endl;
        i++;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

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

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

  int tmp, res = INF;
  for (int i = 2; i != s.size(); ++i) {
    tmp = (s[i - 2] - '0') * 100 + (s[i - 1] - '0') * 10 + (s[i] - '0');
    res = min(res, abs(tmp - 753));
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;


int main() {
	string s, t;
	cin >> s >> t;
	bool isExist;
	for (int i = s.length() - t.length(); i >= 0; i--) {
		isExist = true;

		for (int j = 0; j < t.length(); j++) {
			if (s[i + j] != t[j] && s[i + j] != '?') {
				isExist = false;
			}
		}

		if (isExist) {
			string ans(s.length(),'a');
			for (int j = 0; j < s.length(); j++) {
				if (s[j] != '?') {
					ans[j] = s[j];
				}

				if (j >=i && j <i+t.length()) {
					ans[j] = t[j-i];
				}
			}
			cout << ans << endl;
			break;
		}
	}

	if (!isExist) {
		cout << "UNRESTORABLE" << endl;
	}
}


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

using namespace std;

const int mod = 1000000007;

struct Task {
	int n;
	vector<int> a;

	Task(int n): n(n), a(n) {
		for (auto& item : a) {
			cin >> item;
		}
	}

	void run() {
		vector<int> fact(n + 1);
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) {
			fact[i] = (1LL * fact[i - 1] * i) % mod;
		}
		int result = 1;
		int cur = 1;
		for (int i = 0; i < n; ++i) {
			if (a[i] < cur) {
				int pref = (cur+1)/2;
				result = (1LL * result * pref) % mod;
			} else
			cur += 2;
		}
		result = (1LL * result * fact[(cur-1)/2]) % mod;
		cout << result << endl;
	}
};

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

	int n;
	cin >> n;

	Task a(n);
	a.run();

	return 0;
}

Measured memory_bytes: 1024
put = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997]
main=readLn>>=print.g.f 1 put 2 2
 where f cou pri now quo n |pri==[] = []
                           |now>n   = cou:(f 1 (tail pri) 2 2 n)
                           |(mod quo (head pri))==0 = f (cou+1) pri now (quot quo (head pri)) n
                           |otherwise = f cou pri (now+1) (now+1) n
       g [] = 1
       g (a:p) = mod (a*(g p)) 1000000007

Measured memory_bytes: 1020
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		for(int i = 0; i < n; i++) {
			String str = sc.next();
			System.out.println(solve(str));
		}
	}

	static long solve(String str) {
		str = str.substring(1, str.length()-1);
		if(str.charAt(0)=='[') {
			List<Long> childList = new LinkedList<>();
			long ans =0;
			while(str.length() != 0) {
				int bracketIdx = 1;
				int charIdx =1;
				while(bracketIdx != 0) {
					char i = str.charAt(charIdx);
					if(i == ']') {
						bracketIdx--;
					}else  if (i=='['){
						bracketIdx++;
					}
					charIdx++;
				}
				childList.add(solve(str.substring(0, charIdx)));

				str = str.substring(charIdx);
			}
			childList.sort(null);
			for(int i = 0; i < childList.size()/2+1; i++) {
				ans+= childList.get(i);
			}
			return ans;
		}else {
			return Long.valueOf(str)/2L+1;
		}
	}
}



Measured memory_bytes: 69060
#include<stdio.h>
#include<string.h>

int main(){
  int i, cnt, step[160], n;
  char st[3];

  while(scanf("%d", &n), n){
    for(i=0; i<n; i++){
      scanf("%s", st);
      if(!(strcmp(st, "lu\0"))){
	step[i]=0;
      }else if(!(strcmp(st, "ru\0"))){
	step[i]=1;
      }else if(!(strcmp(st, "ld\0"))){
	step[i]=2;
      }else{
	step[i]=3;
      }
      //      printf("%d ", step[i]);
    }

    //      printf("\n%d\n", step[0]);
    cnt=0;
    for(i=0; i<n-1; i+=2){
      if((step[i]%2) != (step[i+1]%2)){
	cnt++;
      }
    }

     printf("%d\n", cnt);
  }

  
  return 0;
}

Measured memory_bytes: 1812
//============================================================================
// Name        : template.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <vector>
#include <string.h> // for memset in CF judge.
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE // suppress some compilation warning messages (for VC++ users)
// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
// To simplify repetitions/loops, Note: define your loop style and stick with it!
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define forn(i,n) \
for (int i =0; i<(n); i++)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers

// int main() {
//     int x,y,z;
//     cin >> x >> y >> z;
//     swap(x,y); swap(x,z); 
//     cout << x << " " << y << " " << z;
// return 0;
// }

// int main() {
//     int a ,b;
//     cin >> a >> b;
//     vi arr;
//     int sm;
//     forn(i,a) {
//         int x; cin >>x;
//      sm+=x;
//       arr.pb(x);
//     }
//     int ans = 0;
//     forn(i,a) {
//       int val = sm/(4*b) + (sm % (4 *b) != 0);
//       if(arr[i] < val) continue;
//       ans++;
//     }
//      if(ans >= b) cout << "Yes";
//      else cout << "No";
//     // cout << sol;
//     return 0;
// }

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    if(n > k) {
       ll f = (n - (n/k) * k );
        ans = min(f, abs(f-k));
    }
    if(n < k) ans = min(k-n, n);
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);let input_i=-1;const tn=():number=>{input_i++;return Number(input[input_i])};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{input_i++;return String(input[input_i])};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const asc=(ar:number[])=>{const t=[...ar];return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{const t=[...ar];return t.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length-1;i+=2){if(eval(a+op+arr[i])){return arr[i+1]}}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const deduplicate=(a:any[]):any[]=>{return Array.from(new Set(a))}
const main=()=>{
  let n=tn()
  let a=floor(n*0.92)
  for(let i=a;floor(i*1.08)<=n;i++){
    if(floor(i*1.08)==n){
      to(floor(i))
      return
    }
  }
  to(':(')
}
main()

Measured memory_bytes: 7500
#include <iostream>
#include <vector>
using namespace std;
int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  int before = 0;
  int ans = 0;
  int count = 1;
  for (int i = 0; i < N; i++)
  {
    if (before != a[i])
    {
      ans += count / 2;
      before = a[i];
      count = 1;
    }
    else
      count++;
  }
  ans += count / 2;
  cout << ans << endl;
  return 0;
}

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

#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

int main()
{
	ll N; cin >> N;
	ll a[100] = {};
	ll max = 0, min = 1 << 20;
	rep(i, 0, N) {
		cin >> a[i];
		if (max < a[i]) max = a[i];
		if (min > a[i]) min = a[i];
	}
	cout << max - min << endl;

	return 0;
}

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

int main() {
    int N, M; cin >> N >> M;
    set<int> a;
    for (int i = 0; i < M; i++)
    {
        int b; cin >> b;
        a.insert(b);
    }

    ll prev = 0;
    ll ans = 1;
    for (int i = 1; i <= N; i++)
    {
        if(a.count(i)!=0){
            prev = ans;
            ans = 0;
        } else {
            ll tmp = ans;
            ans = (ans + prev)%mod;
            prev = tmp;
            //cout << prev << " " << ans << endl;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    if (N == 0) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 3580
def gcd(x,y): 
	while y != 0:
		x , y = y , x % y 
	return x
n = int(input())
A = list(map(int,input().split()))
lgcds=[1 for _ in range(n)]
rgcds=[1 for _ in range(n)]
lgcd  = A[0]
rgcd = A[-1]
for i in range(1,n):
    lgcd =gcd(A[i-1],lgcd)
    lgcds[i] = lgcd
for i in range(n-2,-1,-1):
    rgcd =gcd(A[i+1],rgcd)
    rgcds[i] = rgcd
ans =[1 for _ in range(n)]
for i in range(n):
    if i ==0:
        ans[i]=rgcds[i]
    elif i ==n-1:
        ans[i]=lgcds[i]
    else:
        ans[i]=gcd(rgcds[i],lgcds[i])
print(max(ans))



Measured memory_bytes: 14460
n = int(input())
v = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]


maximum = 0
profit = []
for i in range(len(v)):
    tmp = v[i] - c[i]
    if tmp > 0:
        maximum += tmp
    tmp = 0

print(maximum)


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int MOD = 1000000007;

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

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


int main(){
    int N;
    double ans = 0;
    double num;
    cin >> N;
    for(int i=0;i<N;i++){
      cin >> num;
      ans += 1/num;
    }
    cout << 1/ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
// 1
//4235
// 6
class Dise {
public:
	Dise();
	//てっぺんは0番
	int DiseNumber[6];
};

Dise::Dise()
{
	//入力
	for (int i = 0; i < 6; i++) {
		cin >> DiseNumber[i];
	}
}

void LengthRotation(int up,int *CopyDise)
{
	if (CopyDise[0] != up) {
		//縦に回す
		for (int i = 1; i <= 3; i++) {
			//縦回転
			swap(CopyDise[0], CopyDise[4]);
			swap(CopyDise[0], CopyDise[5]);
			swap(CopyDise[0], CopyDise[1]);
			if (CopyDise[0] == up) {
				break;
			}
		}
		
		if (CopyDise[0] != up) {
			for (int i = 1; i <= 3; i++) {				
				swap(CopyDise[0], CopyDise[3]);
				swap(CopyDise[0], CopyDise[5]);
				swap(CopyDise[0], CopyDise[2]);
				if (CopyDise[0] == up) {
					break;
				}
			}
		}
	}
}

void SideRotation(int Front, int *CopyDise)
{
	if (CopyDise[1] != Front) {
		for (int i = 1; i <= 3; i++) {
			swap(CopyDise[1], CopyDise[3]);
			swap(CopyDise[1], CopyDise[4]);
			swap(CopyDise[1], CopyDise[2]);
			if (CopyDise[1] == Front) {
				break;
			}
		}
	}	
}

int main()
{
	Dise dise;
	int q, Up, Front, CopyDise[6];

	cin >> q;

	for (int i = 1; i <= q; i++) {
		cin >> Up>>Front;

		//初期化
		for (int i = 0; i < 6; i++) {
			CopyDise[i] = dise.DiseNumber[i];
		}

		//縦
		LengthRotation(Up, CopyDise);
		//横
		SideRotation(Front, CopyDise);
		//結果
		cout << CopyDise[2] << endl;
	}

	return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
const ll mo = 1000000007;
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = 0;
struct UnionFind {
  vector<ll> data;
  UnionFind(ll size) : data(size, -1) { }
  bool unionSet(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};

int main()
{
ll n,m;
cin >> n>>m;
UnionFind arr(n);
rep(i, m)
{
    ll a,b,c;
    cin >> a>>b>>c;
    ans+=arr.unionSet(a-1,b-1);
}

cout << n-ans << endl;
return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

double abs(double a)
{
    return (a >= 0)? a:(-a);
}
int main(void){
    // Your code here!
    int N,T,A,H,n;
    double temp,min = 10000;
    scanf("%d",&N);
    scanf("%d %d",&T,&A);
    for(int i = 1; i <= N; i++)
    {
        scanf("%d",&H);
        temp = abs(T-0.006*H - A);
        //printf("%lf\n",temp);
        if(temp < min)
        {
            min = temp;
            n = i;
        }
    }
    printf("%d\n",n);
}


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

int cnt[10];

int main() {
    for (int i = 0; i < 3; i++) {
        int a, b;
        cin >> a >> b;
        cnt[a]++;
        cnt[b]++;
    }
    for (int i = 1; i <= 4; i++) {
        if (cnt[i] == 3) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}

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

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int main() {
  std::string s;
  std::cin >> s;
  int sum = 0;
  ll result = 0;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == 'B')
      sum++;
    else
      result += sum;
  }
  std::cout << result;
  return 0;
}


Measured memory_bytes: 3692
using System;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            string lines = new string('#', 20);
            int num = int.Parse(Console.ReadLine());
            int[,,] array = new int[4, 3, 10];
            for (int i = 0; i < num; i++)
            {
                string[] info = Console.ReadLine().Split(' ');
                int b, f, r, v;
                b = int.Parse(info[0]);
                f = int.Parse(info[1]);
                r = int.Parse(info[2]);
                v = int.Parse(info[3]);
                array[b - 1, f - 1, r - 1] += v;          
            }

            for (int house = 0; house < 4; house++)
            {
                for (int floor = 0; floor < 3; floor++)
                {
                    for (int room = 0; room < 10; room++)
                    {
                        Console.Write(" " + array[house, floor, room]);
                    }
                    Console.WriteLine();
                }
                if (house != 3)
                {
                    Console.WriteLine(lines);
                }
            }
        }
    }
}

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

int main()
{
    long long n;
    cin >> n;
    long long  t = n, f = 0;

    while (t != 0) {
        f+=t%10;
        t/=10;
    }
    cout << (n%f==0?"Yes":"No") << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
int main(void){
  int n,m,a[3];
  cin >> n;
  for(int i = 0; i < n; i++) cin >> a[i];
  m = min(a[0],min(a[1],n==2?1<<28:a[2]));
  cout << 1 << endl;
  for(int i = 2; i <= m; i++){
    if(a[0]%i || a[1]%i || (n==2?0:a[2]%i))continue;
    cout << i << endl;
  }  
}

Measured memory_bytes: 1160
A,B,C,D = map(int,input().split())
f = 0
while f==0:
    C -= B
    if C<=0:
        f = 1
        break
    # print("青木君",C)
    A -= D
    if A<=0:
        f = 2
        break
    # print("高橋君",A)
if f==1:
    print("Yes")
elif f==2:
    print("No")

Measured memory_bytes: 9120
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int to_int(char ch){ return ch - '0'; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    int n;
    cin >> n;
    while(n--)
    {
        cin >> s >> t;
        if(s.size() < t.size()) swap(s, t);
        reverse(s.begin(), s.end());
        reverse(t.begin(), t.end());
        int up = 0;
        for(int i = 0; i < t.size(); i++)
        {
            int val = to_int(s[i]) + to_int(t[i]) + up;
            if(val > 9)
            {
                val -= 10;
                s[i] = val + '0'; 
                up = 1;
            }
            else
            {
                s[i] = val + '0';
                up = 0;
            }
        }
        int pos = t.size();
        while(up)
        {
            if(pos >= s.size()) break;
            if(to_int(s[pos]) + up > 9) s[pos] = '0';
            else up = 0;
            pos++;
        }
        if(up) s += '1';
        reverse(s.begin(), s.end());
        if(s.size() > 80) cout << "overflow" << endl;
        else cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 3036
#include <stdio.h>

int main(void) {
	int A, B, K;
	scanf("%d%d%d", &A, &B, &K);
	for (int i = 0; i < K; i++) {
		if (i % 2) {	// 青木君(B)
			if (B % 2) B--;
			B /= 2;
			A += B;
		} else {	// 高橋君(A)
			if (A % 2) A--;
			A /= 2;
			B += A;
		}
	}
	printf("%d %d\n", A, B);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
template<typename T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> A;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        A.emplace_back(b, a);
    }
    A.emplace_back(N, N);
    // 終点sort
    sort(A.begin(), A.end());
    // first   : 終点, second  : 始点
    
    int now = A[0].first;
    int ans = 0;
    // 区間が被らなくなったら更新, ans++
    for (int i = 0; i <= M; i++) {
        if (now <= A[i].second) {
            //cout << i+1 << endl;
            now = A[i].first;
            ans++;
        }
    }
    //for (auto e : A) cout << e.first << " " << e.second << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
x=int(input())
for i in range(x):
    gx,gy=map(int,input().split())
    HK= [[0 for j in range(16)] for i in range(16)]
    mttb=[[0 for j in range(16)] for i in range(16)]
    
    for i in range(int(input())):
        x1,y1,x2,y2=map(int,input().split())
        if x1==x2:
            mttb[x1][max(y1,y2)]+=1
        else:
            mttb[max(x1,x2)][y1]+=2
            
    for i in range(16):
        if(mttb[0][i]!=0):
            break
        HK[0][i]=1
    for i in range(16):
        if(mttb[i][0]!=0):
            break
        HK[i][0]=1
        
    for i in range(1,16):
        for j in range(1,16):
            k=mttb[i][j]
            if k==0:
                HK[i][j]=HK[i-1][j]+HK[i][j-1]
            elif k==1:
                HK[i][j]=HK[i-1][j]
            elif k==2:
                HK[i][j]=HK[i][j-1]
                
    ans=HK[gx][gy]
    if ans==0:
        print("Miserable Hokusai!")
    else:
        print(ans)


Measured memory_bytes: 5620
N=int(input())
S=[input() for i in range(N)]
AC=0
WA=0
TLE=0
RE=0
for i in S:
    if i =="WA":
        WA+=1
    elif i=="AC":
        AC+=1
    elif i=="TLE":
        TLE+=1
    else:
        RE+=1
print("AC x",str(AC))
print("WA x",str(WA))
print("TLE x",TLE)
print("RE x",RE)

Measured memory_bytes: 16328
#include <iostream>
#include <set>
#include <string>

int main(){
    int N;
    std::string str;
    std::set<std::string> set;
    std::cin >> N;
    for(int i = 0; i < N; i++){
        std::cin >> str;
        set.insert(str);
    }
    std::cout << set.size() << std::endl;
}

Measured memory_bytes: 19112
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define rg register
#define ll long long 
#define inf 0x3f3f3f3f
inline int read()
{
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x*f;
}
int n;
ll ans;
int a[200005];
int main(){
    n=read();
    for(int i=1;i<=n;i++)
        a[i]=read();    
    sort(a+1,a+1+n);
    //cout<<p<<endl;
    for(int i=1<<30;i;i>>=1)
    {
        int l=1,r=n;
        while(l<r)
        {
            if(a[l]==-1||(~a[r]&&a[l]+a[r]<i))l++;
            else if(a[r]==-1||a[l]+a[r]>i) r--;
            else ans++,a[l]=a[r]=-1;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

constexpr int bit_size = 80*159+1;

int main() {
    int h = 0, w = 0;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            cin >> a.at(i).at(j);
        }
    }
    vector<vector<int>> b(h, vector<int>(w));
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            cin >> b.at(i).at(j);
        }
    }

    vector<vector<int>> field(h, vector<int>(w));
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            field.at(i).at(j) = abs(a.at(i).at(j) - b.at(i).at(j));
        }
    }
    
    vector<vector<vector<bool>>> dp(h, vector<vector<bool>>(w, vector<bool>(bit_size, false)));
    dp.at(0).at(0).at(field.at(0).at(0)) = true; 
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            for (int k=0; k<bit_size; k++) {
                if (dp.at(i).at(j).at(k)) {
                    if (i != h-1) {
                        int tmp = field.at(i+1).at(j);
                        dp.at(i+1).at(j).at(k+tmp) = true;
                        dp.at(i+1).at(j).at(abs(k-tmp)) = true;
                    }
                    if (j != w-1) {
                        int tmp = field.at(i).at(j+1);
                        dp.at(i).at(j+1).at(k+tmp) = true;
                        dp.at(i).at(j+1).at(abs(k-tmp)) = true;
                    }
                }
            }
        }
    }

    for (int i=0; i<bit_size; i++) {
        if (dp.at(h-1).at(w-1).at(i)) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vector<ll> a(3 * N);
    cin >> a;
    priority_queue<int, vector<int>, greater<int>> fpq;
    priority_queue<int, vector<int>, greater<int>> bpq;
    ll fs = 0, bs = 0;
    REP(i, N) {
        fpq.push(a[i]);
        fs += a[i];
    }
    vector<int> v(2 * N);
    FOR(i, N, 3 * N) {
        v[i - N] = a[i];
    }
    sort(ALL(v));
    multiset<int> st;
    multiset<int> bst;
    REP(i, 2 * N) {
        if (i < N) {
            st.insert(v[i]);
            bs += v[i];
        } else {
            bst.insert(v[i]);
        }
    }
    ans = fs - bs;
    FOR(i, N, 2 * N) {
        dump(fs, bs);
        dump(st);
        int ft = fpq.top();
        if (ft < a[i]) {
            fpq.pop();
            fpq.push(a[i]);
            fs += a[i] - ft;
        }
        auto itr = st.find(a[i]);
        if (itr != st.end()) {
            st.erase(itr);
            int bt = *bst.begin();
            bst.erase(bst.begin());
            st.insert(bt);
            bs += bt - a[i];
        } else {
            bst.erase(bst.find(a[i]));
        }
        ans = max(fs - bs, ans);
    }
    cout << ans << endl;
}

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

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

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

int main(){
  int n, k;
  cin >> n >> k;
  
  vector<int> x(n);
  for(int i=0; i<n; i++){
    cin >> x.at(i);
  }
  sort(x.begin(), x.end());
  
  int sum=0;
  for(int i=0; i<k; i++)
    sum += x.at(i);
  
  cout << sum << endl;
  
  
  
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;

#define N 600000
#define NIL -1

int key[N];
int parent[N];
int leftc[N];
int rightc[N];

int root=NIL;
void insert(int z){
  int x,y;
  
  y=NIL;
  x=root;

  while(x!=NIL){
    y=x;
    if(key[z]<key[x]) x=leftc[x];
    else x=rightc[x];
  }  
  
  parent[z]=y;

  if(y==NIL) root=z;
    
  else if(key[z]<key[y]) leftc[y]=z;

  else rightc[y]=z;
  
  
}

bool find(int now,int data){
  if(now==NIL) return false;
  if(data==key[now]) return true;
  if(data<key[now]) return find(leftc[now],data);
  else return find(rightc[now],data);
}

void inorderprint(int now){
  if(now!=NIL){
    inorderprint(leftc[now]);
    printf(" %d",key[now]);
    inorderprint(rightc[now]);
  }
}

void preorderprint(int now){
  if(now!=NIL){
    printf(" %d",key[now]);
    preorderprint(leftc[now]);
    preorderprint(rightc[now]);
  }
}



int main(){

  int n,i,j,data;
  int z=0;
  char str[10];

  for(i=0;i<N;i++){
    parent[i]=NIL;
    key[i]=NIL;
    rightc[i]=NIL;
    leftc[i]=NIL;
  }

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",str);
    if(strcmp(str,"insert")==0) {
      scanf("%d",&data);
      key[z]=data;
      insert(z);
      z++;
    }
    else if(strcmp(str,"find")==0){
      scanf("%d",&data);
      if(find(root,data)==true) printf("yes\n");
      else printf("no\n");
    }
    else if(strcmp(str,"print")==0){
      inorderprint(root);
      cout <<endl;
      preorderprint(root);
      cout <<endl;
    }
  }

  return 0;
}

Measured memory_bytes: 10000
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
#define MOD 1000000007
#define ull unsigned long long int
#define newline cout<<endl
 
 
/* TYPE DEFINITIONS */
typedef     long long int        ll;
typedef     vector<ll>     vi;
typedef     pair<ll,ll>   pi;
 
 
 
/* MATH */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
ll pow(ll a,ll b)
{
   ll res=1;
    while(b>0)
    {
        if(b&1)res=(res*a);
        a=(a*a);
        b>>=1;
    }
    return res;
}
 
  
//
/* MACROS */
 
#define  all(A)         (A).begin() , (A).end()
#define  arrall(A,n)    (A),((A)+(n))
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)     for (int i = 0; i < int(n); i++)
#define  forr(i, n)     for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)  
#define  deb(x)       cout << '>' << #x << ':' << x << endl;

void solve()
{
    ll a,b,k;
    cin>>a>>b>>k;
    ll x=min(a,k);
    a-=x;
    k-=x;
    if(k)
    {
        ll y=min(b,k);
        b-=y;
        k-=y;
    }
    cout<<a<<" "<<b<<endl;

}
int main()
{
 
    FastIO;
    ll t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 256
x_1,y_1,x_2,y_2= gets.strip.split.map(&:to_i)

a = x_2 - x_1
b = y_2 - y_1

x_3 = x_2 - b
y_3 = y_2 + a

x_4 = x_3 - a
y_4 = y_3 - b

print x_3,"\s",y_3,"\s",x_4,"\s",y_4,"\n"

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

int n;
int ab[18][2];

int solve(int mask) {
	vector<pair<int, bool>> q(n);
	for (int i = 0; i < n; i++) {
		bool k = mask & 1<<i;
		q[i] = {ab[i][k], k};
	}
	int cnt = 0;
	while (true) {
		bool done = true;
		for (int i = 1; i < n; i++) {
			if (q[i-1].first > q[i].first) {
				swap(q[i-1], q[i]);
				q[i-1].second = !q[i-1].second;
				q[i].second = !q[i].second;
				cnt++;
				done = false;
			}
		}
		if (done) {
			break;
		}
	}
	int ii = -1;
	for (int i = 0; i < n; i++) {
		if (ii != -1 && q[ii].first != q[i].first) {
			return 1e9;
		}
		if (q[i].second) {
			if (ii == -1) {
				ii = i;
			} else {
				int k = i-ii - 1;
				if (k%2) {
					return 1e9;
				}
				cnt += k + 1;
				q[ii].second = false;
				q[i].second = false;
				ii = -1;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (q[i].second) {
			return 1e9;
		}
	}
	/*
	for (int i = 1; i < n; i++) {
		if (q[i-1].first == q[i].first && q[i-1].second && q[i].second) {
			q[i-1].second = false;
			q[i].second = false;
			cnt++;
		}
	}
	for (int i = 0; i < n; i++) {
		if (q[i].second) {
			return 1e9;
		}
	}
	*/
	return cnt;
}

int main() {
	cin >> n;
	for (int k = 0; k < 2; k++) {
		for (int i = 0; i < n; i++) {
			cin >> ab[i][k];
		}
	}

	int ans = 1e9;
	for (int mask = 0; mask < 1<<n; mask++) {
		ans = min(ans, solve(mask));
	}
	cout << (ans < 1e9 ? ans : -1) << endl;
	return 0;
}



Measured memory_bytes: 384
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
INF = 10**18

N=ri()
xyh=[]
for i in range(N):
    xyh += [rl()]
xyh.sort(reverse=True, key=lambda x:x[2])

ans=[-1]*3
for x in range(101):
    if ans[0] != -1:
        break
    for y in range(101):
        if ans[0] != -1:
            break
        if xyh[0][2] == 0:
            h_m = xyh[0][2]+abs(x-xyh[0][0])+abs(y-xyh[0][1])
            for i in range(1,N):
                rst = xyh[i][2]+abs(x-xyh[i][0])+abs(y-xyh[i][1])
                if h_m > rst:
                    h_m = rst
                if h_m == 0:
                    break
                elif i==N-1:
                    ans = [x,y,h_m]
        else:
            h = xyh[0][2]+abs(x-xyh[0][0])+abs(y-xyh[0][1])
            for i in range(1,N):
                if xyh[i][2] != 0:
                    if h != xyh[i][2]+abs(x-xyh[i][0])+abs(y-xyh[i][1]):
                        break
                elif xyh[i][2] == 0:
                    if h > xyh[i][2]+abs(x-xyh[i][0])+abs(y-xyh[i][1]):
                        break
                if i == N-1:
                    ans = [x,y,h]

print("{} {} {}".format(ans[0],ans[1],ans[2]))

Measured memory_bytes: 3188
import java.util.*
import java.io.*

val MOD = 924844033

fun main(args: Array<String>)
{
	Thread(null, Main(), "whatever", 1 shl 28).start()
}

class Main : Runnable {

	override fun run()
	{
		val inputStream = System.`in`
		val outputStream = System.out
		val `in` = InputReader(inputStream)
		val out = PrintWriter(outputStream)
		val solver = TaskD()
		var test = 1
		test = `in`.nextInt()
		for (t in 1..test)
		{
			solver.solve(t, `in`, out)
		}
		out.close()
	}

	internal class TaskD
	{
		fun solve(testNumber: Int, `in`: InputReader, out: PrintWriter) {
			val INF = 4000000000000000000L
			val dx = intArrayOf(-1, 1, 0, 0)
			val dy = intArrayOf(0, 0, -1, 1)

			var n = `in`.nextLong()
			var a = LongArray(3, {`in`.nextLong()})
			var b = longArrayOf(2, 3, 5)
			var d = `in`.nextLong()

			var f = HashMap<Long, Long>()
			f[0] = 0
			fun solve(n: Long): Long
			{
				if (f.contains(n)) return f[n]!!
				var ret = INF
				for (i in 0..2)
				{
					for (x in arrayOf(n/b[i], n/b[i]+1))
						if (x < n)
						{
							ret = Math.min(ret, solve(x)+a[i]+Math.abs(n-x*b[i])*d)
							if (x*(b[i]-1) <= a[i]/d) ret = Math.min(ret, solve(x)+x*(b[i]-1)*d+Math.abs(n-x*b[i])*d)
						}
				}
				f[n] = ret
				return ret
			}

			var res = solve(n)
			out.println(res)
		}
 
	}

	internal class InputReader(stream: InputStream) {
		var reader: BufferedReader
		var tokenizer: StringTokenizer? = null

		init {
			reader = BufferedReader(InputStreamReader(stream), 32768)
			tokenizer = null
		}

		operator fun next(): String {
			while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
				try {
					tokenizer = StringTokenizer(reader.readLine())
				} catch (e: IOException) {
					throw RuntimeException(e)
				}

			}
			return tokenizer!!.nextToken()
		}

		fun nextInt(): Int {
			return Integer.parseInt(next())
		}

		fun nextLong(): Long {
		    return next().toLong()
		}

	}
}

fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a%b)

fun power(a: Long, b: Long, p: Long): Long
{
	if (b == 0L) return 1L
	var t = power(a, b/2, p)
	t = t*t%p
	if (b%2 == 1L) t = t*a%p
	return t
}


Measured memory_bytes: 58496
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	int max = b / a;
	if (b >= a)
	{
		if (max >= c)
		{
			cout << c << endl;
		}
		else if (max < c)
		{
			cout << max << endl;
		}
	}
	else
	{
		cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#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,i0,n) for(int i=i0;i<n;++i)

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

    string str = "";
    queue<pair<string, int>> que;
    que.push({"", 0});

    while(!que.empty()) {
        string si = que.front().first;
        int cnt = que.front().second;
        que.pop();

        if(si.size()==n) {
            cout << si << endl;
            continue;
        }

        rep(i,cnt+1) {
            string ns = "a";
            ns[0] = 'a'+i;
            int nc = cnt;
            if(i==cnt) ++nc;
            que.push({si+ns, nc});
        }
    }

    return 0;
}

Measured memory_bytes: 8832
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    N,M = LI()
    SC = [LI() for _ in range(M)]
    a = [0 for _ in range(N)]
    pre = [None for _ in range(N)]
    # for s,c in SC:
    #     s = s-1
    #     if (a[s]==c) or (pre[s] is None):
    #         pre[s] = a[s]
    #         a[s] = c
    #     else:
    #         print(-1)
    #         exit(0)
    # ans = int("".join(map(str,a)))
    # if len(str(ans))==N:
    #     print("{}".format(int(ans)))
    # else:
    #     print(-1)

    for i in range(1000):
        i = str(i)
        if len(i)==N:
            for s,c in SC:
                if i[s-1] == str(c):
                    # print(i[s-1], c)
                    continue
                else:
                    break
            else:
                print(i)
                exit(0)
        else:
            continue
    else:
        print(-1)

main()



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

int main(){
	string S;
	cin >> S;
	int N = S.size();
	rep(i, N){
		if(i % 2 == 0) cout << S[i];
	}
	cout << endl;
}

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

#define int long long  
#define IOS ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
 
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vp vector<pii>
#define vs vector<string>
#define all(v) v.begin(),v.end()
 
#define lb  lower_bound
#define ub  upper_bound
#define bs  binary_search
#define ff  first
#define ss  second
#define sz(x) ((int)(x).size())
#define rep(i,l,r) for(int i=(l);i<(r);++i)
 
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
     
#define pi 3.14159265358979323846//20 decimals
#define MOD 1000000007
 

int32_t main(){
 
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
     IOS
  int n,k,q;
  cin>>n>>k>>q;
  int temp=q;
  vi player(n,k);
 while(q--)
{
    int a;
    cin>>a;
    player[a-1]++;
}

for(auto &x:player)
{
    x=x-temp;
}

for(int x:player)
{
    if(x>0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}
return 0;
}

Measured memory_bytes: 1408
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include "bits/stdc++.h"
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# define LOCAL
# define sim template < class c
# define ris return * this
# define dor > debug & operator <<
# define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define show(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int gcd(int a, int b)
{
if(b) return gcd(b,a%b);
return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int h,w,n,x,y;
string s[2];

int32_t main(){_
	//freopen("input","r",stdin);
	cin >> h >> w >> n;
	cin >> x >> y;
	cin >> s[0] >> s[1];
	int f[4];
	f[0] = x;
	f[1] = x;
	f[2] = y;
	f[3] = y;
	for(int i = 0;i < n;i++)
	{
		if(s[0][i] == 'U') f[0]--;
		if(s[0][i] == 'D') f[1]++;
		if(s[0][i] == 'L') f[2]--;
		if(s[0][i] == 'R') f[3]++;
		if(min(f[0],f[1]) < 1 || max(f[0],f[1]) > h) rc("NO");
		if(min(f[2],f[3]) < 1 || max(f[2],f[3]) > w) rc("NO"); 
		if(s[1][i] == 'U') if(f[1] != 1) f[1]--;
		if(s[1][i] == 'D') if(f[0] != h) f[0]++;
		if(s[1][i] == 'L') if(f[3] != 1) f[3]--;
		if(s[1][i] == 'R') if(f[2] != w) f[2]++;
	}
	rc("YES");
	return 0;
}











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

bool okH[105], okW[105];
string mp[105];

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

int h,w;cin>>h>>w;
for(int i=0;i<h;i++){
  cin>>mp[i];
  for(int j=0;j<w;j++){
    if(mp[i][j]=='#'){
      okH[i]=1;
      okW[j]=1;
    }
  }
}
for(int i=0;i<h;i++){
  if(!okH[i])continue;
  bool f=false;
  for(int j=0;j<w;j++){
    if(!okW[j])continue;
    cout<<mp[i][j];
    f=true;
  }
  if(f)cout<<endl;
}
  
  return 0;
}


Measured memory_bytes: 3644