akhauriyash/Code-Regression huggingface dataset:
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

#include<bits/stdc++.h>
using namespace std;

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    int n,k;
    cin>>n>>k;
    bool ok[n+5]{0};
    memset(ok,1,sizeof ok);
    rep(i,1,k){
        int a;
        cin>>a;
        rep(j,1,a){
            int x;
            cin>>x;
            ok[x]=0;
        }
    }
    int ans=0;
    rep(i,1,n) ans+=ok[i];
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3664
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*
int inv[1000001]={0};int invf[1000001]={0};
void findinverse(){
	inv[0]=1;
	inv[1] = 1;
	for(int i = 2; i <=1e6 ; ++i)
		inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;
	invf[0]=1;invf[1]=1;
	for(int i=2;i<=1e6;i++){
		invf[i]=invf[i-1]*inv[i]%mod;
	}
}*/
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedMultiset;
int solve()
{	
	string s;
	cin>>s;
	if(s[s.length()-1]=='s')
		cout<<s<<"es"<<endl;
	else
		cout<<s<<"s"<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}



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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N,K;

int main(){
    cin>>N>>K;
    repi(i,K-N+1,K+N){
        cout<<i<<" ";
    }
    out(" ");
    
    
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  char str[300000];
  scanf("%s",str);
  
  int i,j,k=1,max=0;
  for(i=0;i<strlen(str);i++){
    if(str[i]=='A'){
      j=i;
      break;
  }
  }
  for(i=strlen(str)-1;i!=0;i--){
    if(str[i]=='Z'){
      k=i;
      break;
  }
  }
  
  printf("%d\n",k-j+1);
  return 0;
}

Measured memory_bytes: 384
s = input()

s1 = s[0:2]
s2 = s[2:4]

yl = ["{:02d}".format(i) for i in range(100)]
ml = ["{:02d}".format(i+1) for i in range(12)]

if (s1 in yl and s2 in ml) and (s1 in ml and s2 in yl):
    print('AMBIGUOUS')
elif (s1 not in yl or s2 not in ml) and (s1 not in ml or s2 not in yl):
    print('NA')
elif (s1 in yl and s2 in ml) ^ (s2 not in yl and s1 not in ml):
    print('YYMM')
elif (s2 in yl and s1 in ml) ^ (s1 not in yl and s2 not in ml):
    print('MMYY')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main() {
  int x,n,i,p;
  cin>>x>>n;
  set<int> s;
  for(i=0;i<n;i++){
    cin>>p;
    s.insert(p-x);
  }
  if(n==0) cout<<x<<endl;
  else if(!s.count(0)) cout<<x<<endl;
  else{
    int f=0;
    i=1;
    while(f==0){
      if(!s.count(-i)) {f=1; cout<<x-i<<endl;}
      else if(!s.count(i)) {f=1; cout<<x+i<<endl;}
      else i++;
    }
  }
}

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

#define long long int

const int D = 365;
vector<int> C(26), ans(D, 0);
vector<vector<int>> S(D, vector<int>(26));

void debug1()
{
    //rep(i,26) cout << C[i] << " "; cout << endl;
    rep(i,D){
        rep(j,26)cout << S[i][j] << " ";
        cout << endl;
    }
}
void rand_init()
{
    rep(i,26) C[i] = rand() % 100;
    rep(i,D) rep(j,26) S[i][j] = rand() % 20000;
}
void input()
{
    int tmp;
    cin >> tmp;
    if(tmp == 0)
    {
      rand_init();
      return;
    }
    rep(i,26) cin >> C[i];
    rep(i,D)rep(j,26) cin >> S[i][j];
    rep(i,D) cin >> ans[i]; rep(i,D) ans[i]--; //B,C問題用
}
void output()
{
    for(auto x : ans)
        cout << x+1 << "\n";
}
int calc(vector<int> &vec)
{
    int score = 0;
    vector<int> last(26, -1);
    rep(i,D) score += S[i][ans[i]];
    rep(i,D)
    {
        int cur = vec[i];
        last[cur] = i;
        rep(j,26)
        {
            score -= C[j] * (i - last[j]);
        }
        //cout << score << endl;
    }
    return score;
}
bool is_increase(vector<int> &old, vector<int> &cur, int d, int q)
{
    int a = S[d][q] - S[d][old[d]];
    int p = old[d], b = 0, c = 0;
    int last = -1;
    rep(i,D)
    {
      if(cur[i] == p) last = i;
      else b += C[p] * (i - last);
    }
    last = -1;
    rep(i,D)
    {
      if(cur[i] == q) last = i;
      else c += C[p] * (i - last);
    }
    return (a + b - c > 0);
}
    
void greedy()
{
    rep(i,D) rep(j,26)
        if(S[i][j] > S[i][ans[i]])
            ans[i] = j;
}
void rand_ans()
{
  rep(i,D) ans[i] = rand() % 26;
}
void incremental()
{
    rep(t, 130000)
    {
        int d = rand() % D, q = rand() % 26;
        vector<int> old = ans;
        ans[d] = q;
        if(calc(ans) < calc(old))
            ans = old;
    }
}
void solve()
{
  greedy();
  //rand_ans();
  incremental();
}
void rand_test(int r)
{
    rep(q,r)
    {
        rand_init();
        solve();
        cout << 1000000 + calc(ans) << endl;
    }
}
int main()
{
    input();
    //rand_test(10);
    solve();
    output();
    //cout << calc(ans) << endl;
    return 0;
}

Measured memory_bytes: 3692
# 100以下の2で割りまくれる数を用意
A = [1,2,4,8,16,32,64]
n = int(input())
ans = 0
# nがAの配列内の数より↑ならその数を答えとして選択
for i in range(len(A)):
    if n >= A[i]:
        ans = A[i]
print(ans)



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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, M, X; cin >> N >> M >> X;
    vector<ll> C(N);
    vector<vector<ll>> A(N);
    rep(i, N){
        cin >> C.at(i);
        rep(j, M){ll tmp; cin >> tmp; A.at(i).push_back(tmp);}
    }

    ll ans = INF;
    for (ll bit = 0; bit < (1<<N); ++bit) { // 1を左に2回シフトすると100
        vector<ll> S;
        for (ll i = 0; i < N; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                S.push_back(i);
            }
        }
        vector<ll> level(M); rep(i, M){level.at(i) = 0;}
        ll cost = 0;
        for (auto v: S){
            cost += C.at(v);
            rep (i, M){
                level.at(i) += A.at(v).at(i);
            }
        }

        // check
        bool flag = true;
        rep(i, M){if (level.at(i) < X){flag = false; break;}}
        if (flag){
            if (cost < ans){ans = cost;}
        }
    }
    ll out = (ans < INF) ? ans : -1;
    cout << out << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
const int mod = 1e9+7;
const int mx = INT_MAX;
const long double pi = 4*atan((long double)1);
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
int dp[1005][1005];
int n,m;
char mat[1005][1005];
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>mat[i][j];
		}
	}
	dp[0][0] = 1;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(mat[i][j]=='#')
				continue;
			if(i>0)
				dp[i][j]+=dp[i-1][j]%mod;
			if(j>0)
				dp[i][j]+=dp[i][j-1]%mod;
		}
	}
	cout<<dp[n-1][m-1]%mod;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	map<int, int> cnt;
	for(int i=0; i<n; i++){
		int a;
		cin >> a;
		cnt[a]++;
	}

	int ans=0, ecnt=0;
	for(int i=1; i<=100000; i++){
		if(cnt[i]==0) continue;
		ans++;
		if(cnt[i]%2==0) ecnt++;
	}
	if(ecnt%2==1) ans--;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.Split.Int;
            var N = line[0];
            var X = line[1];
            var L = consoleReader.Split.Int;

            var zahhyo = new List<int> { 0 };
            var lastzahhyo = 0;
            foreach (var l in L)
            {
                lastzahhyo += l;
                zahhyo.Add(lastzahhyo);
            }

            return zahhyo.Count(i => i <= X);
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader()).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }

#pragma warning disable
    public class ConsoleReader { public class SplitLine { string[] splited; public SplitLine(string line) { splited = line.Split(); } public string[] String => splited.ToArray(); public int[] Int => splited.Select(int.Parse).ToArray(); public long[] Long => splited.Select(long.Parse).ToArray(); public ulong[] ULong => splited.Select(ulong.Parse).ToArray(); public double[] Double => splited.Select(double.Parse).ToArray(); } public class RepeatLine { ConsoleReader reader; int num; public RepeatLine(ConsoleReader reader, int num) { this.reader = reader; this.num = num; } public IEnumerable<string> String { get { for (int i = 0; i < num; i++) yield return reader.String; } } public IEnumerable<int> Int { get { for (int i = 0; i < num; i++) yield return reader.Int; } } public IEnumerable<long> Long { get { for (int i = 0; i < num; i++) yield return reader.Long; } } public IEnumerable<string[]> Split { get { for (int i = 0; i < num; i++) yield return reader.Split.String; } } public IEnumerable<int[]> SplitInt { get { for (int i = 0; i < num; i++) yield return reader.Split.Int; } } } public virtual string String => Console.ReadLine(); public int Int => int.Parse(String); public long Long => long.Parse(String); public ulong ULong => ulong.Parse(String); public double Double => double.Parse(String); public SplitLine Split => new SplitLine(String); public RepeatLine Repeat(int count) => new RepeatLine(this, count); }
}

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

string by_x(int n,int x,int m){
    string ans="";
    for(int i=0;i<m;i++){
        char c=n%x+'0';
        ans=c+ans;
        n/=x;
    }
    return ans;
}

int main(){
  int n,m;
  cin >> n >> m;
  int k[m],s[m][10],p[m];
  for(int i=0;i<m;i++){
    cin >> k[i];
    for(int j=0;j<k[i];j++){
      cin >> s[i][j];
    }
    for(int j=k[i];j<10;j++){
      s[i][j]=0;
    }
  }
  for(int i=0;i<m;i++){
    cin >> p[i];
  }
  int ans=0;
  int t=pow(2,n);
  for(int i=0;i<t;i++){
    string st=by_x(i,2,n);
    //if(i==9) cout << st << endl;
    bool ok=true;
    int check[m]={};
    for(int j=0;j<n;j++){
      if(st[j]=='1'){
        for(int k=0;k<m;k++){
          for(int l=0;l<10;l++){
            if(s[k][l]==j+1){
              check[k]++;
            }
          }
        }
      }
    }
    for(int j=0;j<m;j++){
      if(check[j]%2!=p[j]){
        ok=false;
      }
    }
    if(ok) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
N,M = map(int,input().split())    
       
AB = [None]*M
for i in range(M):
    a,b = map(int,input().split())
    if a>b:
        a,b=b,a
    AB[i] = (a-1,b-1)

AB=set(AB)

tree=[[] for _ in range(N)]
for a,b in AB:
    tree[a].append(b)
    tree[b].append(a) #aがbの親、とかが保証されてれば不要。

from collections import deque

groups=[]
been=[0]*N
for i in range(N):
    if been[i]==0:
        group=[i]
        been[i]=1
        q = deque([(i,togo) for togo in tree[i]]) 
        while q:
            parent,x = q.popleft()
            if been[x]==1:
                continue
            been[x]=1
            group.append(x)
            for y in tree[x]:
                if y == parent:#親ノードを飛ばし
                    continue
                q.append((x,y))#子ノードを追加
        groups.append(group)

print(max( len(g) for g in groups))

Measured memory_bytes: 120776
#python3
import numpy as np
n=int(input())
a=np.array([int(i) for i in input().split()])
mod=int(1e9+7)
ans=0
for k in range(60):
  b = (a>>k)&1
  m = np.count_nonzero(b)
  ans += m*(n-m)*2**k
print(ans%mod)

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

int main() {

  int N = 0 ;
  cin >> N ;
  
  int sum = 0 ;
  int l , r ;
  
  for (int i = 0; i < N; i++) {
    cin >> l >> r ;
    sum = sum+r-l+1 ;
  }
	cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
const long long MAXN = 1e5+5;
multiset<pair<long long,long long>> s1;
long long arr[MAXN];
int main(){
    long long n,m;
    cin>>n>>m;
    long long total = 0;
    for(long long i=1;i<=n;i++){
        cin>>arr[i];
        total += arr[i];
    }
    sort(arr+1,arr+n+1);
    for(long long i=1;i<=m;i++){
        long long x,y;
        cin>>x>>y;
        s1.insert(make_pair(y,x));
        
    }
    
    for(long long i=1;i<=n;i++){
        if(s1.empty()){
            break;
        }
        auto it = s1.end();
        it--;
        auto hold = *it;
        
        s1.erase(it);
        if(arr[i]<hold.first){
            total+=(hold.first)-arr[i];
            hold.second--;
        }
        if(hold.second>0){
            s1.insert(hold);
        }
      
        
    }
    cout<<total<<endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    long long a,b,c,k;
    cin >> a >> b >> c >> k;
    if (k%2) cout << b-a;
    else cout << a-b;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  long n,m,l;
  long A[100][100],B[100][100],C[100][100];


  cin >> n >> m >> l;

 for(int i=0;i<n;i++){
   for(int j=0;j<l;j++){
   C[i][j]=0;
   }
 }
 

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

for(int k=0;k<m;k++){
    for(int j=0;j<l;j++){
      cin >> B[k][j];
    }
  }

 for(int i=0;i<n;i++){
   for(int k=0;k<m;k++){
     for(int j=0;j<l;j++){
       
       C[i][j]+=A[i][k]*B[k][j];
     }
   }
 }

 for(int i=0;i<n;i++){
   for(int j=0;j<l-1;j++){
     
     cout << C[i][j] << " " ;
   }
   cout << C[i][l-1] <<endl;
 }
   

    return 0;}

Measured memory_bytes: 1392
import heapq
n,m = map(int,input().split())
a = list(map(lambda x: -int(x),input().split()))
heapq.heapify(a)
for _ in range(m):
    tmp = (-heapq.heappop(a)) // 2
    heapq.heappush(a, -tmp)
print(-sum(a))

Measured memory_bytes: 14180
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> la(n), lb(n);
  for (int i = 0; i < n; ++i) {
    int p;
    cin >> p;
    la[i] += i*20000+1;
    lb[i] += (n-i-1)*20000+1;
    lb[p-1] += i;
  }
  for (int i = 0; i < n; ++i) {
    cout << la[i] << " ";
  }
  cout << endl;
  for (int i = 0; i < n; ++i) {
    cout << lb[i] << " ";
  }
  cout << endl;
}

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

#define pb push_back

using namespace std;

int data[20][20],n;
long long dp[1<<16];
vector<int> rem[17];

void generate(int bitmask,int lv)
{
  if (lv==n)
  {
    rem[__builtin_popcount(bitmask)].pb(bitmask);
    for(int c=0;c<n;c++)
    {
      if (bitmask&(1<<c))
      for(int c2=c+1;c2<n;c2++)
      {
        if (bitmask&(1<<c2))
        dp[bitmask]+=data[c][c2];
      }
    }
  }
  else
  {
    generate(bitmask,lv+1);
    generate(bitmask|(1<<lv),lv+1);
  }
}

int main()
{
  scanf("%d",&n);
  for(int c=0;c<n;c++)
  for(int c2=0;c2<n;c2++)
  scanf("%d",&data[c][c2]);
  generate(0,0);
  // for(int c=0;c<1<<n;c++)
  // {
  //   char tmp[100];
  //
  //   itoa(c,tmp,2);
  //   printf("%0*s %lld\n",n,tmp,dp[c]);
  // }
  for(int c=1;c<=n;c++)
  {
    for(int c2=0;c2<rem[c].size();c2++)
    {
      for(int c3=c/2;c3<c;c3++)
      {
        for(int c4=0;c4<rem[c3].size();c4++)
        {
          if ((rem[c][c2]|rem[c3][c4])==rem[c][c2])
          dp[rem[c][c2]]=max(dp[rem[c][c2]],dp[rem[c3][c4]]+dp[rem[c][c2]^rem[c3][c4]]);
        }
      }
    }
  }
  printf("%lld\n",dp[(1<<n)-1]);
}
/*
generate 2^16 score if they in same group
for 1->16 (1 bit of 1 -> 16 bit of 1)
foreach find minimum of sub 2 group
eg 1 bit -> not do anything
   2 bit -> get from some 1 bit + 1 bit that not intercept
   3 bit -> get from some 1 bit + 2 bit that not intercept

000 001 010 100  011 101 110 111
  0   0   0   0 -100  20  10 -90

0000 1000 0100 0010 0001 1100 1010 1001 0110 0101 0011 1110 1101 1011 0111 1111
   0    0    0    0    0   1M   1M   1M   1M   1M   -1   3M   3M 2M-1 2M-1 1M+2M+2M-1
*/


Measured memory_bytes: 1152
import java.util.Scanner;
import java.util.Stack;

public class Main {
	String input;
	public static void main(String args[]) {
		new Main().run();
	}
	Main() {
		Scanner scan = new Scanner(System.in);
		input = scan.nextLine();
	}
	void run() {
		int len = input.length();
		Stack<Area> areaStack = new Stack<Area>();
		Stack<Integer> slash = new Stack<Integer>();
		for (int i = 0; i < len; i++) {
			switch(input.charAt(i)) {
			case '\\':
				slash.push(i);
				break;
			case '/':
				if (!slash.isEmpty()) {
					Area v = new Area(slash.pop(),i);
					while (!areaStack.isEmpty()) {
						Area latest = areaStack.pop();
						if (!v.isChild(latest)) {
							areaStack.push(latest);
							break;
						}
						v.addSize(latest.getSize());
					}
					areaStack.push(v);
				}
				break;
			case '_':
				break;
			}
		}
		int[] areaSize = new int[areaStack.size()];
		int sum = 0;
		for (int i = 0; i < areaSize.length; i++) {
			areaSize[i] = areaStack.pop().getSize();
			sum += areaSize[i];
		}
		System.out.println(sum);
		System.out.print(areaSize.length);
		for (int i = areaSize.length - 1; i >= 0; i--) {
			System.out.print(" " + areaSize[i]);
		}
		System.out.println();
	}
	class Area {
		private int left;
		private int right;
		private int size;
		Area() {
			left = 0;
			right = 0;
		}
		Area(int l,int r){
			left = l;
			right = r;
			size = right - left;
		}
		public void addSize(int i) {
			size += i;
		}
		public boolean isChild(Area area) {
			return left < area.getLeft() && right > area.getRight();
		}
		public int getLeft() {
			return left;
		}
		public int getRight() {
			return right;
		}
		public int getSize() {
			return size;
		}
	}
}



Measured memory_bytes: 29848
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;


int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  int a, b; cin >> a >> b;
  int x = h / a * a;
  int y = w / b * b;
  int res = h * w - x * y;
  cout << res << '\n';
}


Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    cin>>s>>t;
    s+=s;
    bool ans=false;
    for(int i=0;i<s.size();i++){
        if(s[i]==t[0]){
            for(int j=0;j<t.size();j++){
                if(s[i+j]!=t[j]){
                    ans=false;
                    break;
                }
                ans=true;
            }
        }
        if(ans){break;}
    }
    if(ans){
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i = a:i<b;i++)
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;

int main (){
  string s;
  while (cin >> s){
    int ans = 0;
    REP(i,3){
      if(s[i] == '1') ans ++;
    }

    cout << ans << endl;
  }
  return 0;
}


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

#define DIV 1000000007

using namespace std;

int main(){
	string S;
	cin >> S;
	set<char> hoge;
	bool s = false, n = false, w = false, e = false;
	for(int i = 0; i < S.size(); i++){
		if(S[i] == 'S'){
			s = true;
		}
		if(S[i] == 'N'){
			n = true;
		}
		if(S[i] == 'W'){
			w = true;
		}
		if(S[i] == 'E'){
			e = true;
		}
	}
	if((s ^ n) || (w ^ e)){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main()
{
	string s, t;
	cin >> s >> t;
	int c = 0;
	rep(i, 0, s.size()) {
		if (s[i] != t[i])c++;
	}
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 3856
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
int main(){
	int a, b; cin >> a >> b;

	cout << a + (b / 2) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
int main() {
	int N;	cin >> N;
	vector<int> num(N);
	int maxN = 0;
	for (int i = 0; i < N; ++i) {
		int n = 0;
		int m = i + 1;
		while (m) {
			if (m % 2 == 0) {
				m /= 2;
				++n;
			}
			else {
				break;
			}
		}
		num[i] = n;
		if (maxN <= n) {
			maxN = n;
		}
	}
	for (int i = 0; i < N; ++i) {
		if (num[i] == maxN) {
			cout << i + 1 << endl;
		}
	}
	cin >> N;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll A, B, N;
  IN(A,B,N);

  ll ans = 0;

  if(N>=B){
    chmax(ans, (A*(B-1))/B);
  }else{
    chmax(ans, ((A*N)/B));
    chmax(ans, ((A*(N-1))/B));
  }

  OUT(ans);
  

  return 0;
}

Measured memory_bytes: 3672
n = int(input())
a = [int(input()) for i in range(n)]

from collections import defaultdict
d = defaultdict(bool)
ans = 1
t = a[0]

for _ in range(n):
  if t==2:
    break
  else:
    if d[t]:
      ans = -1
      break
    else:
      d[t] = True
      t = a[t-1]
      ans += 1

print(ans)

Measured memory_bytes: 16652
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 2020;
int a[N][N];
int m, n;
int ans = 0;

int getSum(int x1, int y1, int x2, int y2) {
	return a[x2][y2] + a[x1][y1] - a[x2][y1] - a[x1][y2];
}

int solve(int x, int y) {
	if (x <= n)
		return getSum(x, y, x + n, n) + getSum(0, 0, x, y) + getSum(x + n, 0, 2 * n, y);
	else
		return getSum(0, y, x - n, n) + getSum(x - n, 0, x, y) + getSum(x, y, 2 * n, n);
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &m, &n);
	while(m--) {
		int x, y;
		char c;
		scanf("%d%d %c", &x, &y, &c);
		if (c == 'W')
			x += n;
		x %= 2 * n;
		y %= 2 * n;
		if (y >= n) {
			x += n;
			y -= n;
		}
		x %= 2 * n;
		a[x + 1][y + 1]++;
	}

	for (int x = 1; x < N; x++)
		for (int y = 1; y < N; y++)
			a[x][y] += a[x - 1][y] + a[x][y - 1] - a[x - 1][y - 1];

	for (int x = 0; x < 2 * n; x++)
		for (int y = 0; y < n; y++) {
			ans = max(ans, solve(x, y));
		}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 19804
//
//  main.cpp
//  Atcoder1
//
//  Created by Hamske on 2020/09/17.
//  Copyright © 2020 Author. All rights reserved.
//

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <sstream>

using namespace std;

//#define pb push_back
//#define mp make_pair
#define fi first
#define se second

typedef long long ll;

//#define rep(_i,iv,n) for(int _i=(int)(iv);_i<(int)(n);++_i)
#define rep0(_i,n) for(int _i=0;_i<(int)(n);++_i)
//#define REP(_i,iv,_l,n) for(int _i=(int)(iv),_l=(int)(n);_i<_l;++_i)
#define REP0(_i,_l,n) for(int _i=0,_l=(int)(n);_i<_l;++_i)

//#define all(x) (x).begin(),(x).end()
#define REPV(v,_itr,_end) for(auto _itr=(v).begin(),_end=(v).end();_itr!=_end;++_itr)
#define REPVC(v,_itr,_end) for(auto _itr=(v).cbegin(),_end=(v).cend();_itr!=_end;++_itr)

#define td typedef
//#define tds(stl,type,name) typedef stl<type > name;
#define tdv(type,name) typedef vector<type > name;

typedef vector<bool> vb;
typedef vector<vb > vvb;
typedef vector<int> vi;
typedef vector<vi > vvi;
typedef vector<ll> vll;
typedef vector<vll > vvll;

#define INF 1<<30

td pair<int, int > pii;
td priority_queue<pii,vector<pii>,greater<pii> > pq;

template<typename T>
T ceil(T x,T y){
    return x/y+(x%y==0?0:1);
}

int main(int argc, const char * argv[]) {
    int K;
    scanf("%d",&K);
    stringstream ss;
    rep0(i, K){
        ss<<"ACL";
    }
    printf("%s\n",ss.str().c_str());
    
    return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 +c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int H,W,cnt[30];
char s[15][15];
bool vis[15][15];
void Solve() {
    read(H);read(W);
    for(int i = 1 ; i <= H ; ++i) {
        scanf("%s",s[i] + 1);
    }
    for(int i = 1 ; i <= H ; ++i) {
        for(int j = 1 ; j <= W ; ++j) {
            if(s[i][j] == '#') {
                ++cnt[i + j];
                if(cnt[i + j] >= 2) {puts("Impossible");return;}
            }
        }
    }
    puts("Possible");
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, S, E) for (int(X) = (S); (X) < (E); ++(X))
#define rrep(X, S, E) for (int(X) = (E)-1; (X) >= (S); --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

void solve(long long N, std::string S) {
  ll t = 0;
  ll minT = 0;
  rep(i, 0, N) {
    if (S[i] == '(') {
      t++;
    } else {
      t--;
    }
    minT = min(minT, t);
  }

  if (minT >= 0 && t == 0) {
    print(S);
  } else if (minT < 0) {
    rep(i, 0, -minT) { cout << '('; }

    t = -minT;
    rep(i, 0, N) {
      if (S[i] == '(') {
        t++;
      } else {
        t--;
      }
    }

    if (t == 0) {
      print(S);
    } else {
      cout << S;
      rep(i, 0, t) { cout << ')'; }
      cout << endl;
    }
  } else {
    cout << S;
    rep(i, 0, t) { cout << ')'; }
    cout << endl;
  }
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::string S;
  std::cin >> S;
  solve(N, S);
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
N = int(input())
student_list = [0] * (N + 1)
turn_list = [int(x) for x in input().split()]

for i, s in enumerate(turn_list):
    student_list[s] = i + 1
student_list.pop(0)
for s in student_list:
    print(str(s), end=' ')
print()


Measured memory_bytes: 14648
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    int R;
    cin >> R;
    if(R<1200)
    {
        cout << "ABC";
    }
    else if(R<2800)
    {
        cout << "ARC";
    }
    else
    {
        cout <<"AGC";
    }
    return 0;
}



Measured memory_bytes: 256
def ans():
    n = int(input())
    ps = list(map(int, input().split()))
    cnt = 0
    for i in range(n):
        if i+1 != ps[i]:
            cnt += 1
        if cnt >= 3:
            return False
    return True


if ans():
    print('YES')
else:
    print('NO')



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

int main() {
int  N;
  cin >> N;
int X[110] ;
  for (int i=0;i<N;i++){
    cin >> X[i];
  }
long long mp=pow(10,7);
  for (int j=1;j<=100;j++){
     long long sum=0;
    for (int i=0;i<N;i++){
	  sum +=pow(X[i]-j,2);
    }
 	mp=min(mp,sum);                         
  }
  cout << mp << endl;  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 1e9 + 7;

const ll N = 2010;
ll dp[N];

ll solve(ll cur, ll s) {
    if(cur > s) return 0;
    if(cur == s) return 1;
    if(dp[cur] != -1) return dp[cur];
    ll res = 0;
    for(ll i = 3; i <= s - cur; i++) {
        res = (res + solve(cur + i, s)) % mod;
    }
    dp[cur] = res;
    return res;
}

void solve() {
    ll s;
    cin >> s;
    ll cur = 0;
    for(ll i = 0; i < N; i++) dp[i] = -1;
    solve(cur, s);
    cout << dp[0] << "\n";
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

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

using namespace std;

int main() {

    int N, M;
    cin >> N >> M;

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

    vector <pair<int, int> > AB(N);
    for (int i = 0; i < N; i++) {
        AB[i] = make_pair(A[i], B[i]);
    }

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

    long long ans = 0; // 円
    int drinks = M;

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

        int stock = AB[i].second;
        int temp;
        if (stock <= drinks) {
            temp = stock;
        } else {
            temp = drinks;
        }

        drinks -= temp;
        ans += AB[i].first * (long long)temp;

        if (drinks == 0) {
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
string s[19];
int bx[20],by[20];
int id[19][15];
int dx[8]={-1,-1,-1,0,1,1,1,0};
int dy[8]={-1,0,1,1,1,0,-1,-1};
int B;
typedef pair<int,int> P;
typedef pair<P,int> PP;
set<PP> st;
bool is(int x,int y){
	return 0<=x&&x<19&&0<=y&&y<15;
}
bool isX(int x,int y,int b){
	return is(x,y)&&id[x][y]>=0&& ((b>>id[x][y])&1);
}
bool goal(int x,int y){
	return x==19||(x==18&&is(x,y));
}
int main(){
	rep(i,19) rep(j,15) id[i][j]=-1;
	rep(i,19) cin>>s[i];
	int sx,sy;
	rep(i,19) rep(j,15){
		if(s[i][j]=='O') sx=i,sy=j;
		if(s[i][j]=='X') bx[B]=i,by[B]=j,id[i][j]=B++;
	}
	queue<int> qx,qy,qb,qd;
	qx.push(sx),qy.push(sy),qb.push((1<<B)-1),qd.push(0);
	st.insert(PP(P(sx,sy),(1<<B)-1));
	while(!qx.empty()){
		int x=qx.front(),y=qy.front(),b=qb.front(),d=qd.front();
		qx.pop(),qy.pop(),qb.pop(),qd.pop();
		rep(di,8){
			int nx=x+dx[di],ny=y+dy[di],nb=b,nd=d+1;
			if(!isX(nx,ny,nb)) continue;
			while(isX(nx,ny,nb)){
				nb^=(1<<id[nx][ny]);
				nx+=dx[di],ny+=dy[di];
			}
			if(goal(nx,ny)){
				cout<<nd<<endl;
				return 0;
			}else if(is(nx,ny)&&st.find(PP(P(nx,ny),nb))==st.end()){
				qx.push(nx),qy.push(ny),qb.push(nb),qd.push(nd);
				st.insert(PP(P(nx,ny),nb));
			}
		}
	}
	puts("-1");
}

Measured memory_bytes: 8176
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <bitset>
#include <vector>
#include <queue>
 
using namespace std;
 
typedef long long ll;
#define FOR(i,a,b)   for(ll i = (a); i < (b); i++ )
#define REP(i, n)    FOR(i,0,n)
typedef pair< ll, ll >   cp2;
typedef pair< ll, cp2 >   cp3;
#define fi first
#define se second
#define sec  se.fi
#define thr  se.se
const ll mod = 1000000007;
//              123456789
 
  
///////////////////////////////////////////////
//
//
///////////////////////////////////////////////
 
////////////////////////////////////////////////
////////////////////////////////////////////////
 
 
ll N, k, num, sum;
ll a, b;
 
int main() {
     
    while( cin>>N, N ){
        k = 1;
         
        while( 1 ){
            num = (1LL<<k)-1LL;
            sum = (9*9ll)*num;
            if( N - sum <= 0 ) break;
            N -= sum;
            k++;
        }
        //cout<<"N:"<<N<<endl;
        //cout<<"K:"<<k<<endl;
        N--;
        a = (N/(num*9LL))+1;
        N %= (num*9LL);
        cout<<a;
         
        b = a;
        while( a == b ){
            REP( i, 10 ){
                b = i;
                if( i == a ){
                    num = 9LL*((1LL<<(k-1LL))-1LL);
                }
                else{
                    num = 1LL<<(k-1LL);
                }
                if( N - num < 0 ) break;
                N -= num;
            }
            cout<<b;
            k--;
        }
        while( k-- ){
            if( ((N&(1LL<<k)) == 0) ^ (a > b) ) cout<<a;
            else{                 cout<<b;}
        }
        puts("");
        //cout<<"a:"<<a<<endl;
        //cout<<"b:"<<b<<endl;
    }
    return 0;
}



Measured memory_bytes: 3016
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define print(X) cout << (X) << "\n"
#define _ << " " <<
static const int INF = 1e+9+7;

int main(){
    ll n;
    cin >> n;
    ll max = -1000000;
    ll min = 1000000;
    ll sum = 0;
    rep(i,0,n){
      ll x;
      cin >> x;
      if(x < min) min = x;
      if(x > max) max = x;
      sum += x;

    }
    cout << min _ max _ sum << "\n";


  return 0;
}





Measured memory_bytes: 3136
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
  int a, b;
  cin >> a >> b;
  if(a <= 9 && b <= 9){
    cout << a*b << endl;
  }else{
    cout << -1 << endl;
  }
   return 0;
}


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

int main() {
    vector<int> l(3);
    for(int i=0; i<3; i++){
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    cout << l[0] + l[1] << 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++)
const int INF=1e9;

int main()
{
    int n,x,t;
    cin >>n >>x>>t;

    int tmp=0;
    int cnt=0;
    while(tmp<n)
    {
        tmp+=x;
        cnt++;
    }
    
    cout <<cnt*t;

}
        


        





        



    






Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vector<int> a(n + 1), b(n + 1), c(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
	}
	for (int i = 1; i < n; i++) {
		cin >> c[i];
	}
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		sum += b[a[i]];
	}
	for (int i = 1; i < n; i++) {
		if (a[i + 1] - a[i] == 1)
			sum += c[a[i]];
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace B______
{
    class Program
    {
        static void Main(string[] args)
        {
            var O = Console.ReadLine();
            var E = Console.ReadLine();
            string str = "";
            int o = 0, e = 0;

            for (int i = 0; i < O.Length + E.Length; i++)
                str +=  i % 2 == 0 ? O[o++] : E[e++];

            Console.WriteLine(str);
        }
    }
}


Measured memory_bytes: 11092
#include<cstdio>
int main(){
	long long n,s,f[107];
	int p=1,a[107];
	scanf("%lld",&n);
	f[0]=1;
	for(;n;++p){
		s=0;
		int q=0;
		while(s+f[q]<=n&&q<p)s+=f[q++];
		for(int i=p;i>q;--i)a[i]=a[i-1],f[i]=f[i-1];
		a[q]=p,f[q]=s;
		n-=s;
	}
	printf("%d\n",p*2-2);
	for(int i=1;i<p;++i)printf("%d ",i);
	for(int i=1;i<p;++i)printf("%d ",a[i]);
	return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

int main(){
    int N;
    string S;

    cin >> N >> S;

    int ans = 0;
    for(int i = 1; i < N; i++){
        int count = 0;

        for(char c = 'a'; c <= 'z'; c++){
            bool right = false, left = false;

            for(int j = 0; j < i; j++){
                if(S[j] == c) right = true;
            }

            for(int j = i; j < N; j++){
                if(S[j] == c) left = true;
            }

            if(right && left) count++;
        }

        if(ans < count) ans = count;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
typedef long long ll;
using namespace std;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)

int main()
{
    string aim = "CODEFESTIVAL2016",s;
    cin >> s;
    int ans = 0;
    repi(i,s.size(),0){
        if(s[i]!=aim[i])ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
int main()
{
    vector < string > v ;
    int n,m ;
    cin >> n >> m ;
    string s ;
    for(int i =0 ; i < n ;i++)
    {
        cin >> s ;
        v.push_back(s) ;
    }
    for(int i = 0 ; i < v.size() ; i++)
    {
        cout << v[i] << endl ;
        cout << v[i] << endl ;
    }
}


Measured memory_bytes: 256
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, q; rd(n, q);
  while(q--){
    int v, w; rd(v, w);
    v--; w--;
    if(n==1){writeln(v+1); continue;}
    auto fun(int i){
      int ret=0;
      while(i>0) i=(i-1)/n, ret++;
      return ret;
    }
    auto dv=fun(v), dw=fun(w);
    foreach(_; 0..(dw-dv)) w=(w-1)/n;
    if(v==w){writeln(v+1); continue;}
    while(v!=w){
      v=(v-1)/n;
      w=(w-1)/n;
    }
    writeln(v+1);
  }
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) write(e, " ");
  writeln();
}

Measured memory_bytes: 2300
a=[]
for i in range(3):
  A, B= list(map(int, input().strip().split(' ')))
  a.append(A)
  a.append(B)

sum_1=0
sum_2=0
sum_3=0
sum_4=0
for i in range(6):
  if a[i] == 1:
    sum_1 = sum_1+1
  elif a[i] == 2:
    sum_2 = sum_2+1
  elif a[i] == 3:
    sum_3 = sum_3+1
  else:
    sum_4 = sum_4+1
if sum_1 > 2 or sum_2 > 2 or sum_3 > 2 or sum_4 > 2:
  print("NO")
else:
  print("YES")

Measured memory_bytes: 3064