akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define rip return
#define fo(i,a,b) for(int i = a ; a < b ? i <= b : i >= b ; i += (a < b ? 1 : -1))
#define pb push_back
#define F first
#define S second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using pii = pair <int, int>;
using pll = pair <ll, ll>;
using ld = long double;
// mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

// const int mod = 1e9 + 7;
const int mod = 998244353;
const ll inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-7;

const int N = 1e5 + 5;

int a[N];

int d[N];

void solve () {
	int n;
	cin >> n;
	for (int i = 1 ; i <= n ; ++ i) {
		cin >> a[i];
	}
	queue <int> q;
	q.push (1);
	d[1] = 1;
	while (q.size()) {
		int v = q.front(); q.pop();
		if (!d[a[v]]) {
			d[a[v]] = d[v] + 1;
			q.push (a[v]);
		}
	}
	cout << (d[2] ? d[2] - 1 : -1);
}


int main () {
	ios;
	// double start_time = clock();
	// cout << fixed << setprecision (10);
	int tt = 1;
	// cin >> tt;
	while (tt--) {
		solve();
		cout << "\n";
	}
	// cerr << (clock() - start_time) / CLOCKS_PER_SEC;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(25) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define printdb(a) printf("%.50lf\n", a)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main(){
  lli A,B,C,D,E,F,N,M,K,L,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> K;
  Vec(P,double,N,0);
  rep(i,0,N)cin >> P[i];
  rep(i,0,N)P[i]=(P[i]+1)/2;
  Vec(Q,double,N,0);
  Vec(R,double,0,0);
  Q[0]=P[0];
  rep(i,1,N)Q[i]=Q[i-1]+P[i];
  R.pb(Q[K-1]);
  rep(i,K,N)R.pb(Q[i]-Q[i-K]);
  Sort(R);
  printdb(R[N-K]);
}


Measured memory_bytes: 5492
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define fs first
#define sc second
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<tuple<ll,ll>> vtl;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
#define pf(a) cout << (a) << endl;
#define be(x) (x).begin(),(x).end()

void solve(){
    int n;
    cin>>n;
    if((n/100)*5<(n%100))cout<<0<<endl;
    else cout<<1<<endl;
}

int main(){
    cout<<std::fixed<<std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 256
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 0030
public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N, S, ans;
	public static void main(String[] args) {
		while (true) {
			N = sc.nextInt(); S = sc.nextInt();
			if (N == 0 && S == 0) break;
			ans = 0;
			rec(0, N, 0);
			System.out.println(ans);
		}
	}
	
	static void rec(int i, int n, int sum) {
		if (n == 0) {
			if (sum == S) ans++;
			return;
		}
		
		if (i > 9) return;
		for (int j = i; j <= 9; j++) {
			rec(j + 1, n - 1, sum + j);
		}
	}
}

Measured memory_bytes: 11000
N = int(input())
a = []
for i in range(N):
    a.append(int(input()))
b = [0] * N # 通ったかの判定用

i = 1
cnt = 0
while i != 2 and b[i - 1] == 0: # iが2ではない、もしくは通ったことのないルートのとき
    index = i - 1 # 配列の添え字に変換
    b[index] = 1
    i = a[index]
    cnt += 1

if i == 2:
    re = cnt
else:
    re = -1

print(re)

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

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

int main(void)
{
    int i,c[26],co = 0;
    char a[26];
    scanf("%s",a);
    for (i = 0; i < strlen(a); i++) {
        c[i] = a[i];
    }
    qsort(c, strlen(a), sizeof(int), compare);
    for (i = 0; i < strlen(a); i++) {
        if (c[i] == c[i+1]) {
            co = -1;
            break;
        }else{
            co = 1;
        }
    }
    if (co < 0) {
        printf("no\n");
    }else{
        printf("yes\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;
// auto mod int
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod; return *this;}
  mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod; return *this;}
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

bool f(int a,int b, int c){
  return !(a==0&&b==2&&c==1);
}
bool f(int a,int b, int c,int d){
  return f(b,c,d)
      && f(a,c,d)
      && f(c,b,d)
      && f(b,d,c)
      && f(a,b,d);
}

int main() {
  int n;
  cin >> n;
  mint dp[4][4][4];
  rep(i,4)rep(j,4)rep(k,4){
    if(f(i,j,k) && f(j,i,k) && f(i,k,j)) dp[i][j][k] = 1;
  }
  rep(ni,n-3){
    mint temp[4][4][4];
    rep(i,4)rep(j,4)rep(k,4)rep(l,4){
      if(f(i,j,k,l)) temp[j][k][l] += dp[i][j][k];
    }
    swap(dp,temp);
  }
  mint ans;
  rep(i,4)rep(j,4)rep(k,4) ans += dp[i][j][k];
  cout << ans << endl;
}

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

using namespace std;

int n;
int h[100001],h1[100001];
int cnt1,cnt2;

int main()
{
	//TODO make some code
	ios_base::sync_with_stdio(0);
	cin>>n;
	for (int i=0;i<n;++i)
    {
        cin>>h[i];
        //h1[i]=h[i];
    }
	for (int i=0;i<n-1;++i)
    {
        if (h[i]==i+1)
        {
            ++cnt1;
            swap(h[i],h[i+1]);
        }
    }
    if (h[n-1]==n) ++cnt1;
    /*for (int i=n-1;i>0;--i)
    {
        if (h1[i]==i+1)
        {
            ++cnt2;
            swap(h1[i],h1[i+1]);
        }
    }
    if (h1[0]==1) cnt2=10000001;*/
    cout<</*min(*/cnt1/*,cnt2)*/<<endl;
}


Measured memory_bytes: 640
// abc124_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    string S;
    cin >> S;
    int n = S.size();

    int a = 0, b = 0;
    REP(i, n){
        if (S[i] == ('0' + (char)(i & 1))) {
            a++;
        } else {
            b++;
        }
    }

    print(min(a, b));

    return 0;
}


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


int n,m;
vector <int> a,b,c,p,st;

int main() {


 cin >> n >> m;

 p.resize(m+1);
 for(int i=1;i<=m;i++) cin >> p[i];

 a.resize(n+1);
 b.resize(n+1);
 c.resize(n+1);

 for(int i=1;i<=n-1;i++) cin >> a[i] >> b[i] >> c[i];

 st.resize(n+1);
 for(int i=0;i<=n;i++) st[i] = 0;

 int mint,t;

 for(int i=1;i<m;i++) {
   mint = min(p[i],p[i+1]);
   t = max(p[i],p[i+1]); 
   st[mint]++;
   st[t]--;

 }

 for(int i=2;i<n;i++)st[i] += st[i-1];

 long long sum = 0;

 for(int i=1;i<n;i++){
   sum += min((long long)a[i]*st[i],c[i]+(long long)b[i]*st[i]);
 }

 cout << sum << endl;

 return 0;

}

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  int N,M; cin >> N >> M;

  vector<int> L(M), R(M);
  for(int i = 0; i < M; i++){
    cin >> L[i] >> R[i];
  }
  sort(L.begin(), L.end());
  sort(R.begin(), R.end());

  int ans = R[0] - L[M-1];

  cout << (ans < 0 ? 0 : ans + 1) << endl;

}


Measured memory_bytes: 3924
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef string str;
typedef std::pair<ll,ll> pl;
typedef std::map<string, ll> msl;
typedef std::map<ll, ll> mll;
typedef std::vector<ll> vl;
typedef std::vector<pl> vpl;
const long double EPS = 1e-9;

#define rep(i, n) for(ll (i) = 0; (i) < (n) ; (i)++ )
#define For(i, a, b) for(ll (i) = (a); (i) < (b) ; (i)++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tol(c) char((c)+0x20)
#define tou(c) char((c)-0x20)
#define pb push_back
#define mp make_pair
#define pr(a) cout << (a)
#define prl(a) cout << (a) << endl
#define prl2(a,b) cout << (a) << " " << (b) << endl
#define prs(a) cout << (a) << " "
#define yn(condition) if ((condition)) prl("Yes"); else prl("No");
#define YN(condition) if ((condition)) prl("YES"); else prl("NO");
#define rpr(i,n,ans) rep((i),(n)) prs((ans[(i)]))
#define cpr(i,n,ans) rep((i),(n)) prl((ans[(i)]))
#define in1(a) cin >> (a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define rin1(i,n,a) rep((i),(n)) cin >> (a[(i)])
#define rin2(i,n,a,b) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)])
#define rin3(i,n,a,b,c) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)]) >> (c[(i)])
#define e1 first
#define e2 second
#define ctol(c) ll((c)) - ll('0')
#define ltos(n) to_string((n))
#define items(kv, v) for(auto &(kv): (v))
#define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)]))
#define beto(a,b,c) (a) < (b) && (b) < (c)
#define betc(a,b,c) (a) <= (b) && (b) <= (c) 
#define rsort(a,n) sort(a,a+n,greater<>())
#define Forchar(c,a,z) for(char (c) = (a); (c) <= (z); (c)++) 
#define cntchar(s,c) count(all((s)), c)

const ll mod = 1e9 + 7;
const ll INF = mod * mod;
const ll MAX_N = 100000;

int main(void){
    ll a, b;
    str s,t;
 
    in1(s);
    pr(s[0]);
    pr(s.length()-2);
    prl(s[s.length()-1]);
 
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
pair<long long,long long> p[200010];
long long val[200010];
bool flag[200010];
int main(){
    int i,n;
    long long d,a,ans = 0;
    cin >> n >> d >> a;
    for(i=0;i<n;i++){
        long long x,h; cin >> x >> h;
        p[i] = {x,h};
        flag[i] = true;
    }
    sort(p,p + n);
    int j,k = -1;
    for(i=0;i<n;i++){
        if(val[i]>=p[i].second){
            val[i + 1] += val[i];
            continue;
        }
        while(k<n - 1 && p[k + 1].first<=p[i].first + 2*d){
            k++;
        }
        long long t = ((p[i].second - val[i]) + a - 1)/a;
        val[i] += t*a;
        val[k + 1] -= t*a;
        val[i + 1] += val[i];
        ans += t;
    }
    cout << ans << endl;
}

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


int main(){
	int t=0,h=0;
	
	int x,y,z;
	while(scanf("%d,%d,%d",&x,&y,&z)!=EOF){
		if(x*x+y*y==z*z){
			t++;
		}
		if(x==y){
			h++;
		}
	}
	cout<<t<<endl<<h<<endl;
	
	return 0;
}
  

Measured memory_bytes: 1208
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO 自動生成されたメソッド・スタブ
        int[] x = new int[10000];
        int k=0;
        Scanner scanner = new Scanner(System.in);
        for(int i=0;i<x.length;i++){
            x[i] = scanner.nextInt();
            if(x[i]==0){
                break;
            }
            k++;
        }
        for(int j=0;j<k;j++){
            System.out.println("Case "+(j+1)+": "+x[j]);

        }


    }
}



Measured memory_bytes: 42396
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let s: String = read();
    let mut nv: Vec<u32> = s.chars().map(|c| c as u32 - '0' as u32).collect();
    nv.reverse();

    let mut ans = 0;

    let mut up = 0;

    for i in 0..nv.len() {
        let n = nv[i];

        if n == 5 {
            if up == 0 {
                up = 2;
                ans += 5;
            } else {
                up = 1;
                ans += 4;
            }
        } else if n == 4 {
            if up == 1 {
                up = 2;
                ans += 5;
            } else {
                up = 0;
                ans += 4;
            }
        } else if n < 4 {
            if up == 1 {
                ans += n + 1;
            } else {
                ans += n;
            }
            up = 0;
        } else {
            if up == 0 {
                ans += 10 - n;
            } else {
                ans += 10 - n - 1
            }

            up = 1;
        }
    }

    if up == 1 {
        ans += 1;
    }

    println!("{}", ans);
}


Measured memory_bytes: 12532
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 50;
const ll MOD = 1000000007LL;
 
int main() {
    int N; scanf("%d", &N);
    vector<ll> X(N), Y(N), P(N);
    for(int i=0; i<N; i++) scanf("%lld%lld%lld", &X[i], &Y[i], &P[i]);

    vector< vector<ll> > pre_x(N, vector<ll>(1<<N, LONGINF));
    vector< vector<ll> > pre_y(N, vector<ll>(1<<N, LONGINF));
    for(int bit=0; bit<(1<<N); bit++) {
        for(int i=0; i<N; i++) {
            chmin(pre_x[i][bit], abs(X[i] - 0) * P[i]);
            chmin(pre_y[i][bit], abs(Y[i] - 0) * P[i]);
            for(int j=0; j<N; j++) {
                if(!(bit >> j & 1)) continue;
                chmin(pre_x[i][bit], abs(X[i] - X[j]) * P[i]);
                chmin(pre_y[i][bit], abs(Y[i] - Y[j]) * P[i]);
            }
        }
    }

    vector<int> pws(N+1), conv(1<<N);
    pws[0] = 1;
    for(int i=0; i<N; i++) pws[i+1] = pws[i] * 3;
    for(int bit=0; bit<(1<<N); bit++) {
        for(int i=0; i<N; i++) {
            if(!(bit >> i & 1)) continue;
            conv[bit] += pws[i];                
        }
    }
    
    vector<ll> pre(pws[N]);
    for(int bit=0; bit<(1<<N); bit++) {
        for(int bx=bit; ; bx=(bx-1)&bit) {
            int by = bit ^ bx;
            for(int i=0; i<N; i++) {
                ll ax = pre_x[i][bx];
                ll ay = pre_y[i][by];
                pre[conv[bx] + 2*conv[by]] += min(ax, ay);
            }
            if(bx == 0) break;
        }
    }
    
    int bx = 0, by = 0;
    vector<ll> ans(N+1, LONGINF);
    auto dfs = [&](auto &&self, int k, int cnt) -> void {
        if(k == N) {
            chmin(ans[cnt], pre[conv[bx] + 2*conv[by]]);
            return;
        }

        {
            self(self, k+1, cnt);
        }
        {
            bx ^= (1 << k);
            self(self, k+1, cnt+1);
            bx ^= (1 << k);
        }
        {
            by ^= (1 << k);
            self(self, k+1, cnt+1);
            by ^= (1 << k);
        }
    };
    dfs(dfs, 0, 0);

    for(int i=0; i<=N; i++) printf("%lld\n", ans[i]);
    return 0;
}


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

int main(){
    long long n;
    cin >> n;
    long long f[n][5][2];
    long long p[n][11];

    for(long long i = 0; i < n; i++){
        for(long long j = 0; j < 5; j++){
            for(long long k = 0; k < 2; k++){
                cin >> f[i][j][k];
            }
        }
    }

    for(long long i = 0; i < n; i++){
        for(long long j = 0; j < 11; j++){
            cin >> p[i][j];
        }
    }

    long long j;
    long long k;
    bool open[10];
    long long maxv = -1e9;

    for(long long bit = 0; bit < (1 << 10); bit++){

        for(long long j = 0; j < 5; j++){
            for(long long k = 0; k < 2; k++){
                if(bit & (1 << (2*j + k))){
                    open[2*j+k] = true;
                }
                else{
                    open[2*j+k] = false;
                }
            }
        }

        bool ok = false;
        for(long long j = 0; j < 5; j++){
            for(long long k = 0; k < 2; k++){
                if(open[2*j+ k] == true){
                    ok = true;
                    break;
                }
            }
        }
        if(ok == false){
            continue;
        }
        

        long long cost = 0;
        for(long long i = 0; i < n; i++){
            long long count = 0;
            for(long long j = 0; j < 5; j++){
                for(long long k = 0; k < 2; k++){
                    if(f[i][j][k] == 1 and open[2*j+k] == true){
                        count++;
                    }
                }
            }
            cost += p[i][count];
        }
        maxv = max(maxv, cost);
    }
    
    cout << maxv << endl;

    return 0;
}

Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main(){
    int n,k,l,m,o;
    cin>>n;
    for(int i=3;i<=n;i++){
        k=i%10;
        l=i/1000;
        m=i/100%10;
        o=i/10%10;
        if(i%3==0){
            cout<<" "<<i;
        }else if(k==3 || l==3 || m==3 || o==3){
            cout<<" "<<i;
        }
    }
    cout<<endl;
    return 0;
}

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

int main()
{
// freopen("t.txt","r",stdin);
 int n,a[MAX_N],b[MAX_N]={0};
 int k=0;
 
 cin>>n;
 for (int i=1;i<=n;i++){
 	int d; cin>>d;
 	if (b[d]==0){
 		a[k]=d;
 		k++;
	 	b[d]=1;
	 }
	 
 }
 sort (a ,a+k);
 //for (int i=0;i<k;i++) cout<<a[i]<<" ";
 int res=0;
 for (int i=1;i<k;i++)
 {
 	int t= a[i]-a[i-1];
 	res+=t;
 }
 cout<<res;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}

bool exc(const pair<string,int> &p1, const pair<string,int> &p2){
    if(p1.first > p2.first)return false;
    else if(p1.first < p2.first)return true;
    else return p1.second > p2.second;
}


int main(){
    int N;cin >> N;
    pair<string,int> P[101];
    map<pair<string,int> ,int> S;
    rep(i,N){
        cin >> P[i].first >> P[i].second;
        S[P[i]] = i+1;
    }

    sort(P,P+N,exc);

    rep(i,N){
        cout << S[P[i]] << endl;
    }



    return 0;
}

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

int main(void){
    ll a, b, c;
    ll k;
    cin >> a >> b >> c;
    cin >> k;

    ll ma = 0;
    ma = max(a, max(b, c));
    ll sum = a + b + c - ma;
    ma = pow(2, k) * ma;
    cout << sum + ma << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;

int n, m;
int cntr[100005], cntb[100005];

int main(){
	cin >> n >> m;
	for(int i=1; i<=n; i++){
		cntr[i] = (i == 1);
		cntb[i] = 1 - cntr[i];
	}
	while(m--){
		int s, e;
		scanf("%d %d",&s,&e);
		if(cntr[s] == 0){
			cntb[s]--;
			cntb[e]++;
		}
		else{
			if(cntb[s]){
				cntb[s]--;
				cntr[e]++;
			}
			else{
				cntr[s]--;
				cntr[e]++;
			}
		}
	}
	cout << n - count(cntr + 1, cntr + n + 1, 0) << endl;
}

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

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

	if(n*500 >= k)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
LARGE = 998244353


def solve(n):
    r = 0
    mck = 1
    factorial_n = 1
    factorial_inv = [0] * (n + 1)
    factorial_inv[0] = 1
    for i in range(1, n + 1):
        factorial_n *= i
        factorial_n %= LARGE
    factorial_inv[-1] = pow(factorial_n, LARGE - 2, LARGE)
    for i in range(n):
        factorial_inv[n - i - 1] = (factorial_inv[n - i] * (n - i)) % LARGE
    pow_2 = 1
    for k in range(n // 2):
        r += factorial_n * factorial_inv[n - k] * factorial_inv[k] * pow_2
        r %= LARGE
        pow_2 *= 2
        pow_2 %= LARGE
    res = (pow(3, n, LARGE) - (2 * r)) % LARGE
    return res


def main():
    n = int(input())
    res = solve(n)
    print(res)


def test():
    assert solve(2) == 7
    assert solve(10) == 50007
    # assert solve(1000000) == 210055358


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 118636
import scala.io.StdIn._

object Main {
  def main(args: Array[String]): Unit = {
    while (true) {
      val n = readInt
      if (n == 0) return
      var value = readLine
      for (i <- 0 until n) {
        value = Some(value.split("").toList).map(encode).map(toString).getOrElse("")
      }
      println(value)
    }
  }

  def pack[T](list: List[T]): List[List[T]] = list match {
    case Nil => Nil
    case x :: xs1 =>
      val (first, rest) = list span (y => y == x)
      first :: pack(rest)
  }

  def encode[T](list: List[T]): List[(T, Int)] =
    pack(list) map (ys => (ys.head, ys.length))

  def toString(list: List[(String, Int)]):  String = {
    list.map(x => x._2 + x._1).mkString
  }

}



Measured memory_bytes: 89792
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int n, a, b;

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

  int cnt = 0;
  for ( int i = 1; i <= n; i++ ) {
    int sum = 0;
    for ( int j = i; j > 0; j /= 10) {
      if ( 0 <= j && j <= 9 ) {
        sum += j;
        break;
      } else {
        sum += j % 10;
      }
    }
    if ( a <= sum && sum <= b ) {
      cnt += i;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
def judge(bit):
    for i in range(N):
        if not (bit & (1<<i)):
            continue

        for xy in v[i]:
            x = xy[0]
            y = xy[1]

            if y==1 and not(bit & (1<<x)):
                return False

            if y==0 and (bit & (1<<x)):
                return False
    return True

N = int(input())
v = [[] for _ in range(N)]
for i in range(N):
    A = int(input())
    for _ in range(A):
        x, y = map(int, input().split())
        v[i].append((x-1,y))

res = 0
for bit in range(1<<N):
    if judge(bit):
        conut = 0
        for i in range(N):
            if bit & (1<<i):
                conut += 1
        res = max(res, conut)
print(res)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

double sol(int x,int y){
    return sqrt(x*x+y*y);
}

int main(){
    int n;
    cin>>n;
    double s[2]={INF,INF},d[2]={-1,-1};
    int f[200],a[200],t[200],x[200],y[200];
    rep(i,n){
        cin>>f[i]>>a[i]>>t[i]>>x[i]>>y[i];
    }
    
    for(int i=1;i<n;i++){
        if(t[i-1]==t[i] && a[i-1]!=a[i]){
            double dr=sol(x[i]-x[i-1],y[i]-y[i-1]);
            double tm=f[i]-f[i-1];
            if(dr>d[t[i]]||(dr==d[t[i]]&&s[t[i]]>tm)){
                d[t[i]]=dr;
                s[t[i]]=tm;
            }
        }
    }
    rep(i,2){
        if(d[i]==-1)cout<<-1<<" "<<-1<<endl;
        else printf("%.10lf %.10lf\n",d[i],s[i]/60.0);
    }
}

Measured memory_bytes: 1244
def calcs(x,y,ax,ay,bx,by) ((ax-x)*(by-y)-(bx-x)*(ay-y))/2.0 end
def inpf() a=gets.chomp.split(" ").map(&:to_f)end
def inps() a=gets.chomp.split(" ")end  
def copy(a) Marshal.load(Marshal.dump(a)) end
def kaizyo(n)(n < 2)? 1 : (2..n).inject(:*) end
def scount(a) b=na(a.max+1);a.each{|n|b[n]+=1};return b end
def na(n,d=0) Array.new(n,d)end
def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end
def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end
def bit(n) n.to_s(2).split("").map(&:to_i) end
def inp() a=gets.chomp.split(" ").map(&:to_i)end
n = inp[0]
a = inp
a.sort!{|a,b|b<=>a}
ans = 0
n.times do |i|
  ans += a[2*i+1]
end
p ans

Measured memory_bytes: 28412
#include <bits/stdc++.h>
#define N 202
#define M 100000
using namespace std;

typedef unsigned ui;

ui n, m, s, t;
ui dis[N], cur[N];

struct edge { ui p, v; int c, f; } es[M]; ui eh[N], ec;
void eclr() { memset(eh, 0xff, sizeof(eh)); ec = 0; }
void adde(ui u, ui v, int c) {
	es[ec] = { eh[u], v, c, 0 }; eh[u] = ec++;
	es[ec] = { eh[v], u, 0, 0 }; eh[v] = ec++;
}

bool bfs() {
	static bool vis[N];
	memset(vis, 0, sizeof(vis));
	dis[s] = 0; vis[s] = 1;
	queue<ui> q; q.push(s);
	while (!q.empty()) {
		ui u = q.front(); q.pop();
		for (ui ei = eh[u]; ~ei; ei = es[ei].p) {
			edge& e = es[ei]; ui v = e.v;
			if (vis[v] || e.c <= e.f) continue;
			vis[v] = 1; dis[v] = dis[u] + 1; q.push(v);
		}
	}
	return vis[t];
}

int dfs(ui u, int a) {
	if (u == t || a == 0) return a;
	int sum = 0, f;
	for (ui& ei = cur[u]; ~ei; ei = es[ei].p) {
		edge& e = es[ei]; ui v = e.v;
		if (dis[u] + 1 != dis[v] || (f = dfs(v, min(a, e.c - e.f))) <= 0)
			continue;
		e.f += f; es[ei ^ 1].f -= f;
		sum += f; a -= f;
		if (!a) break;
	}
	return sum;
}

int dinic() {
	int sum = 0;
	while (bfs()) {
		memcpy(cur, eh, sizeof(eh));
		sum += dfs(s, 1 << 30);
	}
	return sum;
}

char g[N][N];

int main(void) {
	ios::sync_with_stdio(0); cin.tie(0);
#ifdef _DEBUG
	ifstream cin("1.in");
#endif
	ui n, m; cin >> n >> m;
	
	for (ui i = 0; i != n; ++i) cin >> g[i];
	ui sx, sy, tx, ty; s = 200, t = 201;
	eclr();
	for (ui i = 0; i != n; ++i)
		for (ui j = 0; j != m; ++j) {
			if (g[i][j] == 'S') { sx = i; sy = j; }
			else if (g[i][j] == 'T') { tx = i; ty = j; }
			else if (g[i][j] == 'o') { adde(i, 100 + j, 1); adde(100 + j, i, 1); }
		}

	adde(s, sx, 500);
	adde(s, sy + 100, 500);
	adde(tx, t, 500);
	adde(ty + 100, t, 500);

	if (sx == tx|| sy == ty) cout << -1 << endl;
	else cout << dinic() << endl;

	return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void ppp(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;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 nCr(int n,int k){
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(void){
  ll n,m;
  scanf("%lld %lld",&n,&m);
  if(n%3<1||m%3<1){
    PRN(0);
    return 0;
  }
  ll a[3],ans=min(n,m);
  for(ll i=1;i<n;i++){
    a[0]=i*m;
    a[1]=(n-i)*(m/2);
    a[2]=(n-i)*(m/2+m%2);
    ans=min(ans,max(z(a[0]-a[1]),max(z(a[1]-a[2]),z(a[0]-a[2]))));
  }
  if(n-m){
    for(ll i=1;i<m;i++){
      a[0]=i*n;
      a[1]=(m-i)*(n/2);
      a[2]=(m-i)*(n/2+n%2);
      ans=min(ans,max(z(a[0]-a[1]),max(z(a[1]-a[2]),z(a[0]-a[2]))));
    }
  }
  PRL(ans);
  return 0;
}


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

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

  for (int i = n - 1; i > 0; i--) {
    if (h[i] < h[i - 1]) {
      if (h[i - 1] - h[i] == 1) {
        h[i - 1]--;
      } else {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

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

int main(){
    int n,k;
    int h[110000];
    cin >> n >> k;
    for(int i = 0;i < n;i++){
        cin >> h[i];
    }
    int count = 0;
    for(int i = 0; i < n;i++){
        if(h[i] >= k) count += 1;
    }
    cout << count << endl;
}

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

using vi = vector<int64_t>;
const int64_t C = 1000000007;


int main(){
  int N;
  vi A(100010);

  cin >> N;
  for (int i=0; i<N; i++){
    cin >> A[i];
  }

  // red[i] : i人までの内赤い帽子の人の人数
  vi red(100010), blue(100010), green(100010); 
  red[0] = 1;

  for(int i=1; i<N; i++){
    if(A[i] == red[i-1]){
      red[i] = red[i-1]+1;
      blue[i] = blue[i-1]; green[i] = green[i-1];
    } else if (A[i] == blue[i-1]){
      blue[i] = blue[i-1]+1;
      red[i] = red[i-1]; green[i] = green[i-1];
    } else if (A[i] == green[i-1]){
      green[i] = green[i-1]+1;
      blue[i] = blue[i-1]; red[i] = red[i-1];
    }
  }

  vi dp(100010); //dp[i] : i人目まででの場合の数  

  if(A[0] != 0){
    cout << 0 << endl;
    return 0;
  } else {
    dp[0] = 3;
  }

  for(int i=1; i<N; i++){
    int r = (A[i] == red[i-1]);
    int b = (A[i] == blue[i-1]);
    int g = (A[i] == green[i-1]);

    dp[i] = dp[i-1] * (r+b+g) % C;
  }

  cout << dp[N-1] << endl;
}

Measured memory_bytes: 4224
import Foundation

func main() {
 var n = Int(readLine()!)!
 var successTimes = 0
 
 for _ in 1...n {
   let inputString = readLine()!
   let split: [Int] = inputString.components(separatedBy: " ").map{Int(String($0))!}
   if (split[0]==split[1]) {
     successTimes += 1
     if (successTimes == 3) {
        print("Yes")
        return
     }
   } else {
     successTimes = 0
   }
 }
 
 print("No")

}

main()

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

#define ll long long
#define ull unsigned long long

#define vi vector < int >
#define vll vector < ll >
#define vs vector < string >

#define pii pair < int, int >
#define pll pair < ll, ll >

#define pb push_back

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

using namespace std;

int main()
{
    fast;

    int n, k;

    cin >> n >> k;

    int a[n + 5];

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

    sort(a, a + n);

    int sum = 0;

    for(int i = 0; i < k; i++) sum += a[i];

    cout << sum << endl;

    return 0;
}




Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
// #pragma GCC optimize("O2")
typedef long long int ll;
typedef long double ld;
typedef map <ll,ll> mm;
typedef vector <ll> mv;
typedef pair <ll,ll> mp;
typedef set <ll> ms;
typedef multiset <ll> mms;
typedef queue <ll> mq;
typedef deque <ll> mdq;
typedef stack <ll> mst;
typedef priority_queue <ll> mpq;
typedef priority_queue <ll, vector<ll>, greater<ll> > mmh;
typedef complex<double> cd;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_multiset tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define flush cout.flush();
#define all(v) v.begin(),v.end()
#define deb(x) cout << #x << " " << x << endl;
#define ff first
#define ss second
#define pb(v) push_back(v)
#define lb(v) lower_bound(v)
#define ub(v) upper_bound(v)
#define cn continue
#define forl(i,n) for(ll i=0;i<n;i++)
#define forlr(i,n) for(ll i=n-1;i>=0;i--)
#define rev(s) reverse(s.begin(),s.end())
void swap(ll &a,ll &b) {
	ll tmp=a;
	a=b;
	b=tmp;
}
ll atoistring(string s) {
	stringstream lol(s);
	ll x;
	lol>>x;
	return x;
}
void pv(mv v) {
	forl(i,v.size()) cout<<v[i]<<" ";
	cout<<"\n";
}
void pa(ll *v, ll size) {
	forl(i,size) cout<<v[i]<<" ";
	cout<<"\n";
}
void removeDups(mv &v) {
	sort(all(v));
	mv::iterator it = unique(v.begin(), v.end());
	v.resize(distance(v.begin(), it));
}
inline ld kthRoot(ld n, ll k) {
	return pow(k, (1.0 / k) * (log(n) / log(k)));
}
ll power(ll x, ll y, ll p) {
	ll res=1;
	x=x%p;
	while(y>0) {
		if(y&1) res = (res*x)%p;
		y=y>>1;
		x=(x*x)%p;
	}
	return res;
}
void checkmod(ll &x, ll mod) {
	if(x>=mod) x%=mod;
}

ll mod = 1e9 + 7;

void thisIsMain() {
	ll n;
	cin>>n;
	ll ans = power(10, n, mod);
	ans += power(8, n, mod);
	ans %= mod;
	ans -= 2 * power(9, n, mod);
	ans %= mod;
	ans += mod;
	ans %= mod;
	cout<<ans<<"\n";
}

int main(void)
{
	fastio
	ll t = 1;
	// cin>>t;
	while(t--) thisIsMain();
	return 0;
}

Measured memory_bytes: 3640
MOD = 10**9+7
# dp[i][j] := Sの後ろからi桁を13で割った余りがjとなるようなものの個数
S = input()
l = len(S)
dp = [[0]*13 for _ in range(l+5)]
dp[0][0] = 1
mul = 1

for i in range(l):
    x = S[-(i+1)]
    if x == "?":
        for k in range(10):
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= MOD
    else:
        k = int(x) # これしか選ぶ余地なし
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= MOD
    mul = mul * 10 % 13
print(dp[l][5]%MOD)


Measured memory_bytes: 62300
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}








int main(){
    int N, M; std::cin >> N >> M;
    std::vector<std::vector<int>> G(N);
    {
        int A, B;
        for(int i(0); i < M; ++i){
            std::cin >> A >> B; --A; --B;
            G[A].push_back(B);
            G[B].push_back(A);
        }
    }
    std::vector<int> prv(N, NIL);
    std::queue<int> que;
    que.push(0);
    while(!que.empty()){
        int v(que.front()); que.pop();
        for(int e: G[v]){
            if(prv[e] != NIL) continue;
            prv[e] = v + 1;
            que.push(e);
        }
    }
    std::cout << "Yes\n";
    for(int i(1); i < N; ++i){
        std::cout << prv[i] << "\n";
    }
    return 0;
}


Measured memory_bytes: 10008
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 1000000000000;

int n6(int N){
    int ans=0;
    while(N>0){
        N/=6;
        ans++;
    }
    return ans;
}

int n9(int N){
    int ans=0;
    while(N>0){
        N/=9;
        ans++;
    }
    return ans;
}

int main(){
    int N;
    cin >>N;
    vl dp(N+1);
    dp[0]=0;
    dp[1]=1;
    rep2(i,2,N+1){
        ll m = dp[i-1];
        rep(j,n6(i)){
            if (dp[i-pow(6,j)]<m) m = dp[i-pow(6,j)];
        }
        rep(j,n9(i)){
            if (dp[i-pow(9,j)]<m) m = dp[i-pow(9,j)];
        }
        dp[i]=m+1;
    }
    cout <<dp[N]<<endl;
}

Measured memory_bytes: 1024
def ceil(n, i):
    dec = 10 ** i
    return n // dec * dec

(n, k) = list(map(int, input().split()))
d = list(map(int, input().split()))
l = []
for i in range(0, 10):
    if i not in d:
        l.append(i)
i = 1
while len(str(n)) >= i:
    nown = n // (10 ** (i - 1)) % 10
    ok = False
    for j in l:
        if j == nown:
            ok = True
            break
        elif j > nown:
            ok = True
            n = ceil(n, i)
            n += int(str(j) + str(l[0]) * (i - 1))
            break
    if not (ok):
        n = ceil(n, i) + 10 ** i
        n += int(str(l[0]) * i)
    i += 1
print(n)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProblemC
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var N = read[0];
            var M = read[1];

            var Ls = new int[M];
            var Rs = new int[M];
            for (int i = 0; i < M; i++)
            {
                read = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                Ls[i] = read[0];
                Rs[i] = read[1];
            }
            var retL = Ls.Max();
            var retR = Rs.Min();
            var ret = retR - retL + 1;
            if (ret <= 0)
                Console.WriteLine(0);
            else
                Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 17984
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rrep(i,n) REP(i,1,n+1)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> PII;
typedef vector<ll> Vl;
typedef vector<int> VI;
typedef tuple<int, int, int> TT;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(), v.end()
#define dmp(x,y) make_pair(x,y)
#define dmt(x, y, z) make_tuple(x, y, z)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
const int MAX = 500000;
const int inf = 1000000007;
const ll mod = 1000000007;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

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

int n, m;

//UF木
struct UnionFind {
private:
	vector<int> par, ran, sz;
	int cnt;
public:
	UnionFind(int n) {
		par.resize(n, 0);
		ran.resize(n, 0);
		sz.resize(n, 1);
		cnt = n;
		rep(i, n) {
			par[i] = i;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y)return;
		if (ran[x] < ran[y]) {
			par[x] = y; sz[y] += sz[x];
		}
		else {
			par[y] = x; sz[x] += sz[y];
			if (ran[x] == ran[y])ran[x]++;
		}
		cnt--;
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int num(int x) { return sz[find(x)]; }

	int total() { return cnt; }
};

int main() {

	cin >> n >> m;

	UnionFind uf(n);

	rep(i, m) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		uf.unite(a, b);
	}

	cout << uf.total() << endl;

	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 10000000007

int main() {
	ll n,m,l;
	cin>>n>>m>>l;
	ll ch[302][302];
	for(ll i=0;i<302;i++){
		for(ll j=0;j<302;j++){
			ch[i][j]=inf;
		}
	}
	for(ll i=0;i<m;i++){
		ll x,y,c;
		cin>>x>>y>>c;
		x--;y--;
		ch[x][y]=c;
		ch[y][x]=c;
	}
	for(ll k=0;k<n;k++){
		for(ll i=0;i<n;i++){
			for(ll j=0;j<n;j++){
				ch[i][j]=min(ch[i][j],ch[i][k]+ch[k][j]);
			}
		}
	}
//	cout << ch[1][0]<<endl;
	vector<ll>ch2[302];
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			ll now=ch[i][j];
			if(now<=l){
				ch2[i].push_back(j);
			}
		}
	}
	ll q;
	cin>>q;
	for(ll i=0;i<q;i++){
		ll s,t;
		cin>>s>>t;
		s--;t--;
	//	cout <<s<<t;
		ll cnt[302];
		ll zan[302];
		for(ll i=0;i<n;i++){
			zan[i]=cnt[i]=-1;
		}
		queue<ll>q;
		q.push(s);
		cnt[s]=0;zan[s]=l;
		bool ans=false;
		while(q.size()!=0){
			ll now=q.front();
			q.pop();
			for(ll i=0;i<ch2[now].size();i++){
				ll nex=ch2[now][i];
				if(cnt[nex]!=-1){
					continue;
				}
				ll pl=0;
				ll nezan=zan[now]-ch[now][nex];
				if(nezan<0){
					pl++;
					nezan=l-ch[now][nex];
				}
				cnt[nex]=cnt[now]+pl;
				zan[nex]=nezan;
				if(s==1&&t==4){
			//		cout << cnt[now]<<" nex"<<nex<<" zanne"<<zan[nex]<<" cnne"<<cnt[nex]<<endl;
				}
				q.push(nex);
				if(nex==t){
					cout <<cnt[nex]<<endl;
					ans=true;
					break;
				}
			}
			if(ans){
				break;
			}
		}
		if(ans!=true){
			cout << -1<<endl;
		}
	}
	// your code goes here
	return 0;
}

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

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

	vector<int> c(26);
	vector<vector<int>> s(D, vector<int>(26));
	vector<int> t(D);
	vector<vector<int>> last(D, vector<int>(26, 0));
	vector<int> sat(D);
	vector<int> sat_tmp(26);

	for (int i = 0; i < 26; i++) {
		cin >> c[i];
	}

	for (int i = 0; i < D; i++) {
		for (int j = 0; j < 26; j++) {
			cin >> s[i][j];
		}
	}

	/*********************************/
	for (int i = 0; i < D; i++) {
		for (int k = 0; k < 26; k++) {
			for (int j = 0; j < 26; j++) {
				if (i == 0) {
					last[i][j] = 0;
				} else {
					last[i][j] = last[i - 1][j];
				}
			}
			last[i][k] = i + 1;
			if (i == 0) {
				sat_tmp[k] = s[i][k];
			} else {
				sat_tmp[k] = s[i][k] + sat_tmp[i - 1];
			}
			int satisfaction = 0;
			for (int j = 0; j < 26; j++) {
				satisfaction += c[j] * (i + 1 - last[i][j]);
			}
			sat_tmp[k] -= satisfaction;
		}
		vector<int>::iterator iter = max_element(sat_tmp.begin(), sat_tmp.end());
		size_t index = distance(sat_tmp.begin(), iter);
		t[i] = index;

		for (int j = 0; j < 26; j++) {
			if (i == 0) {
				last[i][j] = 0;
			} else {
				last[i][j] = last[i - 1][j];
			}
		}
		last[i][t[i]] = i + 1;
		if (i == 0) {
			sat[i] = s[i][t[i]];
		} else {
			sat[i] = s[i][t[i]] + sat[i - 1];
		}
		int satisfaction = 0;
		for (int j = 0; j < 26; j++) {
			satisfaction += c[j] * (i + 1 - last[i][j]);
		}
		sat[i] -= satisfaction;
	}

	// for (int i = 0; i < D; i++) {
	// 	cout << sat[i] << endl;
	// }
	/*********************************/

	for (int i = 0; i < D; i++) {
		cout << t[i] + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 3700
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const int MOD = 998244353;
const ll INF = 1000000000000000000;

ll sum[200010];
int main()
{
	int N, K;
	cin >> N >> K;
	ll ans = 0;
	for (int i = 0; i < N + 1; i++) {
		sum[i + 1] = sum[i] + i + 1;
	}
	for (int i = K; i <= N + 1; i++) {
		ll num1 = sum[i - 1] - sum[0];
		ll num2 = sum[N] - sum[N - i];
		ans = (ans + num2 - num1 + 1) % mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 5000
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	string S, T; 
	cin >> S >> T; 
	int A[100010] = {}; 
	int B[100010] = {}; 
	for(int i = 1; i <= S.size(); i++){
		A[i] = A[i-1] + 1 + S.at(i-1) - 'A'; 
	}
  	for(int i = 1; i <= T.size(); i++){
		B[i] = B[i-1] + 1 + T.at(i-1) - 'A';
	}
	int Q; 
	cin >> Q; 
	for(int i = 0; i < Q; i++){
		int a, b, c, d; 
		cin >> a >> b >> c >> d; 
		if((A[b] - A[a-1]) % 3 == (B[d] - B[c-1]) % 3){
			cout << "YES" << endl; 
		}
		else{
			cout << "NO" << endl; 
		}
	}
}

Measured memory_bytes: 1664
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#include<queue>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int dx[]={1,0,-1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,1,1,-1,-1};
int ceil(int a,int b){
    return (a+b-1)/b;
}
int main(void){
    int n;  
    cin >> n;
    for ( int i=0; i<n; i++ ){
        int Y,M,D;  
        cin>>Y>>M>>D;
        int ans=0;
        while (Y<1000 ){
            D++;
            if (Y%3==0&&D>20||Y%3!=0 && M%2==0 && D>19 ||Y%3!=0 && M%2!=0 && D>20 ){
                D = 1;
                M++;
            }
            if(M>10){
                M =1;
                Y++;
            }
            ans++;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3088