akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> make_v(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto make_v(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(make_v<T>(initValue, args...))>(sz, make_v<T>(initValue, args...));
}

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);

    var(int, K);

    const int N = (1 << K);

    multiset<int, greater<int>> buf;
    rep(i, N) {
        var(int, x);
        buf.insert(x);
    }

    vector<int> slimes { *buf.begin() };
    buf.erase(buf.begin());

    while(!buf.empty()) {
        sort(all(slimes));
        repr(i, slimes.size() - 1, 0) {
            auto lessItr = buf.upper_bound(slimes[i]);
            if (lessItr == buf.end()) {
                print("No");
                return 0;
            }
            assert(*lessItr < slimes[i]);
            slimes.push_back(*lessItr);
            buf.erase(lessItr);
        }
    }

    print("Yes");
    return 0;
}


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

using namespace std;

int n,k,c;

void solve(){
    int i,j;
    string str;
    cin >> n >> k >> c;
    cin >> str;
    vector<int> l(n,0),r(n,0);
    for(i = 0;i < n;i++){
        if(str[i] == 'o'){
            if(i <= c) l[i] = 1;
            else l[i] = l[i-c-1] + 1;
        }
        else if(i == 0) l[i] = 0;
        else l[i] = l[i-1];
    }
    for(i = n-1;i >= 0;i--){
        if(str[i] == 'o'){
            if(i+c+1 >= n) r[i] = 1;
            else r[i] = r[i+c+1] + 1;
        }
        else if(i == n-1) r[i] = 0;
        else r[i] = r[i+1];
    }
    vector<int> ans;
    for(i = 0;i < n;i++){
        int s = 0;
        if(i-1 >= 0) s += l[i-1];
        if(i+1 < n) s += r[i+1];
        if(s < k && str[i] == 'o') ans.push_back(i);
    }
    for(i = 0;i < ans.size();i++){
        cout << ans[i]+1 << endl;
    }
}

int main(){
    solve();
}


Measured memory_bytes: 4216
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv,
    std.functional, std.math, std.numeric, std.range, std.stdio, std.string,
    std.random, std.typecons, std.container;

ulong MAX = 1_000_100, MOD = 1_000_000_007, INF = 1_000_000_000_000;
alias sread = () => readln.chomp();
alias lread(T = long) = () => readln.chomp.to!(T);
alias aryread(T = long) = () => readln.split.to!(T[]);
alias Pair = Tuple!(long, "a", long, "b");
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);

void main()
{
    long a, b, k;
    scan(a, b, k);
    auto takahashi = max(a - k, 0);
    auto aoki = b - max(0, k - a);
    takahashi = max(0, takahashi);
    aoki = max(0, aoki);
    writefln("%s %s", takahashi, aoki);
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}


Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
int main() {
	ll n, m, ans = 0, A[10101];
	cin >> n >> m;
	if (n == 0) {
		if (m != 100)
			cout << m << endl;
		else
			cout << 101 << endl;
	}
	else if (n == 1) {
		if (m != 100)
			cout << m * 100 << endl;
		else
			cout << 10100 << endl;
	}
	else if (n == 2) {
		if (m != 100)
			cout << m * 10000 << endl;
		else
			cout << 1010000 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>
 
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, total;
    total=0;
    cin>>n;
    while(total<n) {
        total+=1000;
    }

    cout<<total-n<<endl;

}




Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
const int N = 1e7 + 5;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,ans = 0;
	cin >> n;
	for(ll i = 1; i <= n; i++)
	{
        for(ll j = i; j <= n; j += i)
		{
            ans += j;
        }
    }
	cout << ans;
	return 0;
}

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

int d[10];



bool digits(int num){
    while(num>0){
        if(d[num%10])return false;
        num /= 10;
    }
    return true;
}


int main(){
    int n,k;
    cin >> n >> k;
    int temp;
    for(int i=0;i<k;i++){
        cin >> temp;
        d[temp]++;
    }
    for(int i=n;;i++){
        if(digits(i)){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n;
main()
{
	cin>>n;
	string s;
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		if(s=="A")cnt++;
		else cnt--;
		if(cnt<0)
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<(cnt?"NO":"YES")<<endl;
}



Measured memory_bytes: 3156
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>




using namespace std;
int main() {
	
	int a, b, c;
	bool f[200] = {};
	cin >> a >> b >> c;
	
	for (int i = 0; i < b; i++) {
		int t;
		cin >> t;
		f[t] = 1;
	}
	int r = 50000;
	int x = 0;
	for (int i = c+1; i <= a; i++) {
		if (f[i])x++; 
	}
	
	r = min(r, x);x = 0;
	for (int i = c - 1; i >= 0; i--) {
		if (f[i])x++;
	}
	r = min(r, x);
	cout << r << endl;

	return 0;
}

Measured memory_bytes: 256
import itertools
def solve():
    N = int(input())
    alphabets = ['a','b','c','d','e','f','g','h','i','j']
    lst = []
    dfs(1, N, alphabets[:N],lst, "", 0)

def dfs(depth, N, alphabets, lst, now, mx):
    if depth > N:
        lst.append(now)
        print(now)
        return
    for i in range(0,mx+1):
        next_mx = mx
        if i == mx:
            next_mx += 1
        dfs(depth+1, N, alphabets, lst, now + alphabets[i], next_mx)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 69336
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define inf 1000000000000000000
#define pii pair<ll, vector<ll>>
const double pi = acos(-1);
ll n;

int solve() {
	cin>>n;
	string s;
	cin>>s;
	int w = 0, r = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'W') w++;
		else r++;
	}
	int ans = min(w, r);
	if(ans == 0) return 0;
	int sw = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'W' && i < n - w) sw++;
	}
	return min(ans, sw);
}
int main() {
	io
	int t = 1;
	//cin>>t;
	while(t--) {
		cout<<solve()<<endl;
	}
}






Measured memory_bytes: 3736
n = int(input())

cnt = {}
mx = 0
for i in range(n):
    s = input()
    if s not in cnt:
        cnt[s] = 0
    cnt[s] += 1
    mx = max(mx, cnt[s])

ans = []
for s in cnt:
    if cnt[s] == mx:
        ans.append(s)

ans.sort()
for s in ans:print(s)

Measured memory_bytes: 95496
n, m = map(int, input().split())
ps = list(map(int, input().split()))
ls = [list(map(int, input().split())) for _ in range(m)]


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = list(range(n + 1))
        self.ranks = [0 for _ in range(n + 1)]

    def get_root(self, x):
        if self.parents[x] == x:
            return x
        self.parents[x] = self.get_root(self.parents[x])
        return self.parents[x]

    def merge(self, x, y):
        x = self.get_root(x)
        y = self.get_root(y)
        if x != y:
            if self.ranks[x] < self.ranks[y]:
                self.parents[x] = y
            else:
                self.parents[y] = x
                if self.ranks[x] == self.ranks[y]:
                    self.ranks[x] += 1


uf = UnionFind(n)
for a, b in ls:
    uf.merge(a, b)
for i in range(1, n + 1):
    uf.get_root(i)
cs = uf.parents
s0 = {c: [] for c in set(cs[1:])}
s1 = {c: [] for c in set(cs[1:])}
for i in range(1, n + 1):
    c = cs[i]
    s0[c].append(ps[i - 1])
    s1[c].append(i)

res = 0
for c in set(cs[1:]):
    res += len(set(s0[c]) & set(s1[c]))
print(res)

Measured memory_bytes: 76352
/* Sum of Number */

#include<stdio.h>

int main(void) {

/* Parameters */
char num[1001];
char c;

int  sum, i, j;

/* Loop */

while (1) {
        /* Get number */
        scanf("%s", num);

        /* If num is Zero, end this program */

        if ( num[0] == '0' ) break;

        /* skip minus char */
        i   = 0;
        sum = 0;
        if ( num[0] == '-' ) i++;

        /* sum up numbers */
        while (1) {
        if ( num[i] == '\0' ) break;
        j = num[i] - '0';
        sum = sum + j ;
        i++;
}
/* print result */
printf("%d\n", sum);
}

return 0;}

Measured memory_bytes: 536
def _print(c):
    a,b = map(int,c)
    print(s[a:b+1])
def _reverse(c):
    global s
    a,b = map(int,c)
    r = s[b-len(s):a-len(s)-1:-1]
    s = s[0:a] + r + s[b+1:]
def _replace(c):
    global s
    a,b,p = c
    a = int(a)
    b = int(b)
    s = s[0:a] + p + s[b+1:]
s = input()
n = int(input())
command = {"print":_print,"reverse":_reverse,"replace":_replace}
for i in range(n):
        c = input().split()
        command[c[0]](c[1:])

Measured memory_bytes: 7764
//minamoto
#include<bits/stdc++.h>
#define R register
#define pb push_back
#define fi first
#define se second
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
const int N=2e5+5;
typedef long long ll;
typedef pair<int,int> pi;
struct node;typedef node* ptr;
inline ll max(R ll x,R ll y){return x>y?x:y;}
struct node{
	ptr lc,rc;ll t,mx;
	inline void upd(){mx=max(lc->mx,rc->mx);}
	inline void ppd(R ll x){t+=x,mx+=x;}
	inline void pd(){if(t)lc->ppd(t),rc->ppd(t),t=0;}
}e[N<<2],*rt,*pp=e;
int n,m;vector<pi>pos[N];
void build(ptr &p,int l,int r){
	p=++pp;if(l==r)return;
	int mid=(l+r)>>1;
	build(p->lc,l,mid),build(p->rc,mid+1,r);
}
void update(ptr p,int l,int r,int ql,int qr,int v){
	if(ql<=l&&qr>=r)return p->ppd(v),void();
	int mid=(l+r)>>1;p->pd();
	if(ql<=mid)update(p->lc,l,mid,ql,qr,v);
	if(qr>mid)update(p->rc,mid+1,r,ql,qr,v);
	p->upd();
}
void change(ptr p,int l,int r,int x,ll v){
	if(l==r)return p->mx=v,void();
	int mid=(l+r)>>1;p->pd();
	x<=mid?change(p->lc,l,mid,x,v):change(p->rc,mid+1,r,x,v);
	p->upd();
}
int main(){
//	freopen("testdata.in","r",stdin);
	n=read(),m=read();
	for(R int l,r,x;m;--m)l=read(),r=read(),x=read(),pos[r].pb(pi(l,x));
	build(rt,1,n);
	fp(i,1,n){
		change(rt,1,n,i,rt->mx);
		for(vector<pi>::iterator it=pos[i].begin();it!=pos[i].end();++it)
			update(rt,1,n,it->fi,i,it->se);
	}
	printf("%lld\n",max(rt->mx,0ll));
	return 0;
}

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

using namespace std;

const int md = 1e9 + 7;
const int N = 1010;

char grid[N][N];
int dp[N][N];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> grid[i][j];
    }
  }
  dp[0][0] = 1;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (grid[i][j] == '#') continue;
      if (grid[i][j + 1] == '.') {
        dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % md;
      }
      if (grid[i + 1][j] == '.') {
        dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % md;
      }
    }
  } 
  cout << dp[h - 1][w - 1] << "\n";
  return 0;
}


Measured memory_bytes: 5248
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

A = [list(map(int, (readline().split()))) for _ in range(3)]
N = int(readline().decode())
B = [int(readline().decode().rstrip()) for _ in range(N)]

card = [[False] * 3 for _ in range(3)]

ans = "No"

for b in B:
    for r in range(3):
        for c in range(3):
            if b == A[r][c]:
                card[r][c] = True

for i in range(3):
    if card[i][0] == card[i][1] == card[i][2] == True:
        ans = "Yes"
    if card[0][i] == card[1][i] == card[2][i] == True:
        ans = "Yes"
if card[0][0] == card[1][1] == card[2][2] == True:
    ans = "Yes"
if card[0][2] == card[1][1] == card[2][0] == True:
    ans = "Yes"

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
ll l0=2, l1=1;
int n;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  while(n){
    ll l = l0+l1;
    l0 = l1;
    l1 = l;
    n--;
  }
  cout << l0 << endl;
}

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

/* #pragma */
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


/*alias*/
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define itn int

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

/* func */
int32_t GCD(int32_t a, int32_t b){return b ? GCD(b, a%b) : a;}
int64_t GCD(int64_t a, int64_t b){return b ? GCD(b, a%b) : a;}
int32_t LCM(int32_t a, int32_t b){return a * b / GCD(a, b);}
int64_t LCM(int64_t a, int64_t b){return a * b / GCD(a, b);}

/*struct*/
struct aaa {
	aaa() {
		cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);
	};
}aaaaaaa;

/* const */
constexpr int32_t INF = 1001001001;
constexpr int64_t LINF = 1001001001001001001ll;
constexpr int32_t MOD = 1e9 + 7; //10^9
constexpr int64_t EPS = 1e-9;
constexpr int32_t dx[] = { 1, 1, 0, -1, -1, -1, 0, 1 }, dy[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
//constexpr int32_t dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
//Counterclockwise from the 6o'clock direction
//Take the x-axis downward and the y-axis right


//g++ -std=c++14 -Wall --pedantic-errors -o template template.cpp
//g++ -std=c++14 -Wall --pedantic-errors template.cpp
//chcp 65001

/*global*/


//#define int int64_t
signed main()
{
    int n; cin >> n;
	vector<int> a(n);
	for(int i = 0, i_len = (int)n; i < i_len; ++i) cin >> a[i];
	vector<int> L(n,-1);
	L[0] = a[0];
	vector<int> R(n,-1);
	R[n-1] = a[n-1];	
	
	//cumGCD
	for(int l = 1; l < n; ++l){
		L[l] = GCD(L[l-1], a[l]);
	}
	for(int r = n-2; r >= 0; --r){
		R[r] = GCD(R[r+1], a[r]);
	}
	int ans = max(L[n-2], R[1]);//L[for文のrの初期値], R[lの初期値]
	//int ans{};
	for(int i = 1; i < n-1; ++i){
		int l = L[i-1];

		int r = R[i+1];

		amax(ans, GCD(l,r));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define ll long long
struct flower{
   ll h,b;
};
int main() {
    int n;
    cin>>n;
    vector<flower> v(n);
    vector<ll> dp(n);
    for(int i=0;i<n;i++)
    cin>>v[i].h;
    for(int i=0;i<n;i++)
    cin>>v[i].b;
    ll ans = v[0].b;
    dp[0] = v[0].b;
    map<ll,ll> mp;
    mp[v[0].h] = v[0].b;
    for(int i=1;i<n;i++)
    {
        dp[i] = v[i].b;
        // cout<<dp[i];
        auto it = mp.upper_bound(v[i].h);
        if(it!=mp.begin())
        {
           --it;
           dp[i]+=(*it).second;
        }
        mp[v[i].h] = dp[i];
        it = mp.upper_bound(v[i].h);
        while(it!=mp.end()&&((*it).second<=dp[i]))
        {
            auto tem = it;
            tem++;
            mp.erase(it);
            it = tem;
        }
        ans = max(ans,dp[i]);
    }
    cout<<ans;
}


Measured memory_bytes: 20224
/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/
#include<bits/stdc++.h>
#define opt std::ios_base::sync_with_stdio(false)
#define I int
#define li      int32_t
#define lli     long long
#define ulli unsigned long long

#define pn           printf("\n")
#define nl           cout<<'\n'
#define sf(N)        scanf("%lld",&N)
#define pf(N)        printf("%lld",N)
#define sf1(N1,N2)    scanf("%lld %lld",&N1,&N2)
#define pf1(N1,N2)    printf("%lld %lld",N1,N2)
#define sf2(N1,N2,N3) scanf("%lld %lld %lld",&N1,&N2,&N3)
#define pf2(N1,N2,N3) printf("%lld %lld %lld",N1,N2,N3)

#define sl          cout<<' '
#define ps          printf(" ")

#define rep(i,a,b)  for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define elif        else if
#define mset(a,b)   memset(a,b,sizeof(a))

#define pb      push_back
#define pob     pop_back
#define itr     iterator
#define sz()    size()
#define szof    sizeof
#define lb      lower_bound
#define ub      upper_bound
#define mp      make_pair
#define vlli    vector<lli>
#define plli    pair<lli,lli>
#define vplli   vector<plli >
#define F       first
#define S       second
#define Dup     erase(unique(V.begin(),V.end()),V.end())

#define bs      binary_search
#define ub      upper_bound
#define lb      lower_bound

#define ALL(V)  V.begin(),V.end()

#define MX1     100000
#define MX2     1000000
#define mod     1000000007
#define Inf     1000000000000000
using namespace std;

lli Power(lli a,lli b)
{
    lli result=1;

    while(b)
    {
        if(b%2)
        {
            result=(result*a)%mod;
        }

        b=b>>1;
        a=(a*a)%mod;
    }

 return result;
}

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("double_squares.txt","r",stdin);
    freopen("double_squares_out.txt","w",stdout);
    #endif //   */

    lli N,i;
    cin>>N;

    vlli V(N);
    rep(i,0,N)
    {
        cin>>V[i];
    }

    map<lli,lli>M;
    map<lli,lli>:: itr it;

    lli cnt=0;
    rep(i,0,N)
    {
        M[V[i]]++;
    }

    for(it=M.begin();it!=M.end();it++)
    {
        it->S=cnt++;
    }

    rep(i,0,N)
    {
        V[i]=M[V[i]];
    }

    cnt=0;
    rep(i,0,N)
    {
        if((V[i]-i)%2)
        {
            cnt++;
        }
    }

    cout<<cnt/2;




 return 0;
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main() {
    int a, b, c, d, e, f;
    int ans1 = 0, ans2 = 0;
    cin >> a >> b >> c >> d >> e >> f;
    a *= 100;
    b *= 100;
    for (int A = 0; a * A <= f; A++) {
        for (int B = 0; b * B + a * A <= f; B++) {
            for (int C = 0; a * A + b * B + c * C <= f; C++) {
                for (int D = 0; a * A + b * B + c * C + d * D <= f; D++) {
                    int suger = c * C + d * D, water = a * A + b * B;
                    if (suger > water / 100 * e)break;
                    if (ans2 * (water + suger) <= ans1 * suger) {
                        ans1 = water + suger;
                        ans2 = suger;
                    }
                }
            }
        }
    }
    cout << ans1 << " " << ans2 << endl;
}

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;

int main(){
  int n,m;
  cin >>n >>m;
  int Low = 0, High = 1e8;
  rep(i,m){
    int l,r;
    cin >>l >>r;
    Low = max(Low, l);
    High = min(High, r);
  }
  int ans = High-Low+1;
  if(ans<0) cout << 0 << endl;
  else cout << ans << endl;
  return 0;
}

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

using namespace std;

#define endl '\n'
#define ll long long

const ll mod = 1e9 + 7;
const ll maxn = 2e8 + 5;
const double pi = 3.1415926535897932384626433832795028841971693993751058209749445923078;
//iostream::sync_with_stdio(false);

int main()
{
    int n;
    cin >> n;
    ll sum = 0 ;
    for(int i = 1; i <= n; i++)
    {
        if(i % 3 != 0 && i % 5 != 0)
        {
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
#define task "tet"
using namespace std;
const ll N = 3e3 + 9;
const ll mod = 998244353;
typedef pair<ll,ll> LL;

ll dp[N][N],n,S,a[N],i,j;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n>>S;
    for (i = 1;i <= n;i++) cin>>a[i];
    dp[0][0] = 1;
    for (i = 1;i <= n;i++){
        for (j = 0;j <= S;j++){
            dp[i][j] += 2*dp[i - 1][j];
            if (j >= a[i]) dp[i][j] += dp[i - 1][j - a[i]];
            dp[i][j] %= mod;
        }
    }
    cout<<dp[n][S];
}


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

using namespace std;

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

	long long ans = min(n, m / 2);
	n -= ans;
	m -= ans * 2;
	ans += m / 4;

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


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll N = S.length();
    stack<ll> s;
    REP(i, N) {
        ll n = S[i] - '0';
        if (s.size() > 0) {
            ll m = s.top();
            if (m != n) {
                s.pop();
                continue;
            }
        }
        s.push(n);
    }
    
    cout << N - s.size() << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0; i<n; i++){
    cin >> s[i];
  }
  
  vector<long long> v(5);
  for(int i=0; i<5; i++){
    v[i] = 0;
  }
  
  for(int i=0; i<n; i++){
    if(s[i][0] == 'M'){
    v[0]++;
    }
  }
  for(int i=0; i<n; i++){
    if(s[i][0] == 'A'){
    v[1]++;
    }
  }
  for(int i=0; i<n; i++){
    if(s[i][0] == 'R'){
    v[2]++;
    }
  }
  for(int i=0; i<n; i++){
    if(s[i][0] == 'C'){
    v[3]++;
    }
  }
  for(int i=0; i<n; i++){
    if(s[i][0] == 'H'){
    v[4]++;
    }
  }
  
  long long sum = 0;
  
  sum = v[0]*v[1]*v[2] + v[0]*v[1]*v[3] + v[0]*v[1]*v[4] + v[0]*v[2]*v[3] + v[0]*v[2]*v[4] + v[0]*v[3]*v[4] + v[1]*v[2]*v[3] + v[1]*v[2]*v[4] + v[1]*v[3]*v[4] + v[2]*v[3]*v[4];
  cout << sum << endl;
	return 0;
}


Measured memory_bytes: 6144
import java.util.*;


public class Main{
    public static void main(String [] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int K=sc.nextInt();
        int []A=new int[N];
        for(int i=0;i<N;A[i++]=sc.nextInt()){}
        
        Main m=new Main();
        m.mergeSort(A, 0, N-1);
        long sum=0;
        for(int i=0;i<N-K;i++)sum=sum+A[i];
        System.out.println(sum);
    }
     public void mergeSort(int []a,int left,int right){
        if(left<right){
            int m=(left+right)/2;
            mergeSort(a, left, m);
            mergeSort(a, m+1, right);
            merging(a,left,m,right);
            
        }
        
        
    }
    private void merging(int[]a,int left,int m,int right){
        int n1=m-left+1;
        int n2=right-(m+1)+1;
        int []L=new int[n1];
        int []R=new int[n2];
        
        for(int i=0;i<n1;i++){L[i]=a[left+i];}
        for(int i=0;i<n2;i++){R[i]=a[m+1+i];}
        
        int i=0;int j=0;
        int k=left;
        while(i<n1&&j<n2){
            if(L[i]<=R[j]){
                a[k]=L[i];
                i++;
            }
            else {
                a[k]=R[j];
                j++;
            }
            k++;
        }
        
        while(i<n1){
            a[k]=L[i];
            i++;
            k++;
        }
        while(j<n2){
            a[k]=R[j];
            j++;
            k++;
        }
    }
    
}



Measured memory_bytes: 83032
import java.util.Scanner;

 class Main {
    static int total;
    static int[] costs;
    static int[] treasures;
    static int min;
    static int[][] memo;

    static int dp(int key, int treasure){

        if(treasure==total){
            min=1000;
            return 0;
        }

        if(key >= costs.length)
            return Integer.MAX_VALUE;


        if(memo[key][treasure]!=0)
            return memo[key][treasure];

        int a =dp(key+1, treasure| treasures[key]) +costs[key];

        int b=dp(key+1, treasure);
        a=(a<0)? Integer.MAX_VALUE: a;
        b=(b<0)? Integer.MAX_VALUE: b;
        memo[key][treasure]=Math.min(a, b);
        return memo[key][treasure];
    }

    public static void main(String[] args) {
        Scanner in =new Scanner(System.in);
        int n= in.nextInt();
        int m = in.nextInt();
        costs = new int[m];
        min=Integer.MAX_VALUE;
        treasures = new int[m];
        memo=new int[1001][9000];
        total=0;
        for(int i=0;i<n;i++){
            total=total | (1<<i);
        }
       //System.out.println("Total " + total);
        for(int i=0;i<m;i++){
            costs[i]=in.nextInt();
            int tres= in.nextInt();
            int t=0;
            for(int j=0;j<tres;j++){
                int k=in.nextInt();
                t|= (1 << (k-1));
            }
            treasures[i]=t;
        }
        int ans  = dp(0,0);
        if(min==Integer.MAX_VALUE) {
            int x=-1;
            System.out.println(x);
        }
        else
            System.out.println(ans);

    }
}


Measured memory_bytes: 84740
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Spandan
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ALucky7 solver = new ALucky7();
        solver.solve(1, in, out);
        out.close();
    }

    static class ALucky7 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.readInt();
            System.out.println((n % 10 == 7 || (n / 10) % 10 == 7 || (n / 100) % 10 == 7) ? "Yes" : "No");

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new RuntimeException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new RuntimeException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

    }
}



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

int main(){
  int n=0, x=0, t=0;
  cin >> n >> x >> t;
  
  if(n%x == 0) cout << (n/x)*t << endl;
  else cout << ((n/x)+1)*t << endl;
}
  
  
  

Measured memory_bytes: 3588
#include <iostream>
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
using namespace std;
typedef long long ll;
const ll LINF = 1e18;
const ll INF = 1e9;


int L[30] = {0};
int main() { 
    int N, M;
    cin >> N >> M;

    REP(i, N) {
        int K; cin >> K;
        REP(j, K) {
            int a; cin >> a;
            L[a-1]++;
        }
    }

    int ct = 0;
    REP(i, M) {
        if(L[i] == N) ct++;
    }
    cout << ct << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d",&a,&b);
    if(a<b){
        c=a;a=b;b=c;
    }
    while(1){
        c=a%b;
        if(c==0)break;
        a=b;
        b=c;
    }
    printf("%d\n",b);
    return 0;
}

Measured memory_bytes: 592
my $N = <STDIN>;

my $sum =0;
my %del;
for(my $i=$N;$i>0;$i--){
 $count = int($N /$i);
 $del{$i} = ($count*$count*$count);
 #print "i$i count$count del$del{$i}  \n";
}
for(my $i=$N;$i>0;$i--){
 #print "i$i  del$del{$i} \n";
 for(my $j=1;$j<$i;$j++){
    if($j==1){ $del{1}=$del{1} - $del{$i};next;}
    if( ($i%$j == 0) ){ $del{$j}= $del{$j} - $del{$i};}
 }
 $sum = $sum + $i*$del{$i};
 #print "i$i del$del{$i} $sum\n";
}
print "$sum";
exit;


Measured memory_bytes: 4716
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(void) {
	int h, n, a, ans = 0;
	cin >> h >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		ans += a;
	}
	if (ans >= h) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}


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

namespace _0195
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int[] shop = new int[5];
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x[0] == 0 && x[1] == 0)
                {
                    break;
                }
                shop[0] = x[0] + x[1];
                for (int i = 1; i < 5; i++)
                {
                    int[] y = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    shop[i] = y[0] + y[1];
                }
                if (shop[0] > shop[1] && shop[0] > shop[2] && shop[0] > shop[3] && shop[0] > shop[4])
                {
                    Console.WriteLine("A " + shop[0]);
                }
                else if (shop[1] > shop[2] && shop[1] > shop[3] && shop[1] > shop[4])
                {
                    Console.WriteLine("B " + shop[1]);
                }
                else if (shop[2] > shop[3] && shop[2] > shop[4])
                {
                    Console.WriteLine("C " + shop[2]);
                }
                else if (shop[3] > shop[4])
                {
                    Console.WriteLine("D " + shop[3]);
                }
                else
                {
                    Console.WriteLine("E " + shop[4]);
                }
            }
        }
    }
}

Measured memory_bytes: 9616
#include<bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
const ll mod = 1000000007;
// const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"
#define TO_STRING(VariableName) # VariableName

template <typename T>ostream &operator<<(ostream &out,const vector<T> &v) {rep(i,(int)v.size()-1)cout<<v[i]<<" ";cout<<v[(int)v.size()-1];return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const map<T1, T2> &p) {out << "(" << p.first << ", " << p.second << ")";return out;}
template <typename T1, typename T2>ostream &operator<<(ostream &out, const pair<T1, T2> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template<class T>void debag(const T &obj){cout<<obj<<endl;}

bool solve(){
  ll n,W;cin>>n>>W;
  ll max_J=2*pow(10,5);
  vector<vector<ll>>dp(n+1,vector<ll>(max_J,INF));
  dp[0][0]=0;

  rep(i,n){
    ll w,v;cin>>w>>v;
    rep(j,max_J){
      if(dp[i][j]==INF)continue;
      chmin(dp[i+1][j],dp[i][j]);
      if(j+v<max_J)chmin(dp[i+1][j+v],dp[i][j]+w);
    } 
  }
  ll ans=0;

  rep(j,max_J){
    if(dp[n][j]<=W)chmax(ans,j);
  }
  cout<<ans<<endl;
  return false;
}

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout<<fixed<<setprecision(30);
  solve();
}


Measured memory_bytes: 159872
s = input()
import itertools
a = itertools.product([0,1],repeat=len(s)-1)

ans = 0
for x in a: # x = (0,1)
  txt = s[0]
  for i,kigo in enumerate(x):
    if kigo:
      txt += "+" + s[i+1]
    else:
      txt += s[i+1]
  ans += sum(list(map(int,txt.split('+'))))

print(ans)


Measured memory_bytes: 3060
import kotlin.math.max

fun main() {
    val n = readLine()!!.toInt()
    var t = 1L
    var a = 1L
    repeat(n) {
        val (ti, ai) = readLine()!!.split(' ').map { it.toInt() }
        val i = max((t + ti - 1) / ti, (a + ai - 1) / ai)
        t = ti * i
        a = ai * i
    }
    println(t + a)
}

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

using namespace std;

typedef long long ll;

typedef double T;
typedef pair<int, ll> P;

typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<T> VT; 
typedef vector<VT> VVT;
typedef vector<P> VP;
typedef vector<VP> VVP;

const ll MOD = 1e9+7; // 998244353;
const T EPS = 1e-7;
const int INF = 1e4;

void fast_io() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

void solve_test() {
    ll n, k;
    cin >> n >> k;
    ll d = n/k;
    ll ans = d*d*d;
    if (k % 2 == 0) {
        ll c = 0;
        for (int i = k/2; i <= n; i += k)
            ++c;
        ans += c*c*c;
    }
    cout << ans << "\n";
}

int main() {
    fast_io();
    solve_test();
}


Measured memory_bytes: 256
import math

import numpy as np
import scipy as scp

# 入力の受け取り
s,t = input().split()
a,b = map(int,input().split())
u = input()

dic = {s:a,t:b}

if u == s:
    dic[s] -= 1
else:
    dic[t] -= 1

print(dic[s],dic[t])

Measured memory_bytes: 12876
n = int(input())
a = [int(i) for i in input().split()]
s = [0] * (n + 1)
for i in range(n):
    s[i + 1] = s[i] + a[i]
    
nums = dict(zip(set(s), [0] * len(set(s))))
for i in range(n + 1):
    nums[s[i]] += 1
num_sub_s = 0
for val in nums.values():
    num_sub_s += val * (val - 1) // 2
print(num_sub_s)

Measured memory_bytes: 54008
#include<bits/stdc++.h>
using namespace std;
int main()
{
   ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
   int a[9];
   for(int i=0;i<9;i++)
   {
       cin>>a[i];
   }
   int n;
   cin>>n;
   bool b[101]={};
   for(int i=0;i<n;i++)
   {
       int t;
       cin>>t;
       b[t]=1;
   }
   if((b[a[0]]==1 && b[a[1]]==1 && b[a[2]]==1)||
       (b[a[3]]==1 && b[a[4]]==1 && b[a[5]]==1)||
       (b[a[6]]==1 && b[a[7]]==1 && b[a[8]]==1)||
       (b[a[0]]==1 && b[a[3]]==1 && b[a[6]]==1)||
       (b[a[1]]==1 && b[a[4]]==1 && b[a[7]]==1)||
       (b[a[2]]==1 && b[a[5]]==1 && b[a[8]]==1)||
       (b[a[0]]==1 && b[a[4]]==1 && b[a[8]]==1)||
       (b[a[2]]==1 && b[a[4]]==1 && b[a[6]]==1))
       {
           cout<<"Yes";
       }
    else
    {
        cout<<"No";
    }
    
   return 0;
}    

Measured memory_bytes: 256
import java.util.*;


class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		Main main = new Main();
		int w = scan.nextInt();
		int n = scan.nextInt();
		
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 0; i < w; i++) {
			list.add(i + 1);
		}
		
		int a, b, index = 0;
		
		for(int i = 0; i < n; i++) {
			
			String[] str = scan.next().split(",");
			a = Integer.valueOf(str[0]);
			b = Integer.valueOf(str[1]);
			
			for(int j = 0; j < w; j++) {
				if( a-1 == j) {
					index = j;
					continue;
				}
				if( b-1 == j) {
					int temp = list.get(index);
					list.set(index, list.get(j));
					list.set(j, temp);
				}
			}
			
		}
		
		for(int i : list) {
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 17204
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	int n;
	cin>>n;
	vi ans(100001,100001);ans[0]=0;
	int arr[12] = {1,6,9,36,81,216,729,1296,6561,7776,46656,59049};
	for(int i=1;i<=100001;i++) {
		for(int j=0;j<12;j++) {
			if(i-arr[j]>=0) {
				ans[i]=min(ans[i],ans[i-arr[j]]+1);
			}
		}
	}
	cout<<ans[n];
}//sum-nsum=n*b;

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3708
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(int i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd 
/****************************/
using namespace std;
int n,k;
int a[200010],b[200010];
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>k;
	rep(i,n) cin>>a[i];
	rep(i,k)
	{
		zero(b);
		rep(j,n)
		{
			int left=max(0,j-a[j]);
			int right=min(n,j+a[j]+1);
			b[left]++;
			b[right]--;
		}
		bool all=true;
		a[0]=b[0];
		if(a[0]!=n) all=false;
		rep3(j,1,n)
		{
			b[j]+=b[j-1];
			a[j]=b[j];
			if(a[j]!=n) all=false;
		}
		if(all) break;
	}
	rep(i,n) cout<<a[i]<<endl;
	return 0;                                                                                                                                     
}

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

int main(){

    string s;
    cin >> s;

    if(s[5] == '1') cout << "TBD" << endl;
    else if(s[6] == '4' || s[6] == '3' || s[6] == '2' || s[6] == '1'){
        cout << "Heisei" << endl;
    }
    else{
        cout << "TBD" << endl;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
using namespace std;
const int M=1e5+10;
int n,k;
string s;
vector<int> a;
int main()
{
    cin>>n>>k>>s;
    int l=0,r=0;
    while(r<s.size())
    {
        while(r<s.size() && s[l]==s[r]) r++;
        a.push_back(r-l);
        //printf("%d ",r-l);
        l=r;
    }
    //puts("");
    int sum=0,ans,mark=s[0]-'0',i,j;
    for(i=0,j=0;i<(int)a.size() && j<k;i++,mark^=1)
        sum+=a[i],j+=!mark;
    //printf("%d\n",sum);
    ans=sum;
    for(;i<a.size();i++,mark^=1)
    {
        if(!mark)
        {
            sum-=a[i-k*2];
            if(i-2*k-1>=0) sum-=a[i-2*k-1];
        }
        sum+=a[i];
        ans=max(ans,sum);
    }
    printf("%d\n",ans);
    return 0;
}


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

using namespace std;

typedef long long ll;

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

	int h, w;
	cin >> h >> w;

	vector<string> v(h);
	rep(i, h) cin >> v[i];

	rep(i, w + 2) cout << "#";
	cout << endl;

	rep(i, h) cout << "#" << v[i] << "#" << endl;

	rep(i, w + 2) cout << "#";
	cout << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
    int a;
    string b;
    string c;
    cin >> a;
    cin >> b;
    cin >> c;
    int n = 0;
    string d, e, f;
    for (int i = 1; i <= a; i++)
    {
        for (int j = 0; j < i; j++)
        {
            d += b[a - j - 1];
            e += c[j];
        }
        for (int j = 0; j < i; j++)
        {
            f += d[d.length() - 1 - j];
        }
        if (e == f)
        {
            n = i;
        }
        d = "";
        e = "";
        f = "";
    }
    cout << a + a - n << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef pair<double, long long> pdl;

const long double pi = 3.141592653589793;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair
#define mod 1000000007

int A[1<<20];int n, a, b;

ll required(int h, int nblast) {
    int s = 0, e = nblast, mid;
    int minm = nblast;
    while (s <= e) {
        mid = (s+e)/2;
        if(ll(h)-mid*ll(a)-(nblast-mid)*ll(b) <= 0) {
            minm = mid;
            e = mid-1;
        } else s = mid+1;
    }
    return minm;
}

bool possible(int nblast) {

    if(ll(a)*nblast < A[n-1]) return false;

    ll sum = 0;
    for(int i = 0;i < n;i++) {
        sum += required(A[i], nblast);
    }

    if(sum <= nblast) return true;
    return false;
}

int main() {
  std::ios::sync_with_stdio(false);
  //freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);
  cin>>n>>a>>b;
  rep(i, n) cin>>A[i];
  sort(A,A+n);

  int s = 1, e = int(1e9), mid;
  int ans = e+1;

  while (s <= e) {
      mid = (s+e)/2;
      if(possible(mid)) {
          ans = mid;
          e = mid-1;
      } else s = mid+1;
  }

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


Measured memory_bytes: 640
// inputに入力データ全体が入る
function Main(input) {
	var lines = input.split("\n");
	var n = parseInt(lines[0].split(" ")[0]);
	var m = parseInt(lines[0].split(" ")[1]);

	var arr = [];
	for(var i=1;i<=m;i++){
		var a = parseInt(lines[i].split(" ")[0]);
		var b = parseInt(lines[i].split(" ")[1]);
		arr.push({a,b});
	}
	arr = arr.sort((a,b)=>{
		return a.b - b.b;
	});
	var ans = 0;
	var las = 0;
	arr.forEach(v=>{
		if(las <= v.a){
			las = v.b;
			ans++;
		}
	});
	console.log(ans);
}



//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 32804
#include <bits/stdc++.h>
using namespace std;
int counter;
void bubble_sort(vector<int> &a,int n){
    int flag=1;
    while(flag){
        flag=0;
        for(int j=n-1;j>0;j--){
            if(a.at(j)<a.at(j-1)){
                swap(a.at(j),a.at(j-1));
                flag=1;
                counter++;
            }
        }
    }
}
int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
    }
    bubble_sort(a,n);
    for(int i=0;i<n-1;i++){
        cout<<a.at(i)<<' ';
    }
    cout<<a.at(n-1)<<endl<<counter<<endl;
}


Measured memory_bytes: 3092