akhauriyash/Code-Regression huggingface dataset:
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;
int main(){
    int H, W, m;
    cin >> H >> W >> m;
    vector<int> h(m);
    vector<int> w(m);
    set<pair<int,int>> b;
    for(int i=0; i<m; i++){
        cin >> h[i] >> w[i];
        b.insert(make_pair(h[i],w[i]));
    }
    sort(h.begin(),h.end());
    sort(w.begin(),w.end());
    vector<pair<int,int>> hcount;
    vector<pair<int,int>> wcount;
    int wc=1,hc=1;
    for(int i=0; i<m-1; i++){
        if(w[i]==w[i+1]) wc++;
        else{
            wcount.push_back(make_pair(wc,w[i]));
            wc=1;
        }
        if(h[i]==h[i+1]) hc++;
        else{
            hcount.push_back(make_pair(hc,h[i]));
            hc=1;
        }
    }
    wcount.push_back(make_pair(wc,w[m-1]));
    hcount.push_back(make_pair(hc,h[m-1]));
    sort(hcount.begin(),hcount.end(),greater<pair<long long ,long long >>());
    sort(wcount.begin(),wcount.end(),greater<pair<long long ,long long >>());
    int I=hcount[0].first,max=hcount[0].first+wcount[0].first-b.count(make_pair(hcount[0].second,wcount[0].second));
    bool fin=0;
    for(auto& i:hcount){
        if(I>i.first) break;
        int J=wcount[0].first;
        for(auto& j:wcount){
            if(J>j.first) break;
            int x;
            x=i.first+j.first-b.count(make_pair(i.second,j.second));
            if(x>max){
                max=x;
                fin=1;
                break;
            }
            else if(max>x){
                fin=1;
                break;
            }
            J=j.first;
        }
        if(fin) break;
    }
    cout << max << endl;
}


Measured memory_bytes: 25992
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795


int bit_count(ll v)
{
	int ret=0;

	for(;v>0;)
	{
		ret++;
		v&=v-1;
	}

	return ret;
}


int msb(ll v)
{
	if(v==0) return -1;

	int ret=0;
	if(v & 0xFFFFFFFF00000000LL) v>>=32,ret+=32;
	if(v & 0xFFFF0000LL) v>>=16,ret+=16;
	if(v & 0xFF00) v>>=8,ret+=8;
	if(v & 0xF0) v>>=4,ret+=4;
	if(v & 0xC) v>>=2,ret+=2;
	if(v & 0x2) v>>=1,ret+=1;
	return ret;
}


int lsb(ll v)
{
	if(v==0) return -1;

	int ret=0;
	if(!(v & 0xFFFFFFFFLL)) v>>=32,ret+=32;
	if(!(v & 0xFFFF)) v>>=16,ret+=16;
	if(!(v & 0xFF)) v>>=8,ret+=8;
	if(!(v & 0xF)) v>>=4,ret+=4;
	if(!(v & 0x3)) v>>=2,ret+=2;
	if(!(v & 0x1)) v>>=1,ret+=1;
	return ret;
}


template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct solve
{
	ll a, b, c, d;
	map<ll,ll> dp;

	solve(ll a, ll b, ll c, ll d) : a(a),b(b),c(c),d(d)
	{
	}
	ll operator()(ll n)
	{
		if(n==0) return 0;
		if(n==1) return d;
		if(dp[n]>0) return dp[n];

		ll ans=a*msb(n)+d*bit_count(n);
		if(ans/n>d) min_u(ans, d*n);

		for(auto x:vector<pii>{{2,a},{3,b},{5,c}})
		{
			int r, cost;
			tie(r, cost)=x;

			int updown=n-n/r*r;
			if(updown==0)
			{
				min_u(ans, cost+(*this)(n/r));
				continue;
			}
			min_u(ans, cost+d*updown+(*this)(n/r));
			min_u(ans, cost+d*(r-updown)+(*this)(n/r+1));
		}
		dp[n]=ans;
		return ans;
	}
};


int main(void)
{
	int t;
	while(scanf("%d", &t)==1)
	{
		ll n;
		int a, b, c, d;
		for(int i=0;i<t;i++)
		{
			scanf("%lld%d%d%d%d", &n, &a, &b, &c, &d);
			printf("%lld\n", solve(a, b, c, d)(n));
		}
	}
	return 0;
}


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

int main() {
  int N;
  cin >>N;
  if (N%1110<=9) {
    cout << "Yes" << endl;
  }
  else if (N%1000%111==0) {
    cout << "Yes" << endl;
  }
  else {
    cout <<"No"<< endl;
  }
}


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

int main(){

	int n;
	cin >> n;

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

	int fm=0,sm=0,mf=0;

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

		if(a[i]==fm){
			mf++;
		}

		if(a[i]>fm){
			mf=1;
			sm=fm;
			fm=a[i];
		}else if(fm!= a[i] && a[i]>sm){
			sm=a[i];
		}



	}

	for(int i=0;i<n;i++){
		if(a[i]!=fm || a[i]==fm && mf!=1){
			cout << fm <<"\n";
		}else{
			cout << sm << "\n";
		}
	}


	return 0;
}

Measured memory_bytes: 2432
local a, b, m = io.read("*n", "*n", "*n")
local at = {}
local bt = {}
local mina, minb = 0, 0
for i = 1, a do
  at[i] = io.read("*n")
  if i == 1 then mina = at[1]
  elseif at[i] < mina then mina = at[i] end
end
for i = 1, b do
  bt[i] = io.read("*n")
  if i == 1 then minb = bt[1]
  elseif bt[i] < minb then minb = bt[i] end
end
local ret = mina + minb
for i = 1, m do
  local x, y, c = io.read("*n", "*n", "*n")
  local r = at[x] + bt[y] - c
  ret = math.min(ret, r)
end
print(ret)


Measured memory_bytes: 2304
#include<stdio.h>
int main(){
  while(1){
  int s1, s2, i;
  int goukei[5], max=0;
  for(i=0; i<5; i++){
    scanf("%d%d",&s1, &s2);
    if(s1==0 && s2==0){
      return 0;
    }
    goukei[i]=s1+s2;
    if(max<goukei[i]){
      max=goukei[i];
    }
  }
    if(max==goukei[0]){
  printf("A %d\n",max);
    }else if(max==goukei[1]){
  printf("B %d\n",max);
    }else if(max==goukei[2]){
  printf("C %d\n",max);
    }else if(max==goukei[3]){
  printf("D %d\n",max);
    }else if(max==goukei[4]){
  printf("E %d\n",max);
    }
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll tmp1,tmp2,tmp3;
const ll mod = 998244353;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y){
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
int main(){
  ll n;
  cin >> n;
  ll sq = sqrt(n);
  for(ll i = 1;i<=sq;i++){
    if(n % i == 0){
      tmp1 = i;
      tmp2 = n/i;
    }
  }
  //cout << tmp1 << tmp2;
  ll sum = tmp1 + tmp2 - 2;
  cout << sum << endl;
}

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

int main()
{
    int N,L;
    cin >> N>>L;

    int min=200;
    for (int i = 0; i < N; i++)
    {
        if(abs(L+i)<abs(min))min = L + i;
    }

    int sum=0;

    for (int i = 0; i < N; i++)
    {
        sum+=(L+i);
    }

    cout<< (sum-min);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#include <stdlib.h>
// #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;
// #pragma comment(linker, "/STACK:102400000,102400000")
// typedef pair<LL,LL> pii;
// tree <pii,null_type,greater<pii>,rb_tree_tag,tree_order_statistics_node_update> tr;
// cin.tie(0);
// std::ios::sync_with_stdio(false);
typedef long long LL;
const int N = 300005;
const int M = 307;
const int INF = 0x3f3f3f3f;
const double inf = 2e9+7;
const double Pi = acos(-1);
const int MOD = 1e9+7;
const double eps = 1e-3;	
int n,m;
int a,b,c;
int cal(int x,int y)
{
	int tmp = 0;
	while (x)
	{
		tmp += x%10;
		x /= 10;
	}
	while (y)
	{
		tmp += y%10;
		y /= 10;
	}
	return tmp;
}
int main()
{
	while (~scanf("%d",&n))
	{
		int ans = INF;
		for (int i=1;i<n;i++)
		{
			int a = i;
			int b = n-i;
			ans = min(ans,cal(a,b));
		}
		printf("%d\n",ans);
	}
	return 0;
}
/*



*/

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

#define Q_MAX (400000)

typedef struct {
	char block[10][11];
    int num[3];
	int time;
} COLOR;

int head, tail;
COLOR queue[Q_MAX];

void enq(COLOR t)
{
	queue[tail++] = t;
	if (tail == Q_MAX) tail = 0;
}

void deq(COLOR *t)
{
	*t = queue[head++];
	if (head == Q_MAX) head = 0;
}

int conv(char c)
{
    return ((c > 'B') + (c > 'G'));
}

int x, y;

void dfs(COLOR *exm, char c, char change, int p, int q)
{
	int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
	int mx, my;
	int i;
	
    exm->num[conv(exm->block[q][p])]--;
    exm->num[conv(c)]++;
	exm->block[q][p] = c;
	
	for (i = 0; i < 4; i++){
		mx = p + dx[i];
		my = q + dy[i];
		if (0 <= mx && mx < x && 0 <= my && my < y && exm->block[my][mx] == change){
			dfs(exm, c, change, mx, my);
		}
	}
}

void check(COLOR p, char col)
{
	if (p.block[0][0] != col){
		p.time++;
		dfs(&p, col, p.block[0][0], 0, 0);
		enq(p);
	}
}

int main(void)
{
	COLOR puzzle, temp;
	int i, j;
	char c;
    
	while (1){
		scanf("%d%d", &x, &y);
		
		if (x + y == 0){
			break;
		}
        memset(puzzle.num, 0, sizeof(puzzle.num));
		
		for (i = 0; i < y; i++){
			for (j = 0; j < x; j++){
				do {
					c = puzzle.block[i][j] = getchar();
				} while (c != 'R' && c != 'G' && c != 'B');
                puzzle.num[conv(c)]++;
			}
		}
		memset(queue, 0, sizeof(queue));
		head = tail = 0;
		puzzle.time = 0;
		enq(puzzle);
        
		while (1){
			deq(&temp);
			
			if (temp.num[0] == x * y || temp.num[1] == x * y || temp.num[2] == x * y){
				break;
			}
			
			check(temp, 'R');
			check(temp, 'G');
			check(temp, 'B');
		}
		
		printf("%d\n", temp.time);
	}
	
	return (0);
}

Measured memory_bytes: 49000
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(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 all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'


void solve(){ 
  int n, m;
  cin >> n >> m;
  multiset<ll> s;
  forn(i,n){
    ll a;
    cin >> a;
    s.insert(a);
  }
  while (m--){
    ll x = *s.rbegin();
    s.erase(s.find(x));
    s.insert(x/2);
  }
  ll ans = 0;
  for (auto e: s){
    ans += (ll) e;
  }
  cout << ans << endl;

}

int main() {
  ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 



*/

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep2(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(i,n) rep2(i,0,n)
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    cout << n*n*n << endl;
    return 0;
}

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <unordered_map>
#include <deque>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> istream& operator>>(istream &is, pair<S, T> &p){ return is >> p.first >> p.second; }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ return os << "[" << p.first << ", " << p.second << "]"; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rof(i, n) for(int i = (n)-1; i >= 0; i --)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)
#define Return(x) { Cout(x); return 0; }

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n, k);
    Cins(int, n, a);
    vc<ll> b;
    b.reserve(n*(n+1)/2);
    Cusum(ll, a, sa);
    For(l, n) for(int r = l; r < n; r ++) b.push_back(sa[r+1] - sa[l]);
    
    ll ans = 0;
    for(ll d = 62; d >= 0; d --){
        ll mask = 1ll << d;
        ans ^= mask;
        int c = 0;
        for(ll &x : b) if((ans & x) == ans) c ++;
        if(c < k) ans ^= mask;
    }
    Cout(ans);
}
 


Measured memory_bytes: 4224
(sx, sy, tx, ty) = tuple(map(int, input().split()))

(dx, dy) = (tx - sx, ty - sy)

ans = "R" * dx + "U" * dy \
    + "L" * dx + "D" * dy \
    + "D" + "R" * (dx + 1) + "U" * (dy + 1) + "L" \
    + "U" + "L" * (dx + 1) + "D" * (dy + 1) + "R"

print(ans)


Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, M;
	cin >> N >> M;
	int k[10];
	int s[10][10] = {};
	rep(i, M) {
		cin >> k[i];
		rep(j, k[i]) {
			int ss;
			cin >> ss;
			s[i][ss - 1] = 1;
		}
	}
	int p[10];
	rep(i, M) cin >> p[i];

	int kotae = 0;
	rep(i, 1 << N) {
		int on[10] = {};
		int OK = 1;
		rep(j, M) {
			rep(x, N) {
				if (s[j][x] && (i >> x & 1)) {
					on[j]++;
				}
			}
			if (on[j] % 2 != p[j]) OK = 0;
		}
		if (OK) kotae++;
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n;
		int z[];
		int wait[];
		Queue<Integer> g = new LinkedList<Integer>();

		z = new int[17];
		Arrays.fill(z, -1);
		wait = new int[100];
		for (int i = 0; i < 600; i++) {
			for (int j = 0; j < 17; j++) {
				if (z[j] == i) {
					z[j] = -1;
				}
			}
			if (i % 5 == 0) {
				g.add(i / 5);
			}
			boolean flag = true;
			while (g.peek() != null && flag) {
				flag = false;
				int m = g.peek() % 5 == 1 ? 5 : 2;
				int l = g.peek();
				int index = 0;
				boolean flag2 = false;
				for (int j = 0; j < 17; j++) {
					flag2 = true;
					for (int k = 0; k < m; k++) {
						if (17 <= j + k || 0 <= z[j + k]) {
							flag2 = false;
						}
					}
					if (flag2) {
						index = j;
						break;
					}
				}
				if (flag2) {
					for (int j = 0; j < m; j++) {
						z[index + j] = i + 17 * (l % 2) + 3 * (l % 3) + 19;
					}
					g.poll();
					flag = true;
				}
			}
			for (int x: g) {
				if (x < 100) {
					wait[x]++;
				}
			}
//			//----------------------------------------------------
//			System.out.printf("%2d: ", i);
//			for (int j = 0; j < 17; j++) {
//				System.out.printf("%4d", z[j]);
//			}
//			System.out.print("  ");
//			for (int x: g) {
//				System.out.printf("%2d", x);
//			}
//			System.out.println();
//			//----------------------------------------------------
		}
		while (sc.hasNext()) {
			n = sc.nextInt();
			System.out.println(wait[n]);
		}
	}
}

Measured memory_bytes: 19100
#include <stdlib.h>
#include <stdio.h>

int main()
{int n,i,flag=0;
char s[101];
    scanf("%d",&n);
    for(i=0;i<n;i++){
     scanf("%c",&s[i]);
     if(s[i]=='Y'){
         flag=1;
     }
    }if(flag==1){
        printf("Four");
    }else
    printf("Three");
    return 0;
}


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

#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);

template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;

constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433L;

template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}

int main() {
    ll N,M,K; cin >> N >> M >> K;
    vector<ll> A(N+1,0),B(M+1,0);
    for(int i = 1; i <= N; ++i) cin >> A[i];
    for(int i = 1; i <= M; ++i) cin >> B[i];
    for(int i = 1; i <= N; ++i) A[i]+=A[i-1];
    for(int i = 1; i <= M; ++i) B[i]+=B[i-1];
    int ans = 0;
    for(int i = 0; i <= N; ++i) {
        if(A[i]>K) continue;
        int cnt = i;
        ll L = K - A[i];
        cnt += (upper_bound(ALL(B),L)-B.begin())-1;
        chmax(ans,cnt);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6416
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define all(vec) (vec).begin(), (vec).end()
#define yn(formula) (formula) ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(formula) (formula) ? (cout << "YES" << endl) : (cout << "NO" << endl)

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vll> vvl;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vp> vvp;
typedef vector<vpl> vvpl;

constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1ll << 59;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };

struct edge { ll to; ll cost; };

/*<ここから>***********************************************************/


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

	cout << n / 3 << endl;


		
	return 0;
}

Measured memory_bytes: 256
from collections import Counter


n = int(input())
a = list(map(int, input().split()))
a.sort()
c = Counter(a)

flags = [True] * (a[-1] + 1)

for e in a:
    for mul in range(2, a[-1] // e + 1):
        flags[e * mul] = False

print(sum([flags[a[i]] and c[a[i]] == 1 for i in range(n)]))


Measured memory_bytes: 38308
/*
      author  : nishi5451
      created : 14.08.2020 19:16:52
*/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;


int main(){
    int d,n;
    cin >> d >> n;
    if(n==100){
        int ans = 101;
        while(d--) ans*=100;
        cout << ans << endl;
    }
    else {
        int ans = n;
        while(d--) ans*=100;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3592
#!/usr/bin/env python3

# Union Findデータ構造


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m, k = map(int, input().split())

group = UnionFind(n)

friends_num = [0 for _ in range(n)]
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    group.union(a, b)
    friends_num[a] += 1
    friends_num[b] += 1

block_list = [[] for _ in range(n)]
for i in range(k):
    c, d = map(int, input().split())
    c, d = c-1, d-1
    block_list[c].append(d)
    block_list[d].append(c)

# print(friends_dict)
# print(block_dict)

for i in range(group.n):
    count = group.size(i) - 1 - friends_num[i]
    for j in block_list[i]:
        if j in block_list[i]:
            if group.same(i, j):
                count -= 1

    print(count, "", end="")


Measured memory_bytes: 26504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

template<typename T>
struct LowLink {
private:
    const vector<vector<T>> &g;
    vector<int> used, ord, low;
    
    int dfs(int idx, int k, int par) {
        used[idx] = true;
        ord[idx] = k++;
        low[idx] = ord[idx];
        bool is_articulation = false;
        int cnt = 0;
        for(auto &to : g[idx]) {
            if (!used[to]) {
                ++cnt;
                k = dfs(to, k, idx);
                low[idx] = min(low[idx], low[to]);
                is_articulation |= ~par && low[to] >= ord[idx];
                if (ord[idx] < low[to]) bridge.emplace_back(minmax(idx, (int)to));
            }
            else if (to != par) {
                low[idx] = min(low[idx], ord[to]);
            }
        }
        is_articulation |= par == -1 && cnt > 1;
        if (is_articulation) articulation.push_back(idx);
        return k;
    }
    
public:
    vector<int> articulation;
    vector<pair<int, int>> bridge;
    
    LowLink(const vector<vector<T>> &g) : g(g) {}
    
    void build() {
        used.assign(g.size(), 0);
        ord.assign(g.size(), 0);
        low.assign(g.size(), 0);
        int k = 0;
        for(int i = 0; i < g.size(); i++) {
            if (!used[i]) k = dfs(i, k, -1);
        }
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll v, e;
    cin >> v >> e;
    vector<vector<ll>> g(v);
    rep(i, e) {
        ll a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    LowLink<ll> link(g);
    link.build();
    vector<int> ans = link.articulation;
    sort(all(ans));
    for(auto x : ans) printf("%d\n", x);
    return 0;
}



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
int32_t main(){
    IOS;
    int a,b,c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;
    return 0;
}



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

int main()
{
    long long N, D;
    cin >> N >> D;
    vector<long long>squareList;
    
    long long maximumValue = 10 * (40 * 40);
    
    long long currentValue = 0;
    long long index = 0;
    
    while (currentValue <= maximumValue) {
        index++;
        currentValue = index * index;
        squareList.push_back(currentValue);
    }
    
    vector<vector<long long> > coords(N, vector<long long>(D, 0));
    
    for (int j = 0; j < N; j++) {
        for (int i = 0; i < D; i++) {
            cin >> coords[j][i];
        }
    }
    
    long long count = 0;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++ ) {
            long long sum = 0;
            for (int k = 0; k < D; k++) {
                sum += (coords[i][k] - coords[j][k]) * (coords[i][k] - coords[j][k]);
            }
            for (int k = 0; k < index; k++) {
                if (sum < squareList[k]) {
                    continue;
                }
                if (sum == squareList[k]) {
                    count++;
                }
            }
        }
    }
    cout << count;
    return 0;
}

Measured memory_bytes: 888
import sys


N, M = map(int, input().split())

C = [None] * M
for i, x in enumerate(sys.stdin.readlines()):
    P, Y = map(int, x.split())
    C[i] = (P, Y, i)

C.sort()

Num = [None] * M

pp = 0
cnt = 0
for P, Y, i in C:
    if P != pp:
        cnt = 1
    else:
        cnt += 1
    pp = P
    Num[i] = (P, cnt)

for P, cnt in Num:
    P = str(P).zfill(6)
    cnt = str(cnt).zfill(6)
    print(P + cnt)


Measured memory_bytes: 32156
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

vector< vector<int> > P;
int Color[100000];

bool bfs( int s ) {
    
    Color[s] = 1;
    
    queue<int> Q;
    
    for ( int i = 0; i < P[s].size(); i++ ) {
        Q.push(P[s][i]);
        Color[P[s][i]] = 0;
    }
    
    while ( !Q.empty() ) {        
        int c = Q.front();
        Q.pop();
        
        int color = 1-Color[c];
        
        for ( int i = 0; i < P[c].size(); i++ ) {
            int n = P[c][i];
            
            if ( Color[n] != -1 && Color[n] != color ) { return false; }
            if ( Color[n] == -1 ) { Q.push(n); }
            Color[n] = color;
        }
        
    }
    
    return true;
}

int main() {
        
    long long N,M;
    cin >> N >> M;
    P.resize(N);
    
    fill( Color, Color+N, -1 );
    
    for ( int i = 0; i < M; i++ ) {
        int a,b;
        cin >> a >> b;
        a--; b--;
        P[a].push_back(b);
        P[b].push_back(a);
    }
    
    if ( bfs(0) ) {
        long long a,b;
        a = b = 0;
        for ( int i = 0; i < N; i++ ) {
            Color[i] ? a++ : b++;
        }
        cout << a*b-M << endl;
    }
    else { cout << N*(N-1)/2 - M << endl; }
    
    return 0;
}

Measured memory_bytes: 6144
Program ABC123B

integer a(5),b(6),x,y,s,p

read(*,*) a

do i=1,5
 b(i)=mod(a(i),10)
end do
b(6)=1

do i=1,5
 do j=1,5
  if (b(i)<b(j)) then
   x=b(i)
   b(i)=b(j)
   b(j)=x
   y=a(i)
   a(i)=a(j)
   a(j)=y
  end if
 end do
end do

s=0
p=1
do while (b(p)==0)
 s=s+a(p)
 p=p+1
end do

if (p<=4) then
s=s+a(p)

do i=p+1,5
 s=s+(a(i)/10+1)*10
end do
end if

write(*,*) s

stop
end

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>

using namespace std;

using ll = long long;

int main()
{
    int N;
    vector<ll> A;
    vector<ll> B;
    cin >> N;
    A.resize(N);
    B.resize(N, 0LL);

    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if(i - 1 >= 0)
        {
            B[i] = A[i] + B[i - 1];
        }
        else
        {
            B[i] += A[i];
        }
    }

    sort(B.begin(), B.end(), greater<ll>());

    ll v = B[0];
    ll cnt = v == 0 ? 2 : 1;
    ll ans = 0LL;

/*
    for (int i = 0; i < N;i++)
    {
        cout << B[i] << " ";
    }
    cout << endl;
*/

    for (int i = 1; i < N; i++)
    {
        if (v == B[i])
        {
            cnt++;
        }
        else
        {
            //cout << "i = " << i << " cnt = " << cnt << endl;
            ans += (cnt * (cnt - 1)) / 2;

            v = B[i];
            cnt = v == 0 ? 2 : 1;
        }
    }

    ans += (cnt * (cnt - 1)) / 2;

    cout << ans << endl;

    return 0;
}
/*
8
1 2 -4 1 2 -2 3 -3
*/

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll h,w,a,b;
	cin>>h>>w>>a>>b;
	rep(i,h){
		rep(j,w)cout<<((i<b)^(j<a)?1:0);
		cout<<endl;
	}
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <map>
#include <algorithm>

using namespace std;

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

  map<string, int> dict;
  for(int i=0; i<size; i++){
    string temp;
    cin >> temp;
    sort(temp.begin(), temp.end());
    dict[temp] += 1;
  }

  long long ans = 0;
  for(auto temp : dict){
    //nCrを使うことで、 個数から組み合わせの数を算出することができるため。
    //r = 2 で固定なので、n! は　n * (n-1)となる。さらにこの際、分母はr!だけになるので、以下のようになる。
    ans += (long long)temp.second * (temp.second-1) / 2;
  }

  cout << ans;

  return 0;
}


Measured memory_bytes: 11136
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<list>
#include<functional>
#define mp make_pair
#define X first
#define Y second
#define INF 1987654321
#define PI 3.14159265358979323846264
#define MOD 1000000007LL
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef complex<double> base;
ll POW(ll a, ll b) { if (b == 0)return 1; if (b == 1)return a; if (b & 1)return (a*POW(a, b - 1)) % MOD; ll t = POW(a, b / 2); return (t*t) % MOD; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[] = { 0,-1,1,0 }, dy[] = { 1,0,0,-1 };//동북남서

inline int dif(char c)
{
	return 123 - c;
}
char s[100001];
int main() {
	int k;
	scanf("%s%d", s, &k);
	int n = strlen(s);
	fup(i,0,n-1,1)
		if (s[i]!='a' && dif(s[i]) <= k) k -= dif(s[i]), s[i] = 'a';
	k %= 26;
	s[n - 1] += k;
	printf("%s", s);
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;


	int X = (N - 1) / (K - 1);	

	if ((N - 1) % (K - 1) != 0) {
		cout << X + 1 << endl;
	}
	else {
		cout << X << endl;
	}
}

Measured memory_bytes: 256
n=int(input())
A=list(map(int, input().split()))
B=sorted(A)
for i in range(n+1):
  if B[i]!=i+1:
    a=i
    break
d=[i for i, x in enumerate(A) if x==a]
x=d[0]
y=d[1]

def cmb(n,r,mod):
    if (r<0 or r>n):
      return 0
    r=min(r,n-r)
    return g1[n]*g2[r]*g2[n-r]%mod

mod=10**9+7 #出力の制限
N=10**5+10
g1=[1,1] # 元テーブル
g2=[1,1] #逆元テーブル
inverse=[0,1] #逆元テーブル計算用テーブル

for i in range(2,N+1):
  g1.append((g1[-1]*i)%mod)
  inverse.append((-inverse[mod%i]*(mod//i))%mod)
  g2.append((g2[-1]*inverse[-1])%mod)

for i in range(1,n+2):
  ans=cmb(n+1,i,mod)-cmb(x+(n-y),i-1,mod)
  print(ans%mod)

Measured memory_bytes: 22404
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

bool used[1000000];


int main(void) {
    int m, k;
    cin >> m >> k;
    
    if (k>=(1<<m) || (m==1 && k==1) ){
      puts("-1");
      return 0;
    }
    
    vector<P> v;
    
    rep(i, 0, (1<<m)) {
      int j = i^k;
      if (used[j]) continue;
      v.pb(mp(i, j));
      used[i] = used[j] = true;
    }
    
    int n = sz(v);
    if (k!=0) rep(i, 0, n) {
      v.pb(mp(v[i].second, v[i].first));
    }
    
    rep(i, 0, sz(v)) {
      if (i>0) printf(" ");
      printf("%d %d", v[i].first, v[i].second);
    }
    cout << "\n";
    return 0;
}




Measured memory_bytes: 4592
while True:
    try:
        (a,b,c,d,e,f) = map(float, raw_input().split())
        y = (a * f - c * d) / (-b * d + e * a)
        x = (c - b * y) / a
        print '{0:.3f} {1:.3f}'.format(x, y)
    except EOFError:
        break

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

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

    rep(i, s.size()) {
        if(s[i]==',') s[i] = ' ';
    }

    cout << s << endl;

 
    return 0;
}

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

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  vector<ll> dp(n+1, INF);
  dp[0] = 0;

  reps1(i, n+1) {
    chmin(dp[i], dp[i-1] + 1);
    for (int j=6; i-j >= 0; j *= 6) {
      chmin(dp[i], dp[i-j] + 1);
    }

    for (int j=9; i-j >= 0; j *= 9) {
      chmin(dp[i], dp[i-j] + 1);
    }
  }

  cout << dp[n] << endl;
  // rep(i, n+1) cout << i << ": " << dp[i] << endl;

  return 0;
}


Measured memory_bytes: 1024
import java.io.*;
import java.util.*;

public class Main {

    private static int N;
    private static int[] A;
    private static int[] B;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);

        N = sc.nextInt();
        A = new int[N];
        B = new int[N];
        for (int i = 0; i < N-1; i++) {
            A[i] = sc.nextInt();
            B[i] = sc.nextInt();
        }
        System.out.println(solve());
    }

    private static int[] distance(int from, Rin r) {
        int[] dist = new int[N+1];
        Arrays.fill(dist, Integer.MAX_VALUE);
        ArrayDeque<Integer> q = new ArrayDeque<>();
        q.add(from);
        dist[from] = 0;

        while(!q.isEmpty()) {
            int n = q.pop();
            List<Integer> nexts = r.get(n);
            for (int next : nexts) {
                if( dist[next] > dist[n] + 1 ) {
                    dist[next] = dist[n] + 1;
                    q.add(next);
                }
            }
        }
        return dist;
    }

    private static String solve() {
        Rin r = mkRin();
        int[] from_1 = distance(1, r);
        int[] from_n = distance(N, r);

        int f = 0;
        for (int i = 1; i <= N; i++) {
            if( from_1[i] <= from_n[i] ) {
                f++;
            }
        }
        int s = N - f;

        if( f > s ) {
            return "Fennec";
        } else {
            return "Snuke";
        }
    }

    private static Rin mkRin() {
        Rin r = new Rin(N);
        for (int i = 0; i < N-1; i++) {
            r.set(A[i], B[i]);
        }
        return r;
    }

    // 隣接リスト
    private static class Rin {

        private final List[] array;

        public Rin(int n) {
            array = new List[n];
            for (int i = 0; i < n; i++) {
                array[i] = new ArrayList<>();
            }
        }

        public void set(int a, int b) {
            get(a).add(b);
            get(b).add(a);
        }

        public List<Integer> get(int n) {
            //noinspection unchecked
            return (List<Integer>)array[n - 1];
        }
    }

    static class FastScanner {

        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

}


Measured memory_bytes: 55000
import sys
input = sys.stdin.readline

INF = 10**14

N, M = map(int, input().split())
graph = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

maxd = 0
Q = int(input())
Query = []
Color = []
for _ in range(Q):
    v, d, c = map(int, input().split())
    if d > maxd:
        maxd = d
    Query.append((v-1, d))
    Color.append(c)

Query = Query[::-1]
Color = Color[::-1]

dp = [[INF]*(maxd+1) for _ in range(N)]
for i, (v, d) in enumerate(Query):
    if i < dp[v][d]:
        dp[v][d] = i

for d in reversed(range(maxd)):
    for v in range(N):
        if dp[v][d+1] < dp[v][d]:
            dp[v][d] = dp[v][d+1]
        for nv in graph[v]:
            if dp[v][d+1] < dp[nv][d]:
                dp[nv][d] = dp[v][d+1]

for v in range(N):
    seq = dp[v][0]
    if seq == INF:
        print(0)
    else:
        print(Color[seq])

Measured memory_bytes: 97584
input_a = input()
input_b = input()
if input_a == input_b:
    print('Yes')
    exit()

alt_a = input_a
res = False

while True:
    alt_a = alt_a[1:] + alt_a[0]

    if alt_a == input_a:
        break

    if alt_a == input_b:
        res = True
        break

print('Yes' if res else 'No')


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

int main() {
  string S, T, U;
  int A, B;
  cin >> S >> T >> A >> B >> U;
  if(S == U){
    A = A -1;
  }
  if(T == U){
    B = B -1;
  }
  cout << A << " " << B << endl;
  
}


Measured memory_bytes: 384
#include<iostream>
#include <string>
#include<vector>
typedef long long ll;

using namespace std;
int main()
{
	int n;
	cin >> n;
	ll kotae = 1;
	for (int i = 1; i <= n; i++) {
		kotae *= i;
		int temp = kotae % (1000000007);
		kotae = temp;
	}
	cout << kotae;
	return 0;
}

Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

#define error(x) cout << #x << " = " << x << endl

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

int n;

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

	cin >> n;

	cout << (n - 1) / 2 << '\n';
}


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

constexpr int table[7][7] = {
	{6, 5, 4, 0, 3, 2, 1},
	{0, 3, 2, 1, 9, 8, 7},
	{4, 0, 12, 2, 1, 10, 8},
	{5, 13, 0, 3, 11, 1, 9},
	{16, 6, 14, 4, 0, 12, 2},
	{17, 15, 6, 5, 13, 0, 3},
	{18, 17, 16, 6, 5, 4, 0},
};

bool is_idempotent(const bitset<128> &filter) {
	for(int i = 0; i < (1 << 19); ++i) {
		bitset<19> current(i);
		bitset<7> next;

		for(int j = 0; j < 7; ++j) {
			int sum = 0;
			for(int k = 0; k < 7; ++k) {
				sum |= current[table[j][k]] << k;
			}
			next[j] = filter[sum];
		}

		int sum = 0;
		for(int k = 0; k < 7; ++k) {
			sum |= next[table[0][k]] << k;
		}
		if(next[0] != filter[sum]) return false;
	}
	return true;
}

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

	for(string s; cin >> s && s != "#";) {
		reverse(begin(s), end(s));
		cout << (is_idempotent(bitset<128>(s)) ? "yes" : "no") << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1188
n = int(input())
fn0 = 1
fn1 = 1
if n == 0:
    fn = fn0
elif n == 1:
    fn = fn1
else:
    for ni in range(2, n+1):
        fn = fn0 + fn1
        fn0 = fn1
        fn1 = fn
print(fn) 


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

int main()
{
  int a, b, c, d, e, f;
  while (scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &f) != EOF) {
    float x, y;
    float gy = (a * e) - (b * d);
    swap(a, e);
    b *= -1;
    d *= -1;
    x = (a * c) + (b * f);
    y = (d * c) + (e * f);
    x /= gy;
    y /= gy;
    if (x == 0) x = abs(x);
    if (y == 0) y = abs(y);
    printf("%.3f %.3f\n", x, y);
  }
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <tuple>
#include <map>
#include <numeric>

using namespace std;
#define PI 3.14159265359
#define ll long long int


ll binarySearch(ll* Array, ll left, ll right, ll key)
{
    while(left < right){
        ll mid = (left + right) / 2;
        if(Array[mid] > key){
            right = mid;
        }else if(Array[mid] == key) return mid;
        else{
            left = mid + 1;
        }
    }

    return -1;
}

int main(void)
{
    ll n;
    cin >> n;
    vector<ll> A(n), B(n), C(n);
    for(ll i = 0; i < n; i++){
        cin >> A[i];
    }
    for(ll i = 0; i < n; i++){
        cin >> B[i];
    }
    for(ll i = 0; i < n; i++){
        cin >> C[i];
    }

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        ll a, c;
        a = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        c = C.end() - upper_bound(C.begin(), C.end(), B[i]);
        ans += a * c;
    }


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

Measured memory_bytes: 2560