alexjercan/bugnet huggingface dataset:
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  queue<long long> bfs;
  for (long long i = 1; i < 10; i++)
    bfs.push(i);
  while (!bfs.empty()) {
    long long now = bfs.front();
    bfs.pop();
    a--;
    if (!a) {
      cout << now << endl;
      return 0;
    }
    if (now % 10 == 9) {
      bfs.push(now * 10 + now % 10 - 1);
      bfs.push(now * 10 + now % 10);
    } else if (now % 10 == 0) {

      bfs.push(now * 10 + now % 10);
      bfs.push(now * 10 + now % 10 + 1);
    } else {
      bfs.push(now * 10 + now % 10 - 1);
      bfs.push(now * 10 + now % 10);
      bfs.push(now * 10 + now % 10 + 1);
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
bool check(long long a) {
  for (; a > 9;)
    if (abs(a % 10 - (a / 10 - a / 100 * 10)) > 1)
      return false;
    else
      a /= 10;
  return true;
}
int main() {
  int a;
  long long i = 10;
  cin >> a;
  if (a < 10) {
    cout << a;
    return 0;
  }
  for (;; i++) {
    if (check(i)) {
      a--;
    }
    if (!(a - 9))
      break;
  }
  cout << i;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

  queue<long long> que;
  for (int i = 1; i < 10; i++) {
    que.push(i);
  }

  int cnt = 0;
  while (1) {
    cnt++;
    auto x = que.front();
    que.pop();

    if (cnt == k) {
      cout << x << endl;
      break;
    }

    int y = x % 10;
    if (y != 0) {
      que.push(10 * x + y - 1);
    }
    que.push(10 * x + y);
    if (y != 9) {
      que.push(10 * x + y + 1);
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

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

bool check(int num) {
  int a;
  if (num < 10)
    return true;

  while (num >= 10) {
    if (abs(num % 10 - ((num / 10) % 10)) > 1)
      return false;
    num = num / 10;
  }

  return true;
}
int main() {
  long long int num;
  num = 1;
  int count = 0;

  int N;
  cin >> N;

  while (true) {
    if (check(num)) {
      count++;
    }
    if (count == N)
      break;
    num++;
  }

  cout << num;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
// #include<bits/stdc++.h>

using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\\n"

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

  priority_queue<long long, vector<long long>, greater<long long>> queue;
  for (int i = 1; i < 10; ++i) {
    queue.push(i);
  }
  long long x = 0;
  for (int i = 0; i < N; ++i) {
    x = queue.top();
    queue.pop();
    if (x % 10ll != 0) {
      queue.push(10ll * x + (x % 10) - 1);
    }
    queue.push(10ll * x + (x % 10));
    if (x % 10 != 9)
      queue.push(10ll * x + (x % 10) + 1);
    // cout << x << endl;
  }

  cout << x << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
// #include<bits/stdc++.h>

using namespace std;
long long MOD = 1000000007LL;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\\n"

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

  string s;
  if (N < 10) {
    cout << N << endl;
    return 0;
  }
  int num = 10;
  long long i = 11;
  long long preI = 10;
  while (num != N) {
    long long add = 0;
    s = to_string(i);
    bool runrun = true;
    bool check = true;
    for (int j = s.length() - 1; 0 < j; --j) {
      int a = s[j - 1] - 0x30;
      int b = s[j] - 0x30;
      if (1 < abs(a - b)) {
        runrun = false;
        break;
      } else if (b - a == 1 && check) {
        int buf = add % 10;
        add *= 10;
        add += max(buf - 2, 0);
        if (add == 0)
          add += 8;
      } else {
        check = false;
      }
    }
    if (runrun) {
      // cout << num << " " << preI << " " << i << " " << add << " " << endl;
      preI = i;
      ++num;
    }
    if (add != 0) {
      i += add;
    } else {
      ++i;
    }
  }

  cout << s << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
using namespace std;

bool lun(string n) {
  int len = n.length();
  for (int i = 1; i < len; i++) {
    if (abs(n[i] - n[i - 1]) > 1)
      return false;
  }
  return true;
}

string nxt(string n) {
  int len = n.length();
  for (int i = len - 2; i >= 0; i--) {
    if (n[i] + 1 != n[i + 1] && n[i + 1] != '9') {
      n[i + 1] += 1;
      for (int j = i + 2; j < len; j++) {
        if (n[j - 1] == '0')
          n[j] = '0';
        else
          n[j] = n[j - 1] - 1;
      }
      return n;
    }
  }
  if (n[0] == '9')
    n = '1' + string(len, '0');
  else {
    n[0]++;
    for (int i = 1; i < len; i++) {
      if (n[i - 1] == '0')
        n[i] = '0';
      else
        n[i] = n[i - 1] - 1;
    }
  }
  return n;
}

int main(void) {
  int k;
  string n = "10";
  cin >> k;
  if (k <= 10) {
    cout << k << endl;
    return 0;
  }
  for (int i = 10; i < k; i++) {
    // cout << n << endl;
    n = nxt(n);
  }
  cout << n << endl;
}


Error: 0

Fixed submission:

#include <iostream>
#include <vector>
using namespace std;

bool lun(string n) {
  int len = n.length();
  for (int i = 1; i < len; i++) {
    if (abs(n[i] - n[i - 1]) > 1)
      return false;
  }
  return true;
}

string nxt(string n) {
  int len = n.length();
  for (int i = len - 2; i >= 0; i--) {
    if (n[i] + 1 != n[i + 1] && n[i + 1] != '9') {
      n[i + 1] += 1;
      for (int j = i + 2; j < len; j++) {
        if (n[j - 1] == '0')
          n[j] = '0';
        else
          n[j] = n[j - 1] - 1;
      }
      return n;
    }
  }
  if (n[0] == '9')
    n = '1' + string(len, '0');
  else {
    n[0]++;
    for (int i = 1; i < len; i++) {
      if (n[i - 1] == '0')
        n[i] = '0';
      else
        n[i] = n[i - 1] - 1;
    }
  }
  return n;
}

int main(void) {
  int k;
  string n = "10";
  cin >> k;
  if (k <= 10)
    return k;
  for (int i = 11; i <= k; i++) {
    // cout << n << endl;
    n = nxt(n);
  }
  cout << n << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

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

  vector<ll> a;
  for (int i = 1; i < 10; i++) {
    a.push_back(i);
  }

  while (1) {
    if (K <= a.size()) {
      cout << a[K - 1] << endl;
      return 0;
    }
    K -= a.size();
    vector<ll> old;
    swap(old, a);
    for (ll x : old) {
      for (int i = -1; i <= 1; i++) {
        int d = x % 10 + i;
        if (d < 0 || d > 9)
          continue;
        ll nx = x * 10 + d;
        a.push_back(nx);
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

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

bool isLunlun(ll x) {
  if (x < 10)
    return true;

  string s = to_string(x);
  rep(i, s.size() - 1) {
    if (abs(int(s[i]) - int(s[i + 1])) > 1) {
      return false;
    }
  }

  return true;
}

int main() {
  int K;
  cin >> K;
  ll ng = -1;
  ll ok = 3234566668;
  // vector<ll> dp(ok, -1);

  // while (ng + 1 < ok)
  // {
  //     ll mean = (ng + ok) / 2;
  //     int cnt = 0;
  //     if (dp[mean] != -1)
  //     {
  //         cnt = dp[mean];
  //     }
  //     else
  //     {
  //         for (ll i = 1; i < mean; i++)
  //         {
  //             if (isLunlun(i))
  //             {
  //                 cnt++;
  //                 dp[i] = cnt;
  //             }
  //         }
  //     }
  // }

  ll cnt = 0;
  for (int i = 1; i < ok; i++) {
    if (isLunlun(i))
      cnt++;
    if (cnt == K) {
      cout << i << endl;
      return 0;
    }
  }

  // cout << isLunlun(123456788) << endl;

  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using ll = long long;

vector<ll> v;
void dfs(ll x, int d) {
  if (d < 0)
    return;
  v.push_back(x);
  int a = x % 10;
  if (a != 0)
    dfs(10 * x + a - 1, d - 1);
  if (a != 9)
    dfs(10 * x + a + 1, d - 1);
  dfs(10 * x + a, d - 1);
}

signed main() {

  int K;
  cin >> K;
  for (int i = 1; i <= 9; i++)
    dfs(i, 9);
  sort(v.begin(), v.end());
  cout << v[K - 1] << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int K;
  cin >> K;
  vector<int> I(1000000);
  int M = 9;
  if (K < 10) {
    for (int i = 1; i < 10; i++) {
      I.at(i - 1) = i;
    }
  } else {
    for (int64_t i = 10; i < 1000000000000000; i++) {
      string L = to_string(i);
      bool ans = true;
      for (int j = 0; j < L.size() - 1; j++) {
        if (abs(L[j] - L[j + 1]) > 1) {
          ans = false;
        }
      }
      if (ans) {
        I.at(M) = i;
        M++;
      }
      if (M > K) {
        break;
      }
    }
  }
  cout << I.at(K - 1) << endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
typedef long long ll;
using namespace std;

int isrunrun(ll a);
/*
int main(){
    int k;
    ll num = 0;
    int state = 0;
    cin >> k;
    if(k > 10000){
        num = 22111101;
        state = 10000;
    }
    while(state < k){
        num++;
        state += isrunrun(num);
        //num++;
    }
    //isrunrun(k);
    cout << num << endl;
    return 0;
}

int isrunrun(ll a){
    int runrun[100];
    //int del = 1;
    int b;
    int i = 0;

    for(i; a > 0; i++){
            runrun[i] = a%10;


        a /= 10;
        //del *= 10;
        //cout << "a " << a << " del " << del << endl;
        //cin >> b;
    }

    for(int j = 0; j < 6; j++){
        cout << runrun[j] << " ";
    }

    for(b = 1; b < i; b++){
        if(abs(runrun[b-1]-runrun[b]) > 1) break;
    }
    //cout << "b= " << b << endl;
    //cout << "i = " << i << endl;
    if(b == i)return 1;
    else return 0;
}
*/

int main() {
  queue<ll> que;
  int k;
  ll x;
  cin >> k;
  for (int i = 1; i < 10; i++) {
    que.push(i);
  }

  for (int i = 0; i < k; i++) {
    x = que.front();
    // cout << x << endl;
    que.pop();
    if (x % 10 != 0)
      que.push(10 * x + (x % 10 - 1));
    que.push(10 * x + x % 10);
    if (x % 10 != 9)
      que.push(10 * x + (x % 10 + 1));
  }
  cout << x << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;

int isrunrun(ll a);

int main() {
  int k;
  ll num = 0;
  int state = 0;
  cin >> k;
  if (k > 10000) {
    num = 22111101;
    state = 10000;
  }
  while (state < k) {
    num++;
    state += isrunrun(num);
    // num++;
  }
  // isrunrun(k);
  cout << num << endl;
  return 0;
}

int isrunrun(ll a) {
  int runrun[100];
  // int del = 1;
  int b;
  int i = 0;

  for (i; a > 0; i++) {
    runrun[i] = a % 10;

    a /= 10;
    // del *= 10;
    // cout << "a " << a << " del " << del << endl;
    // cin >> b;
  }
  /*
  for(int j = 0; j < 6; j++){
      cout << runrun[j] << " ";
  }
  */
  for (b = 1; b < i; b++) {
    if (abs(runrun[b - 1] - runrun[b]) > 1)
      break;
  }
  // cout << "b= " << b << endl;
  // cout << "i = " << i << endl;
  if (b == i)
    return 1;
  else
    return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  ll K = 0;
  cin >> K;

  queue<long long> que;

  rep(i, 9) { que.push(i + 1); }

  ll get = 0;
  rep(i, K) {

    get = que.front();
    que.pop();

    int d = get % 10;
    for (int l = -1; l <= 1; l++) {

      int j = d + l;
      if (j < 0 || j > 9)
        continue;
      que.push(get * 10 + j);
    }
  }

  cout << get << endl;
}

Error: TLE

Fixed submission:

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

unsigned GetDigit(long long num) { return log10(num) + 1; }

int main() {

  ll K = 0;

  cin >> K;

  ll index = 0;
  int count = 0;
  while (1) {

    index++;

    int dig = GetDigit(index);
    ll check = index;
    int flag = 0;
    if (dig != 1) {
      rep(i, dig - 1) {
        int a = check % 10;
        int b = (check / 10) % 10;
        if (abs(a - b) < 2) {
          check = check / 10;
          continue;
        } else {
          flag = 1;
          break;
        }
      }
    }
    if (flag == 1) {
      flag = 0;
      continue;
    }
    count++;
    if (count == K) {
      cout << index << endl;
      return 0;
    }
  }
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long K;
  cin >> K;
  queue<long long> q1;
  for (int i = 1; i <= 9; i++) {
    q1.push(i);
  }
  long long x;
  for (int i = 0; i < K; i++) {
    x = q1.front();
    q1.pop();
    if (x % 10 != 0)
      q1.push(10 * x + (x % 10) - 1);
    q1.push(10 * x + (x % 10));
    if (x % 10 != 9)
      q1.push(10 * x + (x % 10) + 1);
  }
  cout << x << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  long long K;
  cin >> K;
  long long counter = 0;
  long long ans = 0;
  long long i = 1;
  while (true) {
    string num = to_string(i);
    bool flag = true;
    bool rennbann = true;
    if (num.size() >= 2) {
      for (long long j = 0; j < num.size() - 1; j++) {
        int diff = (int)num[j + 1] - (int)num[j];
        if (diff < 0 || diff != 1)
          rennbann = false;
        if (diff < 0) {
          diff = (int)num[j] - (int)num[j + 1];
        }
        if (diff >= 2) {
          flag = false;
          break;
        }
      }
    }
    if (flag)
      counter += 1;
    if (K == counter) {
      ans = i;
      break;
    }
    if (rennbann) {
      int plus = 1;
      for (int x = 2; x < num.size(); x++) {
        plus *= 10;
      }
      i += plus;
    }
    if (!rennbann)
      i += 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  queue<ll> numbers;
  for (ll i = 1; i <= 9; i++)
    numbers.push(i);

  ll k;
  cin >> k;
  while (k > 1) {
    // cout<<numbers.front()<<endl;
    ll curr = numbers.front();
    numbers.pop();

    if (curr % 10 != 0)
      numbers.push((curr * 10 + ((curr % 10) - 1)));
    numbers.push((curr * 10 + ((curr % 10))));
    if (curr % 10 != 9)
      numbers.push((curr * 10 + ((curr % 10) + 1)));
    k--;
  }
  cout << numbers.front() << endl;
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {

#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  queue<ll> numbers;
  for (ll i = 1; i <= 9; i++)
    numbers.push(i);

  ll k;
  cin >> k;
  while (k > 1) {
    // cout<<numbers.front()<<endl;
    ll curr = numbers.front();
    numbers.pop();

    if (curr % 10 != 0)
      numbers.push((curr * 10 + ((curr % 10) - 1)));
    numbers.push((curr * 10 + ((curr % 10))));
    if (curr % 10 != 9)
      numbers.push((curr * 10 + ((curr % 10) + 1)));
    k--;
  }
  cout << numbers.front() << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  queue<ll> Q;
  int K;
  cin >> K;
  for (int i = 1; i <= 9; i++) {
    Q.push(i);
  }
  ll x;
  for (int i = 0; i < K; i++) {
    x = Q.front();
    // cout << x << " ";
    Q.pop();
    if (x % 10 != 0)
      Q.push(10 * x + (x % 10) - 1);
    // cout << Q.front() << " ";
    Q.push(10 * x + (x % 10));
    // cout << Q.front() << " ";
    if (x % 10 != 9)
      Q.push(10 * x + (x % 10) + 1);
    // cout << Q.front() << " ";
  }
  cout << x;
  return 0;
}


Error: TLE

Fixed submission:


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

bool isStepNum(long long n) {

  long long prevDigit = -1;

  while (n) {

    long long curDigit = n % 10;

    if (prevDigit == -1)
      prevDigit = curDigit;
    else {

      if (abs(prevDigit - curDigit) > 1)
        return false;
    }
    prevDigit = curDigit;
    n /= 10;
  }

  return true;
}

void displaySteppingNumbers(long long n, long long m, long long needed) {
  int j = 0, i = 1;
  while (1) {
    if (isStepNum(i))
      j++;
    if (j == needed) {
      cout << i;
      break;
    }
    i++;
  }
}

// Driver program to test above function
int main() {
  long long n = 0, m = 0, needed;
  cin >> needed;
  // Display Stepping Numbers in
  // the range [n, m]
  displaySteppingNumbers(n, m, needed);
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;

using ll = long long;
using LL = long long;

class Edge {
public:
  int from, to;
  ll value, konzatu;
  Edge(int a, int b, ll c, ll d) {
    from = a;
    to = b;
    value = c;
    konzatu = d;
  }
  Edge(LL a, LL b, LL c) {
    from = a;
    to = b;
    value = c;
  }
  Edge(LL a, LL b) {
    from = a;
    to = b;
  }
};

ll cnt = 0;
int K;
void lunlun(int n, string s) {
  if (n == s.size()) {
    cnt++;
    if (cnt == K) {
      cout << s << endl;
    }
    return;
  }
  if (s.empty()) {
    for (int i = 1; i <= 9; i++) {
      s = to_string(i);
      lunlun(n, s);
    }
  } else {
    char c = s.back();
    for (char i = '0'; i <= '9'; i++) {
      if (abs(c - i) <= 1) {
        s.push_back(i);
        lunlun(n, s);
        s.pop_back();
      }
    }
  }
}

int main() {
  cin >> K;

  for (int i = 1; i <= 12; i++) {
    lunlun(i, string());
  }
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;

using ll = long long;
using LL = long long;

class Edge {
public:
  int from, to;
  ll value, konzatu;
  Edge(int a, int b, ll c, ll d) {
    from = a;
    to = b;
    value = c;
    konzatu = d;
  }
  Edge(LL a, LL b, LL c) {
    from = a;
    to = b;
    value = c;
  }
  Edge(LL a, LL b) {
    from = a;
    to = b;
  }
};

ll cnt = 0;
int K;
void lunlun(int n, string s) {
  if (n == s.size()) {
    cnt++;
    if (cnt == K) {
      cout << s << endl;
    }
    return;
  }
  if (s.empty()) {
    for (int i = 1; i <= 9; i++) {
      s = to_string(i);
      lunlun(n, s);
    }
  } else {
    char c = s.back();
    for (char i = '0'; i <= '9'; i++) {
      if (abs(c - i) <= 1) {
        s.push_back(i);
        lunlun(n, s);
        s.pop_back();
      }
    }
  }
}

int main() {
  cin >> K;

  for (int i = 1; i <= 15; i++) {
    lunlun(i, string());
  }
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

ll bfs(int k) {
  queue<ll> que;
  int cur = 0;
  int count = 0;

  for (ll i = 1; i <= 9; ++i) {
    que.push(i);
  }

  ll tmp;
  while (count < k) {
    tmp = que.front();
    que.pop();
    ++count;

    int last = tmp % 10;
    if (last == 0) {
      que.push(tmp * 10);
      que.push(tmp * 10 + 1);
    } else if (last == 9) {
      que.push(tmp * 10 + 8);
      que.push(tmp * 10 + 9);
    } else {
      que.push(tmp * 10 + last - 1);
      que.push(tmp * 10 + last);
      que.push(tmp * 10 + last + 1);
    }
  }

  return tmp;
}

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

  cout << bfs(k) << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
using ll = long long;

ll digit(ll x) {
  int d = 1;
  while (x >= 10) {
    x /= 10;
    ++d;
  }

  return d;
}

bool lunlun(ll x) {
  ll d = digit(x);
  bool lun = true;

  if (d > 1) {
    REP(i, d - 1) {
      ll tmp = x % 10;
      ll tmp2 = x / 10 % 10;
      if (tmp - tmp2 > 1 || tmp - tmp2 < -1) {
        lun = false;
        break;
      }
      x /= 10;
    }
  }

  return lun;
}

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

  int count = 1;
  int cur = 1;
  while (count < k) {
    ++cur;
    if (lunlun(cur))
      ++count;
  }

  cout << cur << endl;

  return 0;
}