akhauriyash/Code-Regression huggingface dataset:
def Combination_mod(n, k):
    ret = f[n]
    ret = (ret * finv[k]) % mod
    ret = (ret * finv[n - k]) % mod
    return ret

mod = 1000000007
h, w, a, b = map(int,input().split())

x = []
xi = b
xj = h - a - 1
while xi < w and xj >= 0:
    x.append([xi, xj])
    xi += 1
    xj -= 1

n = w + h
f = [0] * n
finv = [0] * n

f[0] = 1
finv[0] = finv[1] = 1
for i in range(1, n):
    f[i] = (f[i - 1] * i) % mod

finv[n - 1] = pow(f[n - 1], mod - 2, mod)
for i in range(n - 2, 1, -1):
    finv[i] = ((i + 1) * finv[i + 1]) % mod

ans = 0
for i, j in x:
    ans1 = Combination_mod(i + j, i)
    ans1 *= Combination_mod(w - 1 - i + h - 1 - j, w - 1 - i)
    ans += ans1
    ans %= mod

print(ans)


Measured memory_bytes: 57324
#include <stdio.h>
 
int main()
{
    int max, min, n, i, num[200000];
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&num[i]);
 
    min=num[0];
    max=-100000000000;
 
    for (i = 1; i < n; ++i)
        {
            if (max<num[i]-min)max=num[i]-min;
            if (min>num[i])min=num[i];
             
        }  
    printf("%d\n",max);
    return 0;
}

Measured memory_bytes: 2576
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll a, b, n;
    cin>>a>>b>>n;

    ll c = max(1ll, n / b * b - 1);
    cout<<max(a * c / b - a * (c / b), a * n / b - a * (n / b))<<endl;
}

Measured memory_bytes: 3652
a, b = gets.split
a = a.to_i
# b = b.to_f
b_100 = (b[0] + b[2] + b[3]).to_i
ans = (a * b_100).to_s.split("")
ans.pop
ans.pop
if ans.empty?
  puts 0
else
  puts ans.join
end


Measured memory_bytes: 14432
x1, y1, x2, y2 = map(int, input().split())

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x1 - (x2 - x3)
y4 = y2 + (x2 - x1) - (x2 - x3)

print(x3, y3, x4, y4)

Measured memory_bytes: 2940
from bisect import bisect
import sys
s = input()
t = input()
l = {}
for c in set(t):
    cl = [s.find(c)]
    if cl[0] == -1:
        print("-1")
        sys.exit()
    while True:
        i = s.find(c, cl[-1] + 1)
        if (i == -1):
            break
        cl.append(i)
    l[c] = cl
ofs = -1
count = 0
for c in t:
    lens = len(s)
    ref = bisect(l[c], ofs)
    if ref < len(l[c]):
        ofs = l[c][ref]
    else:
        ofs = l[c][0]
        count += 1
print(lens * count + ofs + 1)


Measured memory_bytes: 7316
#include <bits/stdc++.h>
using namespace std;
int main () {
  string A, B;
  cin >> A >> B;
  string ans = "EQUAL";
  if (A.size() > B.size()) ans = "GREATER";
  else if (A.size() < B.size()) ans = "LESS";
  for(int i = 0; i < A.size(); i++) {
    if(ans != "EQUAL") break;
    if (A.at(i) - '0' > B.at(i) - '0') ans = "GREATER";
  else if (A.at(i) - '0' < B.at(i) - '0') ans = "LESS";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n;
cin >> n;
int count = 0;
int a;
REP(i,n) {
  cin >> a;
  if(a!=i+1) count++;
}
if(count>=3) {
  cout << "NO" <<endl;
} else {
  cout << "YES" << endl;
}
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define arep(a,i,n) for(ll i=(a);i<(n);i++)
#define rep(i,n) for(ll i=0;i<(n);i++)
#define cinf(x,n) for(ll i=0;i<(n);i++)cin>>x[i];
#define coutf(x,n) for(ll i=0;i<(n);i++)cout<<x[i]<<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using namespace std;

int x,ans;

int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	rep(i,n){
		switch(s[i]){
			case 'I':x++;if(x>ans)ans=x;break;
			case 'D':x--;break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3628
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,Path=pin()
    ns=tupin()
    cond=[1]*(N)
    for i in range(Path):
        x,y=pin()
        t=ns[x-1]-ns[y-1]
        if t>0:
            cond[y-1]=0
        elif t<0: cond[x-1]=0
        else: 
            cond[x-1]=0
            cond[y-1]=0
    print(sum(cond))
#%%submit!
resolve()

Measured memory_bytes: 84592
N = int(input())
before = ""
all = set()
check = True
for i in range(N):
    s = input()
    if i == 0:
        before = s
        all.add(s)
    else:
        if before[-1] == s[0]:
            before = s
            all.add(s)
        else:
            check = False
if check:
    print("Yes" if len(all)==N else "No")
else:
    print("No")

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = 1e9;
const LL LLINF = 1e18;

void solve()
{
    int N;
    cin >> N;
    string result;
    cin >> result;
    sort(result.begin(), result.end());

    REP0(i, N - 1)
    {
        string S, tmp;
        cin >> S;
        sort(S.begin(), S.end());
        set_intersection(S.begin(), S.end(),
                         result.begin(), result.end(),
                         inserter(tmp, tmp.end()));
        result.swap(tmp);
        tmp.clear();
    }

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

    cout << result << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

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

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

  int seen[N];
  fill(seen, seen + N, 0);

  for (int i = 1; i < N; i++) {
    int a;
    cin >> a;
    seen[a - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << seen[i] << endl;
  }
}


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

int main(){
  string s; cin >> s;
  int sta=0;
  for(int i=0; i<s.size(); i++){
    if(sta==0&&s[i]=='C'){
      sta++;
    }else if(sta==1&&s[i]=='F'){
      sta++;
      break;
    }
  }
  if(sta==2) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>

using namespace std;

long long result, N,T,a,b,c;
string S;


typedef pair<long long, long long> pl;
vector<pl> re;
vector<pl> bl;
pl buf;

long long Answer[200] = {};


int main() {
	result = 0;
	cin >> a>>b>>c;

	if (b - a + 1 < 2 * c) {
		for (int i = a; i <= b; i++) {
			cout << i << endl;
		}
	}
	else {
		for (int i = a; i < a + c; i++) {
			cout << i << endl;
		}
		for (int i = b-c+1; i <=b; i++) {
			cout << i << endl;
		}

	}





	/*for (int i = 0; i < T; i++) {
		if (Answer[i] == -1) {
			cout << "Case #" << i + 1 << ": OK" << endl;
		}
		else {
			cout << "Case #" << i + 1 << ": " << Answer[i] << endl;
		}

	}*/
	



	//cout << result << endl;

return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

ll a[500000], b[500000];

int main() {
    ll N;
    cin >> N;
    for (int i=1; i<=N; ++i) {
        ll tmp; cin >> tmp;
        a[i] = a[i-1]^tmp;
        b[i] = b[i-1]+tmp;
    }
    ll ans = 0;
    int l = 0;
    for (int r=1; r<=N; ++r) {
        for (; (a[r]^a[l]) != (b[r]-b[l]); ++l);
        ans += (r - l);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5888
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static final int MOD = (int) Math.pow(10, 9);

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        long n = sc.nextLong();
        long res = Long.MAX_VALUE;

        for (long i = 1; i <= (long)Math.sqrt(n); i++) {
            if (n % i == 0) {
                res = Math.min(res, (i + (n / i)) - 2);
            }
        }
        System.out.println(res);
        System.exit(0);
    }

    static private long gcd(long m, long n) {
        if (m < n) { return gcd(n, m); }
        if (m % n == 0) { return n; }
        return gcd(n, m%n);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try{
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

int main() {
  int d, t, s;
  cin >> d >> t >> s;
  
  int total = t * s;
  if (d <= total) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3592
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll N,K;
    cin>>N>>K;
    v P(N),C(N);
    rep(i,0,N){
        cin>>P[i];
        P[i]--;
    }
    rep(i,0,N)cin>>C[i];

    ll ans = -INF;

    rep(i,0,N){
        ll st = i;
        ll loop_N = 0;
        ll loop_sum = 0;
        ll now = i;
        v sums(N+1,0);
        do{
            loop_N++;
            now = P[now];
            loop_sum += C[now];
            sums[loop_N] = sums[loop_N-1]+C[now];
        }while(st != now);
        
        ll max_C = -INF;
        ll sumloop_C = 0;
        ll K2 = K;
        if(loop_sum > 0){
            bool ok = false;
            if(K/loop_N >= 1)ok = true;

            sumloop_C += (K/loop_N) * loop_sum;
            max_C = sumloop_C;
            K2 = K%loop_N;

            rep(j,1,loop_N+1){
                if(j <=K2){
                    max_C = max(sumloop_C + sums[j],max_C);
                }
                else if(ok){
                    max_C = max(sumloop_C- loop_sum + sums[j],max_C);
                }
            }
        }
        else{
            rep(j,1,loop_N+1){
                max_C = max(max_C, sums[j]);
            }
        }
        ans = max(ans, max_C);
    }
    cout<<ans;
    return 0;
}

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

int main(void){
    int a,b;
    cin >> a >> b;
    int ans = 0;
    for(int i = a;i <= b;i++){
        string s = to_string(i);
        bool f = true;
        int bot = s.size() - 1;
        for(int j = 0;j < s.size() / 2;j++){
            if(s[j] != s[bot - j])f = false;
        }
        if(f)ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define moca(a, s, b) a=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<class T>bool chmax(T &a, const T &b) {if(a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if(b<a) {a=b; return 1;} return 0;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

//for(i=0; i<N; i++) cin >> a[i];

class unionFind {
public:
  vector<ll> data;
  
  unionFind(ll size) {
    data.assign(size, -1);
  }
  
  bool same(ll x, ll y) {
    return find(x)==find(y);
  }
  
  void unite(ll x, ll y) {
    x=find(x);
    y=find(y);
    if(x==y) return;
    if(data[x]>data[y]) swap(x, y);
    data[x]+=data[y];
    data[y]=x;
  }
  
  ll find(ll k) {
    if(data[k]<0) return k;
    return data[k]=find(data[k]);
  }
  
  ll size(ll k) {
    return -data[find(k)];
  }
  
};


int main(void) {
  ll i, j, k;
  
  ll N, K;
  cin >> N >> K;
  ll P[5555], C[5555];
  for(i=0; i<N; i++) {
    cin >> P[i];
    P[i]--;
  }
  for(i=0; i<N; i++) cin >> C[i];
  
  unionFind uf=unionFind(N);
  map<ll, set<ll>> mp;
  
  for(i=0; i<N; i++) uf.unite(i, P[i]);
  
  for(i=0; i<N; i++) {
    ll u=uf.find(i);
    if(mp[u].empty()) mp[u]=set<ll>();
    mp[u].insert(i);
  }
  
  ll ans=-INF;
  for(auto it=mp.begin(); it!=mp.end(); it++) {
    set<ll> st=it->sc;
    ll n=st.size();
    ll c=0;
    for(auto ptr=st.begin(); ptr!=st.end(); ptr++) c+=C[*ptr];
    
    ll tK=K;
    ll t=0;
    if(c>0) {
      t=tK/n*c;
      tK%=st.size();
      
      if(tK==0) {
        t-=c;
        tK=n;
      }
      
    }else {
      chmin(tK, n);
    }
    
    vector<ll> v;
    ll now=*st.begin();
    v.push_back(now);
    for(i=1; i<n; i++) {
      now=P[now];
      v.push_back(now);
    }
    for(i=0; i<n; i++) v.push_back(v[i]);
    
    ll sum[v.size()+10];
    for(i=0; i<v.size(); i++) sum[i+1]=sum[i]+C[v[i]];
    
    ll S=-INF;
    for(k=1; k<=tK; k++) for(i=1; i<=(ll)v.size()-k+1; i++) chmax(S, sum[i+k-1]-sum[i-1]);
    
    t+=S;
    chmax(ans, t);
    
    
    if(c>0) {
      tK=K;
      ll tt=max(0LL, (tK/n-1)*c);
      ll SS=0;
      tK-=max(0LL, (tK/n-1)*n);
      for(k=1; k<=tK; k++) for(i=1; i<=(ll)v.size()-k+1; i++) chmax(SS, sum[i+k-1]-sum[i-1]);
      tt+=SS;
      chmax(ans, tt);
    }
    
  }
  
  pt(ans);
  
}
 
 




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

int main(){
  int n;  cin >> n;
  double ans = 0;
  rep(i,n) {
    double a;
    cin >> a;
    ans += 1.0/a;
  }
  ans = 1/ans; 
  printf("%.7f\n",ans);
  return 0;
}

Measured memory_bytes: 256
/*input
1 2 0 4 5
*/
/*

**************************
*						 *
* AUTHOR :: knight_coder *
*						 *
**************************

*/
#include<bits/stdc++.h>
#define lld          long long int
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<lld,lld>
#define msi         map<string,lld>
#define mis         map<lld, string>
#define mpi         map<pair<lld ,lld >,lld >
#define pii         pair<lld,lld>
#define vi          vector<lld>
#define vpi 		vector<pii>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (lld)x.size()
#define hell        1000000007
#define rrep(i,m,n)	for(lld i=m;i>=n;i--)
#define rep(i,m,n)	for(lld i=m;i<n;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define pr(x) 		cout<< x << " ";
#define pre(x)		cout<< x << endl ;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; 
//change null_type to get ordered_map
#define N  100005
void solve()
{
	lld ar[5];
	rep(i,0,5){
		cin >> ar[i];
		if(!ar[i]){
			cout << i+1 << endl;
			return;
		}
	} 
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int tests=1;
	//cin>>tests;
	while(tests--)
	{
		solve();
	}
}

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

using namespace std;

long N;
int ans;

void input(){
  cin >> N;
}

void solve(){
  long tmp;
  for(long i=1;i*i<=N;i++){
    if(N%i==0){
      tmp=N/i;
    }
  }
  while(tmp>0){
    tmp/=10;
    ans++;
  }
}

int main(){
  input();
  solve();
  cout << ans << endl;
  return 0;
}
  


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp   make_pair
using namespace std;
int main(){
    string seq;
    cin>>seq;
    int l = seq.length(),i,j;
    bool possible=true;
    for(i=0,j=l-1;i<j;i++,j--){
        if(seq[i] != seq[j])possible= false;
    }
    if(l%2==0)possible=false;
    else{
        int e = (l-1)/2,i,j;
        for(i=0,j=e-1;i<j;i++,j--){
            if(seq[i] != seq[j])possible =false;
        }
        //cout<<possible;
        i = (l+3)/2;
        i-=1;
        j= l-1;
        for(;i<j;i++,j--){
            if(seq[i] != seq[j])possible =false;
        }
    }
    if(possible)
        cout<<"Yes\n";
    else
    {
            cout<<"No\n";
    }
    

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <map>

#define MAX_INT 2147483647
#define PI 3.141592653589793238462643383279502884L

#define long long long int

using std::vector;
using std::map;
using std::string;
using std::pair;
using std::cin;
using std::cout;
using std::cerr;

// @author: pashka

int main() {
    std::ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> p(n);
    for (int i = 1; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }

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

    vector<vector<int>> d(n);
    for (int i = 0; i < n; i++) {
        d[i].assign(w[i] + 1, MAX_INT);
        d[i][0] = 0;
    }

    for (int i = n - 1; i >= 0; i--) {
//        cerr << i << "\n";
//        for (int j = 0; j <= w[i]; j++) {
//            cerr << d[i][j] << " ";
//        }
//        cerr << "\n";
        int min = MAX_INT;
        for (int j = 0; j <= w[i]; j++) {
            min = std::min(min, d[i][j]);
        }
        if (min == MAX_INT) {
            cout << "IMPOSSIBLE\n";
            return 0;
        }
        if (i > 0) {
            int v = p[i];
            int x = w[i];
            int y = min;
            for (int j = w[v]; j >= 0; j--) {
                int dd = d[v][j];
                d[v][j] = MAX_INT;
                for (int t = 0; t < 2; t++) {
                    if (dd < MAX_INT && j + x <= w[v]) {
                        d[v][j + x] = std::min(d[v][j + x], dd + y);
                    }
                    x ^= y;
                    y ^= x;
                    x ^= y;
                }
            }
        }
    }

    cout << "POSSIBLE\n";

    return 0;
}

Measured memory_bytes: 9856
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}

bool other753(int x){
  return x!=7 && x!=5 && x!=3;
}
/*
n 10^9
 */
string s;
ll dp[11][2][2][2][2][2][2]; // digit, less, 7, 5,3,non-zero,other(contain=1)

int main(){
  cin>>s;
  int l = s.size();
  vector<int> a(l);
  REP(i,l){
    a[i] = s[i] - '0';
    LOG("%d",a[i]);
  }
  LOG("\n");

  dp[0][0][0][0][0][0][0] = 1;

  REP(i,l){
    REP(less,2){
      REP(j, 2){
        REP(k,2){
          REP(m,2){
            REP(n,2){
              REP(p,2){
                REP(x, less ? 10 : a[i]+1){
                  dp[i+1][less || x < a[i]][j || x==7][k || x==5][m || x==3][n || x!=0][p || (other753(x) && (n || x!=0))] += dp[i][less][j][k][m][n][p];

                  //LOG("dp[%d][%d][%d][%d][%d][%d]=%lld\n",i+1,less,j,k,m,n,dp[i][less][j][k][m][n]);
                }
              }
            }
          }
        }
      }
    }
  }

  REP(i,l){
    REP(less,2){
      REP(j,2){
        REP(k,2){
          REP(m,2){
            REP(n,1){
              //LOG("dp[%d][%d][%d][%d][%d][%d]=%lld\n",i+1,less,j,k,m,n,dp[i+1][less][j][k][m][n]);
            }
          }
        }
      }
    }
  }


  ll ans=0;
  REP(less, 2){
    ans += dp[l][less][1][1][1][1][0];
    //LOG("dp[%d][%d][1][1][1][0]=%lld\n",l,less,dp[l][less][1][1][1][0]);
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef gp_hash_table<int, null_type,hash<int>, equal_to<int>, direct_mask_range_hashing<int>, linear_probe_fn<>,
    hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>,true>> hash_set;
typedef gp_hash_table<int,null_type> hash_map;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-9
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 200005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

const ld PI = (ld)4*atanl(1);

mt19937 g1(chrono::steady_clock::now().time_since_epoch().count());

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int len,arr[MAXN];
ll res;

int main(){
    scanf("%d",&len);
    for(int i=1; i<=len; i++)
        scanf(" %d",&arr[i]);
    sort(arr+1,arr+len+1);
    for(int i=len; i>=1; i--){
        ll def = (fpow(4,len-1,MOD)*arr[i]%MOD)*2%MOD;
        res = (res+def)%MOD;

        def = (fpow(4,len-1,MOD)*arr[i]%MOD)*(len-i);
        res = (res+def)%MOD;
    }
    printf("%lld\n",res);
}

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


int main(void){
    long long int N,K;
    cin>>N>>K;
    long long int temp = N%K;
    long long int diff = N%K-K;
    if(diff < 0){
        diff = -diff;
    }
    if(diff<temp) cout << diff<<endl;
    else cout << temp << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++)
#define MAX 100

class State{
    public:
    int p, b, cost;
    State(int p=0, int b=0, int cost=0):p(p), b(b), cost(cost){}
};

int n, B[MAX][2];

int bfs(){
    bool V[MAX][2];
    queue<State> Q;
    rep(i, n) rep(j, 2) V[i][j] = false;
    int s0 = 0, s1 = 0;
    if ( B[s0][0] == 1 ) while( s0+1 < n && B[s0+1][0] == 1) s0++;
    if ( B[s1][1] == 1 ) while( s1+1 < n && B[s1+1][1] == 1) s1++;
    V[s0][0] = V[s1][1] = true;
    Q.push(State(s0, 0, 0));
    Q.push(State(s1, 1, 0));

    State u, v;
    while(!Q.empty()){
	u = Q.front(); Q.pop();
	if ( u.p == n-1 ) return u.cost;

	for ( int r = 0; r < 3; r++ ){
	    int np = u.p + r;
	    int nb = (u.b + 1)%2;
	    if ( np >= n ) continue;
	    if ( B[np][nb] == 2 ) while( B[np][nb] == 2 ) np--;
	    if ( B[np][nb] == 1 ) while( np+1 < n && B[np+1][nb] == 1 ) np++;
	    if ( V[np][nb] ) continue;
	    V[np][nb] = true;
	    Q.push(State(np, nb, u.cost+1));
	}
    }

    return -1;
}

main(){
    while( cin >> n ){
	if ( n == 0 ) break;
	rep(i, n) cin >> B[i][0];
	rep(i, n) cin >> B[i][1];
	int cost = bfs();
	if ( cost < 0 ) cout << "NA" << endl;
	else cout << cost << endl;
    }
}

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

int main() {
  int n, t;
  cin >> n >> t;
  
  vector<int> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  int minv; // 現時点までのリンゴの値段の最小値
  minv = a.at(0);
  vector<int> b(n); // b.at(i)は町iでの（リンゴ1個の）売却で儲ける額の最大値
  b.at(0) = 0;
  
  for(int i = 0; i < n; i++){
    b.at(i) = a.at(i) - minv;
    minv = min(minv, a.at(i));
  }
  
  sort(b.rbegin(), b.rend());
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(b.at(i) == b.at(0)) ans++;
    else break;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 N, K;
  cin >> N >> K;
  vector<i64> A(N);
  for (i64 i = 0; i < N; i++)
    cin >> A[i];
  i64 ok = 1e9, ng = 0;
  while (1 < ok - ng)
  {
    i64 mid = (ok + ng) / 2;
    i64 cnt = 0;
    for (i64 i = 0; i < N; i++)
      cnt += A[i] / mid - (A[i] % mid == 0);
    if (K < cnt)
      ng = mid;
    else
      ok = mid;
  }
  cout << ok << endl;
  return 0;
}


Measured memory_bytes: 4840
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong n, k;

int main() {
    cin >> n >> k;
    llong ans = 0;
    while (n > 0) {
        n /= k;
        ans++;
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

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

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

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int a,b;
	cin >> a >> b;
	cout << (a+b)%24 << "\n";
	return 0;
}


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

int main() {
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
    cout << "vowel";
  } else {
    cout << "consonant";
  }
}

Measured memory_bytes: 3608
/******************************************
* AUTHOR : Harish Manoharan *
******************************************/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i < b; i++)
#define N 100005
#define MOD 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n;
    cin>>n;
    map<string,int> mp;
    mp["AC"]=0;mp["WA"]=0;mp["TLE"]=0;mp["RE"]=0;
    REP(i,0,n)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}

Measured memory_bytes: 3676
#include<iostream>
#include<map>
using namespace std;
long long int T,A,B,C,D,N;
map<long long int,long long int> M;
long long int solve(long long int n){
	long long int a[3],m,id[3]={2,3,5},cost[3]={A,B,C};
	if(M.count(n))return M[n];
	for(int i=0;i<3;i++){
		if(n>=id[i]){
			a[i]=solve(n/id[i])+min((n%id[i])*D+cost[i],(n-n/id[i])*D);
			if(n-n/id[i]<1000000000){
				a[i]=solve(n/id[i])+min((n%id[i])*D+cost[i],(n-n/id[i])*D);
			}else a[i]=solve(n/id[i])+(n%id[i])*D+cost[i];
			if(n%id[i]>0){
				if(n-(n/id[i]+1)<1000000000)a[i]=min(a[i],solve(n/id[i]+1)+min((id[i]-n%id[i])*D+cost[i],(n-(n/id[i]+1))*D));
				else a[i]=min(a[i],solve(n/id[i]+1)+(id[i]-n%id[i])*D+cost[i]);
			}
		}else a[i]=n*D;
	}
	m=min(min(a[0],a[1]),a[2]);
	M[n]=m;
	return m;
}
int main(){
	cin>>T;
	for(int i=0;i<T;i++){
		M.clear();
		cin>>N>>A>>B>>C>>D;
		M[0]=0;M[1]=D;
		cout<<solve(N)<<endl;
	}
	return 0;
}

Measured memory_bytes: 4332
#include <stdio.h>

int	main(void)
{
int	A[256];
int	N, c = 0;
int	tmp;
tmp = scanf("%d", &N);
if( tmp == EOF ) return -101;

if( N==0 || N>200 ) return 1;
for( int f= 0; f< N; ++f)
{
  tmp = scanf("%d", &A[ f ]);
  //if( tmp == EOF ) return -102;
  //printf("%d ", A[ f ]);
}
//printf("\n");

do
{
  int f= 0;
  //printf("-[");
  for( f= 0; f< N; ++f)
  {
    if( A[ f ] %2 != 0 ) break;
    A[ f ] /= 2;
    //printf("%d ", A[ f ]);
  }
  //printf("]\n");

  if( f != N )
  {
    printf("%d", c);
    return	0;
  } else {
	++c;
  }
  //printf("@\n");
} while(-1);

//printf("@\n");
  return 0;
}


Measured memory_bytes: 128
a, b, c, k = map(int, input().split())

if k - a <= 0:
    print(k)
    exit()

k = k - a 
if k - b <= 0:
    print(a)
    exit()
    
k = k - b
if k  - c<= 0:
    print(a - k)
    exit()
print(a - c) 

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N,M; cin>>N>>M;
  	int hours = 0;	
  	int aux;
  
  	for(int i=0;i<M;i++){
    	cin>>aux;
      	hours += aux;
    }
  	
  	int output = (hours>N)?-1:N-hours; cout<<output;
}

Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <array>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <bitset>
#include <tuple>
#include <cmath>
#include <complex>
#include <algorithm>
#include <utility>
#include <regex>
#include <cstdint>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1'000'000'000'000'000'000;
namespace utils{
    template<class T, class Compare> using p_queue = priority_queue<T, vector<T>, Compare>;
    template<class T> using min_queue = p_queue<T, greater<T>>;
    template<class T> using max_queue = p_queue<T, less<T>>;

    template<class T> bool min_update(T& X, const T& A){ if(X > A) {X = A; return true;} return false; }
    template<class T> bool max_update(T& X, const T& A){ if(X < A) {X = A; return true;} return false; }
    using V_Set = unordered_set<int>;
    using E_Set = unordered_map<int, V_Set>;

#define ALL(x) begin(x), end(x)
#define rALL(x) rbegin(x), rend(x)
}
using namespace utils;


void sub_main(istream &is) {
    ll K; is >> K;
    ll X, Y; is >> X >> Y;
    if(!is) return;
    bool negX, negY;
    negX = X < 0; negY = Y < 0;
    X = abs(X); Y = abs(Y);
    if(K % 2 == 0 and (X+Y) % 2 == 1) {
        cout << -1 << endl; return;
    }

    ll s = (X + Y-1) / K + 1;
    if(s == 1){
        if(X+Y == K) {
            cout << "1\n";
            cout << (negX ? -X : X) << ' '
                 << (negY ? -Y : Y) << endl;
            return;
        }
        else s = 2;
    }
    ll t = K * s - X - Y;
    if(t % 2 == 1) {
        s++; t += K;
    }
    t /= 2;
    cout << s << endl;
    ll nX, nY;
    nX = 0; nY = 0;
    ll count = 0;
    while(nX != X or nY != Y){
        count++;
        if(t == 0){
            ll d = K; ll xd = X - nX;
            if(xd > d){ xd = d; d = 0; }
            else{ d -= xd; }
            ll yd = min(d, abs(Y - nY));
            nX += xd; nY += Y < nY ? -yd : yd;
        }
        else{
            if(t < K){
                if(Y < K-t){
                    nY = Y + t;
                    nX += K - (Y+t);
                }
                else{
                    nX -= t;
                    nY = K - t;
                }
                t = 0;
            }
            else{
                nX -= K;
                t -= K;
            }
        }
        cout << (negX ? -nX : nX) << ' '
             << (negY ? -nY : nY) << endl;
    }
    assert(count == s);
}

int main(int argc, char *argv[]) {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(16) << scientific;
#ifdef DEBUG
    string test_cases = "test_E.txt";
    cerr << "DEBUG MODE" <<  endl;
    cerr << test_cases << " -->" << endl;
    auto fs = fstream(test_cases, fstream::in);
    int lp = 0;
    while(fs) {
        lp++;
        cout << lp <<  "#------\n";
        sub_main(fs);
    }
    cout << "------#" << endl;
    if(lp <= 1) sub_main(cin);
#else
    sub_main(cin);
#endif
    return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/11/22  Problem: 073_arc_a / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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

	LL T; cin >> N >> T;
	VL t(N + 1, 0);
	t[N] = LINF;
	FOR(i, 0, N)cin >> t[i];
	FOR(i, 0, N) {
		ans += min(t[i + 1] - t[i], T);
	}
	cout << ans << "\n";

	return 0;
}

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

int main() {
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  int ans = a[2] * 2 - a[0] - a[1];
  if (ans & 1) cout << (ans + 3) / 2 << endl;
  else cout << ans / 2 << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <cstdlib>
#include <limits>

using namespace std;

long N, Z, W;
long a[2000];

long play_Y(int i, long x, long y);

long cache_X[2000];
long cache_Y[2000];

long play_X(int i, long x, long y) {
  if (i == N) return labs(x - y);
  if (cache_X[i] >= 0) return cache_X[i];
  
  long maxscore = -1;

  
  
  for (int j = i; j < N; ++j) {
    long score = play_Y(j + 1, a[j], y);
    if (score > maxscore)
      maxscore = score;
  }

  cache_X[i] = maxscore;
  return maxscore;
}

long play_Y(int i, long x, long y) {
  if (i == N) return labs(x - y);
  if (cache_Y[i] >= 0) return cache_Y[i];
  
  long minscore = numeric_limits<long>::max();
  
  for (int j = i; j < N; ++j) {
    long score = play_X(j + 1, x, a[j]);
    if (score < minscore)
      minscore = score;
  }

  cache_Y[i] = minscore;
  return minscore;
}

int main() {

  for (int i = 0; i < 2000; ++i) {
    cache_X[i] = cache_Y[i] = -1;
  }

  cin >> N >> Z >> W;
  for (int i = 0; i < N; ++i)
    cin >> a[i];

  cout << play_X(0, Z, W) << endl;
  return 0;
}


Measured memory_bytes: 3768
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <time.h>
int main(){
    int k,x;
    scanf("%d %d",&k,&x);
    if(500*k>=x){
        printf("Yes");
        return 0;
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <tuple>

#define rep(i,n) for(ll i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

using Graph = vector<vector<ll>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
  ll A, B, Q;
  cin >> A >> B >> Q;
  // vector<pair<ll, ll>> s(A), t(B); // s_i とそれに最も近いt_iまでの距離
  // vector<ll> x(Q);

  vector<pair<ll, ll>> arr;
  
  rep(i, A) {
    ll d;
    cin >> d;
    arr.push_back(make_pair(d, -1));
  }
  rep(i, B) {
    ll d;
    cin >> d;
    arr.push_back(make_pair(d, -2));
  }
  vector<ll> X(Q);
  rep(i, Q) {
    cin >> X[i];
    arr.push_back(make_pair(X[i], i));
  }

  ll s1, sA, t1, tB;
  s1 = arr[0].first;
  sA = arr[A-1].first;
  t1 = arr[A].first;
  tB = arr[A+B-1].first;

  sort(arr.begin(), arr.end());
  
  ll x[Q][4]; // s0 < x < s1, t2 < x < t3

  ll ns = s1;
  ll nt = t1;
  rep(i, A+B+Q) {
    if(arr[i].second>=0) {
      x[arr[i].second][0] = ns;
      x[arr[i].second][2] = nt;
    } else if(arr[i].second==-1) {
      // s
      ns = arr[i].first;
    } else if(arr[i].second==-2) {
      nt = arr[i].first;
    }
  }

  ns = sA; nt = tB;
  for(ll i=A+B+Q-1; i>=0; i--) {
    if(arr[i].second>=0) {
      x[arr[i].second][1] = ns;
      x[arr[i].second][3] = nt;
    } else if(arr[i].second==-1) {
      ns = arr[i].first;
    } else if(arr[i].second==-2) {
      nt = arr[i].first;
    }
  }

  rep(i, Q) {
    ll ret0 = abs(X[i]-x[i][0]) + abs(x[i][0]-x[i][2]);
    ret0 = min(ret0, abs(X[i]-x[i][1]) + abs(x[i][1]-x[i][2]) );
    ret0 = min(ret0, abs(X[i]-x[i][0]) + abs(x[i][0]-x[i][3]) );
    ret0 = min(ret0, abs(X[i]-x[i][1]) + abs(x[i][1]-x[i][3]) );

    ret0 = min(ret0, abs(X[i]-x[i][2]) + abs(x[i][2]-x[i][0]) );
    ret0 = min(ret0, abs(X[i]-x[i][3]) + abs(x[i][3]-x[i][0]) );
    ret0 = min(ret0, abs(X[i]-x[i][2]) + abs(x[i][2]-x[i][1]) );
    ret0 = min(ret0, abs(X[i]-x[i][3]) + abs(x[i][3]-x[i][1]) );

    cout << ret0 << endl;
  }

  return 0;
}

Measured memory_bytes: 11496
from collections import deque

q=deque()

N=int(input())

for i in range(1,10):
  q.append(i)

for _ in range(N-1):
  x=q.popleft()
  if x%10!=0:
    q.append(10*x+(x%10-1))
  q.append(10*x+(x%10))
  if x%10!=9:
    q.append(10*x+(x%10+1))

print(q.popleft())


Measured memory_bytes: 12384
import java.util.Scanner;


public class Main {
    static Scanner s = new Scanner(System.in);

    public static void main(String[] args) {
        while (true) {
            int num = s.nextInt();
            if(num==0)break;
            int count=0;
            for (int i=1;i*2<num;i++){
                int sum=0;
                for(int j=i;sum<num;j++){
                    sum+=j;
                    if(sum==num){
                        count++;
                        break;
                    }
                }
            }
            System.out.println(count);
        }
    }
}

Measured memory_bytes: 17972
#include <bits/stdc++.h>
using namespace std;
long long n,w,dp[100001],maxi;

int main(){
	cin >> n >> w;
	for(int i = 0 ; i < n ; i += 1){
		int a,b;
		cin >> a >> b;
		for(int j = w ; j >= a ; j -= 1){
			dp[j] = max(dp[j],dp[j-a]+b);
			maxi = max(maxi,dp[j]);
		}
	}
	cout << maxi << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
  string S;
  cin >> S;
  rep(0.,i,3){
    if(S[i] == '1'){
      S[i] = '9';
    }
    else{
      S[i] = '1';
    }
  }
  cout << S << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define INF 1e9
using namespace std;
typedef pair <int,int> P;
typedef pair <P,P> PP;
vector <PP> G[200];
int n,m,H,com,S,T;
priority_queue<PP,vector<PP>, greater<PP> > Q;


int dijkstra(int b){
  while(!Q.empty())Q.pop();
  int D[25][200];
  for(int i=0;i<=H;i++)for(int j=0;j<=n;j++) D[i][j]=INF;
  Q.push(PP(P(0,0),P(S,-1)));
  D[0][0]=0;
  while(!Q.empty()){
    PP t=Q.top();Q.pop();
    int cost=t.f.f,h=t.f.s,pos=t.s.f;
    if(pos==T) return cost;
    if(D[h][pos]<cost)continue;

    for(int i=0;i<(int)G[pos].size();i++){
      int ncost=cost+G[pos][i].f.s;
      int nh=h+G[pos][i].s.f;
      int nx=G[pos][i].f.f;
      if((b&(1<<G[pos][i].s.s)))ncost=cost;
      if(nh>H)continue;
      if(D[nh][nx]>ncost)Q.push(PP(P(ncost,nh),P(nx,-1)));
      D[nh][nx]=min(D[nh][nx],ncost);
    }
  }
  return INF;
}

int main(){
  while(1){
    cin>>n>>m>>H>>com;
    if(!n&&!m&&!H&&!com)break;

    for(int i=0;i<200;i++)G[i].clear();

    for(int i=0,a,b,c,h,r;i<m;i++){
      cin>>a>>b>>c>>h>>r;
      a--,b--,r--;
      G[a].push_back(PP(P(b,c),P(h,r)));
      G[b].push_back(PP(P(a,c),P(h,r)));
    }
    
    cin>>S>>T;
    S--,T--;
    int pass;

    P pc[300];
    cin>>pass;
    for(int i=0;i<pass;i++){
      int j;
      pc[i].s=0;
      cin>>j>>pc[i].f;
      while(j--){
	int a;
	cin>>a;
	pc[i].s|=(1<<(a-1));
      } 
    }

    int dp[100000];
    for(int i=0;i<300;i++)dp[i]=INF;
    dp[0]=0;
    
    for(int i=0;i<(1<<com);i++)    
      for(int j=0;j<pass;j++){
	if(dp[i]>=INF)continue;
	int b=i|pc[j].s,ncost=dp[i]+pc[j].f;
	dp[b]=min(dp[b],ncost);
      }
    
    int ans=INF;
    for(int i=0;i<(1<<com);i++){
      if(dp[i]<INF) ans=min(ans,dp[i]+dijkstra(i));
    }

    if(ans>=INF) ans=-1;
    cout<<ans<<endl;
  }
  return 0;
}

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

int main()
{
    int n;
    cin>>n;
    int a[n+5][3];
    for(int i=0; i<n; i++)
        cin>>a[i][0]>>a[i][1]>>a[i][2];

    int dp[n+5][3];
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];

    for(int i=1; i<n; i++)
    {
        dp[i][0]=a[i][0] + max(dp[i-1][1], dp[i-1][2]);
        dp[i][1]=a[i][1] + max(dp[i-1][0], dp[i-1][2]);
        dp[i][2]=a[i][2] + max(dp[i-1][0], dp[i-1][1]);
    }

    cout<< max(dp[n-1][0], max(dp[n-1][1],dp[n-1][2]))<<endl;
}



Measured memory_bytes: 5912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;
template<typename T> T factorial(T n){
    if(n==1) return 1;
    else return n*factorial(n-1)%MOD;
}
template<typename T> T Pow(T x, T n, T m){
    if(n == 0) return 1;
    if(n % 2 == 0) return Pow(x * x % m, n / 2, m);
    else return x * Pow(x, n - 1, m) % m;
}
template<typename T> T combination(T n, T k, T m){
    return factorial<T>(n) * Pow<T>(factorial(k), m-2, m) % m * Pow<T>(factorial(n-k), m-2, m) % m;
}
struct edge{
    int to; // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using graph = vector<vector<edge>>;
using Graph = vector<vector<int>>;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define MOD 1000000007
#define INF -99999999 
using namespace std;
int euclidean_gcd(int a, int b) {
  if(a < b) return euclidean_gcd(b, a);
  int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main(){
    int K; cin >> K;
    int temp,ans;
    ans = 0;
    for (int i = 1; i <= K; i++)
    {
        for (int j = 1; j <= K; j++)
        {
            for (int k = 1; k <= K; k++)
            {
                temp = euclidean_gcd(i,j);
                temp = euclidean_gcd(temp,k);
                ans += temp;
            }
            
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main()
{
  int  n, k, l[50];
  int  i, j, t, sum;

  scanf("%d %d", &n, &k);

  for(i = 0; i < n; i++) {
    scanf("%d", &l[i]);
    for(j = i; l[j-1] < l[j] && j > 0; j--){
      t = l[j-1];
      l[j-1] = l[j];
      l[j] = t;
    }
  }

  sum = 0;
  for(i = 0; i < k; i++){
     sum += l[i];
  }
  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b)  for(int i=(a),i##formax=(b);i< i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formin=(b);i>=i##formin;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max((x),(y))
#define mins(x,y) x=min((x),(y))
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define all(a) ((a).begin()),((a).end())
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define bit(n) (1LL<<(n))
typedef long long ll;
typedef __int128_t lll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>using P=pair<T,Y>;
template<class T,class Y>ostream& operator<<(ostream&o,P<T,Y>&p){return o<<"("<<p.fi<<","<<p.se<<")";}
template<class T>ostream& operator<<(ostream&o,V<T>&v){for(T&t:v)o<<t<<",";return o<<endl;}
template<class T>void uniq(V<T>&v){sort(all(v));v.erase(unique(all(v)), v.end());}

lll gcd(lll a,lll b,lll&x,lll&y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return(x%m+m)%m;}
ll modPow(lll a,lll n,ll m){lll p=1;for(;n;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return p;}
//V<ll>F,R;void setF(int n,int mod){F=R=V<ll>(++n);F[0]=1;FOR(i,1,n)F[i]=F[i-1]*i%mod;R[n-1]=modInv(F[n-1],mod);FORR(i,n-1,1)R[i-1]=R[i]*i%mod;}
//ll comb(int a,int b,int m){return a<b||b<0?0:F[a]*R[b]%m*R[a-b]%m;}

const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7; //998244353;
const int N = 500;
ll a, b, k;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> a >> b >> k;
  cout << max(a-k, 0ll) << " " << max(b-k+min(a,k), 0ll) << endl;
}

Measured memory_bytes: 256
/*
 * =template=.cpp
 * Copyright (C) 2017 hzw <hzw@huzhenweideMacBook.local>
 *
 * Distributed under terms of the MIT license.
 */
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<signal.h>
#include<unistd.h>
#define FR first
#define SC second
#define MP make_pair
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define pb push_back
#define ws wss
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
void read(int &x)
{
	char ch;int fu=1;
	while ((ch=getchar())<=32);
	x=0;
	if (ch=='-') fu=-1;else x=ch-48;
	while ((ch=getchar())>32) x=x*10+ch-48;
	x*=fu;
}
template<class T> void upmax(T &a,T b) { if (a<b) a=b;}
template<class T> void upmin(T &a,T b) { if (a>b) a=b;}

//---------template--------------
const int N=200100,p=1000000007;
int n;
int a[N],f[N],last[N];
int main()
{
	scanf("%d",&n);
	f[0]=1;
	for (int i=1;i<=n;i++) 
	{
		scanf("%d",&a[i]);
		if (a[i]==a[i-1]) { f[i]=f[i-1];continue;}
		f[i]=f[i-1];
		if (last[a[i]]>0) f[i]=(f[i]+f[last[a[i]]])%p;
		last[a[i]]=i;
	}
	printf("%d\n",f[n]);
}


Measured memory_bytes: 2560