akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;


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(b<a)
		a=b;
}


//vector<pair<int,int>> pairs;  pairs[i] = make_pair(value, value);
//sort(a.begin(),a+index_number);

//cin>>  cout<<'\n'

/*
vector<int> vec(100,-1);全ての値に-1をセット
vector<std::vector<int>> vec{{ 1, 2, 3 },{ 4, 5, 6 }};
vec.size() vec[i].size()
vec.emplace_back(20);追加
*/

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

    int ans = 0;

  
    string s;
    
  
    cin >> s;

    
    for(int i = 0; i < s.length()-1;i++){
        if(s[i] == s[i+1]){
            ans++;
        }
    }
    string a = "Good";

    if(ans >= 1){
        a = "Bad";
    }

    cout << a << endl;
    

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int i,j,n,q,count=0;
		n=scan.nextInt();
		int[] s=new int[n];
		for(i=0;i<n;i++) {
			s[i]=scan.nextInt();
		}
		q=scan.nextInt();
		int[] t=new int[q];
		for(i=0;i<q;i++) {
			t[i]=scan.nextInt();
		}
		for(i=0;i<q;i++) {
			for(j=0;j<n;j++) {
				if(s[j]==t[i]) {
					count++;
					break;
				}
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 39820
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    int b = sc.nextInt();
    if (a%b==0){
      System.out.println(0);
    } else {
      System.out.println(1);
    }
  }
}

Measured memory_bytes: 21588
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;
#include <vector>
#define rep(i,n) for (int i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

int main(){

    
    cin >> K;
    cin >> A;
    cin >> B;

    if(A%K==0){
        cout << "OK" << endl;
    }else if(B%K==0){
        cout << "OK" << endl;
    }else if(A/K<B/K){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
    

}

Measured memory_bytes: 3628
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Tree = vector<VecP>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll n;
	cin >> n;
	Vec a(n), b(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];

	ll max = 1, ansA = 0, ansB = 0;
	Vec p(n);
	repr(i, n){
		if(i == n-1) p[i] = 0;
		else if(i == n-2) p[i] = 1;
		else p[i] = p[i+1]*(n-i-1);
	}
	VecB used(n+1, true);
	rep(i, n){
		ll cnt = 0;
		repn(j, a[i]-1) if(used[j]) cnt++;
		ansA += p[i]*cnt; 
		used[a[i]] = false;
	}

	rep(i, n+1) used[i] = true;

	rep(i, n){
		ll cnt = 0;
		repn(j, b[i]-1) if(used[j]) cnt++;
		ansB += p[i]*cnt; 
		used[b[i]] = false;
	}
	co(abs(ansA-ansB));

	return 0;
}


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

int main(){
	int n,c;
	cin>>n>>c;
	long long wei[n];
	long long val[n];
	for(int i=0;i<n;i++)
		cin>>wei[i]>>val[i];
	long long ans[n+1][c+1];
	for(int i=0;i<n+1;i++){
		for(int j=0;j<c+1;j++){
			if(j==0 || i==0)
				ans[i][j]=0;
			else{
				if(j-wei[i-1]>=0){
					if(ans[i-1][j]<val[i-1]+ans[i-1][j-wei[i-1]])
						ans[i][j]=val[i-1]+ans[i-1][j-wei[i-1]];
					else
						ans[i][j]=ans[i-1][j];
				}
				else
					ans[i][j]=ans[i-1][j];
			}
//			cout<<ans[i][j]<<" ";
		}
//		cout<<endl;
	}
	long long max=0;
	for(int i=0;i<n+1;i++){
		if(max<ans[i][c])
			max=ans[i][c];
	}
	cout<<max<<endl;
			
}

Measured memory_bytes: 79104
import sys
sys.setrecursionlimit(10**7)
L = []
def lunlun(x, cnt, c):
  if cnt == 10:
    L.append(int(x))
    return
  e = int(x[-1])
  if c:
    for i in range(max(e-1, 0), min(e+2, 10)):
      lunlun(x+str(i), cnt+1, 1)
  else:
    lunlun(x+"0", cnt+1, 0)
    for i in range(1, 10):
      lunlun(x+str(i), cnt+1, 1)
lunlun("0", 1, 0)
for i in range(1, 10):
  lunlun(str(i), 1, 1)
L.sort()

k = int(input())
ans = L[k]
print(ans)

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

int main()
{
  ll ans=0;
  ll K,N;
  cin>>K>>N;
  vector<ll> A(N);
  for(ll i=0;i<N;i++){
    cin>>A[i];
  }
  
  if(N==2){
    sort(A.begin(),A.end());
    ans=min(A[1]-A[0],K-(A[1]-A[0]));
  }else{
    vector<ll> B=A;
    sort(B.begin(),B.end());
    B.push_back(B[0]);
    ll MaxB=0;
    for(ll i=0;i<N-1;i++){
      ll tmpMax=min(abs(B[i]-B[i+1]),abs(K-abs(B[i]-B[i+1])));
      MaxB=max(MaxB,tmpMax);
    }
    ll tmpMax=K-(B[N-1]-B[0]);
    MaxB=max(MaxB,tmpMax);
    ans=K-MaxB;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 6400
function Main(s){
  input = s.trim();
  var s = input.split("\n");
  var num = s[0];
  var mystr = s[1];
  var rslt = [];
  for(var i = 1; i < num; i++){
    var a = mystr.substr(0, i).split('');
    var a_rmv_dup = a.filter((x, i, self) => self.indexOf(x) === i);
    var b = mystr.substr(i, num-1).split('');
    var b_rmv_dup = b.filter((x, i, self) => self.indexOf(x) === i);
    var ab = a_rmv_dup.concat(b_rmv_dup)
    var d = ab.filter(function (x, i, self) {
            return self.indexOf(x) === i && i !== self.lastIndexOf(x);
        });
    rslt.push(d.length);
  }
  console.log(Math.max.apply(null, rslt));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
  int x1 , y1 , x2 , y2 ; 
  cin >> x1 >> y1 >> x2 >> y2 ; 
  
  cout << x2+y1-y2 << " " << y2+x2-x1 << " " << x1+y1-y2 << " " << y1+x2 - x1 << endl ; 
  
}

Measured memory_bytes: 3568
#include <iostream>
using namespace std;
typedef long long ll;
ll n, a, d[3];
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n; i++) {
        cin >> a;
        if (a % 4 == 0) d[0]++;
        else if (a % 2 == 0) d[2]++;
        else d[1]++;
    }
    if (d[2]){
        cout << (d[0] >= d[1] ? "Yes" : "No") << endl;
    } else {
        cout << (d[0] >= d[1] - 1 ? "Yes" : "No") << endl;
    }
}


Measured memory_bytes: 256
a, b = map(int, input().split())

if a > b:
    a, b = b, a

if a <= 0 and b >= 0:
    print('Zero')
elif a > 0 and b > 0:
    print('Positive')
else:
    if (- a - b) % 2 == 0:
        print('Negative')
    else:
        print('Positive')


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

int main() {
	int N, M;
	cin >> N >> M;
	vector<int>A(N);
	map<int, int>mp;
	for (int n = 0;n<N;++n) {
		cin >> A[n];
		mp[-A[n]]++;
	}
	for (int m = 0;m<M; ++m) {
		int B, C;
		cin >> B >> C;
		mp[-C] += B;
	}
	long long ans = 0;
	for (auto itr = mp.begin();itr!=mp.end();++itr) {
		if (itr->second >=N) {
			ans += (long long)N * (-1*itr->first);
			break;
		}
		else {
			ans += (long long)itr->second * (-1 * itr->first);
			N -= itr->second;
		}
	}
	cout << ans <<  endl;
	return 0;
}

Measured memory_bytes: 12932
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll n = in(), a = in(), b = in();
	string s; cin >> s;
	ll kokunai = 0, kaigai = 0;
	REP(i, n) {
		if (s[i] == 'a' && kokunai + kaigai < a + b || s[i] == 'b' && kokunai + kaigai < a + b && kaigai < b) {
			if (s[i] == 'a')++kokunai;
			else ++kaigai;
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
}

Measured memory_bytes: 896
#include<stdio.h>

int main()
{
	int A,B,C;
	int a,b,c;
	while(scanf("%d%d%d",&A,&B,&C)!=EOF)
	{
		int t=1000;
		int q=0;
		while(t--)
		{
			if(A%2==1 || B%2==1 || C%2==1) break;
			a=A/2;
			b=B/2;
			c=C/2;
			A=b+c;
			B=a+c;
			C=a+b;
			q++;		
		}
		if(t>0) printf("%d\n",q);
		else printf("-1\n");	
	}
	
	
	
}

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

#define rep(i,n) for(int i =0; i<(int)(n); i++)

int main(){
int N;
char S[10001];
char ans[10001];

scanf("%d %s",&N, S);
 int len = strlen(S);
  rep(i, len){
    if(S[i] + N > 'Z') {
      S[i] = S[i] - 26 + N;
    }else {
      S[i] = S[i] + N;
    }
    printf("%c", S[i]);
  }
   printf("\n");
  return 0;
}

Measured memory_bytes: 128
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
// メイン
int main()
{
	// 入力
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	vector<int> x(N), y(M);
	REP(i, N) cin >> x[i];
	REP(i, M) cin >> y[i];

	sort(x.rbegin(), x.rend());
	sort(y.begin(), y.end());

	int xMax = max(x[0], X);
	int yMin = min(y[0], Y);

	if (xMax < yMin) {
		cout << "No War" << endl;
	} else {
		cout << "War" << endl;
	}

	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
	
	int a;
	
	scanf("2017/01/%d",&a);
	
	if(a/10==0){
		printf("2018/01/0%d\n",a);
	} else {
		printf("2018/01/%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>

int main(){
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if (0 <= x - r && x + r<= W && 0 <= y - r && y + r <= H){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1012
N=int(input())
A=list(map(int,input().split()))
C=[]
cnt=0
for i in A:
  if 1<=i<=399:
    C.append('a')
  elif 400<=i<=799:
    C.append('b')
  elif 800<=i<=1199:
    C.append('c')
  elif 1200<=i<=1599:
    C.append('d')
  elif 1600<=i<=1999:
    C.append('e')
  elif 2000<=i<=2399:
    C.append('f')
  elif 2400<=i<=2799:
    C.append('g')
  elif 2800<=i<=3199:
    C.append('h')
  else:
    cnt+=1
D=len(set(C))
if D==0:
  print(1,cnt)
else:
  print(D,D+cnt)

Measured memory_bytes: 3064
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

n, m = inpl()
a = inpl()
s = sum(a)
cnt = 0
for i in a:
    if i >= s/(4*m):
        cnt += 1
if cnt >= m:
    print('Yes')
else: 
    print('No')


Measured memory_bytes: 4072
#include <stdio.h>
int main(void){
  int D,T,S;
  scanf("%d %d %d",&D,&T,&S);
  int A;
  A=S*T;
  if(A<D){
    printf("No\n");
  }
  else{
    printf("Yes\n");
  }
  return 0;
}

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

int main() {
    int n, q, s[100010], t[50010], left, right, mid, ans=0;
    cin >> n;
    for(int i=0; i<n; i++) cin >> s[i];
    cin >> q;
    for(int i=0; i<q; i++) cin >> t[i];
    
    for(int i=0; i<q; i++) {
        left=0;
        right=n;
        while(left<right) {
            mid=(left+right)/2;
            if(t[i]==s[mid]) {
                ans++;
                break;
            }
            else if(t[i]<s[mid]) {
                right=mid;
            }
            else left=mid+1;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <set>
#include <cstdio>
#include <bitset>
#include <functional>
#include <tuple>
#include <list>
#include <deque>
#include <sstream>
using namespace std;
const constexpr int INF = 1e9;
#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef vector<int> VI;
const constexpr ll MOD = 1e9+7;
struct Less{
   bool operator()(const pair<string, int>&a, const pair<string, int>&b){
        if(a.first==b.first){
            return a.second < b.second;
        }
       return a.first < b.first;
    }
};

ll extGCD(ll a, ll b, ll& x, ll& y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a/b*x;
    return d;
}
ll GCD(ll a, ll b){
    if(a<b) swap(a, b);
    if(b==0) return a;
    return GCD(b, a%b);
}
int par[100010], rr[100010];
void init(){
    for(int i=0; i<100010; ++i){
        par[i]=i;
        rr[i]=0;
    }
}
int root(int x){
    return par[x] == x ? x:par[x] = root(par[x]);
}
bool same(int x, int y){
    return root(x)==root(y);
}
void unite(int x, int y){
    x = root(x);
    y = root(y);
    if(x==y) return ;
    
    if(rr[x]<rr[y]){
        par[x] = y;
    }else{
        par[y] = x;
        if(rr[x]==rr[y]) rr[x]++;
    }
}

ll pow_mod(ll x, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res = res*x%MOD;
        }
        x = x*x%MOD;
        n>>=1;
    }
    return res;
}
ll fac[100010];
int main() {
    fac[1] = 1;
    for(int i=2; i<100010; ++i){
        fac[i] = (i*fac[i-1])%MOD;
    }
    ll N, M; cin >> N >> M;
    if(abs(N-M)>=2){
        cout << 0 << endl;
        return 0;
    }
    if(abs(N-M)==1){
        cout << fac[N]*fac[M]%MOD << endl;
    }else if(N==M){
        cout << (fac[N]*fac[M]%MOD)*2%MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
// 参考:http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=898251#1

#include<iostream>
#include<cstdlib>
using namespace std;
#define WIDTH 4
#define HEIGHT 2
#define MAX WIDTH * HEIGHT
#define LIMIT 50

struct Puzzle{
    char cont[MAX];
    int space; 
};

Puzzle puzzle;
int limit,path[LIMIT],MD[MAX][MAX];

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

int getHeuristic(){
  int sum = 0;
  for(int i = 0;i < MAX;++i){
    if(puzzle.cont[i]=='0')continue;
    sum += MD[i][puzzle.cont[i] - '0'];
  }
  return sum;
}

bool isSolved(){
  for(int i = 0;i < MAX;++i){
    if(puzzle.cont[i] != '0' + i )return false;
  }
  return true;
}

bool dfs(int depth,int prev){
  if(isSolved())return true;
  
  if(depth + getHeuristic() > limit) return false;

  int px,py,tx,ty;
  Puzzle tmp;
  px = puzzle.space % 4;
  py = puzzle.space / 4;
  
  for(int r = 0;r < 4;++r){
    tx = px + dx[r];
    ty = py + dy[r];

    if(max(prev,r) - min(prev,r) == 2)continue;
    if(tx < 0 || ty < 0 || tx >= WIDTH || ty >= HEIGHT)continue;

    tmp = puzzle;
    puzzle.cont[py * WIDTH + px] = puzzle.cont[ty * WIDTH + tx];
    puzzle.cont[ty * WIDTH + tx] = '0';
    puzzle.space = (ty * WIDTH) + tx;

    if(dfs(depth + 1,r)){
        path[depth] = r;
        return true;
    }
    puzzle = tmp;
  }
  return false;
}

void solve(){
  for(limit = getHeuristic();limit <= LIMIT;limit += 2){
    if(dfs(0,-100)){
      cout << limit << endl;
      return;
    }
  }
  cout << "unsolvable" << endl;
}

int main(){
    for(int i = 0;i < MAX;++i){
        for(int j = 0;j < MAX;++j){
            MD[i][j] = abs((i / 4) - (j / 4)) + abs((i % 4) - (j % 4));
        }
    }
    while(1){
        try{
            for(int i = 0;i < MAX;++i){
                cin >> puzzle.cont[i];
                if(cin.fail()){
                    throw "end";
                }
                if(puzzle.cont[i] == '0'){
                    puzzle.space = i;
                }
            }
            solve();
        } catch (const char* e) {
            break;
        }
    }
}


Measured memory_bytes: 3180
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD  = int(1e9) + 7;

int N;
vector<int> G[10010];
vector<int> c;
vector<int> val;

int p = 0;

void dfs(int u)
{
  if (val[u]) return;
  val[u] = c[p++];
  for (int nxt : G[u]) dfs(nxt);
}

signed main()
{
  cin >> N;
  c.resize(N);
  val.resize(N);

  rep(i, 0, N-1) {
    int s, t; cin >> s >> t; --s, --t;
    G[s].push_back(t);
    G[t].push_back(s);
  }

  rep(i, 0, N) cin >> c[i];

  sort(ALL(c), greater<int>());

  dfs(0);

  i64 sum = 0;
  rep(u, 0, N) {
    for (int v : G[u]) sum += min(val[u], val[v]);
  }

  cout << (sum / 2) << '\n';
  rep(i, 0, N) {
    cout << val[i] << (i + 1 < N ? ' ' : '\n');
  }

  return 0;
}



Measured memory_bytes: 1280
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
typedef pair<P,long double> Pi;
typedef pair <long double,int> Pd;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
const long double dinf=10000000000000.0;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
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 (a>b) { a=b; return 1; } return 0; }
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
string s;
cin>>s;
s.erase(unique(all(s)),s.end());
cout<<s.size()<<endl;

}


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

using namespace std;

constexpr int64_t mod_factor = 1'000'000'007;

int main() {
  int N;
  int64_t K;
  cin >> N >> K;
  vector<int64_t> nums;
  for (int i = 0; i < N; ++i) {
    int A;
    cin >> A;
    nums.push_back(A);
  }
  auto sorted = nums;
  sort(sorted.begin(), sorted.end());

  int64_t factor_large = ((K + 1) * K / 2) % mod_factor;
  int64_t factor_small = ((K - 1) * K / 2) % mod_factor;

  int64_t result = 0;
  for (auto outer = nums.cbegin(); outer != nums.cend(); ++outer) {
    for (auto inner = nums.cbegin(); inner != outer; ++inner) {
      if (*outer != *inner) {
        if (*outer < *inner == outer < inner) {
          result = (result + factor_small) % mod_factor;
        } else {
          result = (result + factor_large) % mod_factor;
        }
      }
    }
  }
  cout << result << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a,j;
   cin >>a;
    for(int i;i <= a;i++){
      j=0;
        for(j;j <= a;j++){
            if((i*4 + j*7) == a){
                cout << "Yes";
              return 0;
            }
        }
    }
cout << "No";
  return 0;
}

Measured memory_bytes: 256
class Dice:
    def __init__(self, labels):
        self.up = labels[0]
        self.front = labels[1]
        self.right = labels[2]
        self.left = labels[3]
        self.back = labels[4]
        self.down = labels[5]
    def east(self):
        self.up, self.right, self.down, self.left = self.left, self.up, self.right, self.down
    def north(self):
        self.up, self.back, self.down, self.front = self.front, self.up, self.back, self.down
    def south(self):
        self.up, self.front, self.down, self.back = self.back, self.up, self.front, self.down
    def west(self):
        self.up, self.left, self.down, self.right = self.right, self.up, self.left, self.down

dice = Dice(list(map(int, input().split())))
for cmd in list(input()):
    if cmd == 'E':
        dice.east()
    if cmd == 'N':
        dice.north()
    if cmd == 'S':
        dice.south()
    if cmd == 'W':
        dice.west()
print(dice.up)

Measured memory_bytes: 7772
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var tmp = Console.ReadLine().Split(' ');
            var a = long.Parse(tmp[0]);
            var b = long.Parse(tmp[1]);

            var xor = XorRange(a, b);
            Console.WriteLine(xor);
            //var nomal = XorOld(a, b);
            //Console.WriteLine(nomal);

            //Console.WriteLine(Convert.ToString(xor, 2));
            //Console.WriteLine(Convert.ToString(nomal, 2));
        }

        /// <summary>普通に解く</summary>
        static long XorOld(long a, long b)
        {
            var ret = 0L;
            for (var i = a; i <= b; i++)
            {
                ret ^= i;
            }
            return ret;
        }

        static long XorRange(long a, long b)
        {
            var ret = 0L;
            var aPlus = a + (16 - (a % 16)%16);            
            var nowA = a;
            while (nowA < aPlus)
            {
                ret ^= nowA;
                nowA++;
            }
            var bMinus = b - (b % 16);
            var nowB = bMinus;
            while(nowB <= b)
            {
                ret ^= nowB;
                nowB++;
            }   


            return ret;
        }


    }
}


Measured memory_bytes: 13140
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<vector>
#include<queue>
#include<deque>
#include<string>
#include<utility>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<set>
#include<map>
#include<bitset>
#include<stack>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;

inline ll read(){
    ll Hashimoto=0;
	bool Kanna=1;
    char I_Love=getchar();
    while(I_Love<'0'||I_Love>'9'){
        if(I_Love=='-')Kanna=0;
        I_Love=getchar();
    }
    while(I_Love>='0'&&I_Love<='9'){
        Hashimoto=Hashimoto*10+I_Love-'0';
        I_Love=getchar();
    }
    return (Kanna?Hashimoto:-Hashimoto);
}
template<typename T1,typename T2> inline void Umax(T1 &a,T2 b){
	if(a<b)a=b;
}
template<typename T1,typename T2> inline void Umin(T1 &a,T2 b){
	if(a>b)a=b;
}

#define I_Love_Hashimoto_Kanna main
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define filein(s) freopen(s,"r",stdin);
#define fileout(s) freopen(s,"w",stdout);
#define file freopen("I_Love_Hashimoto_Kanna.out","w",stdout);
#define RE cout<<"I_Love_Hashimoto_Kanna"<<endl;
#define Tone(Kanna) cout<<Kanna<<endl;
#define Tall(Hashimoto,Kanna) for(int I_Love=0;I_Love<(Kanna);++I_Love)cout<<Hashimoto[I_Love]<<(I_Love==(Kanna)-1?"\n":" ");
#define FOR(I_Love,Hashimoto,Kanna) for(int I_Love=Hashimoto;I_Love<(Kanna);++I_Love)
#define MP(Hashimoto,Kanna) make_pair(Hashimoto,Kanna)
#define REV(Kanna) reverse(Kanna.begin(),Kanna.end());
#define SORT(Kanna) sort(Kanna.begin(),Kanna.end());
#define UNIQUE(Kanna) Kanna.erase(unique(Kanna.begin(),Kanna.end()),Kanna.end());
#define inf (1000000000)
#define linf (1000000000000000000ll)
#define mod (1000000007)

int n,a,b;

int I_Love_Hashimoto_Kanna() {
	//完全想清楚了再开始写。
	//写不顺、不知道怎么写、很乱的时候，停下来好好想想。
	//做得慢总比做不出好。
	fastio;
	cin>>n>>a>>b;
	cout<<min(a*n,b)<<endl;
	
	
	return 0;
}


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

using namespace std;

int main() {
    string S;
    cin >> S;
    int ans = 0;

    int ptn_A = 0; // 010101..
    int ptn_B = 0; // 101010..

    int Len = S.length();

    for(int i=0; i < Len; i++) {
        char c = S[i];

        if (i % 2 == 0 && c == '1') {
            ptn_A += 1;
        }

        if (i % 2 == 0 && c == '0') {
            ptn_B += 1;
        }

        if (i % 2 == 1 && c == '0') {
            ptn_A += 1;
        }

        if (i % 2 == 1 && c == '1') {
            ptn_B += 1;
        }
    }

    ans = min(ptn_A, ptn_B);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
def main():
    N, C = map(int, input().split())
    D = [list(map(int, input().split())) for _ in range(C)]
    c = [list(map(int, input().split())) for _ in range(N)]

    cost = [[0] * C for j in range(3)]
    # 前処理
    for k in range(C):
        for i in range(N):
            for j in range(N):
                cost[(i+j)%3][k] += D[c[i][j]-1][k]

    # 全探索
    ans = float('inf')
    for i in range(C):
        for j in range(C):
            for k in range(C):
                if i != j and j != k and k != i:
                    ans = min(ans, cost[0][i] + cost[1][j] + cost[2][k])

    print(ans)





main()

Measured memory_bytes: 43740
#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

//#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector<vector<int>> mat;
//typedef unsigned int uint;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N, K;
	pair<int, int> D;
	int mina = INF;
	int a;

	cin >> N >> K;
	K--;
	rep(i, 0, N)
	{
		cin >> a;
		if (chmin(mina, a))
		{
			D.first = i;
			D.second = N - i - 1;
		}
	}

	/*int ans = 0;
	while (D.first > 0)
	{
		ans++;
		D.first -= K;
	}
	D.second += D.first;
	while (D.second > 0)
	{
		ans++;
		D.second -= K;
	}*/

	cout << (D.first+D.second+K-1)/K << endl;

	return 0;
}

Measured memory_bytes: 256
N=int(input())
A=[[int(input()),i,0] for i in range(N)]
#print(A)

A.sort()
for i in range(N):
  A[i][2]=i
#print(A)

A.sort(key=lambda x: x[1])
#print(A)

ans=0
for i in range(N):
  if i%2==0 and A[i][2]%2!=0:
    ans+=1
print(ans)

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

namespace AOZ
{
	class MainClass
	{
		static void Main(string[] args)
		{
			int h, w;
			StringBuilder ans = new StringBuilder();
			do
			{
				var input_arr = Console.ReadLine().Split(' ');
				h = int.Parse(input_arr[0]); w = int.Parse(input_arr[1]);
				if (h == 0 && w == 0)
					break;
				else
				{
					StringBuilder sb = new StringBuilder();
					for (int h_i = 0; h_i < h; h_i++)
					{
						for (int w_i = 0; w_i < w; w_i++)
						{
							if (h_i == 0 || h_i == h - 1 || w_i == 0 || w_i == w - 1)
								sb.Append("#");
							else
								sb.Append(".");
						}
						sb.AppendLine();
					}
					ans.AppendLine(sb.ToString());
				}
			} while (true);
			Console.Write(ans.ToString());
		}
	}
}



Measured memory_bytes: 15968
n,nc=map(int,input().split())
d=[list(map(int,input().split())) for _ in range(nc)]
c=[list(map(int,input().split())) for _ in range(n)]
from collections import defaultdict
dct=defaultdict(int)
for x in range(n):
  for y in range(n):
    for ci in range(nc):
      if (ci,(x+y)%3) in dct:
        dct[(ci,(x+y)%3)]+=d[c[x][y]-1][ci]
      else:
        dct[(ci,(x+y)%3)]=d[c[x][y]-1][ci]

def func(c1,c2,c3): #(i+j)%=0をc1に、=1をc2に、=2をc3に塗るときの違和感
  ret=dct[(c1,0)]+dct[(c2,1)]+dct[(c3,2)]
  return ret
ans=float('inf')
for c1 in range(nc):
  for c2 in range(nc):
    if c1==c2:continue
    for c3 in range(nc):
      if c1==c3 or c2==c3:continue
      ans=min(ans,func(c1,c2,c3))
print(ans)
#print(dct)

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

int main(){
  long long N,x,y;
  cin>>N;
  vector<long long>a(N),b(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
              for(int u=1;u<N;u++){
    if(a[u]<a[u-1]){
      break;
    }
              if(u==N-1){
                cout<<"YES"<<endl;
                return 0;
              }
            }
    for(int i=0;i<N;i++){

    for(int j=i+1;j<N;j++){
      for(int u=0;u<N;u++){
    b[u]=a[u];
  }
     b[i]=a[j];
      b[j]=a[i];
            for(int u=1;u<N;u++){
    if(b[u]<b[u-1]){
      break;
    }
              if(u==N-1){
                cout<<"YES"<<endl;
                return 0;
              }
            }
  }
  }
    cout<<"NO"<<endl;
  }

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

int main() {
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> p(N, K - Q);
    rep(i, 0, Q) {
        int a; cin >> a;
        a--;
        p[a]++;
    }
    for(auto a : p) {
        if(a > 0) cout << "Yes" << '\n';
        else cout << "No" << '\n';
    }
    return 0;
}


Measured memory_bytes: 1024
# coding: utf-8
# Your code here!
import itertools

P = [] 
for i in range(5):
    time = int(input())
    P.append(time)


    

m = 1000000
for nums in itertools.permutations(P):
    
    s = 0
    
    for i, num in enumerate(nums):
        s += num
        if s % 10 != 0 and i != 4:
            s += (10 - s % 10)
    m = min([m, s])

print(m)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

int main(){
	string S;
	cin>>S;
	if(S[0]==S[1]||S[1]==S[2]||S[2]==S[3]){
		cout<<"Bad"<<endl;
	}else{
		cout<<"Good"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n,k,d,i,j,b,sum;
  int a[100];
  sum = 0;
  scanf("%d %d", &n, &k);
  for(i=0;i<n;i++){
    a[i] = 0;
  }
  for(i=0;i<k;i++){
    scanf("%d", &d);
    for(j=0;j<d;j++){
      scanf("%d",&b);
      a[b-1] = 1;
    }
  }
  for(i=0;i<n;i++){
    if(a[i] == 1)
      sum += 1;
  }
  printf("%d", n -sum);
  return 0;
}

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

struct card {
    char suit;
    int value;
};

void bubbleSort(card A[], const int N)
{
    int flag = 1;

    for( int i = 0; flag; ++i ){
        flag = 0;

        for( int j = N-1; i < j; --j )
            if( A[j].value < A[j-1].value ){
                swap(A[j], A[j-1]);
                flag = 1;
            }
    }
}

void selectionSort(card A[], const int N)
{
    for( int i = 0; i < N; ++i ){
        int min = i;
      
        //i???????????§A[i]?????????????°???????????????????????±???????
        for( int j = i; j < N; ++j )
            if( A[j].value < A[min].value )
                min = j;
       
        //i??¨min?????°????????°??????
        if( i != min ) swap(A[i], A[min]);
    }
}

int main()
{
    //??\???
    int N;
    scanf("%d%*c", &N);
    card A[N], B[N]; //A:bubbleSort, B:selectionSort
    for( int i = 0; i < N; ++i ){
        scanf("%c%d%*c", &A[i].suit, &A[i].value);
        B[i] = A[i];
    }


    bubbleSort(A, N);
    selectionSort(B, N);


    //????????????????????????????????????
    for( int i = 0; i < N; ++i ){
        if( 0 < i ) printf(" ");
        printf("%c%d", A[i].suit, A[i].value);
    }
    printf("\n");
    printf("Stable\n");

    //?????????????????????????????????
    int flag = 1;
    for( int i = 0; i < N; ++i ){
        if( 0 < i ) printf(" ");
        printf("%c%d", B[i].suit, B[i].value);
        if( !(B[i].suit == A[i].suit && B[i].value == A[i].value) ) flag = 0;
    }
    printf("\n");
    if( flag ) printf("Stable\n");
    else printf("Not stable\n");

    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int arr[200005];
int n, tmp;
int main() {
	cin >> n;
	for(int i = 1; i < n; i++) {
		cin >> tmp;
		arr[tmp]++;
	}
	for(int i = 1; i <= n; i++) {
		cout << arr[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 4376
#include<bits/stdc++.h>
using namespace std;
int n,x,tot,ano,me=0x7fffffff;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(x%10)
		me=min(x,me);
		if(x%10)
			ano+=x;
		else
			tot+=x;
	}
	if(ano==0)
		return 0*printf("0");
	if(ano%10)
		return 0*printf("%d",ano+tot);
	printf("%d",ano+tot-me);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int DP[210000][2] = {};

int main(){
    string s;
    cin >> s;
    DP[1][0] = 1;
    for(int i = 2; i <= s.size(); i++){
        DP[i][0] = DP[i - 1][1] + 1;
        DP[i][1] = DP[i - 2][0] + 1;
        if(s[i - 1] != s[i - 2]){
            DP[i][0] = max(DP[i][0], DP[i - 1][0] + 1);
        }
        if(i < 4 || s[i - 2] != s[i - 4] || s[i - 1] != s[i - 3]){
            DP[i][1] = max(DP[i][1], DP[i - 2][0] + 1);
        }
    }
    cout << max(DP[s.size()][0], DP[s.size()][1]) << endl;
    return 0;
}

Measured memory_bytes: 2180
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<set>
#include<tuple>
#include<utility>
#include <cctype>
using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define enter "\n"

typedef long long ll;


int abc104_c(){
    //入力
    string s;
	cin >> s;
  
    //処理
  	s[3]='8';
  
    //出力
    cout << s << enter;
    return 0;
}

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


Measured memory_bytes: 256
import std;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long A, B, N;
    scan(A, B, N);
    auto f = (long x) => (A * x) / B - A * (x / B);
    if (N < B)
    {
        writeln(f(N));
        return;
    }
    writeln(max(f(B), f(B - 1)));
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define w(t) int t;cin>>t; while(t--)
using namespace std;



int main(){
    ll n;
    cin>>n;
    ll arr[n];
    for(ll i=0;i<n; i++) cin>>arr[i];
    ll dp0[n], dp1[n];
    dp0[0] = 0;
    dp1[0] = 0;
    dp0[1] = arr[0];
    dp1[1] = arr[1];
    for(ll i=2; i<n; i++){
        if(i%2==0){
            dp0[i] = max(dp1[i-1], dp0[i-1]);
            dp1[i] = max(dp1[i-2], dp0[i-2]) + arr[i];
        }
        else{
            dp1[i] = dp0[i-1] + arr[i];
            dp0[i] = dp0[i-2] + arr[i-1];
        }
        // dp0[i] = max(dp0[i-1], dp1[i-1]);
        // if(i-2>=0){
        //     dp1[i] = max(dp0[i-2], dp1[i-2]) + arr[i];
        // }
        // else dp1[i] = arr[i];
    }
    cout<<max(dp1[n-1], dp0[n-1]);
}

Measured memory_bytes: 8300
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    public static ArrayList<Long> list;
    static void solve(InputReader in, PrintWriter out){
        list = new ArrayList<>();
        int k = in.ni();
        for (long i = 1; i <= 9; i++) {
            list.add(i);
            dfs(i);
        }
        Collections.sort(list);
        out.println(list.get(k-1));
    }
    public static void dfs(long x){
        if(x > 1e10) return;
        long f = x-x/10*10;
        list.add(10*x+f);
        dfs(10*x+f);
        if(f!=0){
            list.add(10*x+f-1);
            dfs(10*x+f-1);
        }
        if(f!=9){
            list.add(10*x+f+1);
            dfs(10*x+f+1);
        }
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

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

int main(){
    vector<int> n(3);
    for (int i = 0; i < 3;i++){
        cin >> n.at(i);
    }
    sort(n.begin(), n.end());
    cout << n.at(2) * 10 + n.at(1) + n.at(0);
}


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

int main() {
	int i;
	char G[51], K[51];
	scanf("%s", K);
	scanf("%s", G);
	for (i = 0; i < strlen(G); i++) {
		printf("%c%c", K[i], G[i]);
	}
	if (strlen(K) > strlen(G)) {
		printf("%c", K[i]);
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //String[] s1 = sc.nextLine().split(" ");

        int n = Integer.parseInt(sc.nextLine());
        String[] s1 = new String[n];
        int[] intS1 = new int[n];

        int max1=0;
        int max2=0;
        for (int i = 0;i < s1.length;i++) {
        	intS1[i]=Integer.parseInt(sc.nextLine());
        	if (max1<=intS1[i]) {
        		max2=max1;
        		max1=intS1[i];
        	} else if (max2<=intS1[i]) {
        		max2=intS1[i];
        	}
        }

        for (int i = 0;i < s1.length;i++) {
        	if (intS1[i]==max1) {
        		System.out.println(max2);
        	} else {
        		System.out.println(max1);
        	}
        }
    }
}

Measured memory_bytes: 157816
//#define NDEBUG

#include <bits/stdc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define F first
#define S second
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}
#define pii pair<int, int>
#define pll pair<ll, ll>
#define modadd(a, b) (((a % MOD) + (b % MOD)) % MOD)
#define modtimes(a, b) (((a % MOD) * (b % MOD)) % MOD)

//#define TEST

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

int main(){
    StarBurstStream

    int n;
    cin >> n;

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

    int ans = 0;
    for(int i = 0; i < n; i++){
        int t;
        cin >> t;
        ans += t;
    }
    //cerr << ans << "\n";

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

    for(int i = 0; i < n - 1; i++){
        if(a[i] + 1 == a[i + 1]){
            ans += c[a[i] - 1];
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
long long gcd(long long  a, long long b)
{
	if (a < b) swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main()
{
	int N;
	long long A[100000];
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
	}
	long long an = A[0];
	for (int i = 1; i < N; i++) {
		an = gcd(an, A[i]);
	}
	printf("%lld", an);
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<bitset>
#define lson node<<1,st,mid
#define rson node<<1|1,mid+1,ed
#define mem(a,x) memset(a,x,sizeof(a))
#define me(a) memset(a,0,sizeof(a))
#define IOS ios::sync_with_stdio(false)
#define lowbit(x) x&(-x)
#define up(i,x,y) for(long long i=x;i<y;i++)
#define down(i,x,y) for(long long i=x;i>=y;i--)
#define in freopen("in.txt","r",stdin)
#define out freopen("out.txt","w",stdout)   
typedef long long ll;
const ll mod = 1e9+7;
const ll INF = 0x3f3f3f3f;
const ll maxn = 1e6+5;
const double pi = acos(-1.0);
const double eps=1e-9;
using namespace std;
int main(){
	ll a,b,c;
	cin>>a>>b>>c;
	swap(a,b);
	swap(a,c);
	cout<<a<<" "<<b<<" "<<c<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s;
  cin >> n >> s;
  int x = 0;
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'I') x++;
    if(s[i] == 'D') x--;
    ans = max(x, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256