stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

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

#define rep(i,b) for(int i = 0; i < (b); i++)

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

#define show(x)  cerr << #x << " = " << (x) << endl;

#define int long long

using namespace std;



template <typename X, typename T>

auto vectors(X x, T a) {

	return vector<T>(x, a);

}



template <typename X, typename Y, typename Z, typename... Zs>

auto vectors(X x, Y y, Z z, Zs... zs) {

	auto cont = vectors(y, z, zs...);

	return vector<decltype(cont)>(x, cont);

}



template<typename T>

ostream& operator << (ostream& os, vector<T>& v){

	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;

}

template<typename T>

istream& operator >> (istream& is, vector<T>& v){

	for(T& x: v){ is >> x; } return is;

}



const int M = 1000000007;



signed main(){

	int n;

	string s;

	cin >> n >> s;



	vector<int> num(26, 0);

	for(auto i : s){

		num[i - 'a']++;

	}



	vector<int> a, b;

	rep(s,1 << 13){

		int sum = 1;

		rep(j,13){

			if((s >> j) bitand 1){

				(sum *= num[j]) %= M;

			}

		}

		a.emplace_back(sum);

	}



	rep(s,1 << 13){

		int sum = 1;

		rep(j,13){

			if((s >> j) bitand 1){

				(sum *= num[j + 13]) %= M;

			}

		}

		b.emplace_back(sum);

	}



	int ans = 0;

	int b_sum = 0;

	rep(i,b.size()){

		(b_sum += b[i]) %= M;

	}

	rep(i,a.size()){

		(ans += a[i] * b_sum % M) %= M;

	}



	cout << ans - 1 << endl;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

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

#define rep(i,b) for(int i = 0; i < (b); i++)

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

#define show(x)  cerr << #x << " = " << (x) << endl;

#define int long long

using namespace std;



template <typename X, typename T>

auto vectors(X x, T a) {

	return vector<T>(x, a);

}



template <typename X, typename Y, typename Z, typename... Zs>

auto vectors(X x, Y y, Z z, Zs... zs) {

	auto cont = vectors(y, z, zs...);

	return vector<decltype(cont)>(x, cont);

}



template<typename T>

ostream& operator << (ostream& os, vector<T>& v){

	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;

}

template<typename T>

istream& operator >> (istream& is, vector<T>& v){

	for(T& x: v){ is >> x; } return is;

}



const int M = 1000000007;



signed main(){

	int n;

	string s;

	cin >> n >> s;



	vector<int> num(26, 0);

	for(auto i : s){

		num[i - 'a']++;

	}





	int ans = 1;

	rep(i,num.size()){

		(ans *= num[i] + 1) %= M;

	}



	cout << ans - 1 << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



typedef unsigned long long int ll;



ll inf = 1e9+7;



int main()

{

    ios::sync_with_stdio(0);

    std::cin.tie(0);

    ll n;

    char c;

    cin >> n;

    vector<ll> s(n+1,0);

    for(ll i = 1; i <= n; i++)

    {

        cin >> c;

        s.at(i) = (ll)((c-'a')+1);

    }



    sort(s.begin(), s.end());



    vector<ll> dp(1e5+1,0);

    vector<ll> b(1e5+1,0);

    ll tem, tem2;



    for(ll i = 1; i <= n; i++)

    {

        tem = s[i];

        if(b.at(tem) == 0)

        {

            dp.at(i) = (2*dp.at(i-1)+1)%inf;

        }

        else

        {

            dp.at(i) = ((2*dp.at(i-1)%inf) + inf - dp.at(b.at(tem)-1) )%inf;

        }

        b.at(tem) = i;

    }





    cout << dp.at(n);











    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>



using namespace std;



typedef long long int ll;



ll inf = 1e9+7;



int main()

{

    ios::sync_with_stdio(0);

    cin.tie(0);

    int n, k, d;

    cin >> n;

    vector<int> a(26,0);



    char c;

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

    {

        cin >> c;

        a.at(c-'a')++;

    }



    ll sum = 1;

    for(int i = 0; i < 26; i++)

    {

        sum *= (ll)(a.at(i)+1);

        sum %= inf;

    }



    cout << (sum-1);









    return 0;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define MAXN 100005

#define mod 1000000007

typedef long long ll;

using namespace std;

vector<ll> arr,book,dp;

int main(){

    ll n;

    cin >> n;

    arr.assign(n,0);

    book.assign(MAXN,0);

    dp.assign(MAXN,0);

    char x;

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

        cin >> x;

        arr[i]=x-'a'+1;

    }

    sort(arr.begin(),arr.end());

    for(ll i=1;i<=n;i++){

        if(!book[arr[i-1]]){

            dp[i]=(2*dp[i-1]+1)%mod;

        }

        else{

            int t=book[arr[i-1]];

            dp[i]=(dp[i-1]*2%mod+mod-dp[t-1]%mod)%mod;

        }

        book[arr[i-1]]=i;

    }

    cout << dp[n]%mod << '\n';

    return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define foi for(int i=0; i<n; i++)

#define foj for(int j=0; j<n; j++)

#define ll long long int

#define vi vector<int>

#define maxn 200005

#define mod 1000000007

using namespace std;



int cnt[30];

char c;

int main() {

    int n;

    cin >> n;

    foi {

        cin >> c;

        cnt[c-'a']++;

    }

    ll ans=1;

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

        ans=ans*(cnt[i]+1)%mod;

    }

    ans--;

    if (ans<0) ans+=mod;

    cout << ans << '\n';

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

using vi = vector<int>;

using vc = vector<char>;

using vb = vector<bool>;

using vd = vector<double>;

using vs = vector<string>;

using vll = vector<long long>;

using vpii = vector<pair<int, int>>;

using vvi = vector<vector<int>>;

using vvc = vector<vector<char>>;

using vvs = vector<vector<string>>;

using vvb = vector<vector<bool>>;

using pii = pair<int, int>;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)

#define reps(i,n) for(int i = 1; i <= (int)(n); i++)

#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)

#define rreps(i,n) for(int i = (int)(n); i > 0; i--)

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

#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)

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

#define rall(x) (x).rbegin(), (x).rend()

#define call(x) (x).cbegin(), (x).cend()

#define MAX(x) *max_element(all(x))

#define MIN(x) *min_element(all(x))

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 (b<a) {a=b; return 1;} return 0;}

const int INF = INT_MAX;

const int MOD = 1000000007;

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

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



int main() {

    int N;

    cin >> N;

    vll dp(100500, INF);

    dp[0] = 0;

    reps(i, N) {

        int j = 0;

        while (i - pow(6, j) >= 0) {

            chmin(dp[i], dp[i - pow(6, j)] + 1);

            j++;

        }

        j = 0;

        while (i - pow(9, j) >= 0) {

            chmin(dp[i], dp[i - pow(9, j)] + 1);

            j++;

        }

    }

    cout << dp[N] << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i,n) for(int i = 0; i < (int)(n); i++)

#define fi first

#define se second

#define pb push_back

#define eb emplace_back

#define sz(x) (int)(x).size()

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

using namespace std;

using ll = long long;

using P = pair<int, int>;

using vi = vector<int>;

using vc = vector<char>;

using vb = vector<bool>;

using vs = vector<string>;

using vll = vector<long long>;

using vp = vector<pair<int, int>>;

using vvi = vector<vector<int>>;

using vvc = vector<vector<char>>;

using vvll = vector<vector<long long>>;

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 (b<a) {a=b; return 1;} return 0;}



const int INF = 1001001001;



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0);



    int n;

    cin >> n;

    vector<int> dp(n+1, INF);

    dp[0] = 0;

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

        int power = 1;

        while (i - power >= 0) {

            chmin(dp[i], dp[i - power] + 1);

            power *= 6;

        }

        power = 1;

        while (i - power >= 0) {

            chmin(dp[i], dp[i - power] + 1);

            power *= 9;

        }

    }

    cout << dp[n] << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

typedef pair<int,int> P;

typedef vector<vector<int> > Graph;



const int INF = 1<<29;

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

int dp[100010];

int main(){

    int n;

    cin >> n;

    rep(i,100010){

        dp[i]=INF;

    }

    dp[0]=0;

    int k;

    int l;

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

        chmin(dp[i],dp[i-1]+1);

        k=1;

        l=1;

        while(i-pow(6,k)>=0){

            chmin(dp[i],dp[i-(int)pow(6,k)]+1);

            k++;

        }

        while(i-pow(9,l)>=0){

            chmin(dp[i],dp[i-(int)pow(9,l)]+1);

            l++;

        }

    }

    cout << dp[n] << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

typedef pair<int,int> P;

typedef vector<vector<int> > Graph;



//a進法でのnの総和

int wa(int n,int a){

    int res = 0;

    while(n>0){

        res += n%a;

        n /= a;

    }

    return res;

}

int main(){

    int n;

    cin >> n;

    int res = n;

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

        int now = wa(i,6) + wa (n-i,9);

        res = min (res,now);

    }

    cout << res << endl;

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<cstdio>

#include<iostream>

using namespace std;

#define min(a,b) ((a)<(b)?(a):(b))

int dp[100010];

int main(){

	int N;

	cin>>N;

	dp[0]=0;

	for(int i=1;i<=100000;i++){

		int min=1+dp[i-1];

		int j=6;

		while(i>=j){

			//if(i-j<0)break;

			min=min(min,(1+dp[i-j]));

			j*=6;

		

		}

		j=9;

		while(i>=j){

			

			//if(i-j<0)break;

			min=min(min,(1+dp[i-j]));

			j*=9;

		

		}

		dp[i]=min;

	}

	cout<<dp[N];

}

// Optimized solution to the same problem (faster):
#include <iostream>

#include <string.h>

#include <vector>

#include <algorithm>

#include <cmath>

#include <map>

#include <functional>

#include <cassert>

#include <utility>

#include <stack>

#include <queue>

using namespace std;

#define min(a,b) ((a)<(b)?(a):(b))

#define max(a,b) ((a)>(b)?(a):(b))

#define REP(i,n) for(int i=0;i<n;i++)

#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)

#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef pair<int,int> Pi;

typedef long long int ll;

const int INF=(ll)(1<<30)-1;

const ll INFl=(ll)9223372036854775807;

const int MAX=10000;

const ll MOD=(ll)1e9+7;

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

int lcm(int a,int b){return a/gcd(a, b)*b;}



int n;



int main(){

	cin>>n;

	int ans=INF;

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

		int t=n;

		int s=i;

		int tans=0;

		t-=6*i;

		while(s>0){

			tans+=(s%6);

			s/=6;

		}

		while(t>0){

			tans+=(t%9);

			t/=9;

		}

		ans=min(tans,ans);

	}

	cout<<ans<<endl;

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
 #include <iostream>

 #include <vector>

 #include <map>

 #include <string>

 #include <algorithm>

 using namespace std;



 template<class T> inline bool chmin(T& a, T b) {

    if (a > b) {

        a = b;

        return true;

    }

    return false;

}

template<class T> inline bool chmax(T& a, T b) {

    if (a < b) {

        a = b;

        return true;

    }

    return false;

}



 typedef long long ll;

 const long long INF = 1LL << 60;







 int main()

 {

   int n;

   cin >> n;



   vector<long long> dp(100010, INF);



   dp.at(0) = 0;

   for(int i = 1; i <= n; i++)

   {

       int num = 1;

       while(num <= i)

       {

           chmin(dp.at(i), dp.at(i-num) + 1);

           num *= 6;

       }



       num = 9;

       while(num <= i)

       {

           chmin(dp.at(i), dp.at(i-num) + 1);

           num *= 9;

       }

   }



   cout << dp.at(n) << endl;



    return 0;

 }

// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

using namespace std;

int main(){

    int n; cin >> n;

    int INF = 100000;

    vector<int> dp(n+1, INF);

    dp[0] = 0;

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

        dp[i] = 1 + dp[i-1];

        int power = 6;

        while(power <= i){

            dp[i] = min(dp[i], dp[i-power]+1);

            power *= 6;

        }

        power = 9;

        while(power <= i){

            dp[i] = min(dp[i], dp[i-power]+1);

            power *= 9;

        }

    }

    cout << dp[n] << endl;

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



#define ft first

#define sd second



using namespace std;



typedef long long ll;

typedef pair<int, int> pii;

typedef pair<ll, ll> pll;





const int MAXT = 9, MAXN = 1000 * 1000 + 3;









int p9[MAXT], p6[MAXT], dp[MAXN], n;





int main() {

	p9[0] = p6[0] = 1;

	for (int i = 1; i < MAXT; i++)

		p9[i] = p9[i - 1] * 9, p6[i] = p6[i - 1] * 6;

	cin >> n;

	memset(dp, 127, sizeof dp);

	dp[0] = 0;

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

		dp[i] = dp[i - 1] + 1;

		for (int j = 0; j < MAXT; j++) {

			if (i < p9[j])

				break;

			dp[i] = min(dp[i], dp[i - p9[j]] + 1);

		}

		for (int j = 0; j < MAXT; j++) {

			if (i < p6[j])

				break;

			dp[i] = min(dp[i], dp[i - p6[j]] + 1);

		}

	}

	cout << dp[n];

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



int main()

 {

  int n; cin>>n;

  int sum= n;

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

    int cc=0,t=i;

    while(t>0)

 {

      cc += t%6;

      t /= 6;

    }

    t = n-i;

    while(t>0)

{

      cc += t%9;

      t /= 9;

    }

    if(sum>cc) sum = cc;

  }

  cout<<sum;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <algorithm>

#include <iostream>

#include <vector>

using namespace std;



vector<int> a(100001, -1);



int dp(int b) {

	if (!b) return 0;

	if (a[b] != -1) return a[b];

	vector<int> c;

	if (1 <= b) c.push_back(dp(b - 1) + 1);

	for (int i = 6; i <= b; i *= 6) c.push_back(dp(b - i) + 1);

	for (int i = 9; i <= b; i *= 9) c.push_back(dp(b - i) + 1);

	a[b] = *min_element(c.begin(), c.end());

	return a[b];

}



int main() {

	int N;

	cin >> N;

	cout << dp(N);

}

// Optimized solution to the same problem (faster):
#include <algorithm>

#include <climits>

#include <iostream>

#include <vector>

using namespace std;



vector<int> a;



int dp(int b) {

	if (a[b] != -1) return a[b];

	int c = INT_MAX;

	if (0 < b) c = dp(b - 1);

	for (int i = 6; i <= b; i *= 6) c = min(dp(b - i), c);

	for (int i = 9; i <= b; i *= 9) c = min(dp(b - i), c);

	a[b] = c + 1;

	return a[b];

}



int main() {

	int N;

	cin >> N;

	a.resize(N + 1, -1);

	a[0] = 0;

	cout << dp(N);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



const int MAX_N = 100010;

int memo[MAX_N];



int rec(int n){

    if(n == 0) return 0;

    if(memo[n] != -1) return memo[n];



    int res = n;

    

    // 1, 6, 36, ...

    for(int i = 1; i <= n; i *= 6){

        res = min(res, rec(n - i) + 1);

    }



    // 1, 9, 81, ...

    for(int i = 1; i <= n; i *= 9){

        res = min(res, rec(n - i) + 1);

    }



    return memo[n] = res;

}



int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);



    int N;

    cin >> N;

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

        memo[i] = -1;

    }



    cout << rec(N) << endl;



    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



int dp[100010];

const int INF = 1e9;



int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);



    int n;

    cin >> n;

    vector<int> A;

    A.push_back(1);

    for(int i = 6; i <= n; i *= 6){

        A.push_back(i);

    }

    for(int i = 9; i <= n; i *= 9){

        A.push_back(i);

    }



    sort(A.begin(), A.end());



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

        dp[i] = INF;

    }



    dp[0] = 0;

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

        for(auto x : A){

            if(i < x) break;

            dp[i] = min(dp[i], dp[i - x] + 1);

        }

    }



    cout << dp[n] << endl;









    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <vector>

#include <algorithm>

#include <string>

#include <set>

#include <queue>

#include <stack>

#include <tuple>

#include <cmath>

#include <iomanip>

#include <map>

#include <stdio.h>

#include <cstring> //memset(dp,0,sizeof(dp))

#include <functional>

#define ll long long

#define rep(i,n) for(int i=0;i<(n);i++)

#define rrep(i,n) for(int i=n-1;i>=0;i--)

#define fi first

#define se second

#define pb push_back

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

using namespace std;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}

template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

typedef pair<int,int> P;

typedef pair<ll,ll> Pll;

//小数点以下　cout << fixed << setprecision(10) << num << endl;

//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA

//long*long<0で判定するな

//開区間と閉区間

//アルファベットが何番目かは x=s[i]-'a'

//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ

//切り上げ：(a+(b-1))/b

//32bit以上は 1ull<<j

// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索

// for(auto u:mp) u.fi u.se も可能

//n個のgcd,lcmは一つずつみて更新していく

//大きな数を扱うときは素因数分解した形で持っておく

// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;

//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]

const ll MOD = 1000000007;

const int MAX = 1001001;



int memo[MAX];

int rec(int n){

    if(n==0) return 0;

    if(memo[n]!=-1) return memo[n];

    int ret=n;

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

        int six=pow(6,i);

        int nine=pow(9,i);

        if(n-six>=0) chmin(ret,rec(n-six)+1);

        if(n-nine>=0) chmin(ret,rec(n-nine)+1);

    }

    return memo[n]=ret;

}



signed main(){

    int n; cin >> n;

    memset(memo,-1,sizeof(memo));

    cout << rec(n) << endl;

}


// Optimized solution to the same problem (faster):
#include <iostream>

#include <vector>

#include <algorithm>

#include <string>

#include <set>

#include <queue>

#include <stack>

#include <tuple>

#include <cmath>

#include <iomanip>

#include <map>

#include <cstring> //memset(dp,0,sizeof(dp))

#define ll long long

#define rep(i,n) for(int i=0;i<(n);i++)

#define repp(i,n) for(int i=n-1;i>=0;i--)

#define fi first

#define se second

#define pb push_back

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

using namespace std;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}

template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

typedef pair<int,int> P;

typedef pair<ll,ll> Pll;



signed main(){

    int n; cin >> n;

    int dp[n+1];

    rep(i,n+1) dp[i]=1001001;

    dp[0]=0;

    rep(i,n+1){

        int k=1;

        if(i+1<=n) chmin(dp[i+1],dp[i]+1);

        k=6;

        while(i+k<=n){

            chmin(dp[i+k],dp[i]+1);

            k*=6;

        }

        k=9;

        while(i+k<=n){

            chmin(dp[i+k],dp[i]+1);

            k*=9;

        }

    }

    cout << dp[n] << endl;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<iomanip>

#include<algorithm>

#include<cmath>

#include<vector>

#include<string>

#include<bitset>

using namespace std;



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

#define ROF(i,b,a) for (int i=(b);i>(a);--i)

#define REP(i,n) FOR(i,0,n)

#define PER(i,n) ROF(i,n-1,-1)



typedef int i32;

typedef long long int i64;

typedef unsigned long long int ui64;

typedef float f32;

typedef double f64;

typedef long double f128;



constexpr int MAX_N = 1e5+100;

int dp[MAX_N];



int main(){

    int N;cin>>N;

    REP(i,MAX_N){

        dp[i] = N;

    }

    dp[0] = 0;

    REP(i,N+1){

        for(int pow=1;pow<=i;pow*=6) dp[i] = min(dp[i-pow]+1,dp[i]);

        for(int pow=1;pow<=i;pow*=9) dp[i] = min(dp[i-pow]+1,dp[i]);

    }

    cout << dp[N];

}










// Optimized solution to the same problem (faster):
#include<iostream>

#include<iomanip>

#include<algorithm>

#include<cmath>

#include<vector>

#include<string>

#include<bitset>

#include<queue>

using namespace std;



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

#define ROF(i,b,a) for (int i=(b);i>(a);--i)

#define REP(i,n) FOR(i,0,n)

#define PER(i,n) ROF(i,n-1,-1)



int n_base_sum(int a,int n){

    int res = 0;

    while(a>0){

        res += a%n;

        a /= n;

    }

    return res;

}



int main(){

    int N;cin>>N;

    int ans=N;

    REP(i,N+1){

        int tmp = n_base_sum(i,6) + n_base_sum(N-i,9);

        ans = min(ans,tmp);

    }

    cout << ans;

}




// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<iomanip>

#include<algorithm>

#include<cmath>

#include<vector>

#include<string>

#include<bitset>

using namespace std;



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

#define ROF(i,b,a) for (int i=(b);i>(a);--i)

#define REP(i,n) FOR(i,0,n)

#define PER(i,n) ROF(i,n-1,-1)



typedef int i32;

typedef long long int i64;

typedef unsigned long long int ui64;

typedef float f32;

typedef double f64;

typedef long double f128;



constexpr int MAX_N = 1e5+100;

int dp[MAX_N];



int main(){

    int N;

    cin >> N;

    REP(i,MAX_N){

        dp[i] = i;

    }

    REP(i,N+1){

        for(int pow=1;i+pow<=N;pow*=6) dp[i+pow] = min(dp[i+pow],dp[i]+1);

        for(int pow=1;i+pow<=N;pow*=9) dp[i+pow] = min(dp[i+pow],dp[i]+1);

    }

    cout << dp[N];

}




// Optimized solution to the same problem (faster):
#include<iostream>

#include<iomanip>

#include<algorithm>

#include<cmath>

#include<vector>

#include<string>

#include<bitset>

#include<queue>

using namespace std;



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

#define ROF(i,b,a) for (int i=(b);i>(a);--i)

#define REP(i,n) FOR(i,0,n)

#define PER(i,n) ROF(i,n-1,-1)



int n_base_sum(int a,int n){

    int res = 0;

    while(a>0){

        res += a%n;

        a /= n;

    }

    return res;

}



int main(){

    int N;cin>>N;

    int ans=N;

    REP(i,N+1){

        int tmp = n_base_sum(i,6) + n_base_sum(N-i,9);

        ans = min(ans,tmp);

    }

    cout << ans;

}




// Fastest known solution for this problem: