akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T = double>
using point = complex<T>; // 2D point only

using ll = long long;
using ull = unsigned long long;
using ldob = long double;

template <typename T = int>
using ii = pair<T,T>;
template <typename T = int>
using iii = pair<T,ii<T>>;
template <typename T = int>
using ii_i = pair<ii<T>,T>;
template <typename T = int>
using vi = vector<T>;
template <typename T = int>
using vvi = vector<vi<T>>;
template <typename T = int>
using vii = vector<ii<T>>;
template <typename T = int>
using viii = vector<iii<T>>;
template <typename T = int>
using lim = numeric_limits<T>;

#define re real()
#define im imag()
#define fi first
#define se second
#define all(v) v.begin(), v.end()

// OST
template <typename T>
using ordered_set = __gnu_pbds::tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// from: https://codeforces.com/blog/entry/62393
// struct custom_hash {
// 	static uint64_t splitmix64(uint64_t x) {
// 		// http://xorshift.di.unimi.it/splitmix64.c
// 		x += 0x9e3779b97f4a7c15;
// 		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
// 		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
// 		return x ^ (x >> 31);
// 	}

// 	size_t operator()(uint64_t x) const {
// 		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
// 		return splitmix64(x + FIXED_RANDOM);
// 	}
// };

const int INF = ~(1<<31);
const ll LINF = (1LL << 60);
const long double EPS = 1e-9;
const long double PI = acos(-1);

const int N = 15;
const int NN = 101;
const int MOD = 1e9+7;
const int IMAX = 1e9+7;
const ll LMAX = 1e15+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};
const int dx8[8] = {-1,-1,-1,0,0,1,1,1};
const int dy8[8] = {-1,0,1,-1,1,-1,0,1};

ll n, m, x, c[N], a[N][N];

int main () {
	ios_base::sync_with_stdio(false); cin.tie(0); // cout.tie(0);
	// cout.precision(2); cout << fixed;

	cin >> n >> m >> x;
	for (int i = 0; i < n; ++i) {
		cin >> c[i];
		for (int j = 0; j < m; ++j) {
			cin >> a[i][j];
		}
	}

	ll ans = LINF;
	for (int msk = 0; msk < (1<<n); ++msk) {
		vector<ll> brain(m, 0);
		ll cost = 0;
		for (int i = 0; i < n; ++i) {
			if (msk&(1<<i)) {
				cost += c[i];
				for (int j = 0; j < m; ++j) {
					brain[j] += a[i][j];
				}
			}
		}
		bool ok = true;
		for (int i = 0; i < m; ++i)
			ok &= brain[i] >= x;
		if (ok)
			ans = min(ans, cost);
	}

	cout << (ans == LINF ? -1 : ans) << endl;

	return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>

using namespace std;

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

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;

int N, A[1<<20];

int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(nullptr);

 cin >> N;
 rep(i, N) cin>>A[i];
 ll ans = 0;
 for(int i = 1;i < N;i++) {
   if(A[i] < A[i-1]) {
     ans += A[i-1]-A[i];
     A[i]=A[i-1];
   }
 }
 cout<<ans;



 return 0;
}


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

int main() {
  int a, b, t;
  cin >> a >> b >> t;
  
  int ans = (t / a) * b;
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
// Java implementation of the approach 
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main { 
	

	public static class FastReader {
		BufferedReader br;
		StringTokenizer root;
		
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (root == null || !root.hasMoreTokens()) {
				try {
					root = new StringTokenizer(br.readLine());
				} catch (Exception addd) {
					addd.printStackTrace();
				}
			}
			return root.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception addd) {
				addd.printStackTrace();
			}
			return str;
		}
	}
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static FastReader sc = new FastReader();
	public static void main(String[] args) throws IOException {
		
		int n = sc.nextInt()%10;
		if(n == 2 || n == 5 || n == 7 || n == 9 || n == 4) out.print("hon");
		else if(n == 0 || n == 1 || n == 6 || n == 8) out.print("pon");
		else out.print("bon");
	   
		out.close();
		
	}
	


}


Measured memory_bytes: 32800
#include <vector>
#include <iostream>

const int kMaxJumpStep = 3;

int dp(const int N){
	std::vector<int> step(N+1);
	step[0] = 1;

	for (int i = 0; i < N; i++){
		for (int j = i + 1; j <= i + kMaxJumpStep; j++){
			if (j > N) break;
			step[j] += step[i];
		}
	}

	return step[N];
}

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

	while (1){
		int n;
		std::cin >> n;
		if (n == 0) break;
		std::cout << dp(n)/3650 + 1 << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1196
#include <iostream>
#include <vector>
#include <string>
#include <cmath>



using namespace std;

int NumStr(string str)
{
	int n = str.size();
	int sum = 0;
	for(int i=0; i<n; i++){
		if(str[i] == 'A')sum += (pow(4.,i) * 1);
		else if(str[i] == 'C')sum += (pow(4.,i) * 2);
		else if(str[i] == 'G')sum += (pow(4.,i) * 3);
		else if(str[i] == 'T')sum += (pow(4.,i) * 4);
	}
	return sum;
}

void InsertFlag(vector<bool> &flag,string str)
{
	int num_str = NumStr(str);
	flag[num_str] = true;
}

void FindFlag(const vector<bool> &flag,string str)
{
	int num_str = NumStr(str);
	if(flag[num_str] == true)cout << "yes" << endl;
	else if(flag[num_str] == false)cout << "no" << endl;
}

int main()
{
	int n;
	cin >> n;
	vector<bool> flag;
	flag.resize(16777216);

	for(int i=0; i<n; i++){
		string command, str;
		cin >> command >> str;
		if(command == "insert")InsertFlag(flag, str);
		else if(command == "find")FindFlag(flag, str);
	}
}

Measured memory_bytes: 3116
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<int> a(n), b(n), c(m), d(m);
	rep(i,n) cin >> a[i] >> b[i];
	rep(i,m) cin >> c[i] >> d[i];
	rep(i,n){
		int dist = 1e9;
		int ans = -1;
		rep(j,m){
			int calcdist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if(calcdist < dist){
				dist = calcdist;
				ans = j+1;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
def gcd(n,m):
    n,m=sorted([n,m])
    while(m%n!=0):
        n,m=m%n,n
    return n
def lcm(n,m):
    return n*m//gcd(n,m)
cd=lcm(c,d)
print((b-a+1)-(b//c-(a-1)//c)-(b//d-(a-1)//d)+b//(cd)-(a-1)//(cd))

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

bool comp(P a, P b) { return a.second < b.second; }

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N, M; cin >> N >> M;
    map<int, vector<int> > mp;
    for (int i = 0; i < N; ++i){
        int a, b; cin >> a >> b;
        mp[a].push_back(b);
    }

    ll ans = 0;
    priority_queue<int> que;
    for (int i = 0; i <= M; ++i){
        for(auto it : mp[i]){
            que.push(it);
        }
        if(!que.empty()){
            ans += que.top(); que.pop();
        }
    }
    cout << ans << endl;

    return 0;
}



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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
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;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

void cntfill(Vi &x,int n){
    REP(i,0,n){
        if(i==0) x[i]=n;
        else x[i]=x[i-1]+(n-2*i);
    }
}


signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    Vi a(n),b(m);
    REP(i,0,n) cin>>a[i];
    REP(i,0,m) cin>>b[i];
    
    sort(ALL(a));
    sort(ALL(b));
    Vi x(n-1),y(m-1);
    REP(i,0,n-1) x[i]=a[i+1]-a[i];
    REP(i,0,m-1) y[i]=b[i+1]-b[i];
    
    Vi cntx(n),cnty(m);
    cntfill(cntx,n-1);
    cntfill(cnty,m-1);

    int ansx=0,ansy=0;
    REP(i,0,n-1){
        ansx = (ansx+(x[i]*cntx[i])%MOD)%MOD;
    }
    REP(i,0,m-1){
        ansy = (ansy+(y[i]*cnty[i])%MOD)%MOD;
    }
    cout<<(ansx*ansy)%MOD<<endl;
    return 0;
}


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

int main()
{
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	cout << (s[0] == s[1] && s[2] == s[3] && s[0] != s[2] ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
   int a[3];
   cin>>a[0]>>a[1]>>a[2];
   sort(a,a+3);
   cout<<a[0]+a[1]<<endl;
   
   
}

Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define int long long
using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

signed main(){
  int n;
  cin>>n;
  int a[n];
  int sum=0;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }
  rep(i,n-1)a[i+1]+=a[i];
  int temp,ans=3000000000;
  for(int i=0;i<n-1;i++){
    temp=abs(2*a[i]-sum);
    if(temp<ans)ans=temp;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
using namespace std;

int main()
{
    int n, k;
    string s;

    cin >> n;
    cin >> s;
    cin >> k;

    char t = s[k-1];

    for(int i = 0;i < n; i++) {
        if(s[i] != t) {
            s[i] = '*';
        }
    }
    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

public static class Program
{
    static void Main()
    {
        char[] s = Console.ReadLine().ToCharArray();
        char[] t = Console.ReadLine().ToCharArray();
        Dictionary<char,char> S_pair = new Dictionary<char, char>();
        Dictionary<char, char> T_pair = new Dictionary<char, char>();
        String ans = "Yes";
        for (int i = 0; i < s.Length; i++)
        {
            if (S_pair.ContainsKey(s[i]) && S_pair[s[i]] != t[i])
            {
                ans = "No";
            }
            else if (T_pair.ContainsKey(t[i]) && T_pair[t[i]] != s[i])
            {
                ans = "No";
            }
            else
            {
                S_pair[s[i]] = t[i];
                T_pair[t[i]] = s[i];
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13536
from collections import defaultdict


def prime_factor(n):
    d = defaultdict(int)
    for i in range(2, n + 1):
        if i * i > n:
            break

        while n % i == 0:
            d[i] += 1
            n //= i

    if n != 1:
        d[n] += 1

    return d


N = int(input())
X = list(map(int, input().split()))
MOD = 10 ** 9 + 7

ctr = defaultdict(int)
buf = []
for n in X:
    d = prime_factor(n)
    buf.append(d)
    for key in d:
        ctr[key] = max(ctr[key], d[key])

total = 1
for key, val in ctr.items():
    total *= pow(key, val, MOD)
    total %= MOD

ans = 0
for i, n in enumerate(X):
    cur = total
    for key, val in buf[i].items():
        cur = cur * pow(pow(key, val, MOD), MOD - 2, MOD) % MOD

    ans += cur
    ans %= MOD

print(ans)


Measured memory_bytes: 78896
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
string getRank(int idx)
{
    string res = "";
    if(idx == 0) res += "NA"; 
    if(idx == 1) res += "E";
    if(idx == 2) res += "D";
    if(idx == 3) res += "C";
    if(idx == 4) res += "B";
    if(idx == 5) res += "A";
    if(idx == 6) res += "AA";
    if(idx == 7) res += "AAA";
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    double a, b;
    pair<double, double> p[] = {{70, 148},{55, 116},{50, 105},{43, 89},{40, 83},{37.50, 77},{35.50, 71}};
    while(cin >> a >> b)
    {
        int i;
        for(i = 0; i < 7; i++)
        {
            if(a >= p[i].first || b >= p[i].second)
            {
                cout << getRank(i) << endl;
                break;
            }
        }
        if(i == 7) cout << getRank(i) << endl;
    }
    return 0;
}




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

signed main(){
	int N, S, i, j;
	scanf("%lld%lld", &N, &S);
	vector<int> X(N), P(N);
	for(i = 0; i < N; i++){
		scanf("%lld%lld", &X[i], &P[i]);
	}
	if(X[N - 1] < S){
		printf("%lld\n", abs(X[0] - S));
		return 0;
	}
	if(S < X[0]){
		printf("%lld\n", abs(X[N - 1] - S));
		return 0;
	}
	vector<vector<int>> Xs(2, vector<int>(0)), Ps(2, vector<int>(0));
	for(i = 0; i < N && X[i] < S; i++){
		Xs[0].push_back(X[i]);
		Ps[0].push_back(P[i]);
	}
	for(i = N - 1; i >= 0 && X[i] > S; i--){
		Xs[1].push_back(X[i]);
		Ps[1].push_back(P[i]);
	}
	int ans = 0, now = S;
	for(i = 0, j = 0; i < Xs[0].size() && j < Xs[1].size();){
		if(Ps[0][i] >= Ps[1][j]){
			if(now == S){
				ans += abs(Xs[1][j] - now);
			}
			ans += abs(Xs[0][i] - now);
			Ps[0][i] += Ps[1][j];
			now = Xs[0][i];
			j++;
		}
		else{
			if(now == S){
				ans += abs(Xs[0][i] - now);
			}
			ans += abs(Xs[1][j] - now);
			Ps[1][j] += Ps[0][i];
			now = Xs[1][j];
			i++;
		}
	}
	ans += abs(S - now);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3996
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  char x;
  cin >> x;
  if (isupper(x)) cout << 'A' << endl;
  else cout << "a"<< endl;
  return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
typedef long long ll;
const ll MOD = 1e9+7;

int main(){
  ll n,k,ma,mi,ans=0;
  cin>>n>>k;
  for(ll i=k;i<=n+1;i++){
    ans+=(i*(n-i+1)+1)%MOD;
    ans%=MOD;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vll vector<vector<long long>>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
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;
}
//以上テンプレ

int main(){
    ll N,T;
    cin>>N>>T;
    vl vec(N);
    rep(i,N) cin>>vec.at(i);
    vl dp(N,INF);
    rep(i,N){
        if(i==0){
            dp.at(0)=vec.at(0);
        }else{
            chmin(dp.at(i),dp.at(i-1));
            chmin(dp.at(i),vec.at(i));
        }
    }
    ll count=0;
    ll mv=0;
    for(ll i=1;i<N;i++){
        ll prof=vec.at(i)-dp.at(i-1);
        if(mv==prof){
            count++;
        }else if(mv<prof){
            count=1;
            mv=prof;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N,M;
      cin >> N >> M;
      vector<int> X(N);//初期化されてる
      int box;
      
      for(int i=0;i<2*M;i++){
        cin >> box;
        X.at(box-1)++;
      }
      for(int i=0;i<N;i++){
        cout << X.at(i) << endl;
      }
      
    }

Measured memory_bytes: 3588
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <random>
#include <tuple>
#include <iomanip>
#include <cstring>

using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n-1); i >= 0; i--)
#define pb push_back
#define f first
#define s second
//const ll INFL = 1LL << 60;//10^18 = 2^60
const ll INFL = 1LL << 60;
const int INF = 1 << 30;//10^9
ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

//最大公約数
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

ll kai_mod(ll x){
  if(x == 1) return 1;
  return x * kai_mod(x-1) % MOD;
}


int main(void){
  ll N;
  cin >> N;
  vector<double> A(N);
  rep(i, N) cin >> A[i];
  sort(A.begin(), A.end());
  double ans = A[0];
  for(int i = 1; i < N; i++){
    ans = (ans + A[i]) / 2;
  }
  cout << fixed << setprecision(10) << ans << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int k, a[5];
int ta = inf;
bool mu;

signed main() {
	cin >> k;
	rep(i, 5) {
		cin >> a[i];
		if (a[i] < k) {
			mu = true;
			ta = min(ta, a[i]);
		}
	}
	if (mu&&(k%ta))cout << k / ta + 5 << endl;
	else if (mu)cout << k / ta - 1 + 5 << endl;
	else cout << 5 << endl;
}

Measured memory_bytes: 256
N, x = map(int, input().split())
*a, = map(int, input().split())
a = a+[0]
ans = 0
for i in range(0, N):
    d = a[i]+a[i+1]-x
    if d > 0:
        for j in range(i+1, i-1, -1):
            s = min([a[j], d])
            d -= s
            a[j] -= s
            ans += s
print(ans)


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

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

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> x(n),y(n),h(n);
  for(Int i=0;i<n;i++) cin>>x[i]>>y[i]>>h[i];

  for(Int cx=0;cx<=100;cx++){
    for(Int cy=0;cy<=100;cy++){
      Int z=1e15;
      for(Int i=0;i<n;i++)
	chmin(z,h[i]+abs(cx-x[i])+abs(cy-y[i]));      
      Int flg=z>0;
      for(Int i=0;i<n;i++)
	flg&=max<Int>(z-abs(cx-x[i])-abs(cy-y[i]),0LL)==h[i];
      
      if(flg){
	cout<<cx<<" "<<cy<<" "<<z<<endl;
	return 0;
      }
    }
  }
  assert(0);
  return 0;
}


Measured memory_bytes: 256
import Control.Applicative ((<$>))
import Data.Array (listArray, (!))
import Data.List (sort, foldl')

main :: IO ()
main = do
    [n,m] <- getInts
    cs <- getInts
    print $ solve n m $ sort cs

getInts :: IO [Int]
getInts = map read . words <$> getLine



solve :: Int -> Int -> [Int] -> Int
solve n _ (_:cs) = table ! n
    where
        table = foldl' build initial cs
        initial = listArray (0,n) [0..n]
        build pre c = res
            where
                res = listArray (0,n)
                        [x | y <- [0..n]
                           , let x | c > y = pre ! y
                                   | otherwise = let res1 = pre ! y 
                                                     res2 = 1 + (res ! (y-c))
                                                  in res2 `seq` min res1 res2]

Measured memory_bytes: 120828
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc,char **argv){
    char s[200000];
    scanf("%s",s);
    int ans;
    
    ans=strrchr(s,'Z')-strchr(s,'A');
    
    printf("%d",ans+1);
  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(){
  int i;
  char s[100];
  scanf("%s",s);
  for(i=0;i<3;i++){
    if(s[i]=='9')s[i]='1';
    else s[i]='9';
  }
  printf("%s",s);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() 
{
    string s;
    cin>>s;
    int cnt=0;

    for(int i=0,j=s.size()-1;i<=j;i++,j--)
    {
        if(s[i] != s[j])cnt++;
    }
    cout<<cnt;
}


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

#define ln '\n'
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VI d(n);
    REP(i, n) cin >> d[i];
    sort(ALL(d));
    if (n % 2 == 0) {
        cout << d[n / 2] - d[n / 2 - 1] << ln;
    } else {
        cout << 0 << ln;
    }
    return 0;
}


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

int main() {
	long double a,b,m,h,am,ah;
	long double x,ans,p,y;
	cin>>a>>b>>h>>m;
	am = 6 * m;
	ah = 0.5 * (h * 60 + m);
	x = (ah-am)*3.1415926535/180;
    y = cos(x);
	p = 2*a*b*y;
	ans = (a*a)+(b*b)-p;
	ans = pow(ans,0.5);
	cout<<fixed<<setprecision(10)<<ans<<endl;
	return 0;
}


Measured memory_bytes: 4164
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end
require 'bigdecimal'

N = get_int

sum = BigDecimal(0)

N.times do |i|
  x, u = gets.chomp.split
  num = BigDecimal(x)
  if u == 'JPY'
    sum += num
  else
    sum += num * BigDecimal(380000)
  end
end

puts sum.to_f


Measured memory_bytes: 14616
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,a,b) for (int i=a; i<b; ++i)

bool comp(pair <ll, ll> &A, pair <ll,ll> &B)
{
    if (A.first!=B.first)
    {
        return A.first>B.first;
    }
    else return A.second>B.second;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll N,M;
    cin >> N >> M;
    vector < pair <ll, ll> > X(N);
    loop(i,0,N) cin >> X[i].first >> X[i].second;
    sort(X.begin(), X.end(), comp);
    ll reward=0;
    ll day=0;
    multiset <ll> rewards;
    loop(i,0,N)
    {
        if (X[i].first+day<=M)
        {
            day++;
            rewards.insert(X[i].second);
        }
        else 
        {
            if (rewards.size()==0) continue;
            auto it=rewards.begin();
            ll r=*it;
            if (r<X[i].second)
            {
                rewards.erase(it);
                rewards.insert(X[i].second);
            }
        }
    }
    for (auto it=rewards.begin(); it!=rewards.end(); it++)
    {
        reward+=*it;
    }
    cout << reward << "\n";
    return 0;
}

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

int main()
{
	int r,c;

	cin >> r >> c ;
	double **cell = new double*[r+1];
	for(int i=0;i<r+1;++i)
		cell[i] = new double[c+1];

	for(int i=0;i<r;++i)
		for(int j=0;j<c;++j)
			cin >> cell[i][j];

	for(int i=0;i<r;++i){
		int count = 0;
		for(int j=0;j<c;++j){
			count += cell[i][j];
		}
		cell[i][c] = count;
	}

	for(int i=0;i<c;++i){
		int count = 0;
		for(int j=0;j<r;++j){
			count += cell[j][i];
		}
		cell[r][i] = count;
	}

	int count = 0;
	for(int i=0;i<c;++i){
		count += cell[r][i];
	}
	cell[r][c] = count;


	for(int i=0;i<=r;++i){
		for(int j=0;j<=c;++j){
			cout << cell[i][j];
			if(j != c)
				cout << ' ';
		}
		cout << endl;
	}

	for(int i=0;i<r+1;++i)
		delete[] cell[i];
	delete[] cell;
	return 0;
}

Measured memory_bytes: 1368
import java.util.Scanner;
public class Main {
    public int bubbleSort (int[] a, int n) {
        int tmp, sw = 0;
        boolean flag = true;
        for(int i = 0 ; flag ; i++) {
            flag = false;
            for(int j = n-1 ; j >= i+1 ; j--) {
                if (a[j] < a[j-1]) {
                    tmp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = tmp;
                    flag = true;
                    sw++;
                }
            }
        }
        return sw;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Main main = new Main();
        int len, m = 0;
        len = sc.nextInt();
        int[] b = new int[len];
        for (int i = 0 ; i < len ; i++) {
            b[i] = sc.nextInt();
        }
        m = main.bubbleSort(b, len);
        for (int j = 0 ; j < len ; j++) {
            if(j != 0) System.out.print(" ");
            System.out.print(b[j]);
        }
        System.out.println();
        System.out.println(m);
    }
}


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

int main(){
	int N,K;
	int a;
	float b;
	cin >> N >> K;
	float Nf,Kf;
	Nf=N;
	Kf=K;
	a=N/K;
	b=Nf/Kf;
	if(a==b){
		cout << 0;
	}else{
		cout << 1;
	}

	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

ll p(ll x) {
	if (x == 0) { return 1; }
	return p(x - 1) * 2;
}


int main() {

	ll X, Y, Z;
	cin >> X >> Y >> Z;
	cout << (X - Z) / (Y + Z);

	system("PAUSE");

	

}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;

void solve() {
	cin >> N;
	if(N < 1200) cout << "ABC\n";
	else if(1200 <= N && N < 2800) cout << "ARC\n";
	else cout << "AGC\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 256
def f(x,n):
	if x == 1: return [n];
	if x % 2 == 1:
		return f(x >> 1,n + 1) + [n]
	else:
		return [n] + f(x - 1,n + 1)

p = f(input(),1)
p += range(len(p),0,-1)
print len(p)
print ' '.join(list(map(str,p)))



Measured memory_bytes: 2568
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	l := getNextFloat64(scanner)

	fmt.Fprintln(writer, l*l*l/27.0)

}


Measured memory_bytes: 640
order_time = [int(input()) for i in range(5)]

remains = {}
for i, ot in enumerate(order_time):
    remains[i] = ot % 10 if ot % 10 > 0 else 10 

total_time = 0
cnt = 0
for i, r in sorted(remains.items(), key=lambda x: -x[1]):
    if r == 10 or cnt == 4:
        total_time += order_time[i]
    else:
        total_time += order_time[i] + (10 - r)
    cnt += 1

print(total_time)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  int n,m,ans=0,s,c,j=0;
  cin>>n>>m;
  int a[n+1],u[n+1];
  for(int i=1;i<=n;i++){
    if(i==1){
        a[i]=1;
    }
    else{
        a[i]=0;
    }
    u[i]=0;
  }
  for(int i=0;i<m;i++){
    cin>>s>>c;
    if(n!=1&&s==1&&c==0){
      j=1;
    }
    else if(a[s]!=c&&u[s]==1){
      j=1;
    }
    else{
      a[s]=c;
      u[s]=1;
    }
  }
  if(j==1){
    cout<<-1<<endl;
  }
  else if(m==0&&n==1){
      cout<<0<<endl;
  }
  else{
    for(int i=1;i<=n;i++){
      ans+=a[i]*pow(10,n-i);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>//sort,reverse
#include<utility>//pair
#include<queue>//queue,priority queue
#include<deque>//double_ended queue
typedef long long LL;
using namespace std;
int main()
{ 
    int a,b,q;
    cin>>a>>b>>q;
    LL s[a];
    LL t[b];
    for(int i=0;i<a;i++){cin>>s[i];}
    for(int i=0;i<b;i++){cin>>t[i];}
    LL ans[q];
    for(int i=0;i<q;i++){
        LL x;
        cin>>x;
        //二分探査
        int m=0;
        int M=a-1;
        LL sl;
        LL sr;
        LL tl;
        LL tr;
        if(x<s[0]){sl=100000000000;sr=s[0]-x;}
        else if(x>s[a-1]){sr=100000000000;sl=x-s[a-1];}
        else{
            while(M-m>1){
                int k=(M+m)/2;
                if(s[k]<=x){m=k;}
                else{M=k;}
            }
            sl=x-s[m];
            sr=s[M]-x;
        }
        m=0;
        M=b-1;
        if(x<t[0]){tl=100000000000;tr=t[0]-x;}
        else if(x>t[b-1]){tr=100000000000;tl=x-t[b-1];}
        else{
            while(M-m>1){
                int k=(M+m)/2;
                if(t[k]<=x){m=k;}
                else{M=k;}
            }
            tl=x-t[m];
            tr=t[M]-x;
        }
        LL a[3];
        a[0]=max(sl,tl);
        a[1]=max(sr,tr);
        a[2]=min(sl,sr)+min(tl,tr)+min(sl,min(sr,min(tl,tr)));
        ans[i]=min(a[0],min(a[1],a[2]));
    }
    for(int i=0;i<q;i++){cout<<ans[i]<<endl;}
    return 0;
}

Measured memory_bytes: 3712
package main

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

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func main() {
	defer flush()

	R := readInt()
	C := readInt()
	K := readInt()

	goods := make([][]int, R)
	for i := 0; i < R; i++ {
		goods[i] = make([]int, C)
	}
	for i := 0; i < K; i++ {
		r := readInt() - 1
		c := readInt() - 1
		v := readInt()
		goods[r][c] = v
	}

	dp := make([]int, C+1)
	cur := make([]int, 4)
	for i := 0; i < R; i++ {
		for k := 0; k < 4; k++ {
			cur[k] = 0
		}
		cur[0] = dp[0]
		for j := 0; j < C; j++ {
			if goods[i][j] != 0 {
				for k := 2; k >= 0; k-- {
					cur[k+1] = max(cur[k+1], cur[k]+goods[i][j])
				}
			}
			for k := 0; k < 4; k++ {
				dp[j] = max(dp[j], cur[k])
			}
			cur[0] = max(cur[0], dp[j+1])
		}
	}

	result := -1
	for k := 0; k < 4; k++ {
		result = max(result, cur[k])
	}

	println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

var stdoutWriter = bufio.NewWriter(os.Stdout)

func flush() {
	stdoutWriter.Flush()
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdoutWriter, args...)
}


Measured memory_bytes: 81704
n, m, l = [int(i) for i in input().split()]
left = [[int(i) for i in input().split()] for _ in range(n)]
right = [[int(i) for i in input().split()] for _ in range(m)]
ans = [[0] * l for _ in range(n)]
for i, left_v in enumerate(left):
    for j, right_v in enumerate(list(zip(*right))):
        ans[i][j] = sum([x * y for (x, y) in zip(left_v, right_v)])
for row in ans:
    print(*row)



Measured memory_bytes: 7048
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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 N,six=1,nine=1,cnt=1e9,tmp,t;
set<int> s;

int main(){
    cin>>N;
    rep(i,N+1){
        tmp=0;
        t=i;
        while(t>0){
            tmp+=t%6;
            t/=6;
        }
        t=N-i;
        while(t>0){
            tmp+=t%9;
            t/=9;
        }
        if(cnt>tmp)cnt=tmp;
    }
    out(cnt);

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  string S,T;
  cin >> S >> T;
  cout << T + S << endl;
  return 0;
}


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

#ifndef ONLINE_JUDGE
#define debarr(a,x,y)cerr<<#a<<":";for(int i=x;i<=y;i++)cerr<<a[i]<<" ";cerr<<endl;
#define debmat(mat,row,col)cerr<<#mat<<":\n";for(int i=0;i<row;i++){for(int j=0;j<col;j++)cerr<<mat[i][j]<<" ";cerr<<endl;}
#define deb(...)dbs(#__VA_ARGS__,__VA_ARGS__)
template<class S, class T>ostream &operator<<(ostream &os, const pair<S, T> &p) {return os << "(" << p.first << "," << p.second << ")";}
template<class T>ostream &operator<<(ostream &os, const vector<T> &p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>ostream &operator<<(ostream &os, const set<T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>ostream &operator<<(ostream &os, const multiset<T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class S, class T>ostream &operator<<(ostream &os, const map<S, T>&p) {os << "["; for (auto&it : p)os << it << " "; return os << "]";}
template<class T>void dbs(string str, T t) {cerr << str << ":" << t << "\n";}
template<class T, class...S>void dbs(string str, T t, S... s) {int idx = str.find(','); cerr << str.substr(0, idx) << ":" << t << ","; dbs(str.substr(idx + 1), s...);}
#else
#define deb(...){}
#define debarr(a,x,y){}
#define debmat(mat,row,col){}
#endif
#define pr(x) {cout << x << "\n"; return;}
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }

#define int              long long
#define ld               long double
#define fi               first
#define se               second
#define mp               make_pair
#define pb               push_back
#define rep(i,n)         for(int i=0;i<n;i++)
#define re(i,n)          for(int i=1;i<=n;i++)
#define fr(i,a,b)        for(int i=a;i<=b;i++)
#define fb(i,a,b)        for(int i=a;i>=b;i--)
#define sz(x)            (int)x.size()
#define all(x)           x.begin(),x.end()
#define ini(x,y)         memset(x,y,sizeof(x))
typedef vector<int>      vi;
typedef pair<int, int>   pii;
typedef vector<pii>      vii;
typedef map<int, int>    mii;
typedef set<int>         si;
const int N = 2e5 + 10;
int n, x, m;
int cycle[N], vis[N];
void solve(int tc)
{
	cin >> n >> x >> m;
	if (x == 0) pr(0);
	if (x == 1) pr(n);
	int ans = x, pre = x;
	vis[ans] = 1;
	for (int i = 2; i <= n; i++)
	{
		pre = (pre * pre) % m;
		ans += pre;
		if (pre == 0)  break;
		if (vis[pre]) {
			int rem = n - i;
			int  len = 0;
			cycle[len] = 0;
			int st = pre;
			while (1)
			{
				pre = (pre * pre) % m;
				len++;
				cycle[len] = pre + cycle[len - 1];
				if (pre == st) break;
			}
			ans += (rem / len) * cycle[len];
			rem %= len;
			ans += cycle[rem];
			break;
		}
		else {
			vis[pre] = 1;
		}
	}
	cout << ans << endl;

}




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


	int t = 1;
	//cin >> t;
	for (int i = 1; i <= t; i++) solve(i);
	return 0;
}

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

using namespace std;
#define ll long long int

int main()
{
    ll t;
    t = 1;
    // cin t;
    while (t--)
    {
        ll n;
        cin >> n;
        ll a[n];
        ll count[100001] = {0};
        ll sum = 0;
        for (int i = 0; i < n; i++)
        {
            cin >> a[i];
            count[a[i]]++;
            sum += a[i];
        }
        ll q;
        cin >> q;
        while (q--)
        {
            ll x, y;
            cin >> x >> y;
            sum = sum - count[x] * x + count[x] * y;
            count[y] += count[x];
            count[x] = 0;
            cout << sum << endl;
        }
        
    }
}


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

int func(int a, int b) {
  int r = a % b;
  if (r == 0) return b;
  return func(b, r);
}

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  if (A < B) swap(A, B);
  int x = func(A, B);
  
  if (C % x == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);
    long long a,b;
    cin>>a>>b;
    long long res=a*b;
    cout<<res<<endl;
    

    



    return 0;
}

Measured memory_bytes: 3612
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>


using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long H, long long W, long long A, long long B){
  string s = "";
  string t = "";
  for(int i=1; i<=W; i++){
    if(i<=A) {
      s+='1';
      t+='0';
    } else {
      s+='0';
      t+='1';
    }
  }
  for(int i=1; i<=H; i++) {
    if(i<=B) {
      std::cout << s << std::endl;
    } else {
      std::cout << t << std::endl;
    }
  }
}

int main(){
  long long H;
  scanf("%lld",&H);
  long long W;
  scanf("%lld",&W);
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  solve(H, W, A, B);
  return 0;
}



Measured memory_bytes: 1280
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);
    
    string S;
    cin >> S;
    int tmp = 0;
    LL ans = 0;
    for(int i=0; i<S.size(); i++){//白を左に寄せていく
        if(S[i] == 'W'){
            ans += i-tmp;
            tmp++;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1360
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<62;
const LL INF=1<<17;



int main(){
    int k,n;cin >> n >> k;
    LL ans=LINF;
    vector<LL> h(n);
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    sort(ALL(h));
    for (int i = k-1; i < n; i++) {
        ans=min(h[i]-h[i-k+1],ans);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<set>
#include<iostream>
#include<stdlib.h>
using namespace std;
typedef long long ll;


int main(void) {
	int N;
	int ans = 0;
	cin >> N;
	int* a = (int*)malloc(sizeof(int)*N);
	for (int i = 0;i < N;i++) {
		cin >> a[i];
		ans += (a[i] - 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256