akhauriyash/Code-Regression huggingface dataset:
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector<std::vector<int>> graph(n);
  loop(n-1) {
    int u, v; std::cin >> u >> v;
    u--, v--;
    graph.at(u).emplace_back(v);
    graph.at(v).emplace_back(u);
  }
  debug(graph);

  int s = 0, t = n - 1;
  int r0 = -1, r1 = -1, dist = -1;
  std::vector<int> depth(n,-1);
  auto dfs = [&] (auto&& dfs, int crr) -> bool {
    bool ret = false;
    if (crr == t) {
      ret = true;
      dist = depth.at(t);
    }
    int cd = depth.at(crr);
    for (int nxt : graph.at(crr)) {
      int & nd = depth.at(nxt);
      if (nd != -1) continue;
      nd = cd + 1;
      ret |= dfs(dfs, nxt);
    }
    if (dist != -1 && ret && cd == dist / 2) r0 = crr;
    if (dist != -1 && ret && cd == dist / 2 + 1) r1 = crr;
    return ret;
  };
  depth.at(s) = 0;
  dfs(dfs, s);
  debug(depth, r0, r1);

  auto count = [&] (auto&& f, int crr, int prv) -> int {
    int ret = 1;
    for (int nxt : graph.at(crr)) {
      if (nxt == prv || (crr==r0 && nxt==r1) || (crr==r1 && nxt==r0)) continue;
      ret += f(f, nxt, crr);
    }
    return ret;
  };
  int x = count(count, r0, r0);
  int y = count(count, r1, r1);
  debug(x,y);

  bool ans = x > y;
  std::cout << (ans ? "Fennec" : "Snuke") << std::endl;
  return 0;
}

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

int main(void) {
  int n, m;
  cin >> n >> m;

  int last_yasumi=n;
  for(int i = 0; i < m; i++){
    int tmp;
    cin >> tmp;
    last_yasumi -= tmp;
  }

  if(last_yasumi<0){
    cout << -1 << endl;
  } else {
    cout << last_yasumi << endl;
  }
}


Measured memory_bytes: 3628
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;

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

    if(x>=30){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;

}


Measured memory_bytes: 3620
N, M = map(int, input().split())
l=[list(map(int, input().split())) for _ in range(M)]

max_L, min_R = (0, N)

for r in l:
    if r[0]>max_L:
        max_L = r[0]
    if r[1]<min_R:
        min_R = r[1]
if min_R >= max_L:
    print(min_R - max_L + 1)
else:
    print(0)


Measured memory_bytes: 27344
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define SUM(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}

class BMagic2 {
public:
  static void solve(istream &cin, ostream &cout) {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int ans = 0;
    while (B <= A) {
      ans++;
      B *= 2;
    }
    while (C <= B) {
      ans++;
      C *= 2;
    }
    if (ans <= K) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  BMagic2 solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 3648
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class BBuffet {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,m=-2,ans=0;
        in>>n;
        vector<int> a(n),b(n),c(n-1);
        for(auto&i:a) in>>i,--i;
        for(auto&i:b) in>>i;
        for(auto&i:c) in>>i;
        fr(i,n){
           ans+=b[a[i]];
           if(a[i]==m+1) ans+=c[m];
           m=a[i];
        }
        out<<ans<<endl;
    }
};

int main() {
    BBuffet solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end());
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
string s[11000];
signed main() {
    cin >> N;
    rep(i, N) { cin >> s[i]; }
    int AB = 0, A = 0, B = 0, a = 0, b = 0;
    rep(i, N) {
        string ss = s[i];
        if (ss[0] == 'B') { B++; }
        if (ss[ss.length() - 1] == 'A') { A++; }
        if (ss[0] != 'B' && ss[ss.length() - 1] == 'A') { a = 1; }
        if (ss[0] == 'B' && ss[ss.length() - 1] != 'A') { b = 1; }
        for (int i = 1; i < ss.length(); i++) { if (ss[i - 1] == 'A' && ss[i] == 'B') { AB++; }}
    }
    if (a == 0 && b == 0) { A--, B--; }
    cout << AB + max(0LL, min(A, B)) << endl;
}

Measured memory_bytes: 896
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

s = input().rstrip()
n = len(s)

t = s[0:(n-1)//2]
q = s[(n+2)//2:n]

if s == s[::-1] and t == t[::-1] and q == q[::-1]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9032
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
using namespace std;
typedef long long int ll;

int N;
int h[100010];
ll dp[100010];

ll INF = 1LL << 60;

void chmin(ll &a, ll b){
  if (a > b){
    a = b;
  }
}

int main(){

  cin >> N;
  
  for (int i = 0; i < N; i++){
    cin >> h[i];
  }
  
  for (int i = 0; i < 100010; i++){
    dp[i] = INF;
  }
  
  //初期条件
  dp[0] = 0;
  
  //ループ
  for (int i = 1; i < N; i++){
    chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
    if (i > 1) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
  }

  cout << dp[N-1];        
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, Y;
  cin >> N >> Y;
  Y /= 1000;
  int x = -1, y = -1, z = -1;
  for(int i = 0; i <= N; i++){
    for(int j = 0; j <= N-i; j++){
      if(10*i + 5*j + (N-i-j) == Y){
        x = i;
        y = j;
        z = N - i - j;
        break;
      }     
    }    
  }
  cout << x << ' ' << y << ' ' << z << endl;
}

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

using namespace std;

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

	int n, a = 0;
	string s;

	cin >> n >> s;

	for (int i = 0; i < n; ++i) {

		if (s[i] == ')') {
			--a;
			if (a < 0) {
				s.insert(0, "(");
				++i;
				++n;
				a = 0;
			}
		}
		else {
			++a;
		}
	}

	cout << s;
	for (int i = 0; i < a; ++i)
		cout << ")";
	cout << "\n";
	return 0;
}

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

int main()
{
	int n,m,c,num[21][21],nn,sum;
	while (cin>>n>>m>>c)
	{
		nn = 0;
		for (int j = 0; j < m; j++)
			scanf("%d", &num[0][j]);
		for (int i = 1; i <= n; i++)
		{
			sum = c;
			for (int j = 0; j < m; j++)
			{
				scanf("%d", &num[i][j]);
				sum += num[i][j] * num[0][j];
			}
			if (sum > 0)
				nn++;
		}
		cout << nn << endl;
		
	}


	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int n, q, key, i, count = 0, right, left, mid;
	int s[100000];
	cin >> n;
	for (i = 0; i < n; i++)cin >> s[i];
	cin >> q;
	for (i = 0; i < q; i++)
	{
		cin >> key;
		left = 0; right = n;
		while (left < right)
		{
			mid = (left + right) / 2;
			if (s[mid] == key)
			{
				count++;
				break;
			}
			else if (s[mid] < key)left = mid + 1;
			else right = mid;
		}
	}
	cout << count << endl;
    return 0;
}

Measured memory_bytes: 1552
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<ll>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int n;
pair<double, double> xy[10];
bool pass[8];

double calc(int a, int b)
{
    return sqrt(pow((xy[a].fi - xy[b].fi), 2) + pow((xy[a].se - xy[b].se), 2));
}

int main()
{
    cin >> n;
    rep(i, 0, n) cin >> xy[i].fi >> xy[i].se;
    vi array;
    double ans = 0;
    int cnt = 0;
    rep(i, 0, n) array.push_back(i);
    do
    {
        cnt++;
        double sum = 0;
        rep(i, 0, n - 1)
        {
            sum += calc(array[i], array[i + 1]);
        }
        ans += sum;
    } while (next_permutation(array.begin(), array.end()));
    cout << setprecision(7) << fixed << ans / cnt << endl;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(x) cout<<x<<endl

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
const ULL INF = 1e18;
const int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

//function
//--------------------------------------------
LL gcd(LL, LL);
bool isEven(LL);
void coutY();
void coutN();
LL ave(LL, LL);
bool isMultiOf(LL, LL);

int main() {
	int a, b, c; cin >> a >> b >> c;
	if (2 * b == a + c)cout<<"YES";
	else cout<<"NO";
}

LL gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}
bool isEven(LL a) {
	return !((bool)(a % 2));
}
void coutY() {
	cout << "Yes" << endl;
	return;
}
void coutN() {
	cout << "No" << endl;
	return;
}
LL ave(LL a, LL b) {
	return (a + b) / 2;
}
bool isMultiOf(LL a, LL b) {
	return a % b == 0;
}

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

#define MOD 1000000007

long long mod_inv(long long a){
  long long left = MOD-2;
  long long ks = a;
  long long ans = 1;
  while(left > 0){
    if(left%2 == 1){
      ans = ans*ks%MOD;
    }
    ks=ks*ks%MOD;
    left /= 2;
  }
  return ans;
}

long long comb(long long n, long long r){
  long long ans = 1;
  for(int i=1;i<=r;i++){
    ans = ans*(n+1-i)%MOD*mod_inv(i)%MOD;
  }
  return ans;
}

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  int s;
  cin >> s;
  long long ans = 0;
  for(int i=1;i<1000;i++){
    if(s-i*3 < 0) break;
    int left = s-i*3;
    ans += comb(i+left-1,left);
    ans %= MOD;
    //cout << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var inf = 2147483647
var dbg = false

func main() {
	sc := NewScanner()
	N, T := sc.NextInt(), sc.NextInt()
	min := inf
	for i := 0; i < N; i++ {
		c, t := sc.NextInt(), sc.NextInt()
		if t <= T && c < min {
			min = c
		}
	}
	ans := "TLE"
	if min != inf {
		ans = fmt.Sprint(min)
	}
	fmt.Println(ans)
	// suppress warnings
	if dbg {
		fmt.Println(N, T)
		if false {
			_ = sc.NextToken()
		}
	}
}

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return &Scanner{sc: sc}
}

func (r *Scanner) SetBuffer(size int) {
	buf := make([]byte, size)
	r.sc.Buffer(buf, size)
}

func (r *Scanner) NextToken() string {
	r.sc.Scan()
	return r.sc.Text()
}

func (r *Scanner) NextInt64() int64 {
	n, e := strconv.ParseInt(r.NextToken(), 10, 64)
	if e != nil {
		panic(e)
	}
	return n
}

func (r *Scanner) NextInt() int {
	n, e := strconv.ParseInt(r.NextToken(), 10, 32)
	if e != nil {
		panic(e)
	}
	return int(n)
}


Measured memory_bytes: 640
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_D main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions
void get_primes(vb& prime, const int PMAX) {
    prime = vb(PMAX + 1, true);
    prime[0] = false;
    prime[1] = false;

    for(int i=2; i*i<=PMAX; i++) {
        for(int j= i*2; j <=PMAX; j+=i) {
            prime[j] = false;
        }
    }
}
#endif 

void prime_factorize(map<ll,ll>& fac, ll n, vi& pm) {
    if (pm.size()==0) {
        vb is_pm;
        get_primes(is_pm, n + 1);

        REP(i,n+1) {
            if (is_pm[i]) pm.push_back(i);
        }
    }

    for(int p : pm) {
        while(n > 0) {
            if (n%p == 0){
                fac[p]++;
                n /= p;
            } else {
                break;
            }
        }
    }
}

vi e;
int ans;
void dfs(int n, ll res) {
    if (n >= e.size()) {
        if (res == 75) ans++;
        return;
    }

    if (res > 75) return;
    
    REP(i, e[n]+1) {
        dfs(n + 1, res*(i + 1));
    }
}

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

    int N; cin >> N;

    vb is_pm;
    get_primes(is_pm, N + 1);
    vi pm;
    REP(i,N+1) {
        if (is_pm[i]) pm.push_back(i);
    }

    map<ll, ll> mp;
    FOR(i,2,N+1){
        prime_factorize(mp, i, pm);
    }

    for(auto p : mp) {
        e.push_back(p.second);
    }

    ans = 0;
    dfs(0, 1);
    
    cout << ans << endl;
    e.clear();


    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <tuple>
#include <cassert>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
using namespace std;
template <class T> inline void setmax(T & a, T const & b) { a = max(a, b); }
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

constexpr int inf = 1e9+7;
int main() {
    int n, e, t; scanf("%d%d%d", &n, &e, &t); -- t;
    vector<bool> w(n); repeat (i, n) { int w_i; scanf("%d", &w_i); w[i] = w_i; }
    vector<int> goal(e), cnt(e);
    vector<vector<int> > src(e);
    vector<vector<int> > use(n);
    repeat (i, e) {
        scanf("%d%d", &goal[i], &cnt[i]); -- goal[i];
        src[i].resize(cnt[i]); repeat (j, cnt[i]) { scanf("%d", &src[i][j]); -- src[i][j]; }
        for (int s : src[i]) use[s].push_back(i);
    }
    vector<int> cost(n, inf);
    reversed_priority_queue<pair<int, int> > que;
    repeat (i, n) if (w[i]) {
        que.emplace(1, i);
    }
    auto use_law = [&](int j) {
        vector<int> costs(src[j].size());
        repeat (k, src[j].size()) {
            costs[k] = cost[src[j][k]];
        }
        whole(sort, costs);
        whole(reverse, costs);
        int cost_i = 0;
        repeat (k, costs.size()) {
            setmax(cost_i, costs[k] + k);
        }
        int i = goal[j];
        if (cost_i < cost[i]) {
            que.emplace(cost_i, i);
        }
    };
    while (not que.empty()) {
        int cost_i, i; tie(cost_i, i) = que.top(); que.pop();
        if (cost[i] <= cost_i) continue;
        assert (cost[i] == inf);
        cost[i] = cost_i;
        for (int j : use[i]) {
            cnt[j] -= 1;
            if (cnt[j] == 0) {
                use_law(j);
            }
        }
    }
    int result = cost[t];
    if (result == inf) result = -1;
    printf("%d\n", result);
    return 0;
}

Measured memory_bytes: 2884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main()
{
    ll N, K; cin >> N >> K;
    vector<int> A(N), F(N); cin >> A >> F;
    sort(A.begin(), A.end(), greater<int>());
    sort(F.begin(), F.end());
    vector<ll> AxF(N); for (int i = 0; i < N; i++) AxF[i] = (ll)A[i] * F[i];

    ll l = -1, r = (ll)A.front() * F.back(), c, k;
    while (r - l > 1) {
        c = l + (r - l) / 2;
        k = K;
        for (int i = 0; i < N; i++) {
            ll d = AxF[i] - c;
            if (d > 0) {
                k -= (d + F[i] -1) / F[i];
                if (k < 0) break;
            }
        }
        if (k >= 0) {
            r = c;
        } else {
            l = c;
        }
    }

    cout << r << endl;
}


Measured memory_bytes: 3328
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx")
#pragma region header
#include <bits/stdc++.h>
#define all(a) begin(a), end(a)
#define rep1(i, n) for (decltype(+n) i = 0; i < (n); i++)
#define rrep1(i, n) for (auto i = n - 1; i > static_cast<decltype(i)>(-1); i--)
#define rep2(i, a, b) for (auto i = (a); i < (b); i++)
#define rrep2(i, a, b) for (auto i = b - 1; i >= a; i--)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep2, rep1) (__VA_ARGS__)
#define rrep(...) GET_MACRO(__VA_ARGS__, rrep2, rrep1) (__VA_ARGS__)
#define each(i, a) for (auto &&i : (a))
using namespace std;

using vi = vector<int>;

template <class T>
void COUT(const T &x) { cout << x << endl; }

constexpr int lshift(const int &x) noexcept { return 1ll << x; }

#pragma endregion header

void solve(int N, vi a, vi b) {
  int ans = 0;
  vi t(29, 1), u(29);
  rep(i, 28) t[i + 1] = t[i] << 1;
  rep(i, 29) u[i] = t[i] * 2 - 1;
  rrep(k, 29) {
    each(x, a) x &= u[k];
    each(x, b) x &= u[k];
    sort(all(b));
    bool odd = false;
    int t1 = t[k], t2 = t[k] * 2, t3 = t[k] * 3, t4 = t[k] * 4;
    each(x, a) odd ^= ((lower_bound(all(b), t4 - x) - lower_bound(all(b), t3 - x)) ^ (lower_bound(all(b), t2 - x) - lower_bound(all(b), t1 - x))) & 1;
    if(odd) ans += lshift(k);
  }
  COUT(ans);
}


#pragma region main
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);

  int N;
  cin >> N;
  vi a(N);
  for(int i = 0 ; i < N ; i++){
    cin >> a[i];
  }
  vi b(N);
  for(int i = 0 ; i < N ; i++){
    cin >> b[i];
  }
  solve(N, move(a), move(b));
}
#pragma endregion main


Measured memory_bytes: 4792
#include<set>
#include<map>
#include<cmath>
#include<queue>
#include<bitset>
#include<string>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cstdlib>
#include<cstring>
#include<sstream>
#include<iostream>
#include<algorithm>

#define For(i,x,y) for (int i=x;i<y;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define lf else if

#define dprintf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> Vi;

int IN(){
	int c,f,x;
	while (!isdigit(c=getchar())&&c!='-');c=='-'?(f=1,x=0):(f=0,x=c-'0');
	while (isdigit(c=getchar())) x=(x<<1)+(x<<3)+c-'0';return !f?x:-x;
}

char s[5];

bool check(ll x){
	printf("? %lld\n",x);
	fflush(stdout);
	scanf("%s",s);
	return s[0]=='Y';
}
void Work(ll l,ll r){
	ll res;
	while (l<=r){
		ll mid=(l+r)/2;
		if (check(mid*10)) res=mid,r=mid-1;else l=mid+1;
	}
	printf("! %lld\n",res);
	fflush(stdout);
	exit(0);
}

int main(){
	for (ll i=10;i<=ll(1e11);i*=10)
		if (!check(i)){
			Work(i/10,i-1);
		}
	for (ll i=9,j=1;;i=i*10+9,j*=10)
		if (check(i)){
			printf("! %lld\n",j);
			fflush(stdout);
			return 0;
		}
}

Measured memory_bytes: 596
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def _I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def pf(s): return print(s, flush=True, end=" ")

N=_I()
A=LI()


for i in range(1,N+1,2):
	pf(A[-i])
if N%2==0:
    for i in range(0,N,2):
	    pf(A[i])
else:
	for i in range(1,N,2):
		pf(A[i])
	


Measured memory_bytes: 29028
def find(x):
    while G[x][0]!=x:
        x = G[x][0]
    return x
def union(x,y):
    xa = find(x)
    ya = find(y)
    if G[xa][1]>=G[ya][1]:
        G[ya][0] = xa
        G[xa][1] = max(G[xa][1],G[ya][1]+1)
    else:
        G[xa][0] = ya
        G[ya][1] = max(G[ya][1],G[xa][1]+1)
N,M = map(int,input().split())
G = {i:[i,0] for i in range(1,N+1)}
for _ in range(M):
    x,y,z = map(int,input().split())
    union(x,y)
hist = [0 for _ in range(N+1)]
for i in range(1,N+1):
    x = find(i)
    hist[x] = 1
print(sum(hist))

Measured memory_bytes: 74980
n, m = map(int, input().split())
py = []
for i in range(m):
	a = list(map(int, input().split()))
	py.append([a[0], a[1], i])
py.sort()

num = []
ken = py[0][0]
x = 0
for i in range(m):
	if py[i][0] == ken:
		x += 1
		spl = ['0' for i in range(6-len(str(py[i][0])))]
		sxl = ['0' for i in range(6-len(str(x)))]
		sp = ''.join(spl)
		sx = ''.join(sxl)
		s = sp+str(py[i][0])+sx+str(x)
		num.append([py[i][2], s])
	else:
		ken = py[i][0]
		x = 1
		spl = ['0' for i in range(6-len(str(py[i][0])))]
		sxl = ['0' for i in range(6-len(str(x)))]
		sp = ''.join(spl)
		sx = ''.join(sxl)
		s = sp+str(py[i][0])+sx+str(x)
		num.append([py[i][2], s])
num.sort()
for i in range(m):
	print(num[i][1])

Measured memory_bytes: 41416
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
using ll =long long;
#define PI 3.14159265358979
using P = pair<ll , ll>;
//using map = map<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;

int main(){
    ll a;
    cin >> a;
    cout << a*a*a + a*a + a << endl;

    return 0;
}

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

int main(){
 string s;
  int n;
  n=s.size();
int p=0;
  cin>>n;

 cin>>s;
  
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
  if(s.at(i)==s.at(j)){
  p+=1;
    break;
  }
      else{
      break;
      }
    }
  }
  cout<<n-p<<endl;
 }
  

Measured memory_bytes: 512
# coding: utf-8
n,u,v,m=map(int,input().split())
usa=[list(map(int,input().split())) for i in range(n)]
neko=[list(map(int,input().split())) for i in range(n)]
usadic={}
nekodic={}
usatable=[0 for i in range(2*n+2)]
nekotable=[0 for i in range(2*n+2)]
for i in range(n):
    for j in range(n):
        usadic[usa[i][j]]=[]
        nekodic[neko[i][j]]=[]
        usadic[usa[i][j]].append(i)
        nekodic[neko[i][j]].append(i)
        usadic[usa[i][j]].append(n+j)
        nekodic[neko[i][j]].append(n+j)
        if i==j:
            usadic[usa[i][j]].append(2*n)
            nekodic[neko[i][j]].append(2*n)
        if i+j==n-1:
            usadic[usa[i][j]].append(2*n+1)
            nekodic[neko[i][j]].append(2*n+1)
usacount=0
nekocount=0
for i in range(m):
    t=int(input())
    if t in usadic:
        for x in usadic[t]:
            usatable[x]+=1
            if usatable[x]==n:
                usacount+=1
    if t in nekodic:
        for x in nekodic[t]:
            nekotable[x]+=1
            if nekotable[x]==n:
                nekocount+=1
    if n==1:
        usacount=min(usacount,1)
        nekocount=min(nekocount,1)
    if usacount>=u and nekocount>=v:
        print('DRAW')
        break
    elif usacount>=u:
        print('USAGI')
        break
    elif nekocount>=v:
        print('NEKO')
        break
else:
    print('DRAW')




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

int main(){
  int n;
  cin>>n;
  int ans=0;
  for(int cn=1;cn<=n;cn+=2){
    int cnt=0;
    for(int i=1;i<=cn;i++){
      if(cn%i)continue;
      cnt++;
    }
    if(cnt==8)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
int dp[3][1001][1001];
map<char,int>latte;
int main(){
    latte['J']=0;latte['O']=1;latte['I']=2;
    int n,m,x;
    cin>>n>>m>>x;
    for(int i=1;i<=n;i++){
        string str;
        cin>>str;
        for(int j=1;j<=m;j++){
            int idx=latte[str[j-1]];
            for(int k=0;k<3;k++){
                dp[k][i][j]=dp[k][i-1][j]+dp[k][i][j-1]-dp[k][i-1][j-1];
                if(idx==k)dp[k][i][j]++;
            }
        }
    }

    while(x--){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        for(int i=0;i<3;i++){
            if(i!=0)cout<<" ";

            int ans=dp[i][c][d]-dp[i][a-1][d]-dp[i][c][b-1]+dp[i][a-1][b-1];
            cout<<ans;
        }
        cout<<endl;
    }
    /*
    for(int k=0;k<3;k++){
        cout<<endl;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                cout<<dp[k][i][j]<<" ";
            }
            cout<<endl;
        }
    }*/
    return 0;
}

Measured memory_bytes: 12912
#include <bits/stdc++.h>
#define N 200005
using namespace std;
int a[N],len,n;
bool f[N];
bool check(int x){
	for(int i=1;i<=len;++i) f[i]=a[i]>=x;
	for(int i=0;i<n-1;++i){
		if((f[n+i]&&f[n+i+1])||(f[n-i]&&f[n-i-1])) return 1;
		else if((!f[n+i]&&!f[n+i+1])||(!f[n-i]&&!f[n-i-1])) return 0;
	}
	return f[1];
}
int main(){
	int l=1,r,i,ans;
	scanf("%d",&n);r=len=2*n-1;
	for(i=1;i<=len;++i) scanf("%d",&a[i]);
	while(l<=r){
		int mid=l+r>>1;
		if(check(mid)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	cout<<ans;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
 int n;
 cin>>n;
 vector<double> p(n);
 for(int i=0;i<n;i++) cin>>p[i];
 vector<vector<double>> dp(n+1,vector<double>(n+1));
 dp[n][0]=1;
 for(int i=n-1;i>=0;i--){
  for(int j=0;j<=n;j++){
   if(j>=1) dp[i][j]=(1-p[i])*dp[i+1][j]+p[i]*dp[i+1][j-1];
   else dp[i][j]=(1-p[i])*dp[i+1][j];
  }
 }
 double res=0;
 for(int i=(n+1)/2;i<=n;i++){
  res+=dp[0][i];
 }
 cout.precision(12);
 cout<<fixed;
 cout<<res<<endl;
 return 0;
}

Measured memory_bytes: 70784
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using uint1024_t = mp::uint1024_t;
using namespace std;


int main() {
	int D, G;
	cin >> D >> G;
	vector<pair<int ,int>>a(D);
	rep(i, D) {
		int p, c;
		cin >> p >> c;
		a[i].first = p;
		a[i].second = (i + 1) * 100 * p + c;
	}
	int ans = 1e9;
	int i = 0;
	while (i < pow(2, D)) {
		int sum = 0;
		int count = 0;
		rep(j, D) {
			if (i&(1LL << j)) {
				sum += a[j].S;
				count += a[j].F;
			}
		}
		bool flag = true;
		bool flag2 = false;
		int tmpc = 0;
		if (sum < G) {
			int rest = G - sum;
			for (int j = D - 1; j >= 0; j--) {
				if (!(i&(1LL << j)) && flag) {
					flag = false;
					while (rest > 0) {
						rest -= (j + 1) * 100;
						tmpc++;
					}
					if (tmpc < a[j].F) {
						flag2 = true;
					}
				}
			}
			if (flag2) {
				count += tmpc;
			}
		
		}
		else {
			flag2 = true;
		}
		if (flag2) {
			ans = min(ans, count);
		}
		i++;
	}
	cout << ans << endl;
}


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

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

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

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


int main()
{
    int h,w;
    cin>>h>>w;
    vector<string> a(h);
    bool wskip[100],hskip[100];
    
    for(int i = 0; i < 100; i++)
    {
        wskip[i]=true;
        hskip[i]=true;
    }
    
    for(int i = 0; i < h; i++)
    {
        cin>>a[i];
    }
    
    
    for(int hh = 0; hh < h; hh++)
    {
        for(int ww = 0; ww < w; ww++)
        {
            if(a[hh][ww]=='#')
            {
                hskip[hh]=false;
                break;
            }
        }
    }
    
    for(int ww = 0; ww < w; ww++)
    {
        
        for(int hh = 0; hh < h; hh++)
        {
            if(a[hh][ww]=='#')
            {
                wskip[ww]=false;
                break;
            }
        }        
    }
    
    
    for(int hh = 0; hh < h; hh++)
    {
        if(hskip[hh]==false)
        {
            
            for(int ww = 0; ww < w; ww++)
            {
                if(wskip[ww]==false)
                {
                    cout<<a[hh][ww];
                }
            }
            cout<<endl;
        }
        
    }
    

    return 0;
}

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

int main() {
int x;
cin >> x;
vector<int> ok(100000);
for(long long i=0;i<100000;i++){
    ok[i]=0;
}
for(int i=1;i<40;i++){
    for(int p=2;p<1000;p++){
        long long tmp=pow(i,p);
        if(tmp<=x){ok.push_back(tmp);}
        else break;
    }
}
sort(ok.begin(),ok.end(),greater<int>());
cout << ok[0];

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define f(a,b,c) for(int a = b, _ = c; a < _; a++)
using namespace std;
typedef long long int lli;
typedef pair<int, int> pii;
#define mp make_pair
#define pb push_back
#define pp pop_back
#define fs first
#define sc second

int main(){
  #ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
  #endif
  int n, a;
  cin >> n >> a;
  cout << n * n - a;
  return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> ans(n + 1, 0);
    for (int x = 1; x <= 100; ++x) {
        for (int y = 1; y <= 100; ++y) {
            for (int z = 1; z <= 100; ++z) {
                int val = x * x + y * y + z * z + x * y + y * z + x * z;
                if (val <= n) {
                    ans[val]++;
                }
            }
        }
    }
    for (int i = 1; i <= n; ++i) cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 3652
// Copyright 2020 yaito3014
#include <bits/stdc++.h>
using namespace std;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  cout << max(A * B, C * D) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100
#define INFTY 10000
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

int prim()
{
  int u,minv;
  int d[MAX],p[MAX],color[MAX];
  for(int i=0;i<n;i++)
    {
      d[i]=INFTY;
      p[i]=-1;
      color[i]=WHITE;
    }
  d[0]=0;
  while(1)
    {
      minv=INFTY;
      u=-1;
      for(int i=0;i<n;i++)
	{
	  if(minv>d[i]&&color[i]!=BLACK)
	    {
	      u=i;
	      minv=d[i];
	    }
	}
      if(u==-1)break;
      color[u]=BLACK;
      for(int v=0;v<n;v++)
	{
	  if(color[v]!=BLACK&& M[u][v]!=INFTY)
	    {
	      if(d[v]>M[u][v])
		{
		  d[v]=M[u][v];
		  p[v]=u;
		  color[v]=GRAY;
		}
	    }	 
	}       
    }
  int sum=0;
  for(int i=0;i<n;i++)
    {
      if(p[i]!=-1)sum+=M[i][p[i]];
    }
  return sum;
}

int main()
{
  scanf("%d",&n);
  for(int i=0;i<n;i++)
    {
      for(int j=0;j<n;j++)
	{
	  int e;
	  scanf("%d",&e);
	  M[i][j]=(e==-1)?INFTY:e;
	}
    }
  printf("%d\n",prim());
  
  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define PIE 3.14159265358979323

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;}
template <class T>
T GCD(T a, T b) {if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) { return (a * b) / GCD(a, b);}

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    int max = -INF;
    int count = 0;
    rep(i,n){
        if (chmax(max, h[i])) count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#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>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#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
typedef long long ll;
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;
}
struct edge {
    ll to,cost;
};

/*
const int COM_MAX = 500500;
long long fac[COM_MAX],finv[COM_MAX],inv[COM_MAX];
void init(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < COM_MAX; i++){
        fac[i] = fac[i-1]*i%MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD;
        finv[i] = finv[i-1]*inv[i]%MOD;
    }
}
long long COM(int n,int k){
    if(n < k || n < 0 || k < 0) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
*/

int main(){
    ll N; cin >> N;
    int a[12] = {1,6,36,216,1296,7776,46656, 9,81,729,6561, 59049};
    int m[200010]; fill(m,m+200010,MM);
    m[0] = 0;
    for (int i = 0; i < 100010; i++){
        for (int j = 0; j < 12; j++){
            if (i >= a[j] && m[i-a[j]] != MM){
                m[i] = min(m[i], m[i-a[j]] + 1);
            }
        }
    }
    cout << m[N] << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int main() {
    long long n, ans = 0;
    cin >> n;
    for (int i = 1; i < n; i++)
        ans += (n - 1) / i;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3620
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

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

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var N = cin.ReadInt;
            var works = new List<Work>();
            for(int i = 0; i < N; i++)
            {
                works.Add(new Work(){Need = cin.ReadInt, Deadline = cin.ReadInt});
            }
            works.Sort((a, b) => a.Deadline - b.Deadline);

            int time = 0;
            foreach(var work in works)
            {
                time += work.Need;
                if (time > work.Deadline)
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            Console.WriteLine("Yes");
            return;
        }
        public class Work
        {
            public int Need {get; set;}
            public int Deadline {get; set;}
        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 25636
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int a = sc.nextInt();
        if(h%a>0){
            System.out.println(h/a+1);
        } else {
            System.out.println(h/a);
        }
    }
}

Measured memory_bytes: 23124
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define i_inf int(1e9)
#define i_half_inf int(1e5)
#define ll_inf ll(1e9)*ll(1e9)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main() {
    int X;
    cin >> X;
    if (X == 3 || X == 5 || X == 7) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((LL)1e9+7) 
#define INF ((LL)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	string str;
	int N;
	cin >> str;
	N = str.size();
	map<char, int> m;
	foreach(i, str){
		++m[i];
	}
	foreach(i, m){
		if((i.second-1)*2+i.second > N){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRT(v) sort(v.begin(),v.end())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
    int n,x;
    cin >> n >> x;
    int m[110];
    REP(i,0,n){
        cin >> m[i];
        x -= m[i];
    }
    //処理
    int minm = INT_MAX;
    REP(i,0,n) minm = min(minm,m[i]);
    //出力
    cout << n+x/minm << ENT;
    return 0;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> a(H+2, vector<char>(W+2, '#'));
  for(int i = 1; i < H+1; i++) {
    for(int j = 1; j < W+1; j++) {
      cin >> a.at(i).at(j);
    }
  }

  for(int i = 0; i < H+2; i++) {
    for(int j = 0; j < W+2; j++) {
      cout << a.at(i).at(j);
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n; cin >> n;
    vector<int> l(n),r(n);
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> l[i] >> r[i];
        ans += r[i] - l[i] + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int T,s[400010],F[400010],r,in[100010],out[100010];
int ta[100010],nt[200010],to[200010];
char cl[100010];
void g(int i,int l,int r){
  if(F[i]==0)return ;
  s[i]=r-l-s[i];
  if(r-l>1){
    F[i*2  ]=1-F[i*2  ];
    F[i*2+1]=1-F[i*2+1];
  }
  F[i]=0;
}
void ud(int a,int b,int i,int l,int r){//printf("%d %d %d\n",i,l,r);
  g(i,l,r);
  if(r<=a||b<=l)return;//printf("a\n");
  if(a<=l&&r<=b){
    F[i]=1-F[i];
    g(i,l,r);
  }
  else{
    ud(a,b,i*2  ,l,(l+r)/2);
    ud(a,b,i*2+1,(l+r)/2,r);
    s[i]=s[i*2]+s[i*2+1];
  }
}
int ff[100010]={};
void f(int a){//printf("!!%d\n",a);
  int i;
  if(ff[a])return ;
  ff[a]=1;
  if(cl[a]=='G')ud(r,r+1,1,0,T);
  in[a]=r++;
  for(i=ta[a];i+1;i=nt[i])f(to[i]);
  out[a]=r;
  return ;
}
int main(){
  int n,m,i,p,a,b;
  scanf("%d %d",&n,&m);
  for(T=1;T<n;T*=2);
  for(i=0;i<=n;i++)ta[i]=-1;
  for(i=0;i<n-1;i++){
    a=i+2;
    scanf("%d",&b);
    nt[i    ]=ta[to[i+n-1]=a];
    nt[i+n-1]=ta[to[i    ]=b];
    ta[a]=i;
    ta[b]=i+n-1;
  }
  //for(i=0;i<n*2-2;i++)printf("%d\n",to[i]);
  /*for(i=1;i<=n;i++){printf("%d:",i);
    int j;
    for(j=ta[i];j+1;j=nt[j])printf("%d ",to[j]);printf("\n");
    }//*/
  for(i=0;i<n;i++)scanf(" %c",&cl[i+1]);
  f(1);
  //for(i=0;i<n;i++)printf("%d %d\n",in[i],out[i]);
  for(i=0;i<m;i++){
    scanf("%d",&p);
    ud(in[p],out[p],1,0,T);
    printf("%s\n",s[1]*2>n?"broccoli":"cauliflower");
  }
  return 0;
}
  



Measured memory_bytes: 9660