akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String [] formula = input.readLine().split("\\s+");
        int x = Integer.parseInt(formula[0]);
        int y = Integer.parseInt(formula[2]);
        System.out.println(formula[1].equals("+")?(x + y):(x - y));

    }
}


Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

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

    ll N;
    cin >> N;
    vec a(N);
    Rep (i, N) {
        cin >> a[i];
    }

    ll tmp = 1;
    Rep (i, N) {
        if (a[i] == tmp) {
            tmp++;
        }
    }

    if (tmp == 1) {
        cout << -1 << endl;
    } else {
        cout << N - tmp + 1 << endl;
    }
}

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

/*
stackの実装
push,popの実装

NULLの代わりにconstを使ってNILというnodeを作っておくと良さそう。


*/
#define max 2147483647


void merge(int *a,int left,int mid,int right){
        int n1 = mid - left;
        int n2 = right - mid;
        int L[n1+1],R[n2+1];
        int i;
        for(i=0;i<n1;i++){
            L[i] = a[left + i];
        }
        for(i=0;i<n2;i++){
            R[i] = a[mid + i];
        }
        L[n1]=max;
        R[n2]=max;
        int j=0,k=0;
        for(i=left;i<right;i++){
            if(L[j]<R[k]){
                a[i] = L[j];
                j++;
            }
            else{
                a[i] = R[k];
                k++;
            }
        }

}


void merge_sort(int *a,int left,int right){
    int middle;
    if(left + 1 < right){
        middle = (left + right)/2;
        merge_sort(a,left,middle);
        merge_sort(a,middle,right);
        merge(a,left,middle,right);
    }
}


int main(void){
    int n;
    scanf("%d",&n);
    n = 2*n;
    int i,l[n];
    for(i=0;i<n;i++){
        scanf("%d",&l[i]);
    }
    merge_sort(l,0,n);
    int counter = 0;
    if(n%2 == 0){
        for(i=0;i<n;i+=2){
            counter += l[i];
        }
    }else{//0 1 2 3 4 
        for(i=1;i<n;i+=2)
        counter += l[i];
    }
    printf("%d\n",counter);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる

//—————————————————————————————————————————————————

ll com(ll n, ll k){
	if(n<k) return 0;
	if(k==0) return 1;
	ld r = 1;
	for(ld i=0;i<k;++i){
		r = r*(ld)(n-i)/(ld)(k-i);
	}
  ll re=r;
	if(abs(re-r)<0.01) return re;
  re++;
  if(abs(re-r)<0.01) return re;
  return re-2;
}

//—————————————————————————————————————————————————

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


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

  vector<ld> p(n);
  rep(i,n){
    cin>>p[i];
  }

  sort(all(p));
  reverse(all(p));

  ld sum=0;
  rep(i,a){
    sum+=p[i];
  }
  cout << fixed << setprecision (20);   
  cout << sum/a << endl;

  int sa=0;
  int di=0;
  rep(i,n){
    if(p[i]==p[a-1]) sa++;
  }
  rep(i,a){
    if(p[i]!=p[a-1]) di++;
  }

  if(p[0]!=p[a-1]){
    cout << com(sa,a-di) << endl;
  }
  else {
    ll ans=0;
    for(int i=a-di;i<=b-di;i++){
      ans+=com(sa,i);
    }
    cout << ans << endl;
  }

}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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;}

int main(){
    string s,t;cin>>s>>t;
    int ans=0;
    rep(i,s.size()){
        if(s[i]!=t[i])ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3860
#include<stdio.h>
 
#define MAX 100005
#define NIL -1
 
struct Node{
  int parent;
  int left;
  int right;
};
 
struct Node N[MAX];
 
int n, H, D[MAX];
 
int getDepth(int u){
  int d = 0;
  while(N[u].parent >= 0){
    u = N[u].parent;
    d++;
  }
   
  return d;
}
 
void printTree(int u){
  int t;
 
  if(N[u].parent == NIL) printf("node %d: parent = %d, depth = %d, root, ", u, N[u].parent, D[u]);
   
  else if(N[u].left == NIL) printf("node %d: parent = %d, depth = %d, leaf, ", u, N[u].parent, D[u]);
   
  else printf("node %d: parent = %d, depth = %d, internal node, ", u, N[u].parent, D[u]);
     
  printf("[");
 
  t = u;
 
  if(N[t].left != NIL){
    printf("%d", N[t].left);
 
    if(N[N[t].left].right == NIL) printf("]\n");
 
    else printf(",");
 
    t = N[t].left;
 
    while(N[t].right != NIL){
      printf(" %d",N[t].right);
       
      if(N[N[t].right].right == NIL) printf("]\n");
 
      else printf(",");
 
      t = N[t].right;
    }
  }
   
  else printf("]\n");
}
 
int main(){
  int i, j, d, v, c, l, r;
   
  scanf("%d", &n);
   
  for(i = 0; i < n; i++){
    N[i].parent = N[i].left = N[i].right = NIL;
  }
   
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);
 
    for(j = 0; j < d; j++){
      scanf("%d", &c);
 
      N[c].parent = v;
       
      if(j == 0) N[v].left = c;
       
      else if (j >= 1) N[r].right = c;
      r = c;
    }
  }
   
  for(i = 0; i < n; i++) D[i] = getDepth(i);
   
  for(i = 0; i < n; i++) printTree(i);
  return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int cnt=0;
    string s1,s2;
    cin>>s1>>s2;
    int s = s1.size();
    for(int i=0;i<s;i++) {
        if(s1[i] != s2[i]) cnt++;
    }
    cout<<cnt<<endl;
}



Measured memory_bytes: 3916
import sys
import math
input = sys.stdin.readline
def main():
    a,b,h,m = map(int, input().split())
    if abs(m/60 - (h/12+m/720)) >= 1/2:
        sita = (1-abs(m/60 - (h/12+m/720))) * 2 * math.pi
        c_si = math.cos(sita)
        ans = math.sqrt(a**2+b**2-2*a*b*c_si)
        print(ans)
    else:
        sita = abs(m/60 - (h/12+m/720)) * 2 * math.pi
        c_si = math.cos(sita)
        ans = math.sqrt(a**2+b**2-2*a*b*c_si)
        print(ans)
        
        
        
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 9540
n,k = map(int,input().split())
cnt = 0
num = []
for i in range(n):
    a,b = map(int,input().split())
    num.append((a,b))
num.sort()
for i in range(n):
    cnt += num[i][1]
    if cnt >= k:
        print(num[i][0])
        exit()

Measured memory_bytes: 83348
N = int(input())
A = []
 
for _ in range(N):
    A.append(int(input()))
    
a = b = 0
    
for i in range(N):
    if A[i] >= a:
        b = a
        a = A[i]
    elif A[i] > b:
        b = A[i]
 
for i in range(N):
    if A[i] < a:
        print(a)
    else:
        print(b)

Measured memory_bytes: 12512
#include <bits/stdc++.h>
#define itn int
#define gI gi

using namespace std;

typedef long long ll;

inline int gi()
{
	int f = 1, x = 0; 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 f * x;
}

inline ll gl()
{
	ll f = 1, x = 0; 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 f * x;
}

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n, m, k;
	n = gi(), k = gi();
	if (n * 500 >= k) puts("Yes");
	else puts("No"); 
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main() 
{
  string s; cin >> s;
  string t = "";
  for(int i = 0; i < s.size(); i++){
    t += s[s.size()-1-i];
  }
  if(s == t){
    string a = "",b = "";
    for(int i = 0; i < s.size()/2; i++){
      a += s[i];
      b += s[s.size()/2+i+1];
    }
    if(a == b){
      cout << "Yes" << endl;
    }
    else cout << "No" << endl;
  }
  else cout << "No" << endl;
  system("pause");
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=2e5+5;
int gcd(int n,int m)
{
    if(n==0)
        return m;
    else
    {
        return gcd(m%n,n);
    }
}
int32_t main()
{
    IOS;
    char c;
    cin>>c;
    cout<<char(c-'a'+1+'a')<<endl;



}


Measured memory_bytes: 256
A=[]
while True:
	try:
		x,y=map(int,input().split(','))
		A.append((x,y))
	except:
		break
amount_of_sales=0
sales_number=0
for i in A:
	amount_of_sales+=i[0]*i[1]
	sales_number+=i[1]
print(amount_of_sales)
print(int(sales_number/len(A)+0.5))

Measured memory_bytes: 7580
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().solve();
	}

	private void solve() throws IOException {
		try {
			solveA();
			//			 solveB();
			//			 solveC();
			//			 solveD();
			//			 solveE();
			//			 solveF();
		} finally {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.flush();
				out.close();
			}
		}

	}

	private void solveA() {
		String numN = next();

		out.println(numN.equals(new StringBuilder(numN).reverse().toString()) ? "Yes" : "No");
	}

	private void solveB() {
		int numN = nextInt();

		out.println("");
	}

	private void solveC() {
		int numN = nextInt();

		out.println("");
	}

	private void solveD() {
		int numN = nextInt();

		out.println("");
	}

	private void solveE() {
		int numN = nextInt();

		out.println("");
	}

	private void solveF() {
		int numN = nextInt();

		out.println("");
	}

	private final PrintWriter out = new PrintWriter(System.out);
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

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

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 20948
unittest
{
	assert( [ "4", "1 -3 1 0" ].parse.expand.solve == 4 );
	assert( [ "5", "3 -6 4 -5 7" ].parse.expand.solve == 0 );
	assert( [ "6", "-1 4 3 2 -5 4" ].parse.expand.solve == 8 );
}

import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.strip.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto ps = 0L;
	auto pd = 0L;
	auto ms = 0L;
	auto md = 0L;
	
	foreach( i, a; as )
	{
		ps += a;
		ms += a;
		if( i % 2 == 0 )
		{
			if( ps <= 0 ) pd -= ps - 1, ps -= ps - 1;
			if( 0 <= ms ) md += ms + 1, ms -= ms + 1;
		}
		else
		{
			if( 0 <= ps ) pd += ps + 1, ps -= ps + 1;
			if( ms <= 0 ) md -= ms - 1, ms -= ms - 1;
		}
	}
	
	return min( pd, md );
}


Measured memory_bytes: 5124
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a1 = sc.nextInt();
    int a2 = sc.nextInt();
    int a3 = sc.nextInt();

    if(a1+a2+a3>=22)
      System.out.println("bust");
    else
      System.out.println("win");
  }
}


Measured memory_bytes: 22996
A, B=map(int, input().split())
def f(x, y):
  return ((y-x+1)//2)%2

if A%2==0 and B%2==1:
  print(f(A, B))
elif A%2==1 and B%2==1:
  print(f(A+1, B)^A)
elif A%2==0 and B%2==0:
  print(f(A, B-1)^B)
else:
  print((f(A+1, B-1)^A)^B)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

const int xi[4]={0, 1, 0, -1}, yi[4]={1, 0, -1, 0};
const int INF = 1e9;

signed main() {
    int H, W;
    cin >> H >> W;
    V(V(char)) s(H, V(char)(W));
    int wcnt = 0;
    rep(i, H) rep(j, W) {
        cin >> s[i][j];
        if(s[i][j] == '.') wcnt++;
    }

    queue<P> q;
    q.push(P(0, 0));
    vvi d(H, vi(W, INF));
    V(V(bool)) visit(H, V(bool)(W, false));
    if(s[0][0]=='.') d[0][0] = 1; else d[0][0] = 0;
    while(!q.empty()) {
        P now = q.front();
        q.pop();
        rep(i, 4) {
            int ny = now.fi+yi[i], nx = now.se+xi[i];
            if(ny<0||ny>=H||nx<0||nx>=W) continue;
            if(!visit[ny][nx] && s[ny][nx]=='.') {
                d[ny][nx] = min(d[ny][nx], d[now.fi][now.se]+1);
                visit[ny][nx] = true;
                q.push(P(ny, nx));
            }
        }
    }
    int res = d[H-1][W-1];
    if(res!=INF) cout << wcnt-res << endl;
    else cout << -1 << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	/*int t;
	scanf("%d",&t);
	while(t--)*/
	//{
		char s[1000000];
		scanf("%s",s);
		int l=strlen(s),c=0,i;
		for(i=0;i<l/2;i++)
		{
			if(s[i]==s[l-i-1])
			{
				c++;
			}
		}
		if(c==i)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	//}
}

Measured memory_bytes: 1632
#include<iostream>
using namespace std;
#include<vector>
#include<set>
#include<cmath>
#include<iomanip>
#include<algorithm>
#define int long long int
int memo[101][101];
void function()
{
	int i=0,j=0;
	for(i=0;i<=100;i++)
	{
		for(j=0;j<=100;j++)
		{
			if(j>i)
			{
				memo[i][j]=0;
			}
		}
	}
	memo[1][1]=1;
	for(i=2;i<=100;i++)
	{
		memo[i][1]=i;
	}
	for(i=2;i<=100;i++)
	{
		for(j=2;j<=100;j++)
		{
			memo[i][j]=(memo[i-1][j]+memo[i-1][j-1]);
		}
	}
}
int ncr(int n,int r)
{
	if(r>n)
	   return 0;
	return memo[n][r];
}
int32_t main()
{
	function();
	int n,a,b;
	cin>>n>>a>>b;
	int arr[n],j;
	for(j=0;j<n;j++)
	  cin>>arr[j];
	sort(arr,arr+n);
	for(j=0;j<n/2;j++)
	{
		int temp=arr[j];
		arr[j]=arr[n-1-j];
		arr[n-1-j]=temp;
	}
	set<int> st;
	int sum=0;
	for(j=0;j<a;j++)
	{
		sum+=arr[j];
		st.insert(arr[j]);
	}
	if(st.size()>1)
	{
		int total=0;
		for(j=a-1;j>=0;j--)
		{
			if(arr[j]==arr[a-1])
			{
				total++;
			}
		}
		int count=0;
		for(j=0;j<n;j++)
		{
			if(arr[j]==arr[a-1])
			{
				count++;
			}
		}
		double val=(double)(sum)/a;
		printf("%.10lf\n",val);
		int final=memo[count][total];
		cout<<final<<endl;
	}
	else
	{
		int count=0;
		int val=arr[0];
		for(j=0;j<n;j++)
		{
			if(arr[j]==val)
			  count++;
		}
		int answer=0;
		for(j=a;j<=min(b,count);j++)
		{
			answer+=ncr(count,j);
		}
		double ans=arr[0];
		printf("%.10lf\n",ans);
		cout<<answer<<endl;
	}
}


Measured memory_bytes: 384
n=int(input())
w=[input() for _ in range(n)]
j=True
t=w[0][-1]
for i in range(1,n):
    if w[i][0]!=t:
        j=False
    else:
        t=w[i][-1]
from collections import Counter
c=Counter(w)
x=[list(c.items())[i][1] for i in range(len(list(c.items())))]
if max(x)>1:
    j=False
print("Yes" if j else "No")

Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}


int main(){
    int N,Ma,Mb; cin >> N >> Ma >> Mb;
    int a[44],b[44],c[44];
    int dp[440][440][44];
    for(int i = 0; i < 440; i++){
        for(int j = 0; j < 440; j++){
            for(int k = 0; k < 44; k++){
                dp[i][j][k] = MM;
            }
        }
    }
    for(int i = 0; i < N; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    dp[0][0][0] = 0;
    dp[a[0]][b[0]][0] = c[0];
    int mn = MM;
    for(int i = 0; i < 404; i++){
        for(int j = 0; j < 404; j++){
            for(int num = 1; num < N; num++){
                dp[0][0][num] = 0;
                if (i >= a[num] && j >= b[num] && dp[i-a[num]][j-b[num]][num-1] != MM){
                    dp[i][j][num] = min(dp[i][j][num-1], dp[i-a[num]][j-b[num]][num-1] + c[num]);
                } else if (dp[i][j][num-1] != MM) {
                    dp[i][j][num] = min(dp[i][j][num],dp[i][j][num-1]);
                }
            }
        }
    }
    for(int i = 0; i < 404; i++){
        for(int j = 0; j < 404; j++){
            if (dp[i][j][N-1] != MM && i % Ma == 0 && j % Mb == 0 && i / Ma == j / Mb && (i != 0 || j != 0)){
                mn = min(mn,dp[i][j][N-1]);
            }
        }
    }
    if (mn != MM){
        cout << mn << endl;
    } else {
        cout << -1 << endl;
    }
}

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

int main(){
  int N;
  cin >> N;
  int A[N],B[N],C[N],HpmaxA[N],HpmaxB[N],HpmaxC[N];
  for(int i;i<N;i++) cin >> A[i] >> B[i] >> C[i];
  HpmaxA[0] = A[0];
  HpmaxB[0] = B[0];
  HpmaxC[0] = C[0];
  for(int i=1;i<N;i++){
  	HpmaxA[i] = max(HpmaxB[i-1] + A[i],HpmaxC[i-1] + A[i]);
    HpmaxB[i] = max(HpmaxA[i-1] + B[i],HpmaxC[i-1] + B[i]);
    HpmaxC[i] = max(HpmaxA[i-1] + C[i],HpmaxB[i-1] + C[i]);
  }
  cout << max(HpmaxA[N-1],max(HpmaxB[N-1],HpmaxC[N-1])) << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    int l, r; sc(l), sc(r);
    int left, right, ans = 2020;
    if (l/2019 == r/2019){
        rep(i, l%2019, r%2019+1){
            rep(j, l%2019, r%2019+1){
                if (i == j) continue;
                ans = min(ans, i*j%2019);
            }
        }
    }else{
        rep(i, l%2019, 2020){
            rep(j, 0, r%2019+1){
                if (i == j) continue;
                ans = min(ans, i*j%2019);
            }
            rep(j, l%2019, 2020){
                if (i == j) continue;
                ans = min(ans, i*j%2019);
            }
        }
        rep(i, 0, r%2019+1){
            rep(j, 0, r%2019+1){
                if (i == j) continue;
                ans = min(ans, i*j%2019);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
## https://atcoder.jp/contests/abc051/submissions/3281251
import heapq

def dijkstra(graph, node, start):
    dist = [float("inf") for _ in range(node)]
    
    dist[start] = 0
    q = []
    heapq.heappush(q, (0, start))
    
    while q:
        cost, cur_node = heapq.heappop(q)
        
        if dist[cur_node] < cost:
            continue
        
        for nex_cost, nex_node in graph[cur_node]:
            dist_cand = dist[cur_node] + nex_cost
            if dist_cand < dist[nex_node]:
                dist[nex_node] = dist_cand
                heapq.heappush(q, (dist[nex_node], nex_node))

    return dist

def main():
    n, m = map(int, input().split())
    adj = [[] for _ in range(n)]
    for i in range(m):
        a, b, c = map(int, input().split())
        a -= 1
        b -= 1
        adj[a].append((c, b))
        adj[b].append((c, a))
    shortest = []
    for i in range(n):
        shortest.append(dijkstra(adj, n, i))
    ans = 0
    for i in range(n):
        for cost, j in adj[i]:
            if cost > shortest[i][j]:
                ans += 1
    print(ans // 2)
                                                                                                                                                                                                     
if __name__=='__main__':
    main()



Measured memory_bytes: 3572
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include<bitset>
#include <iomanip>

using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;



#define ll long long




/*
class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d, e, H, W, L;
long long A[200005] = {};
long long B[5005][5] = {};
long long C[205][205] = {};
long long x[200005] = {};
long long y[200005] = {};
bool f, ff;
string S[2];
set <long long>sll;
pl bufpl;
vector <long long>vl[3];
vector <pl>vpl;
vector <string> vs;
set<ll> llset;

/*struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}


ll minn, maxx;
double ansa;

int main() {

	cin >> W>>H>>a>>b;

	ansa = (double)(W * H) / (double)2.0000000000;


	cout << ansa << ' ';
	e=0;
	if (W / 2 == a && W % 2 == 0) {
		if (H / 2 == b && H % 2 == 0) {
			e = 1;
		}
	}

	cout << e << endl;

	return 0;

}


Measured memory_bytes: 256
import sys
import math
import bisect

def main():
    n, m = map(int, input().split())
    wa = [0] * n
    ac = [0] * n
    penalty = 0
    for _ in range(m):
        p, s = input().split()
        p = int(p) - 1
        if s == 'WA':
            wa[p] += 1
        else:
            if ac[p] == 0:
                ac[p] = 1
                penalty += wa[p]
            ac[p] = 1
    print('%d %d' % (sum(ac), penalty))

if __name__ == "__main__":
    main()


Measured memory_bytes: 4596
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int N,K,ans,LR,RL;
string s;
main()
{
	cin>>N>>K>>s;
	for(int i=1;i<s.size();i++)
	{
		if(s[i-1]==s[i])ans++;
		else
		{
			if(s[i]=='L')RL++;
			else LR++;
		}
	}
	for(int i=0;i<K;i++)
	{
		if(LR&&RL)
		{
			LR--;
			RL--;
			ans+=2;
		}
		else if(LR)LR--,ans++;
		else if(RL)RL--,ans++;
		else break;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
#define MAX 101

int D[MAX];

bool check(){
    if ( D[1] % 2 == 0 || D[2] % 2 == 0 ) return false;
    for ( int i = 3; i < MAX; i++ ) if ( D[i] % 2 == 1 ) return false;
    return true;
}

main(){
    int a, b;
    while( cin >> a >> b ){
	for ( int i = 1; i <= MAX; i++ ) D[i] = 0;
	D[a]++; D[b]++;
	while(1){
	    cin >> a >> b;
	    if ( a == 0 && b == 0) break;
	    D[a]++; D[b]++;
	}
	if ( check() ) cout << "OK" << endl;
	else cout << "NG" << endl;
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(a,b,c) for(int i=a;i<b;i+=c)  
typedef pair<ll , pair<ll, ll> > pi;
int pow(int x,int y){
    int res=1;
    while(y){
        if(y&1) res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}   
struct Compare {
    constexpr bool operator()(pi const & a,
                              pi const & b) const noexcept
    { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); }
 
};
void prefix_function( string s,ll arr[] )
{
     long long border=0; arr[0]=0;
    for(long long i=1;i<s.size();i++)
    {
      while(border>0 && s[i]!=s[border])
        border=arr[border-1];
     
     if(s[i]==s[border])
         border++;
      else
       border=0;
      
      arr[i]=border;
    }
}
ll mod=998244353;
ll add( ll a , ll b)
{
    return (((a%mod)+(b%mod))%mod);
}
ll mul(ll a,ll b)
{
  return (((a%mod)*(b%mod))%mod);
}
//send mod-2 for a^-1 if mod is a prime number
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = mul(res, a);
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}
ll dsu_arr[100000];
ll dsu_sz[100000];
void dsu(ll n)
{
    for(ll i=0;i<=n;i++)
    {
        dsu_arr[i]=i;
        dsu_sz[i]=1;
    }
}
ll find(ll x)
{
     ll root=x;
    while (root!=dsu_arr[root])
    {
        root=dsu_arr[root];
    }
    while(x!=dsu_arr[x])
    {
        dsu_arr[x]=root;
        x=dsu_arr[x];
    }
    return root;
}
ll merge(ll x,ll y)
{
    ll root1=find(x);
    ll root2=find(y);
    
    if(root1==root2)
    return 0ll;
 
    if(dsu_sz[x]>dsu_sz[y]){
    dsu_arr[root2]=root1;
    dsu_sz[x]+=dsu_sz[y];
    }
    else
    {
         dsu_sz[y]+=dsu_sz[x];
        dsu_arr[root1]=root2;
    }
    return 1ll;
}


int main()
{
map<ll,ll>row;
map<ll,ll>col;
map<pair<ll,ll>,bool>ma;
ll mx_r=0,mx_c=0;
ll n,m,b;
cin>>n>>m>>b;
for(ll i=0;i<b;i++)
{
    ll u,v;
    cin>>u>>v;
    ma[{u,v}]=true;
    row[u]++;
    mx_r=max(mx_r,row[u]);
    col[v]++;
    mx_c=max(mx_c,col[v]);
}
vector<ll>r,c;
for(ll i=1;i<=n;i++)
{
    if(mx_r==row[i])
    r.push_back(i);
}
for(ll i=1;i<=m;i++)
{
    if(mx_c==col[i])
    c.push_back(i);
}
for(ll i=0;i<r.size();i++)
{
    for(ll j=0;j<c.size();j++)
    {
        if(!ma[{r[i],c[j]}])
        {
            cout<<mx_c+mx_r<<endl;
            return 0;
        }
    }
}
cout<<mx_c+mx_r-1<<endl;


}



   
      
    
        



Measured memory_bytes: 67848
#include<iostream>
#include<math.h>
using namespace std;
#include<vector>
#include<algorithm>
int main(){
    int n;
    cin >> n;
    vector<double> v(n);
    for(int i=0; i<n; i++){
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    for(int i=1; i<n; i++){
        v[i]= (v[i-1]+v[i])/2;
    }
    cout << v[n-1] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n;
  cin>>n;
int a[500];
for(int i=0;i<n;i++){
	cin>>a[i];
}
int p=a[0];
for(int i=1;i<n;i++)
{
	if(a[i]>p)
	p=a[i];
}
int sum=0;
for(int i=0;i<n;i++){
	sum=sum+a[i];
}

if(sum-p>p)
cout<<"Yes";
else
cout<<"No";
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


fn main() {
    let n: usize = read();
    for i in 0..n{
        let a:i32 = read();
        if  a%2==0{
            if a%3!=0 && a%5!=0{
                return println!("DENIED");
            }
        }
    }
    return println!("APPROVED");
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
//      std macros
typedef long long ll;
typedef pair<int ,int> pii;
typedef pair<ll ,ll> pll;
//      dereference
#define F first
#define S second
#define pb push_back
#define mp make_pair
//      loops
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,a,b) for(int i=a;i<=b;++i)
#define PER(i,b,a) for(int i=b;i>=a;--i)
#define all(X) (X).begin(), (X).end()
//      I/O
#define sd(n) scanf("%d",&n)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define sll(n) scanf("%lld",&n)
#define sll2(x,y) scanf("%lld%lld",&x,&y)
#define sll3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define ss(s) scanf("%s",s)
//      debug
#define debug(x) cerr<<"debug->"<<#x<<"::"<<x<<endl
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n"
#define debug4(x,y,z,w) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<"\n"
//      set values
#define mset(n,k) memset(n,k,sizeof(n))
//modular expo
ll power(ll a,ll b, ll c){
    ll x=1,y=a;
    while(b>0){
        if(b&1)
            x=(x*y)%c;
        y=(y*y)%c;
        b/=2;
    }
    return x%c;
}
int dx[]={0,-1,0,1};
int dy[]={-1,0,1,0};//clockwise from left
int dr[]={1,1,0,-1,-1,-1, 0, 1};
int dc[]={0,1,1, 1, 0,-1,-1,-1};//anticlockwise from down
int main() {

	ll x;
	sll(x);
	printf("%lld\n",24+24-x);
	
	
	return 0;
}

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

using namespace std;

int N, K;
int a[128];
int dp[100024];

int solve(int k) {
	if(k<0) {
		return true;
	}
	if(k<a[0]) {
		return false;
	}
	if(dp[k]) {
		return dp[k]-1;
	}
	for(int n=0; n<N; ++n) {
		if(!solve(k-a[n])) {
			dp[k] = 2;
			return true;
		}
	}
	dp[k] = 1;
	return false;
}

int main() {
	scanf("%d%d", &N, &K);
	for(int n=0; n<N; ++n) {
		scanf("%d", &a[n]);
	}
	printf("%s\n", solve(K) ? "First" : "Second");

	return 0;
}


Measured memory_bytes: 5248
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T,vector<T>,greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
const int mod = 1e9 + 7, inf = 1e16;

int modpow(int x, int n) {
	if (n == 0) return 1;
	if (n % 2) return x * modpow(x * x % mod, n / 2) % mod;
	return  modpow(x * x % mod, n / 2) % mod;
}
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

signed main() {
	int x, a;
	cin >> x >> a;
	if (x < a) cout << 0 << endl;
	else cout << 10 << endl;
}

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

int n,m,x;
vector<int> c;
vector<vector<int>> a;

bool judge(int bit);
int cost(int bit);

int main(){
    cin>>n>>m>>x;
    c.resize(n);
    a.resize(n);
    REP(i,n){
        cin>>c[i];
        a[i].resize(m);
        REP(j,m){
            cin>>a[i][j];
        }
    }
    int min_=0;

    for(int bit=0; bit<(1<<n); bit++){
        if(judge(bit)){
            if(min_==0){
                min_=cost(bit);
            }else{
                min_=min(min_,cost(bit));
            }    
        }
    }           
    
    cout<<(min_==0 ? -1 : min_)<<endl;
}

bool judge(int bit){
    vector<int> und(n);

    REP(i,n){
        if(bit& (1<<i)){
            REP(j,m){
                und[j]+=a[i][j];
            }
        }
    }

    REP(i,m){
        if(und[i]<x){
            return false;
        }
    }

    return true;
}

int cost(int bit){
    int sum=0;
    REP(i,n){
        if(bit& (1<<i)){
            sum+=c[i];
        }
    }

    return sum;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
inline int read() {
	int x=0,f=1;
	char c=getchar();
	for (;!isdigit(c);c=getchar()) if (c=='-') f=-1;
	for (;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
typedef long long giant;
const int maxn=1e5;
struct ant {
	int x,w;
} a[maxn];
int b[maxn],c[maxn],n,l,t;
giant cs=0;
inline int up(int x) {
	if (x>=0) return x;
	return x%l+l;
}
int main() {
	n=read(),l=read(),t=read();
	for (int i=0;i<n;++i) {
		int &x=a[i].x=read(),&w=a[i].w=(read()==1?1:-1);
		b[i]=c[i]=up(x+w*t)%l;
	}
	for (int i=1;i<n;++i) if (a[i].w!=a[0].w) {
		int d=up((a[0].x-a[i].x)*a[i].w);
		int k=2*t-d;
		if (k<0) continue;
		cs+=1+k/l;
	}
	int p=cs*a[0].w;
	((p%=n)+=n)%=n;
	sort(b,b+n);
	for (int i=0;i<n;++i) if (b[i]==c[0]) {
		int the=i+(i<n-1 && b[i+1]==b[i] && a[0].w==1);
		rotate(b,b+(the>=p?the-p:n-p+the),b+n);
		break;
	}
	for (int i=0;i<n;++i) printf("%d\n",b[i]);
	return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

ll LIS(vector<ll>& sequence){
    multiset<ll> s;
    s.insert(sequence[0]);
    
    for(ll i = 1; i < sequence.size(); i++){
        ll now = sequence[i];
        //広義単調増加列の場合、以下を now >= *--s.end()にする
        if(now >= *--s.end()) s.insert(now);
        else{
            auto itr = s.upper_bound(now);
            s.erase(itr);
            s.insert(now);
        }
    }
    return s.size();
}

int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    ll tp;
    rep(i,N) cin >> tp, A[i] = -tp;
    pr(LIS(A));
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>

using namespace std;

int rec(int n, int m) {

  if (n <= 0)
    return 0;
  else
    return 1 + rec(n-m, m);
}

int main(void) {

  int L, A, B, C, D;
  cin >> L >> A >> B >> C >> D;
  
  int s, t, u;
  s = rec(A, C);
  t = rec(B, D);
  
  u = max(s, t);
  cout << L - u << endl;
  return 0;
  
}

Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
int main() {
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	if (e-a<=k) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
  return 0;
}

Measured memory_bytes: 256
// 写経of snuke
#include <bits/stdc++.h>

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define mins(x,y) (x=min(x,y))
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

const ll LINF = 1001002003004005006ll;


int a,b,c,d;
 
map<ll,ll> mem;
ll f(ll x) {
  if (!x) return 0;
  if (mem.count(x)) return mem[x];
  ll res = LINF;
  if (LINF/d > x) res = x*d;
  auto f2 = [&](ll y) {
    if (y >= x) return LINF;
    return f(y);
  };
  {
    ll l = x/2*2, r = l+2;
    mins(res, f2(l/2)+a+(x-l)*d);
    mins(res, f2(r/2)+a+(r-x)*d);
  }
  {
    ll l = x/3*3, r = l+3;
    mins(res, f2(l/3)+b+(x-l)*d);
    mins(res, f2(r/3)+b+(r-x)*d);
  }
  {
    ll l = x/5*5, r = l+5;
    mins(res, f2(l/5)+c+(x-l)*d);
    mins(res, f2(r/5)+c+(r-x)*d);
  }
  return mem[x] = res;
}

void solve() {
	ll n;
	cin >> n;
	cin >> a >>b >>c >>d;
	mem = map<ll, ll>();
	cout << f(n) << endl;
}
int main()
{
	int T;
	cin >> T;

	rep(i,T){
		solve();
	}
}


Measured memory_bytes: 4836
#include <bits/stdc++.h>
#define sz(x) ((int)(x).size())
using namespace std;
typedef long long ll;
const int n = 100 + 5;
const int INF = 1e6;

int H, W, N, K, T;

bool M[n][n];
int dp[n][n];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> H >> W;
	for(int i = 0; i < H; ++i){
		for(int j = 0; j < W; ++j){
			char c; cin >>c;
			M[i][j] = c == '#';
		}
	}

	dp[0][0] = M[0][0];

	for(int i = 0; i < H; ++i){
		for(int j = 0; j < W; ++j){
			if(i != 0 || j != 0) dp[i][j] = INF;
			if(i>0){
				int v = dp[i-1][j] + (M[i][j] && !M[i-1][j]);
				dp[i][j] = min(v, dp[i][j]);
			}
			if(j>0){
				int v = dp[i][j-1] + (M[i][j] && !M[i][j-1]);
				dp[i][j] = min(v, dp[i][j]);
			}
		}
	}
	cout << dp[H-1][W-1] << endl;
	return 0;
}


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

#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  int x;
  cin >> x;
  int ans = 0;
  REP(i,a) {
    REP(j,b) {
      REP(k,c) {
        if (500 * i + 100 * j + 50 * k == x) ans++;
      }
    }
  }
  cout << ans << endl;
}

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

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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    vector<ll> dp(n, 0);
    vector<ll> wyst(n, 0);
    for (int i = 0; i < n; ++i)
    {
        if (a[i] == 0)
        {
            if (wyst[0] == 0)
            {
                if (i == 0)
                    dp[i] = 3;
                else
                    dp[i] = 0;
            }
            if (wyst[0] == 1)
                dp[i] = (dp[i - 1] * 2) % MOD;
            if (wyst[0] == 2)
                dp[i] = dp[i - 1];
        }
        else
        {
            if (wyst[a[i]] == 0)
            {
                if (wyst[a[i] - 1] == 0)
                    dp[i] = 0;
                if (wyst[a[i] - 1] == 1)
                    dp[i] = dp[i - 1];
                if (wyst[a[i] - 1] == 2)
                    dp[i] = (dp[i - 1] * 2) % MOD;
                if (wyst[a[i] - 1] == 3)
                    dp[i] = (dp[i - 1] * 3) % MOD;
            }
            if (wyst[a[i]] == 1)
            {
                if (wyst[a[i] - 1] < 2)
                    dp[i] = 0;
                if (wyst[a[i] - 1] == 2)
                    dp[i] = dp[i - 1];
                if (wyst[a[i] - 1] == 3)
                    dp[i] = (dp[i - 1] * 2) % MOD;
            }
            if (wyst[a[i]] == 2)
            {
                if (wyst[a[i] - 1] < 3)
                    dp[i] = 0;
                if (wyst[a[i] - 1] == 3)
                    dp[i] = dp[i - 1];
            }
        }
        ++wyst[a[i]];
    }
    cout << dp[n - 1];
    return 0;
}


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

#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 998244353 
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi  first

#define se second
#define pb push_backP
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}
ll ans[10005][10005];

ll sol(ll i,ll j){
    if(i<0)
        return 0;
    else if(j<0)
        return inf;
    else
    {
        return ans[i][j];
    }
    
}

int main(){
	boost;

	ll h,n;
    cin>>h>>n;

    ll arr[n+1],a[n+1];

    for(int i = 0;i<n;i++){
        cin>>arr[i+1]>>a[i+1];
    }

    for(ll i = 0;i<=h;i++){
        for(ll j = 0;j<=n;j++){
            if(i==0&&j==0){
                ans[i][j] = 0;
            }else if(i==0){
                ans[i][j] = 0;
            }else if(j==0){
                ans[i][j] = inf;
            }else{
                ans[i][j] = min(a[j] + sol(i-arr[j],j),sol(i,j-1));
            }
        }
    }

    // for(ll i = 0;i<=h;i++){
    //     for(ll j = 0;j<=n;j++)
    //         cout<<ans[i][j]<<" ";
    //     cout<<endl;
    // }
    cout<<ans[h][n];
	return 0;
}

Measured memory_bytes: 779008
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<vector>
#define mp make_pair
#define pb push_back
using namespace std;

template<class T>inline void read(T &x) {
  x = 0;
  T tmp = 1;
  char c = getchar();
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') tmp = -1, c = getchar();
  while (c >= '0' && c <= '9')
    x = (x << 1) + (x << 3) + c - '0', c = getchar();
  x *= tmp;
}

const int N = 1e7;
char s[N];
int k;

int main(void) {
  scanf("%s", s);
  scanf("%d", &k);
  int n = strlen(s);
  for (int i = 0; i < n; ++i)
    if (i % k == 0) printf("%c", s[i]);

  return 0;
}


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

flag =0
counter =0
for i in A:
    counter +=1
    if (i %2 ==1) or ((i%3)==0 or (i%5) == 0):
        pass
    else:
        flag =1

if flag== 1:
    print("DENIED")
else:
    print("APPROVED")



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

int main(){
    int n, a[101];
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        for(int j = i; j > 0; --j){
            if(a[j-1] > a[j]){
                int b = a[j];a[j]=a[j-1];a[j-1]=b;
            }
        }
        for(int j = 0; j < n-1; ++j)
            cout << a[j] << " ";
        cout << a[n-1] << endl;
    }
}


Measured memory_bytes: 3084
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    long int n,i,cnt=0,hig=0;
    cin>>n;
    long int h[n];
    for(i=0;i<n;i++)
    {
        cin>>h[i];
    }
    for(i=0;i<n-1;i++)
    {
        if(h[i]>=h[i+1])
        {
            cnt++;
            
        }
        else
        {      if(hig<cnt)
                 { hig=cnt;}
            cnt=0;
            
        }
    }
    if(hig<cnt)
      { hig=cnt;}
   cout<<hig; 
    return 0;
}


Measured memory_bytes: 1024