akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        long a = nl();
        long b = nl();
        long x = nl();

        out.println(b / x - a / x + (a % x == 0 ? 1 : 0));
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 8276
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const long long int  mod  = 1000000007;
int main()
{
	int n,pp,ppp;
	ll i;
	cin>>n;
	vector<int> v,a(n),b(n);
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		v.push_back(a[i]);
	}
	for(i=0;i<n;i++)
		cin>>b[i];
	sort(v.begin(),v.end());
	ll k=0;
	do
	{
		int flag=1,smit=1;
		for(i=0;i<n;i++)
		{
			if(v[i]!=a[i])
			{
				flag=0;
				break;
			}
		}
		if(flag==1)
		{
			pp=k;
		}
		for(i=0;i<n;i++)
		{
			if(v[i]!=b[i])
			{
				smit=0;
				break;
			}
		}
		if(smit==1)
		{
			ppp=k;
		}
		k++;
	}while(next_permutation(v.begin(), v.end()));
	cout<<abs(pp-ppp);
}


Measured memory_bytes: 3588
fun main(args:Array<String>){
    var (a,b,c) = readLine()!!.split(" ").map { it.toLong() }

    var bc = Math.min(b,c)
    c -=bc
    var ac = Math.min(c,a)
    c -= ac
    c = if(c>0) 1 else 0

    println(b+bc+ac +c)




}

Measured memory_bytes: 37888
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

ll N,M;
ll inf = 1e9+7;
int main(){
    cin >> N >> M;
    vector<int> S(N+1,0),T(M+1,0);
    for(int i=1;i<=N;i++) cin >> S[i];
    for(int j=1;j<=M;j++) cin >> T[j];
    vector<vector<ll>> dp(N+1,vector<ll>(M+1,0));
    vector<vector<ll>> sum(N+1,vector<ll>(M+1,0));
    dp[0][0] = 1;
    for(int i=0;i<=N;i++){
        for(int j=0;j<=M;j++){
            if(i!=0 && j!=0 && S[i]==T[j]) (dp[i][j] += sum[i-1][j-1])%=inf;
            (sum[i][j] += dp[i][j])%=inf;
            if(j!=0) (sum[i][j] += sum[i][j-1])%=inf;
        }
        if(i!=0) for(int j=0;j<=M;j++) (sum[i][j] += sum[i-1][j])%=inf;
    }
    cout << sum[N][M] << endl;
}

Measured memory_bytes: 62976
import itertools

N = int(input())
ans = 0
for i in range(3, len(str(N))+1) :
    for ptn in itertools.product([3,5,7], repeat = i) :
        if (3 not in ptn) or (5 not in ptn) or (7 not in ptn) :
            continue
        a = int("".join(list(map(str,ptn))))
        if a <= N :
            ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <complex>
using namespace std;

bool overflow;

void checkOverflow(complex<int> a)
{
    if(a.real() < -10000 || a.real() > 10000 || a.imag() < -10000 || a.imag() > 10000)
        overflow = true;
}

complex<int> readSum(string&, int&);

complex<int> readProduct(string& s, int& i)
{
    int n = s.size();

    complex<int> ret(1, 0);
    for(;;){
        complex<int> a;
        if(s[i] == 'i'){
            a = complex<int>(0, 1);
            ++ i;
        }else if('0' <= s[i] && s[i] <= '9'){
            while(i < n && '0' <= s[i] && s[i] <= '9'){
                a *= 10;
                a += s[i] - '0';
                ++ i;
                checkOverflow(a);
            }
        }else{
            ++ i;
            a = readSum(s, i);
            ++ i;
        }
        ret *= a;
        checkOverflow(ret);

        if(i < n && s[i] == '*')
            ++ i;
        else
            return ret;
    }
}

complex<int> readSum(string& s, int& i)
{
    int n = s.size();

    complex<int> ret = complex<int>(0, 0);
    bool add = true;
    for(;;){
        complex<int> a = readProduct(s, i);
        if(add)
            ret += a;
        else
            ret -= a;
        checkOverflow(ret);

        if(i < n && s[i] == '+')
            add = true;
        else if(i < n && s[i] == '-')
            add = false;
        else
            return ret;
        ++ i;
    }
}

int main()
{
    for(;;){
        string s;
        if(!(cin >> s))
            return 0;

        overflow = false;
        int i = 0;
        complex<int> ret = readSum(s, i);

        if(overflow){
            cout << "overflow" << endl;
        }else{
            if(ret.real() != 0 || ret.imag() == 0)
                cout << ret.real();
            if(ret.imag() != 0){
                if(ret.imag() > 0 && ret.real() != 0)
                    cout << '+';
                cout << ret.imag() << 'i';
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 492
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

/*----------------CLASSIC SEGMENT TREE----------------*/
#define oper max
const ll NEUT=0;
struct STree { // [cerrado-abierto)
    vector<ll> st;int n;
    STree(int n): st(4*n+5,NEUT), n(n) {}
    void upd(int k, int s, int e, int p, ll v){
        if(s+1==e){st[k]=v;return;}
        int m=(s+e)/2;
        if(p<m)upd(2*k,s,m,p,v);
        else upd(2*k+1,m,e,p,v);
        st[k]=oper(st[2*k],st[2*k+1]);
    }
    ll query(int k, int s, int e, int a, int b){
        if(s>=b||e<=a)return NEUT;
        if(s>=a&&e<=b)return st[k];
        int m=(s+e)/2;
        return oper(query(2*k,s,m,a,b),query(2*k+1,m,e,a,b));
    }
    void upd(int p, ll v){upd(1,0,n,p,v);}
    ll query(int a, int b){return query(1,0,n,a,b);}
}; // usage: STree st(n);st.upd(i,v);st.query(s,e);

int main(){FIN;
	ll n; cin>>n;
	ll h[n],a[n];
	fore(i,0,n)cin>>h[i],h[i]--;
	fore(i,0,n)cin>>a[i];
	STree st(n);
	fore(i,0,n){
		st.upd(h[i],st.query(0,h[i])+a[i]);
	}
	cout<<st.query(0,n);
	return 0;
}

Measured memory_bytes: 9600
a, b, c, x, y = map(int, input().split(" "))
answer = 0

if c*2 < a + b:
    #ABピザに変更するインセンティブが発生している
    if x > y:
        ab_needed = y
        if a < c*2:
            answer += (x-y)*a
        else:
            answer += (x-y)*2*c
    else:
        ab_needed = x
        if b < c*2:
            answer += (y-x)*b
        else:
            answer += (y-x)*2*c
    answer += ab_needed*2*c
else:
    answer += a*x + b*y

print(answer)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main () {
	string S[] = {"Sunny", "Cloudy", "Rainy"};
	string k;
	cin >> k;
	for (int i = 0; i < 3; i++) {
		if (S[i] == k) cout << S[(i+1)%3] << endl;
	}
}

Measured memory_bytes: 256
def main():
    l, r = map(int, input().split())

    res = 2018
    for i in range(l, r):
        for j in range(l+1, r+1):
            mod = (i*j)%2019
            if mod < res:
                res = mod
            if res == 0:
                break
        else:
            continue
        break
        
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38768
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define int long long
int pr[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47 };
int pk[30]; const int sp = 15;
signed main() {
	int n; cin >> n;
	if (n < 10) {
		cout << "0\n";
		return 0;
	}
	for (int i = 2; i <= n; i++) {
		int p = i;
		for (int j = 0; j < sp; j++) {
			while (p%pr[j] == 0) {
				p /= pr[j];
				pk[j]++;
			}
		}
	}
	int a = 0, b = 0, c = 0, d = 0, e = 0;
	for (int i = 0; i < sp; i++) {
		if (pk[i] >= 2) { a++;
			if (pk[i] >= 4) { b++;
				if (pk[i] >= 14) { c++;
					if (pk[i] >= 24) { d++;
						if (pk[i] >= 74)e++;
					}
				}
			}
		}
	}
	cout << b * (b - 1)*(a - 2)/2 + c * (b - 1) + d * (a - 1) + e << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
using namespace std;

void solve(){
  string s; cin >> s;
  int n = stoi(s);
  int num = 0;
  for(int i = 0; i < s.length(); i++){
    num += (int)s[i] - '0';
  }
  if(n % num == 0) cout << "Yes\n";
  else cout << "No\n";
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
/*input

*/


//assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<ll int,ll int>
#define vpii        vector< pii >
#define vi          vector<ll int>
#define vs			vector< string >
#define vvi         vector< vector< ll > >
#define inf			(ll)1e18
#define all(it,a)   for(auto it=(a).begin();it!=(a).end();it++) 
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define repr(i,a,b) for(ll int i=a;i>b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define whatis(x)   cout << #x << " is " << x << "\n";
#define graph(n)    adj(n,vector< ll > () )
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int solve()
{
	ll n,k;cin>>n>>k;
	vi a(n);
	vi dp(n,inf);
	dp[0]=0;
	rep(i,0,n) cin>>a[i];

	rep(i,1,n) rep(j,1,k+1) if(i-j>=0) dp[i] = min(dp[i-j]+abs(a[i]-a[i-j]),dp[i]); 
	cout<<dp[n-1]<<"\n";
	return 0;
}

int main()
{
	auto start = chrono::high_resolution_clock::now();

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

	ll test_cases=1;
	//cin>>test_cases;
	while(test_cases--)
		solve();

	auto stop = chrono::high_resolution_clock::now();
	auto duration = chrono::duration_cast<chrono::milliseconds>(stop-start);
	// cout<<"\nduration: "<<(double)duration.count()<<" milliseconds";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,ans = 0;
    cin >> n;
    int l[n * 2];
    rep(i, n * 2)cin >> l[i];
    qsort(l, n * 2, sizeof(int), asc);
    for (int i = 0; i < n * 2; i += 2) {
        ans += l[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())

con = [[0]*(N+1) for _ in range(N+1)]
edge = []
for i in range(M):
    a, b = map(int, input().split())
    con[a][b] = con[b][a] = 1
    edge.append((a, b))

def floodfill(listz, comp):
    cnt = 0
    #print('comp = {}'.format(comp))
    while len(listz):
        newlistz = []
        for node in listz:
            compo[node] = comp
            cnt += 1
            #print(node)
            for i in range(1, N+1):
                if visited[i] == 0 and con[node][i] > 0:
                    visited[i] = 1
                    newlistz.append(i)
        listz = newlistz

    return cnt

ans = 0

for kk in range(M):
    a, b = edge[kk]
    con[a][b] = con[b][a] = 0
    #print('cut edge{} {}'.format(a, b))
    visited = [0] * (N + 1)
    compo = [0] * (N + 1)
    compID = 0
    total = 0
    for i in range(1, N+1):
        if visited[i] == 0:
            visited[i] = 1
            count = floodfill([i], compID)
            if count > 0:
                compID += 1
                total += count
                if total >= N:
                    break

    if compID > 1:
        ans += 1
    #return
    con[a][b] = con[b][a] = 1


print(ans)


Measured memory_bytes: 68356
import java.util.*;
public class Main{
    /*
      .0.
      3.1
      .2.
    */
    int[][] dx = {{0,1,0,-1,0},
                  {1,0,-1,0,0},
                  {0,-1,0,1,0},
                  {-1,0,1,0,0}};
    int[][] dy = {{-1,0,1,0,0},
                  {0,1,0,-1,0},
                  {1,0,-1,0,0},
                  {0,-1,0,1,0}};
    int[][][] memo;
    int w;
    int h;
    int[][] s;
    int[] cost;

    void run(){
        Scanner sc = new Scanner(System.in);
        while(true){
        w = sc.nextInt();
        h = sc.nextInt();
        if(w == 0 && h == 0){
            break;
        }
        s = new int[h][w];
        for(int i = 0; i < h; i++){
            for(int ii = 0; ii < w; ii++){
                s[i][ii] = sc.nextInt();
            }
        }
        cost = new int[4];
        for(int i = 0; i < 4; i++){
            cost[i] = sc.nextInt();
        }
        memo = new int[h][w][4];
        for(int i = 0; i < h; i++){
            for(int ii = 0; ii < w; ii++){
                Arrays.fill(memo[i][ii], Integer.MAX_VALUE);
            }
        }
        DFS(0,0,1,0);
        //System.out.println(Arrays.toString(memo[h-1][w-1]));
        int ans = Integer.MAX_VALUE;
        for(int m: memo[h-1][w-1]){
            ans = Math.min(ans, m);
        }
        System.out.println(ans);
        }
    }
    void DFS(int x, int y, int dir, int total_cost){
        if(x < 0 || w <= x || y < 0 || h <= y){
            return;
        }
        if(memo[y][x][dir] <= total_cost){
            return;
        }
        memo[y][x][dir] = total_cost;
        
        //パネルに従う
        int cur = s[y][x];
        DFS(x + dx[dir][cur], y + dy[dir][cur], (dir + cur) % 4, total_cost);
        
        //指示を出す
        for(int command = 0; command < 4; command++){
            DFS(x + dx[dir][command], y + dy[dir][command], (dir + command) % 4, total_cost + cost[command]);
        }
    }   
    public static void main(String[] args){
        new Main().run();
    }
}
    

Measured memory_bytes: 42832
import numpy as np

s = input()
s_list = np.array([1 if s[i] == "p" else 0 for i in range(len(s))])
myhand = np.array([0 if i % 2 == 0 else 1 for i in range(len(s))])
print(np.sum(myhand - s_list))


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

int main() {
	int n, c, k;
	cin >> n >> c >> k;
	vector<int> t(n);
	for (auto &e : t) {
		cin >> e;
	}
	sort(begin(t), end(t));
	int m = 0, a = 0, b = 0;
	for (auto e : t) {
		if (m == 0 || c <= a || b + k < e) {
			m++;
			a = 1;
			b = e;
		} else {
			a++;
		}
	}
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long X;
int main(){
	cin >> X;
	long long num = 2;
	for(int i = 0; i < X; i++){
		num = 1 + num + num + 1;
	}
	cout << num << endl;
}



Measured memory_bytes: 256
N, M = map(int, input().split())
v = [set() for _ in range(N)]
for _ in range(M) :
    A, B = map(int, input().split())
    v[A-1].add(B-1)
    v[B-1].add(A-1)
    
visited = [[False] * N for _ in range(2)]
visited[0][0] = True

q = [(0, 0)]
while q :
    parity, cur = q.pop()
    parity ^= 1
    for nex in v[cur] :
        if visited[parity][nex] :
            continue
        visited[parity][nex] = True
        q.append((parity, nex))

o, e = 0, 0
for i in range(N) :
    if visited[0][i] and not visited[1][i] :
        e += 1
    elif not visited[0][i] and visited[1][i] :
        o += 1

print((N * (N - 1) - o * (o - 1) - e * (e - 1)) // 2 - M)

Measured memory_bytes: 77164
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

const long long int INF=99999999999999,inf=199999;
const long long int mod=1000000007;

long long int n,dp[200000]={},a[200000],mymax=1;
string str[2000];


int main() {
    int count=0;
    map<long long int,long long int>mp;
	cout << fixed << setprecision(10);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    dp[n]=a[1];
    for(int i=1;i<=n-1;i++){
        dp[i]=INF;
    }
    dp[n+1]=INF;
    for(int i=2;i<=n;i++){
        long long int ng=n-mymax,ok=n+1,mid;
        while(ok-ng>1){
            mid=(ok+ng)/2;
            if(dp[mid]<a[i]){
                ng=mid;
            }else{
                ok=mid;
            }
            //cout<<i<<" "<<ok<<" "<<ng<<endl;;
        }
        if(ng==n-mymax){
            //cout<<i;
            dp[n-mymax]=a[i];
            mymax++;
            
        }else{
            dp[ng]=a[i];
        }

    }
    cout<<mymax;
} 


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(){
  int n ,x, y,max;
  cin >> x;
  cin >> y;
  cin >> n;
  if(x > y){
    max = x;
  }else{
    max = y;
  }
  for(int i=1;i<=max;i++){
    if(i*max >= n){
      cout << i;
      break;
    }
  }
  return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long i=0; i<=(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
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; }

bool isprime(long long int val) {
 if (val <= 1)return false;
 for (long long int i = 2; i*i <= val; i++) {
   if (val%i == 0LL)return false;
 }
 return true;//素数
}

int main(int argc, char const *argv[]) {
  vector<ll> cnt(10000001,1);
  ll n;
  cin >> n;
  for(ll i=2;i<=n;i++){ 
    for (ll j = i; j <= n; j+=i){
      cnt[j]++;
    }
  }
  ll ans = 0;
  for(ll i=0;i<=n;i++) ans += i * cnt[i];
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 81200
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> v(n);

    for (int i = 0, in; i < n && cin >> in; ++i)
        v[i] = in;

    int ans {};

    for (int i = 0; i < n; ++i)
    {
        if (v[i] == i + 1)
        {
            if (i != (n - 1))
                swap(v[i], v[i + 1]);
            else
                swap(v[i], v[i - 1]);

            ++ans;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define  FIFO ios::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define  inf 2e18
#define  mod 1000000007
#define  bg begin()
#define  en end()
#define  ll long long int
#define  pb push_back
#define  mp make_pair
#define  pii pair<int,int>
#define  pll pair<ll,ll>
#define  vi vector<int>
#define  vll vector<long long int>
#define  vpll vector<pair<long long int,long long int> >
#define  vpii vector<pair<int,int> >
#define  vstr vector<string>
#define  mpii map<int ,int>
#define  mpll map<long long int,long long int >
#define  max3(a,b,ser) max(a,max(b,ser))
#define  min3(a,b,ser) min(a,min(b,ser))
#define  setbits(x)  __builtin_popcountll(x)
#define  zerobits(x) __builtin_ctzll(x) //zeros after rightmost set bit
#define  w(t) ll t; cin>>t; while(t--)
#define  vin(v,m) for(int i=0;i<m;i++){ll x;cin>>x; v.pb(x);}
#define  for0(i,m) for(int i=0;i<m;i++)
#define  for1(i,m) for(int i=1;i<=m;i++)
#define  forn(i,a,b) for(int i=a;i<=b;i++)
#define  forv(it,v) for(auto it=v.begin();it!=v.end();it++)
#define  mem(a,val) memset(a,val,sizeof(a))
#define  Sort(vec) sort(vec.begin(),vec.end())
#define  RSort(vec) sort(vec.rbegin(),vec.rend())
#define  eb emplace_back
#define  bs binary_search
#define  lb(v,a) lower_bound(v.begin(),v.end(),a)
#define  ub(v,a) upper_bound(v.begin(),v.end(),a)
#define  deb1(x) cerr<<#x<<": "<<x<<" "<<endl
#define  deb2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define  deb3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define  deb4(a, b, ser, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#ser<<": "<<ser<<" | "<<#d<<": "<<d<<endl
#define  FF first
#define  SS second
#define  yes "YES"
#define  no "NO"
#define  PI 3.141592653589793238462643383279502884L
#define  printv(v) for(auto it=v.bg;it!=v.en;it++) cout<<*it<<" "<<endl;
// find_by_order(p)  returns iterator to kth element starting from 0;
// order_of_key(p) returns count of elements strictly smaller than p;
//order of key returns the index if the element was present.
template <typename T>
using orderedset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll Ceil(ll a, ll b) {return a / b + (a % b != 0);}
ll fastModExp(ll a, ll b) { ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
ll Logn(ll m, ll r) {return (m > r - 1) ? 1 + Logn(m / r, r) : 0;}
// 2- Dimensional vector:- vector<vector<int> > v(m, vector<int> (26, 0));
// Add mod when using mod(avoid -)
int n, m, k, s = 0;
map<pii, int> mpx;
bool vis[10000][10000];
vector<vector<string> > v;
int cnt = 0;


int main()
{
    ll n;
    cin >> n;
    vll v;
    vin(v, n);
    ll cnt = 0;
    for0(i, n)
    {
        if ((i + 1) % 2 == 1 && v[i] % 2 == 1)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3632
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

template<typename T>
void print_old(vector<T>vec){
    for(int i=0; i< vec.size(); i++)
      cout<< vec[i]<<" ";
}
//  prints any type which supports iterators...
template <class T>
void print(T& c){
   for( typename T::iterator i = c.begin(); i != c.end(); i++ ){
      std::cout << *i << " ";
   }
   cout<< "\n";
}
// void f(const vector< int >& v) {
// int r = 0;
// tr(v, it) {
// r += (it)(*it);
// }
// return r;
// }
typedef vector< int > vi;
typedef pair< int,int > pii;
typedef vector<string> vs;
typedef vector<vi> vv;
#define sz(a) int((a).size())
#define pb push_back
#define forn(n) for(int i =0 ; i< n; i++)
#define all(c) c.begin(), c.end()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define ll long long


// you cannot assign memory in stack for cost using arrays...better to 
// use vector or use heap array...
int main(){
    fastio;
  
    int t = 1;
    while(t--){
       int n;
       
       int temp;
       scanf("%d", &n);
    //    cin >> n;
       vector<int> vec;
       vector<int> cost(n, 0);
       for(int i = 0; i < n; i++){
        //    cin >> temp;
           scanf("%d", &temp);
           vec.pb(temp);
       }
       cost[0] = 0;
       cost[1] = abs(vec[1]-vec[0]);
       for(int i = 2; i< n; i++){
       cost[i] = min(cost[i-2] + abs(vec[i]-vec[i-2]), cost[i-1] + abs(vec[i] - vec[i-1])); 
       }
      printf("%d\n" , cost[n-1]);
    // cout << cost[n-1];
    }
    return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
long long ans;
int a,b,n;
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        ans+=b-a+1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string S;
  cin >> S;
  bool l = false, r = false;
  if (S[0] == '0') {
    if (S[1] != '0') l = true;
  }
  else if (S[0] == '1') {
    if (S[1] == '0' || S[1] == '1' || S[1] == '2') l = true;
  }
  if (S[2] == '0') {
    if (S[3] != '0') r = true;
  }
  else if (S[2] == '1') {
    if (S[3] == '0' || S[3] == '1' || S[3] == '2') r = true;
  }
  if (l) {
    if (r) cout << "AMBIGUOUS" << endl;
    else cout << "MMYY" << endl;
  }
  else {
    if (r) cout << "YYMM" << endl;
    else cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 3040
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vll vector<ll>
#define vi vector<int>
#define vvll vector<vll>
#define wh(t) while(t--)
#define fi(n) for(ll i = 0; i < n; i++)
#define fj(n) for(ll j = 0; j < n; j++)
#define fu(i,s,e) for(ll i = s; i <=e; i++)
#define fd(i,s,e) for(ll i = s; i >=e; i--)
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define fr first
#define se second
#define sll stack<ll>
#define qll queue<ll>
using namespace std;
const ll M = 1e9+7;
//const ll M = 998244353;

ll pmp(ll x,ll n){ll a = 1;while(n > 0){if(n & 1) a = (a * x)%M;x = (x * x)%M;n = n>>1;}return a;}

void solve(){
	ll n;
	cin >> n;
	vll a(n);
	fi(n) cin >> a[i];
	ll ans = 0;
	ll mx = a[0];
	fi(n){
		ans+=max(0LL,mx-a[i]);
		mx = max(mx,a[i]);
	}
	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	#endif
	ll t;
	t = 1;
	// cin >> t;
	wh(t){
		solve();
	}
	cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
	return 0;
}

Measured memory_bytes: 4716
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int m,n,cnt=1,aa[220000];
pair<int,int> pp[220000];
string s,ss[220000];
char c;
double d;
queue<int> que;
signed main(){
    cin>>n>>s;
    cout<<((s[0]-48)*n*10+(s[2]-48)*n+(s[3]-48)*n/10)/10;
}

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

using namespace std;

int N;
int A[54];
int B[54], C[54];

int main(){
    scanf("%d", &N);
    for(int i = 1; i <= N; ++i) scanf("%d", A + i);
    for(int i = 1; i <= N; ++i) scanf("%d", B + i);
    for(int i = 1; i < N; ++i) scanf("%d", C + i);
    int ans = 0;
    for(int i = 1; i <= N; ++i){
        ans += B[A[i]];
        if(i < N && A[i] + 1 == A[i + 1]){
            ans += C[A[i]];
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
# 横チェック
def yoko(bingo,b):
    i,j = 0,0
    isbingo = False
    for i in [0,1,2]:
        for j in [0,1,2]:
            if bingo[i][j] in b:
                if j==2:
                    return True
            else:
                break
    return False

def tate(bingo,b):
    i,j = 0,0
    isbingo = False
    for j in [0,1,2]:
        for i in [0,1,2]:
            if bingo[i][j] in b:
                if i==2:
                    return True
            else:
                break
    return False

def naname(bingo,b):
    i,j = 0,0
    isbingo = False
    for i,j in zip([0,1,2],[0,1,2]):
        if bingo[i][j] in b:
            if i==2:
                return True
        else:
            break
    for i,j in zip([0,1,2],[2,1,0]):
        if bingo[i][j] in b:
            if i==2:
                return True
        else:
        	break
    return False

row1 = list(map(int, input().split()))
row2 = list(map(int, input().split()))
row3 = list(map(int, input().split()))
n = int(input())
i = 0
b = []
while(i < n):
  b.append(int(input()))
  i += 1

bingo = []
bingo.append(row1)
bingo.append(row2)
bingo.append(row3)
if (tate(bingo,b))|(yoko(bingo,b))|(naname(bingo,b)):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <stdio.h>

int main() {
  int i, j, number_k, sum, count = 0;
  scanf("%d %d", &number_k, &sum);
  for(i = 0; i <= number_k; i++) {
    for(j = 0; j <= number_k; j++) {
      if(0 <= sum - (i + j) && sum - (i + j) <= number_k) {
        count++;
      }
    }
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 128
//問3　2717 佐久間 翼
import java.util.Scanner;
public class Main{
    
    public void solve(){
        Scanner sc = new Scanner(System.in);
        int kaisu=1;
        int ichi=0;
        int N=sc.nextInt();
        while(N!=0){
        for(int cnt=0;cnt<N;cnt++){
            int k=sc.nextInt();
            if(k>=2){
                kaisu++;
            }else if(k==1){
                ichi++;
            }
        }
        if(kaisu>=2){
            System.out.println(kaisu+ichi);
        }else{
            System.out.println("NA");
        }
        kaisu=1;
        ichi=0;
        N=sc.nextInt();
            
    }
    }
            
    public static void main(String[]args){
        Main obj = new Main();
        obj.solve();
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll n;
ll a[e5];
ll dp[e5];
ll mem[e5];
ll b;
ll c;
ll pre[e5];
ll zero[e5];
ll d[e5];
ll dp0[e5];
ll dpx[e5];

int main(){
  cin >> n;
  for(ll i = 1;i <= n;i++) cin >> a[i];
  dp[0] = 1;
  for(ll i = 1;i <= n;i++){
    b = b^a[i];
  }
  if(b != 0){
    mem[0] = dp[0];
    for(ll i = 1;i <= n;i++){
      c = c^a[i];
      dp[i] = mem[c^b];
      mem[c] += dp[i];
      mem[c] %= mod;
    }
    cout << dp[n] << endl;
  }else{
    mem[0] = dp[0];
    for(ll i = 1;i <= n;i++){
      c = c^a[i];
      dp[i] = mem[c^b];
      mem[c] += dp[i];
      mem[c] %= mod;
    }
    for(ll i = 1;i <= n;i++){
      b = b^a[i];
      d[i] = b;
      if(b == 0) zero[i]++;
    }
    for(ll i = 1;i <= n;i++){
      zero[i] += zero[i-1];
    }
    fill(dp0,dp0+e5,1ll);
    for(ll i = 1;i <= n;i++){
      if(d[i] != 0){
        dp0[d[i]] += dpx[d[i]]*(zero[i]-zero[pre[d[i]]]);
        dpx[d[i]] += dp0[d[i]];
        dp0[d[i]] %= mod;
        dpx[d[i]] %= mod;
        pre[d[i]] = i;
      }
    }
    ll ans = 0;
    for(ll i = 0;i < e5;i++){
      ans += dpx[i];
      ans %= mod;
    }
    cout << (dp[n] + ans)%mod << endl;
  }


}


Measured memory_bytes: 49408
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F first
#define S second
#define mod 1000000007
#define pb push_back
#define FOR(i,a,n) for(ll i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define UB upper_bound
#define LB lower_bound
const int NUM = 2e5 + 5;

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int num_tests=1; 
    //cin>>num_tests;
    while(num_tests-->0){
        int a; cin >> a;
        cout << a*(1 + a + a*a);
    }   
}

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
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; }
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;







int main() {
	VI v(4, 0);

	REP(i, 3) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		v[a]++;
		v[b]++;
	}
	sort(ALL(v));
	if (v[0] == v[1] && v[1] == 1 && v[2] == v[3] && v[2] == 2) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
	
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    if (N==1) {
        cout << "Yes";
    } {
        
        int H[N];
        for (int i=0; i<N; i++) {
            cin >> H[i];
        }

        int prebious, target, following = 0;
        prebious = H[0];
        target = H[1];
        following = H[2];

        for (int i=1; i<(N-1); i++) {
            following = H[i+1];
            if (0 < (prebious - target)) {
                cout << "No";
                break;
            } else if (0 > (prebious - target)) {
                target -= 1;
            }
            if (0 < (target - following)) {
                cout << "No";
                break;
            }

            prebious = target;
            target = following;

            if (i == (N-1-1)) {
                cout << "Yes";
            }

        }    

    }


    return 0;
}

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

int main() {
	int x, y;
	scanf("%d %d", &x, &y);
	for(int i = 0;i <= x;i++){
		if((i * 2) + ((x - i) * 4) == y){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
#define re register int
#define F(x,y,z) for(re x=y;x<=z;x++)
#define FOR(x,y,z) for(re x=y;x>=z;x--)
typedef long long ll;
#define I inline void
#define IN inline int
template<class D>I read(D &res){
	res=0;register D g=1;register char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-')g=-1;
		ch=getchar();
	}
	while(isdigit(ch)){
		res=(res<<3)+(res<<1)+(ch^48);
		ch=getchar();
	}
	res*=g;
}
const int INF=1e9+7;
int n,m,cnt,a[20],b[20],c[20],now[60][2],ans,p[20];
vector<int>q[60][2];
IN solve(){
	int r=0;
	F(i,1,n-1){
		F(j,i+1,n)if(p[i]>p[j])r++;
	}
	return r;
}
int main(){
	read(n);ans=INF;
	F(i,1,n)read(a[i]);
	F(i,1,n)read(b[i]);
	F(i,0,(1<<n)-1){
		cnt=0;
		F(j,0,n-1){
			if((i>>j)&1)c[j+1]=b[j+1];
			else c[j+1]=a[j+1];
		}
		if(cnt&1)continue;
		//F(j,1,n)cout<<c[j]<<" ";
		//cout<<endl;
		sort(c+1,c+1+n);
		F(j,1,n)q[c[j]][j&1].emplace_back(j);
		cnt=0;
		F(j,1,n){
			if((i>>(j-1))&1){
				if(now[b[j]][(j&1)^1]>=q[b[j]][(j&1)^1].size()){
					cnt=-1;break;
				}
				p[j]=q[b[j]][(j&1)^1][now[b[j]][(j&1)^1]],now[b[j]][(j&1)^1]++;
			}
			else{
				if(now[a[j]][(j&1)]>=q[a[j]][(j&1)].size()){
					cnt=-1;break;
				}
				p[j]=q[a[j]][(j&1)][now[a[j]][(j&1)]],now[a[j]][(j&1)]++;
			}
		}
		
		//if(cnt!=-1)cout<<i<<" "<<cnt<<endl;
		if(cnt!=-1)ans=min(ans,solve());
		F(j,1,n)q[c[j]][j&1].clear(),now[c[j]][j&1]=0;
	}
	if(ans==INF)cout<<"-1";
	else cout<<ans;
	return 0;
}


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

int main(){
    int A,B,C;
    scanf("%d%d%d",&A,&B,&C);
    if(A%2==0||B%2==0||C%2==0)
        puts("0");
    else
        printf("%lld",min(1ll*A*B,min(1ll*B*C,1ll*A*C)));
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    static long steps[];
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        boolean maps[][] = new boolean[H][W];
        for(int h=0; h<H; h++) {
            String tmp = sc.next();
            for(int w=0; w<W; w++) {
                switch(tmp.charAt(w)) {
                    case '#':
                        maps[h][w] = false;
                        break;
                    case '.':
                        maps[h][w] = true;
                        break;
                }
            }
        }
        int [][] horizontal = new int[H][W];
        // horizontal
        for(int h=0; h<H; h++) {
            int tmpCount = 0;
            int beginIndex = -1;
            for(int w=0; w<W; w++) {
                if(maps[h][w]) {
                    tmpCount++;
                    if(beginIndex==-1) beginIndex = w;
                    if(w==W-1) {
                        for(int i=beginIndex; i<=w; i++) {
                            horizontal[h][i] = tmpCount;
                        }
                    }
                } else {
                    if(beginIndex==-1) continue;
                    // flush buffer
                    for(int i=beginIndex; i<=w-1; i++) {
                        horizontal[h][i] = tmpCount;
                    }
                    beginIndex=-1;
                    tmpCount=0;
                }
            }
        }

        int [][] vertical = new int[H][W];
        // vertical
        for(int w=0; w<W; w++) {
            int tmpCount = 0;
            int beginIndex = -1;
            for(int h=0; h<H; h++) {
                if(maps[h][w]) {
                    tmpCount++;
                    if(beginIndex==-1) beginIndex = h;
                    if(h==H-1) {
                        for(int i=beginIndex; i<=h; i++) {
                            vertical[i][w] = tmpCount;
                        }
                    }
                } else {
                    if(beginIndex==-1) continue;
                    // flush buffer
                    for(int i=beginIndex; i<=h-1; i++) {
                        vertical[i][w] = tmpCount;
                    }
                    beginIndex=-1;
                    tmpCount=0;
                }
            }
        }
/*
        dump(horizontal, H, W);
        System.out.println();
        dump(vertical, H, W);
*/
        int result = 0;
        for(int h=0; h<H; h++) {
            for(int w=0; w<W; w++) {
                if(result < horizontal[h][w] + vertical[h][w] - 1) {
                    result = horizontal[h][w] + vertical[h][w] - 1;
                }
            }
        }

        System.out.println(result);
    }

    static void dump(int[][] data, int height, int width) {
        for(int h=0; h<height; h++) {
            for(int w=0; w<width; w++) {
                System.out.print(data[h][w] + " ");
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 84228
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(),(v).end())
#define RSORT(v) sort((v).rbegin(),(v).rend())
const ll MOD = 1000000007;

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}



void solve(long long X){
    ll sum = 0;
    ll i = 0;
    while(sum < abs(X)){
        i++;
        sum += i;
    }
    cout << i << endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int> dp(200000,INF);
	dp[0]=0;
	rep(i,n){
		if(dp[i]==INF) continue;
		chmin(dp[i+1],dp[i]+1);
		int now=6;
		while(i+now<=n){
			chmin(dp[i+now],dp[i]+1);
			now*=6;
		}
		now=9;
		while(i+now<=n){
			chmin(dp[i+now],dp[i]+1);
			now*=9;
		}
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
 int $(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
signed main(){
  int a,b,e=10000000000,d,f,g=0;
  cin>>a>>b;
  vector<int> c(a);
  fo(i,a)
  c.at(i)=i+b;
  for(int i=0;i<a;i++){
    d=abs(c.at(i));
    if(e>d){
      e=d;
      f=i;
    }
  }
fo(i,a)
g+=c.at(i);
cout<<g-c.at(f)<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
				
		int[][] p = new int[1000][2];
		int index = 0;
		while( n != 0 ){
			int[] a = new int[n];    // Point of A
			int[] b = new int[n];    // Point of B
			for(int i = 0; i < n; i++){
				a[i] = stdIn.nextInt();
				b[i] = stdIn.nextInt();
				if( a[i] > b[i] ){
					p[index][0] += (a[i] + b[i]);
				} else if( a[i] < b[i] ){
					p[index][1] += (a[i] + b[i]);
				} else {
					p[index][0] += a[i];
					p[index][1] += b[i];
				}
			}
			index++;
			n = stdIn.nextInt();			
		}
		
		for(int i = 0; i < index; i++){
			System.out.println(p[i][0] + " " + p[i][1]);
		}
	}
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

typedef ll V;
typedef pair<V, V> pVV;
const V INF_V = LLONG_MAX;
const int ME = 18;
const int N = 1<<ME;
class RMQ_segtree{
public:
    pVV dat[2*N-1];
    RMQ_segtree(){
        REP(i, 2*N-1) dat[i] = make_pair(INF_V, -1);
    }

    void update(int k, V a){
        //k番目の要素をaに変更
        k += N-1;
        dat[k] = make_pair(a, k-(N-1));
        while(k>0){
            k = (k-1)/2;
            dat[k] = min(dat[2*k+1], dat[2*k+2]);
        }
    }

   pVV recursion(int a, int b, int k, int l, int r){
        //最小値計算用の再帰関数
        if(r<=a || b<=l) return make_pair(INF_V, -1);
        if(a<=l && r<=b) return dat[k];
        else{
            pVV vl = recursion(a, b, 2*k+1, l, (l+r)/2);
            pVV vr = recursion(a, b, 2*k+2, (l+r)/2, r);
            return min(vl, vr);
        }
    }

    pVV minimum(int a, int b){
        //区間[a, b)の最小値
        return recursion(a, b, 0, 0, N);
    }

    void print_val(int a, int b){
        //区間[a, b)の値を出力
        for(int i=a;i<b;i++) cout << dat[i+N-1].first << endl;
        cout << endl;
    }
};


int main(){
	ll N;
	cin >> N;
	vector<ll> h(N), a(N);
	REP(i, N) cin >> h[i];
	REP(i, N) cin >> a[i];

	vector<pll> x(N);
	REP(i, N) x[i].first=h[i], x[i].second=i;
	sort(x.begin(), x.end());
	RMQ_segtree rs;
	REP(i, N){
		ll tmp;
		if(x[i].second==0) tmp = 0;
		else tmp = -rs.minimum(0, x[i].second).first;
		if(tmp==-INF_V) tmp = 0;
		rs.update(x[i].second, -tmp-a[x[i].second]);
	}
	ll res = -1;
	REP(i, N) res = max(res, -rs.minimum(i, i+1).first);
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 14720
//
//  main.cpp
//  AizuOnlineJudge
//
//  Created by TomoyaYamaguchi on 2016/08/05.
//  Copyright ?? 2016??´ TomoyaYamaguchi. All rights reserved.
//

#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            cout << i << "x" << j << "=" << i*j << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1116
#include "bits/stdc++.h"
#include <math.h>
#include <time.h>
using namespace std;
const long long mod = 1000000007;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
bool dbg = false;
long long gcd(long long a, long long b){
   if (a % b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a % b));
   }
}
long long lcm(long long a, long long b){
   return (a / gcd(a, b))* b;
}
//---------------------------------------------------------------------------------------------------
/*ここからいじる*/
//---------------------------------------------------------------------------------------------------

void solve(){
}
int main(){
    int n;
    cin >> n;
    int num;
    vector<int>pn(n);
    for(int i = 0; i < n; i++){
        cin >> pn.at(i);
    }
    num = pn.at(0);
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(pn.at(i) <= num){
            ans++;
        }
        num = min(num, pn.at(i));
    }
    cout << ans << endl;
    solve();
    return 0;
}



Measured memory_bytes: 1024