akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j); i <= (int) (k); ++i)
#define Rep(i, j, k) for(R int i = (j); i >= (int) (k); --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 100011;
const ll INF = 5e16;

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread(buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		R ll x = 0; R int f = 0; R char dd;
		for (; !isdigit(ch); dd) f ^= (ch == '-');
		for (; isdigit(ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) x = -x, putchar('-');
		if (x > 9) write(x / 10); putchar(x % 10 | 48);
	}

	inline void wrn ( ll x ) { write(x), putchar(' '); }

	inline void wln ( ll x ) { write(x), putchar('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x), wln(y); }

}

using IO::wln;
using IO::read;

namespace Cesare {
	
	ll n, k, Ans, h[N];
	
	int main() {
		n = read(), k = read();
		For ( i, 1, n ) h[i] = read();
		For ( i, 1, n ) Ans += h[i] >= k;
		return wln(Ans), 0;
	}
	
}

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);

	return Cesare :: main();
}

/*

*/






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

using namespace std;

char a[1005][1005];

int main(){
	int k, l, res = 0;
	cin >> l >> k;
	for(int i = 0; i < l; i++){
		for(int j = 0; j < k; j++){
			cin >> a[i][j];
		}
	}
	for(int i = 0; i < l; i++){
		for(int j = 0; j < k; j++){
		res = 0;
		if(a[i][j] == '#'){
			cout << '#';
			continue;
		}
	if(a[i][j + 1] == '#') res++;
	if(a[i][j - 1] == '#') res++;
	if(a[i + 1][j] == '#') res++;
	if(a[i - 1][j] == '#') res++;
	if(a[i + 1][j + 1] == '#') res++;
	if(a[i - 1][j - 1] == '#') res++;
	if(a[i + 1][j - 1] == '#') res++;
	if(a[i - 1][j + 1] == '#') res++;
		cout << res;
	}
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>

using namespace std;

int abs(int x){
    if(x > 0) return x;
    else return -x;
}

int main(){
    int n;
    scanf("%d", &n);
    int t, a;
    scanf("%d %d", &t, &a);
    int h[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &h[i]);
    }
    int mn = 1000000000;
    int ans;
    for(int i = 0; i < n; i++){
        int temp = 1000 * t - h[i] * 6;
        if(mn > abs(temp - a * 1000)){
            ans = i + 1;
            mn = abs(temp - a * 1000);
        }
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 128
n, q = map(int, input().split())
s = input()
info = [list(map(int, input().split())) for _ in range(q)]
all = s.count('AC')
ans = []
lt = [all]
rt = [all]
# for i in range(n):
#     lt.append(all - s[i:].count('AC'))
#     rt.append(all - s[:n-i].count('AC'))
for i in range(1, n):
    if s[i-1] == 'A' and s[i] == 'C':
        lt.append(lt[i-1] - 1)
    else:
        lt.append(lt[i-1])
    if s[n-i-1] == 'A' and s[n-i] == 'C':
        rt.append(rt[i-1] - 1)
    else:
        rt.append(rt[i-1])

rt.reverse()
# print(lt)
# print(rt)
# print(rt)
for l, r in info:
    ans.append(lt[l-1] + rt[r-1] - all)

for i in range(q):
    print(ans[i])

Measured memory_bytes: 36908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

int main() {
    // your code goes here
    ll n;
    bool ans=true;
    char s[50];
    cin >> s;
    n=strlen(s);
    if(n%2==1) cout << "No" << endl;
    else {
        rep(i,0,n-1){
            if(i%2==0&&s[i]!='h') ans=false;
            if(i%2==1&&s[i]!='i') ans=false;
        }
        if(ans) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    
    let answer = 1;
    
    for(let i=2; i<32; i++) {
        let pow = 1;
        let cnt = 0;
        
        while(Math.pow(i, pow) <= N) {
            let temp = Math.pow(i, pow);
            
            // console.log("cnt:" + cnt)
            // console.log("temp;" + temp)
            
            if(temp <= N && cnt > 0) {
                answer = Math.max(answer, temp)
            }
            
            pow++;
            cnt++;
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ll = long long int;
using vec = vector<ll>;
using P = pair<int,int>;
const int INF = 1e9+7;

int main() {
  int n;
  cin >> n;
  vec a(n+1), l(n+1), u(n+1), b(n+1);
  rep (i,n+1) {
    cin >> a[i];
  }

  l[n] = a[n];
  u[n] = a[n];
  for (int i = n-1; i >= 0; i--) {
    l[i] = (l[i+1] + 1) / 2 + a[i];
    u[i] = u[i+1] + a[i];
  }

  if (1 < l[0] || 1 > u[0]) {
    cout << -1 << endl;
    return 0;
  }

  ll sum = 1;
  b[0] = 1-a[0];
  for (int i = 1; i < n+1; i++) {
    b[i] = min(b[i-1]*2, u[i]) - a[i];
    if (a[i] + b[i] < l[i]) {
      cout << -1 << endl;
      return 0;
    }
    sum += a[i] + b[i];
    // cout << l[i] << " " << u[i] << " " << b[i] << endl;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 6380
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
    lint ans=1,N;
    cin >> N;
    rep(i,N) ans=(ans*(i+1))%MOD;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
#include<ios>
#include<iomanip>

using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	ll K,A,B;
	cin>>K>>A>>B;

	if(K>=(A+1)&&B-A>1)
	{  
		ll fc=K-(A-1);
		ll cnt=fc/2;
		ll c=B+(cnt-1)*(B-A);
		ll cc=fc%2;
		cout<<c+cc<<endl;
	}
	else
	{
		cout<<K+1<<endl;
	}
}

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

void dfs(vector <int> v[], vector <int> &l, int &sol, int i) {
    for (int j = 0; j < v[i].size(); j ++) {
        if (l[v[i][j]] == 0)   dfs(v, l, sol, v[i][j]);
        l[i] = max(l[i], l[v[i][j]] + 1);
        sol = max(sol, l[i]);
    }
}

int main ()
{
    int n, m;
    cin >> n >> m;
    vector <int> v[n + 1], l(n + 1, 0);
    while (m --) {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
    }
    int sol = 0;
    for (int i = 1; i <= n; i ++) {
        dfs(v, l, sol, i);
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 9472
#include <algorithm>
#include <climits>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define DEBUG(x) cerr << #x << ": " << x << "\n"

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

const int MOD = 1000000007;

long modpow(long a, int n) {
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        long h = modpow(a, n / 2);
        return h * h % MOD;
    } else {
        return a * modpow(a, n - 1) % MOD;
    }
}

long comb(int a, int b) {
    if (b > a - b) {
        return comb(a, a - b);
    }
    long m = 1, d = 1;
    REP(i, b) {
        m *= (a - i);
        d *= (b - i);
        m %= MOD;
        d %= MOD;
    }
    return m * modpow(d, MOD - 2) % MOD;
}

// main
int main() {
    int N, M;
    cin >> N >> M;
    long res = 1;
    for (int i = 2; i * i <= M; ++i) {
        if (M % i != 0) {
            continue;
        }
        int c = 0;
        while (M % i == 0) {
            ++c;
            M /= i;
        }
        res *= comb(c + N - 1, c);
        res %= MOD;
    }
    if (M != 1) {
        res *= N;
        res %= MOD;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dig(long long x){
    if(x<0){
        return 0;
    }
    int ret = 0;
    while(x>0){
        ret += (int)(x%10);
        x/=10LL;
    }
    return ret;
}
int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    
    long long n;
    string s;
    cin >> s;
    n = stol(s);
    int ans = 9*(s.length()-1);
    ans = max(ans,dig(n));
    long long p = 10LL;
    for(int i = 1; i<s.length(); i++){
        long long now = n-p;
        now -= now%(p);
        now += (p-1LL);
        ans = max(ans,dig(now));
        p*=10LL;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(){
	int N;
	while(cin >> N){
		vector<int> a(N);
		for(int i=0;i<N;i++) cin >> a[i];
		vector<int> b;
		b.push_back(0);
		for(int i=0;i<N;i++) b.push_back(a[i]);
		sort(b.begin(), b.end());
		b.erase(unique(b.begin(), b.end()), b.end());
		map<int,int> numToIdx;
		for(int i=0;i<b.size();i++) numToIdx[b[i]] = i;
		vector< pair<int,int> > check;
		check.push_back(make_pair(0,-1));
		for(int i=0;i<N;i++){
			if(a[i] > check.back().first) check.push_back(make_pair(a[i], i));
		}
		vector<int> hold(b.size(), 0);
		int end = N;
		int numEnd = b.size();
		vector<long long> res(N, 0);
		for(int i=check.size()-1;i>0;i--){
			int curIdx = check[i].second;
			for(int j=curIdx;j<end;j++) hold[numToIdx[a[j]]]++;
			int numIdx = numToIdx[check[i-1].first]+1;
			for(int j=numIdx;j<numEnd;j++){
				res[curIdx] += (long long)hold[j] * (b[j] - b[numIdx-1]);
				hold[numIdx-1] += hold[j];
			}
			end = curIdx;
			numEnd = numIdx;
		}
		for(int i=0;i<N;i++) cout << res[i] << endl;
	}
}



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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long 
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab  (int  x ) { return (x>0?x:-x); }
//
//
int main(){
	int n ; 
	cin >> n ;
	vector<double> a(n) ; 
	for(double& d : a )cin >> d; 
	double ans=0 ; 
	for(double d : a )ans += 1/d ;
	ans = 1/ans ;
	printf("%.5f",ans); 
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc060/tasks/arc073_a

#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 INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;

ll N, T, t, l, sum;
int main()
{
  sum = 0;
  cin >> N >> T >> t;

  l = 0;
  sum += T;
  REP(i, N - 1)
  {
    cin >> t;
    sum += min(T, t - l);
    l = t;
  }

  cout << sum << '\n';

  return 0;
}


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

const int MOD = 1000000007;
const int INF = 999999999;

int main(){
   string n;
   cin >> n;
   rep(i, 3){
      if(n[i] == '7'){
         cout << "Yes" << endl;
         return 0;
      }
   }
   cout << "No" << endl;
return 0;}

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

int main()
{

	ios_base::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
	ll a,b;
	cin >> a >> b;
	ll c = a*b;
	if(c%2 == 0) cout << "Even\n";
	else cout << "Odd" << endl;







	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
    int A,B,sum,mul,min;
    while(scanf("%d %d",&A,&B)!=EOF)
    {
        sum=A+B;
        min=A-B;
        mul=A*B;
        if(sum>=min)
        {
            if(sum>=mul)
                printf("%d\n",sum);
            else
                printf("%d\n",mul);
        }
        else if(sum>=mul)
        {
            if(sum>=min)
                printf("%d\n",sum);
            else
                printf("%d\n",min);
        }
        else
        {
            if(min>=mul)
                printf("%d\n",min);
            else
                printf("%d\n",mul);
        }
    }
    return 0;
}


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

int main(){
	int K, A, B;
	bool ans = false;
	cin >> K >> A >> B;
	for (int i = A; i <= B; i++){
		if(i % K == 0){
			ans = true;
			break;
		}
	}
	
	if(ans){
		cout << "OK" << endl;
	} else {
		cout << "NG" << endl;
	}
}

Measured memory_bytes: 3632
<?php
fscanf(STDIN, '%d', $N);
$A = explode(' ', trim(fgets(STDIN)));
$A = array_map('process', array_keys($A), array_values($A));
sort($A);
$z = $A[intdiv($N, 2)];
$arr = array_map(function($x) use ($z) {return abs($x - $z);}, $A);
printf('%d', array_sum($arr));

function process($x, $y) {
    return (int)$y - $x - 1;
}


Measured memory_bytes: 47604
#include<iostream>
#include<cstdlib>
#include<string>
using namespace std;
int main(){
  string a,b,c;
  double d,e,f;
  while(getline(cin,a,',')){
    d=atof(a.c_str());
    getline(cin,b,',');
    e=atof(b.c_str());
    getline(cin,c,'\n');
    f=atof(c.c_str());
    if(e/f/f>=25)
      cout<<d<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
import sys

def solve(H: int, W: int, S: "List[int]"):
    # print(S)

    hcnts = [[0]*W for _ in range(H)]
    for h in range(H):
        hcnts[h][0] = S[h][0]
        for t in range(1,W):
            hcnts[h][t] = (S[h][t]+hcnts[h][t-1])*S[h][t]
    for h in range(H):
        for t in range(W-2,-1,-1):
            hcnts[h][t] = max(hcnts[h][t],hcnts[h][t+1])*bool(hcnts[h][t])

    wcnts = [[0]*W for _ in range(H)]
    for h in range(W):
        wcnts[0][h] = S[0][h]
        for t in range(1,H):
            wcnts[t][h] = (S[t][h]+wcnts[t-1][h])*S[t][h]
    for h in range(W):
        for t in range(H-2,-1,-1):
            wcnts[t][h] = max(wcnts[t][h],wcnts[t+1][h])*bool(wcnts[t][h])
    # print(hcnts)
    # print(wcnts)
    a = [hcnts[h][w]+wcnts[h][w]-1 for h in range(H) for w in range(W)]
    print(max(a))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [[ int(_.replace(".", "1").replace("#", "0")) for _ in next(tokens)] for _ in range(H)]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 250760
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        long N = sc.nextLong();
        long X = sc.nextLong();

        _out.println((3 * (N - gcd(N, X))));
    }
    private static long gcd(long a, long b) {
        if (a < b) {
            return gcd(b, a);
        }
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 21844
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0)return 0;
		V<V<int>> a(n);
		for(int i=0;i<n;i++){
			int t;
			cin>>t;
			if(t==0)continue;
			a[i].assign(t,0);
			for(int j=0;j<t;j++)cin>>a[i][j];
			if(t)sort(all(a[i]));
		}
		int m;
		cin>>m;
		V<int> out(m);
		for(int i=0;i<m;i++)cin>>out[i];
		sort(all(out));
		int ans=-1,cnt=0;
		for(int i=0;i<n;i++){
			int num=0;
			for(int j=0;j<a[i].size();j++){
				if(a[i][j]==out[num])num++;
				if(num==m){
					ans=i+1;
					cnt++;
					break;
				}
			}
		}
		if(ans==-1||cnt>1)cout<<-1<<"\n";
		else cout<<ans<<"\n";
	}
}


Measured memory_bytes: 3228
N,M = map(int,input().split())
AB = [tuple(int(i) for i in input().split()) for j in range(N)]
AB.sort()
ans = 0
for i in range(N):
    a,b = AB[i]
    if M -b > 0:
        ans += a*b
        M -= b
    else:
        ans += M*a
        break
print(ans)

Measured memory_bytes: 16992
N, M, X = gets.chomp.split(" ").map(&:to_i)

DATA = []

N.times.map { gets.chomp }.each do |row|
  values = row.split(" ").map(&:to_i)
  DATA << {c: values.shift, a: values}
end

def hoge(arr)
  price = 0
  lern = []

  arr.each do |i|
    price += DATA[i][:c]

    M.times do |j|
      lern[j] = 0 unless lern[j]
      lern[j] += DATA[i][:a][j]
    end
  end

  {
    price: price,
    learned: lern.map{|l| X - l}.all?{|v| v <= 0}
  }
end

results = []

N.times do |j|
  (0..N-1).to_a.combination(j+1).to_a.each do |_arr|
    results << hoge(_arr)
  end
end

lern_arr = results.select{|h| h[:learned]}

puts lern_arr.count == 0 ? -1 : lern_arr.map{|h| h[:price]}.sort.first

Measured memory_bytes: 15536
#include<iostream>
using namespace std;
int main(){
    int H,W;
    int A[101][101];
    cin >> H >> W;
    
     for(int i=0;i<101;i++){
        for(int j=0;j<101;j++){
            A[i][j] = 0;
        }
    }
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> A[i][j];
        }
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            A[i][W] += A[i][j];
            A[H][j] += A[i][j];
        }
    }
    
    for(int i=0;i<H;i++){
        A[H][W] += A[i][W];
    }
    
    for(int i=0;i<H+1;i++){
        for(int j=0;j<W+1;j++){
            if(j==W){
                cout << A[i][j] << endl;
            }else{
                cout << A[i][j] << " ";
            }
        }
    }
    
    
    
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

bool isok1(ll x, vector<int> &A) {
    int K = A.size();
    for (int i = 0; i < K && x >= 2; ++i)
        x -= x % A[i];
    return x >= 2;
}

ll misearch(vector<int> &A) {
    ll ok = 1e15, ng = 1;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        (isok1(mid, A) ? ok : ng) = mid;
    }
    return ok;
}

bool isok2(ll x, vector<int> &A) {
    int K = A.size();
    for (int i = 0; i < K && x > 2; ++i)
        x -= x % A[i];
    return x <= 2;
}

ll masearch(vector<int> &A) {
    ll ok = 1, ng = 1e15;
    while (abs(ok - ng) > 1) {
        ll mid = (ok + ng) / 2;
        (isok2(mid, A) ? ok : ng) = mid;
    }
    return ok;
}

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

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

    ll mi = misearch(A);
    ll ma = masearch(A);

    if (mi > ma)
        cout << -1 << endl;
    else
        cout << mi << " " << ma << endl;

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define endl "\n"
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];

    ll ans = 0;
    rep(i, 1, n) {
        if (a[i - 1] > a[i]) {
            int diff = a[i - 1] - a[i];
            ans += diff;
            a[i] += diff;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3984
#include<iostream>
using namespace std;
int main(void)
{
	int b, f, r, v, n;
	int MUR[4][3][10];
	for (int i = 0; i < 4; i++)
		for (int j = 0; j < 3; j++)
			for (int p = 0; p < 10; p++)
				MUR[i][j][p] = 0;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> b >> f >> r >> v;
		MUR[b -1][f -1][r -1] += v;

	}
	for (int i = 0; i < 4; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			for (int p = 0; p < 10; p++)
			{
				cout << " " << MUR[i][j][p];
			}
			cout << endl;
		}
		if (i != 3)
		{


			cout << "####################" << endl;

		}

	}









	return 0;


}



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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >>D;
  
  if ( A + B > C + D) {
    cout << "Left" << endl;
  }
  else if ( A + B < C + D) {
    cout << "Right" << endl;
  }
  else  {
    cout << "Balanced" << endl;
  }
  
}


Measured memory_bytes: 256
#include <stdio.h>
//#include <string.h>

int main() {
    int n, i, x, include3 = 0;

    scanf("%d", &n);

    i = 1;

    while (1) {
        if (!include3) {
            // check num
            x = i;
            if (x % 3 == 0) {
                printf(" %d", i);
                if (++i <= n) {
                    include3 = 0;
                    continue;
                }
                else
                    break;
            }
        }
        include3 = 0;

        // include3
        if (x % 10 == 3) {
            printf(" %d", i);
            if (++i <= n) {
                include3 = 0;
                continue;
            }
            else
                break;
        }

        x /= 10;
        if (x) {
            include3 = 1;
            continue;
        }

        if (++i <= n) {
            include3 = 0;
            continue;
        }
        else
            break;
    }

    printf("\n");

    return 0;
}


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

int main(){
    size_t H, W;
    cin >> H >> W;
    auto f = [](auto h, auto w){
        auto ret = h;
        for(unsigned long i = 0; i < w; ++i){
            auto k = i * h, l = max((h / 2) * (w - i), h * ((w - i) / 2)), m = min(((h + 1) / 2) * (w - i), h * ((w - i + 1) / 2));
            ret = min(ret, max({k, l, m}) - min({k, l, m}));
        }
        return ret;
    };
    cout << (H * W % 3 ? min(f(H, W), f(W, H)) : 0) << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AGC010A
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var c = a.Count(x => x % 2 == 1);
            if(c%2 == 1)
            {
                Console.WriteLine("NO");
            }
            else
            {
                Console.WriteLine("YES");
            }
        }
    }
}


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

int main()
{
    int n;
    string s;
    cin >> n >> s;
    
    if(s.substr(0, n / 2) == s.substr(n / 2, n))
    {
        cout << "Yes" << "\n";
    } else 
    {
        cout << "No" << "\n";
    }
    return 0;
}

Measured memory_bytes: 3540
num = input().split()
num_i = [int(s) for s in num]

if((num_i[0]+num_i[1]) > (num_i[2]+num_i[3])):
    print('Left')
elif((num_i[0]+num_i[1]) == (num_i[2]+num_i[3])):
    print('Balanced')
else:
    print('Right')

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

#define ALL(a)  (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define REP(i,n) for(int i=0;i<(int)n;++i)

#define CLEAR(a) memset((a), 0, sizeof(a))

inline int toInt(string s) { int x; istringstream iss(s); iss >> x; return x; }
template<class T> inline string toString(T x) { ostringstream oss; oss <<x ; return oss.str(); }
template<class T> inline T sqr(T x) { return x * x; }

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(int argc, char *argv[]) {
  string s;
  int w;
  cin >> s >> w;
  for (int i = 0; i < SZ(s); i += w) cout << s[i];
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}
int n,m;
vector<int> v[100001];
vector<bool> al(100001,false);
vector<int> ans(1000001,0);

void dfs(int i){
    for(int j=0;j<v[i].size();j++){
        if(al[j]==false){
            ans[v[i][j]]=i;
            al[j]=true;

        }
    }

}
int main(){
cin>>n>>m;
rep(i,m){
    int a,b;
    cin>>a>>b;
    v[a].push_back(b);
    v[b].push_back(a);
}

al[1]=true;
queue<int>q;
q.push(1);

while(!q.empty()){

    int qs = q.size();



    for(int i=0;i<qs;i++){
        int miti = q.front();

        q.pop();
        for(int j=0;j<v[miti].size();j++){
            if(!al[v[miti][j]]){
                ans[v[miti][j]]=miti;
                al[v[miti][j]]=true;
                q.push(v[miti][j]);
            }
    }

    }

}

bool f= true;
for(int i=2;i<=n;i++){
    if(!al[i]){
        cout<<"No"<<endl;
        return 0;
    }
}
cout<<"Yes"<<endl;
for(int i=2;i<=n;i++){
    cout<<ans[i]<<endl;
}



    
return 0;
}


Measured memory_bytes: 13876
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <chrono>
#include <random>
#include <unordered_map>
#include <cassert>
#pragma GCC optimize("O3")
#pragma comment(linker, "STACK:36777216")
using namespace std;
using i64 = int64_t;
constexpr i64 MOD = 1e9 + 7;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
using vi = vector<i64>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ii = pair<i64, i64>;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << max({10 * a + b + c, a + 10 * b + c, a + b + 10 * c});
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		String s = n();
		String t = n();

		int sl = s.length();

		boolean ok = false;

		for (int i = 0; i < 110; i++) {
			s = s.charAt(sl - 1) + s.substring(0, sl - 1);

			if (s.equals(t)) {
				ok = true;
				break;
			}
		}

		if (ok) {
			out(Y);
		} else {
			out(N);
		}

	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static double nd() {
		return sc.nextDouble();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void out(Object obj) {
		System.out.println(obj.toString());
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static double max(double d, double e) {
		return Math.max(d, e);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static double min(double d, double e) {
		return Math.min(d, e);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}

class XY {
	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}


Measured memory_bytes: 21844
#include<stdio.h>

int main(){
	int n,i,max=0;
	int a[101]={0};
	while(scanf("%d",&n)!=EOF){
		a[n]++;
		if(a[n]>max)max=a[n];
	}
	for(i=1;i<101;i++)if(a[i]==max)printf("%d\n",i);

	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define xxx         exit(0);
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;

}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) {
    return (ll)(log(x) / log(base));
}
ll a[101],dp[100005][2]; ll n;
ll E(ll k, ll p)
{
	if(dp[k][p]!=-1) return dp[k][p];
	ll ans=0;
	rep(i,0,n){
		if(a[i]<=k){
			ans=ans || (!E(k-a[i],!p));
		}
	}
	return dp[k][p]=ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll i,j,k,l,m,h,w,val;
    	cin>>n>>k;
    	rep(i,0,n) cin>>a[i];
		repi(i,0,k) dp[i][0]=-1, dp[i][1]=-1;
		dp[0][0]=0; dp[0][1]=0;
		if(E(k,0)==1) cout<<"First";
		else cout<<"Second";
		cout<<'\n';
	}
	return 0;
}

Measured memory_bytes: 9832
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
	ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
	ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }

	ModInt inverse() const {
		signed a = x, b = MOD, u = 1, v = 0;
		while (b) {
			signed t = a / b;
			a -= t * b; std::swap(a, b);
			u -= t * v; std::swap(u, v);
		}
		if (u < 0) u += Mod;
		ModInt res; res.x = (unsigned)u;
		return res;
	}
};
typedef ModInt<998244353> mint;
mint modpow(ll _a, ll n) {
	mint r=1,a=_a;
	while(n){
		r*=((n%2)?a:1);
		a*=a;
		n>>=1;
	}
	return r;
}


ll n,s,a[3010],ans=0;
mint dp[3010][6010][3];

int main(void){
	cin>>n>>s;
	reg(i,1,n)cin>>a[i];
	dp[0][0][0]=1;
	reg(i,1,n){
		dp[i][0][0] += dp[i-1][0][0];  // 現状維持
		dp[i][0][1] += dp[i-1][0][0];
		dp[i][a[i]][1] += dp[i-1][0][0];
		dp[i][0][2] += dp[i-1][0][0];
		dp[i][a[i]][2] += dp[i-1][0][0];
		rep(j,s+1){
			dp[i][j][1] += dp[i-1][j][1];  // 現状維持
			dp[i][j+a[i]][1] += dp[i-1][j][1];
			dp[i][j][2] += dp[i-1][j][1];
			dp[i][j+a[i]][2] += dp[i-1][j][1];
			dp[i][j][2] += dp[i-1][j][2];  // 現状維持
		}
	}
	// reg(i,1,n){
	// 	rep(j,s+1)cerr<<dp[i][j][0]<<" ";
	// 	cerr<<endl;
	// }
	// cerr<<"-"<<endl;
	// reg(i,1,n){
	// 	rep(j,s+1)cerr<<dp[i][j][1]<<" ";
	// 	cerr<<endl;
	// }
	// cerr<<"-"<<endl;
	// reg(i,1,n){
	// 	rep(j,s+1)cerr<<dp[i][j][2]<<" ";
	// 	cerr<<endl;
	// }
	cout<<dp[n][s][2].get()<<endl;
	return 0;
}

Measured memory_bytes: 212352
/* Headers */
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>
#include <cctype>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define FOR(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
#define ROF(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
#define FORL(i,a,b,c) for(long long i=(a);i<=(b);i+=(c))
#define ROFL(i,a,b,c) for(long long i=(a);i>=(b);i-=(c))
#define FORR(i,a,b,c) for(register int i=(a);i<=(b);i+=(c))
#define ROFR(i,a,b,c) for(register int i=(a);i>=(b);i-=(c))
#define RevEdge(x) x^1
#define lowbit(x) x&(-x)
#define LeftChild(x) x<<1
#define RightChild(x) (x<<1)+1
#define CLOSE_IN() fclose(stdin);
#define CLOSE_OUT() fclose(stdout);
#define FILE_IN(x) freopen(x,"r",stdin);
#define FILE_OUT(x) freopen(x,"w",stdout);
#define IOS(x) std::ios::sync_with_stdio(x)
#define Dividing() printf("-----------------------------------\n");
namespace FastIO {
#define gc() (iS == iT ? (iT = (iS = ibuff) + fread(ibuff, 1, SIZ, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
    const int SIZ = 1 << 21 | 1;
    char* iS, * iT, ibuff[SIZ], obuff[SIZ], * oS = obuff, * oT = oS + SIZ - 1, fu[110], cc;
    int fr;
    inline void out() {
        fwrite(obuff, 1, oS - obuff, stdout);
        oS = obuff;
    }
    template<class Type>
    inline void read(Type& x) {
        x = 0;
        Type y = 1;
        for (cc = gc(); (cc > '9' || cc < '0') && cc != '-'; cc = gc());
        cc == '-' ? y = -1 : x = (cc & 15);
        for (cc = gc(); cc >= '0' && cc <= '9'; cc = gc())
            x = x * 10 + (cc & 15);
        x *= y;
    }
    template<class Type>
    inline void print(Type x, char text = '\n') {
        if (x < 0)
            * oS++ = '-', x *= -1;
        if (x == 0)
            * oS++ = '0';
        while (x)
            fu[++fr] = x % 10 + '0', x /= 10;
        while (fr);
            * oS++ = fu[fr--];
        * oS++ = text;
        out();
    }
    inline void prints(char x[], char text = '\n') {
        for (register int i = 0; x[i]; ++i)
            * oS++ = x[i];
        * oS++ = text;
        out();
    }
}
using namespace FastIO;
template<typename T>
inline T max(T a, T b) {return (a > b) ? a : b;}
template<typename T>
inline T min(T a, T b) {return (a > b) ? b : a;}
/* definitions */
const int MAXN = 1e5 + 10;
std::vector<int> G[MAXN], ans;
std::stack<int> k;
int n, m;
bool visited[MAXN];
/* functions */
inline void dfs(int u, int vis) {
    visited[u] = true;
    (!vis) ? k.push(u) : ans.push_back(u);
    for(auto v : G[u]) {
        if(visited[v]) continue;
        dfs(v, vis); break;
    }
}
int main(int argc, char *argv[]) {
    /*FILE_IN("data.in");*/ read(n); read(m);
    while(m --> 0) {
        int u, v; read(u); read(v);
        G[u].push_back(v);
        G[v].push_back(u);
    } dfs(1, 0);
    while(true) {
        int u = k.top(); k.pop();
        if(k.empty()) break; ans.push_back(u);
    } dfs(1, 1); printf("%d\n", int(ans.size()));
    for(auto i : ans) printf("%d ", i);
    return 0;
}


Measured memory_bytes: 15244
#!/usr/bin/env python3
n = int(input())
a = n
for i in range(n + 1):
    j = n - i
    c = 0
    while i > 0:
        c += i % 6
        i //= 6
    while j > 0:
        c += j % 9
        j //= 9
    a = min(a, c)
print(a)

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

#define rep(i, n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i, s, n) for(long long i=(s);i<(long long)(n);i++)
#define repi(i, n) for(int i=0;i<(int)(n);i++)
#define rep2i(i, s, n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(), v.end()

using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

const ll INF = (1LL<<60);
const int INFi = (1<<29);

int main(){

    ll n, d; cin >> n >> d;
    vvll x(n, vll(d));
    rep(i, n){
        rep(j, d){
            cin >> x[i][j];
        }
    }

    ll ans = 0;
    rep(i, n-1){
        rep2(j, i+1, n){
            ld sum = 0.0;
            rep(k, d){
                sum += pow(x[i][k]-x[j][k], 2); 
            }
            ld dist = sqrt(sum);
            if(floor(dist)==ceil(dist)){
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

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

    vector<vector<ll>> cnt(10,vector<ll>(10,0));
    for(int i = 1; i <= n; i++){
        string nat = to_string(i);
        int f = nat[0]-'0';
        int r = nat[nat.size()-1]-'0';
        cnt[f][r]++;
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        string nat = to_string(i);
        int r = nat[0]-'0';
        int f = nat[nat.size()-1]-'0';
        if(f != 0){
            ans += cnt[f][r];
        }
    }
    cout << ans << endl;
    return 0;

}


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

using namespace std;

int main(){
	int e,m;
	while(cin >> e,e){
		m = 1000000;
		for(int z = 0;pow(z,3) <= e;z++){
			int y = sqrt(e - pow(z,3));
			int x = e - pow(y,2) - pow(z,3);
			m = min(m,x + y + z);
			//cout << x << ":" << y << ":" << z << " " << (x+y+z) << endl;
		}
		cout << m << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
#define int ll
#define ll long long
using namespace std;
const int N=55;
const int mod=1e9+7;
struct st{
	ll dp[N][N];
};
int n;ll k,sum;
st f;
st add(st a,st b)
{
	st res;
	for(int k=0;k<n;k++)
	{
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				res.dp[i][j]+=a.dp[i][k]*b.dp[k][j]%mod;
				res.dp[i][j]%=mod;
			}
		}
	}
	return res;
}
st kissme(ll x)
{
//	cout<<x<<endl;
	st res;
	if(x==1)return f;
	if(x%2==1)
	{
		res=kissme(x/2);
		res=add(res,res);
		res=add(res,f);
	}
	else
	{
		res=kissme(x/2);
		res=add(res,res);
	}
	return res;
}
st ans;
signed main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			cin>>f.dp[i][j];
		}
	}
	ans=kissme(k);
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			sum+=ans.dp[i][j];
//			cout<<ans.dp[i][j]<<' ';
			sum%=mod;
		}
//		cout<<endl;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 9984
//
//  main.cpp
//  A
//
//  Created by Sultan.
//  Copyright © 2017 Sultan. All rights reserved.
//
//  CF Handle : 2017_Scayre_TBIL_777
//
//  ARSEN TOKSYN ZVER UUUU!!!!
//

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define ll long long
#define ull unsigned ll
#define ioi exit(0);

#define f first
#define s second

#define inf 1e9 + 7;

#define NFS ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define lb(x) lower_bound(x)
#define ub(x) upper_bound(x)

#define pb(x) push_back(x)
#define ppb(x) pop_back(x)

#define endl "\n"

#define in(x) insert(x)

#define rep(x,y,z) for(int x=y;x<=z;x++)
#define per(x,y,z) for(int x=y;x>=z;x--)

#define all(x) x.begin(),x.end()

using namespace std;

ll n,l;

ll a[200500],b[200500];

map <ll,ll> m;

int main(){
    
    NFS
    
    cin >> n;
    
    for(int i=1;i<=n;i++){
        cin >> a[i];
        m[a[i]]++;
    }
    
    cin >> l;
    
    for(int i=1;i<=l;i++){
        bool ok=0;
        cin >> b[i];
        if(m[b[i]]>0){
            ok=1;
            m[b[i]]--;
        }
        if(ok==0){
            cout << "NO" << endl;
            ioi
        }
    }
    
    cout << "YES" << endl;
    
    ioi
}


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

int main(){
  int p, q, r;
  cin >> p >> q >> r;
  int res = 9999;
  res = min(res, p + q);
  res = min(res, p + r);
  res = min(res, q + r);
  cout << res << endl;
  return 0;
}

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

template<typename T>
using reversed_priority_queue = \
    std::priority_queue<T, std::vector<T>, std::greater<T> >;

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef pair<ll, ll> PLL;

signed main() {
    ll N;
    cin>>N;
    vector<ll> a(3*N);
    rep(i,0,3*N){
        cin>>a[i];
    }

    // maxv[i]: [0 i]の間で最大N個の合計値
    vector<ll> maxv(3*N,0);
    {
        ll s = 0;
        reversed_priority_queue<ll> q;
        rep(i,0,N){
            s += a[i];
            q.push(a[i]);
        }
        maxv[N-1] = s;
        rep(k,N,3*N){
            if (a[k] > q.top()) {
                s -= q.top();
                s += a[k];
                q.pop();
                q.push(a[k]);
            }
            maxv[k] = s;
        }
    }

    // minv[i]: [0 i]の間で最大N個の最小値
    vector<ll> minv(3*N,0);
    {
        ll s = 0;
        priority_queue<ll> q;
        rep(i,2*N,3*N){
            s += a[i];
            q.push(a[i]);
        }
        minv[2*N] = s;
        for (ll k=2*N-1; k>=0; k--) {
            if (a[k] < q.top()) {
                s -= q.top();
                s += a[k];
                q.pop();
                q.push(a[k]);
            }
            minv[k] = s;
        }
    }

    ll ans = -10e15;
    rep(k,N,2*N+1){ // [0 k)が前半、[k 3N)が後半
        // printf("maxv[%d]=%d minv[%d]=%d\n",k-1,maxv[k-1],k,minv[k]);
        ans = max(ans, maxv[k-1] - minv[k]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9068
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

ll ctDigits(ll n)
{
    ll ans=0;
    while(n!=0)
    {
        ans++;
        n/=10;
    }
    return ans;
}

int main()
{
    ll n,i,j;
    cin>>n;


    ll ans = INF;
    for(i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            ll x = n/i;
            ll y = n/i;
            ans = min(ans, max(ctDigits(x) , ctDigits(y)));
        }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <math.h>


using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;
	
	int K = 0;

	if (A > B){
		K = A;
	}
	else{
		K = B;
	}

		for (int i = K; i >= 0; i--) {
			if (abs(A - i) == abs(B - i)){
				cout << i << endl;
				//system("pause");
				return 0;
			}
		}

	cout << "IMPOSSIBLE"<< endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256