alexjercan/bugnet huggingface dataset:
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
  long long int n, m, i, j, k, l;
  cin >> n >> m;
  if (n == 0)
    cout << n << endl;
  else {
    if (n % m == 0)
      cout << 0 << endl;
    else {
      l = n / m;
      n -= m * l;
      j = abs(n - m);
      if (j < n) {
        k = 1;
        while (k) {
          k = abs(j - m);
          if (k < j) {
            j = k;
          } else
            break;
        }
        cout << j << endl;
      } else {
        cout << n << endl;
      }
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;
int main() {
  int n, m, i;
  cin >> n >> m;
  if (n == 0)
    cout << m << endl;
  else {
    if (n % m == 0)
      cout << 0 << endl;
    else {
      int t = abs(n - m);
      int k = 1;
      while (k) {
        k = abs(t - m);
        if (k < t) {
          t = k;
        } else
          break;
      }
      cout << t << endl;
    }
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

void process();
LL GCD(LL a, LL b);
int main() {
  ULL N, K;
  ULL min = 10e18 + 1;
  cin >> N >> K;
  while (min > N) {
    min = N;
    if (N > K) {
      N = N % K;
    } else {
      N = K - N;
    }
  }
  cout << min << endl;
  return 0;
}

LL GCD(LL a, LL b) { return b; }

void process() {}

Error: WA

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

void process();
LL GCD(LL a, LL b);
int main() {
  LL N, K;
  LL ans;
  cin >> N >> K;
  if (N == 0) {
    if (N >= K) {
      ans = GCD(N, K);
    } else {
      ans = GCD(K, N);
    }
    if (ans == K) {
      ans = 0;
    }
  } else {
    ans = 0;
  }
  cout << ans << endl;
  return 0;
}

LL GCD(LL a, LL b) {
  LL temp;
  while (a % b > 0) {
    temp = a % b;
    a = b;
    b = temp;
  }
  return b;
}

void process() {}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long int n, k;
  cin >> n >> k;
  int t = 0;
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }
  n = n % k;
  while (t == 0) {
    if (n > abs(n - k)) {
      n = abs(n - k);
    } else {
      break;
    }
  }
  cout << n << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  long long int n, k;
  cin >> n >> k;
  int t = 0;
  if (k == 1) {
    cout << 0 << endl;
    return 0;
  }
  while (t == 0) {
    if (n > abs(n - k)) {
      n = abs(n - k);
    } else {
      break;
    }
  }
  cout << n << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long N, K;
  cin >> N >> K;
  N %= K;
  cout << min(N, abs(N - K)) << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  long long N, K;
  cin >> N >> K;
  if (K == 1) {
    cout << 0 << endl;
    return 0;
  }

  while (1) {
    if (N < abs(N - K))
      break;
    N = abs(N - K);
  }
  cout << N << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long long N, K; // 1 <= N, K <= 10^18 , in Z
  cin >> N >> K;
  long long A = N % K;
  cout << min(A, K - A) << endl;
}

Error: WA

Fixed submission:

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

int main() {
  int N, K = 0;
  cin >> N >> K;

  int M = max(N, K) + 1;
  vector<int> vec(M);
  vec.at(0) = N;

  int i;
  for (i = 1; i < M; i++) {
    vec.at(i) = abs(vec.at(i - 1) - K);
  }

  sort(vec.begin(), vec.end());
  cout << vec.at(0);
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

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

Error: 0

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  int result = 0;
  for (int a = 0; a >= 0; a++) {
    if (N <= K) {
      cout << min(N, K - N) << endl;
      break;
    } else {
      N = N % K;
    }
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long N, K;
  cin >> N >> K;
  long sub = N % K;
  if (sub > K - sub)
    cout << K - sub << endl;
  else
    cout << sub << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  int sub = N % K;
  if (sub > K - sub)
    cout << K - sub << endl;
  else
    cout << sub << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ld long double
#define db double
#define pi 3.1415926535897932384626
#define PI acos(-1.0)
#define endl "\\n"
#define mod 1000000007
#define mk make_pair
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x, y) fixed << setprecision(y) << x
#define w(t)                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define sc(a) scanf("%lld", &a);
#define pr(a) printf("%lld\\n", a)
#define f(i, a, n) for (ll i = a; i < n; i++)
#define m(a) memset(a, 0, sizeof(a))
#define FastIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0), cout.tie(0)

int main() {
  FastIO;

  ll n, k;
  cin >> n >> k;
  cout << min(n % k, k - (n % k));

  return 0;
}

Error: WA

Fixed submission:

/* Author - thiolhub */

#include <bits/stdc++.h>

using namespace std;

#define ll long long int
#define ld long double
#define db double
#define pi 3.1415926535897932384626
#define PI acos(-1.0)
#define endl "\\n"
#define mod 1000000007
#define mk make_pair
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define mii map<int, int>
#define pqb priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define setbits(x) __builtin_popcountll(x)
#define zrobits(x) __builtin_ctzll(x)
#define ps(x, y) fixed << setprecision(y) << x
#define w(t)                                                                   \\
  ll t;                                                                        \\
  cin >> t;                                                                    \\
  while (t--)
#define sc(a) scanf("%lld", &a);
#define pr(a) printf("%lld\\n", a)
#define f(i, a, n) for (ll i = a; i < n; i++)
#define m(a) memset(a, 0, sizeof(a))
#define FastIO                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0), cout.tie(0)

int main() {
  FastIO;

  int n, k;
  cin >> n >> k;
  cout << min(n % k, k - (n % k));

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

#include <iostream>
#include <math.h>
#define LL long long
#define FIO ios_base::sync_with_stdio(false), cin.tie(0)
using namespace std;

int main() {
  LL n, k;
  cin >> n >> k;
  if (n % k == 0) {
    cout << 0 << endl;
    return 0;
  }

  LL a = n % k, b = abs(k - a);
  if (a < b)
    cout << a << endl;
  else
    cout << b << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, k;

  cin >> n >> k;
  int t;
  int m = 1;
  if (k == 1) {
    cout << 0 << endl;
    m = 0;
  }
  if (n % 2 == 0 && k % 2 == 0) {
    cout << 2 << endl;
    m = 0;
  }
  while (m) {
    t = n - k;
    if (t < 0) {
      t = -t;
    }
    if (t == n || t == 0) {
      cout << t << endl;
      m = 0;
    } else
      n = t;
  }

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

#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

int main() {
  long long int n, k;
  cin >> n >> k;
  if (n == k)
    cout << 0;
  else if (n < k) {
    if (n < labs(n - k))
      cout << n;
    else
      cout << labs(n - k);
  } else {
    if (n % k == 0)
      cout << 0;
    else {
      n = n % k;
      cout << abs(n - k);
    }
  }
}

Error: TLE

Fixed submission:

#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

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

  while (true) {
    if (labs(n - k) < n) {
      n = labs(n - k);
    } else {
      ans = n;
      break;
    }
  }
  cout << n << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long N, K;
  cin >> N >> K;
  long t = N % K;
  if (t >= K - t) {
    cout << K - t << endl;
  }
  if (t < K - t) {
    cout << t << endl;
  }
}


Error: 0

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  int t = (N - K);
  if (N % t >= K - (N % t)) {
    cout << K - N % t << endl;
  }
  if (N % t < K - (N % t)) {
    cout << N % t << endl;
  }
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  unsigned long N, K;
  cin >> N >> K;
  unsigned long x, y;

  if (N % K) {
    x = N / K + 1;
  } else {
    x = N / K;
  }
  y = N - x * K;
  cout << min(-y, y + K) << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  int x, y;

  if (N % K) {
    x = N / K + 1;
  } else {
    x = N / K;
  }
  y = N - x * K;
  cout << min(abs(y), y + K) << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  long int N, K;
  cin >> N >> K;
  long int ans = min(N % K, K - N % K);
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  int ans = min(N % K, K - N % K);
  cout << ans << endl;
}
Problem p02719 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k;
  cin >> n >> k;
  long long a = n % k;
  long long ans = min(a, k - a);
  cout << ans;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int a = n % k;
  int ans = min(a, k - a);
  cout << ans;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

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

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

Error: WA

Fixed submission:

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

int main() {
  long n, kk;
  cin >> kk;
  vector<long> vec;
  for (int a = 0; a < 4; a++) {
    for (int b = a - 1; b < a + 2; b++) {
      if (b < 0 || 9 < b) {
        break;
      }
      for (int c = b - 1; c < b + 2; c++) {
        if (c < 0 || 9 < c) {
          break;
        }
        for (int d = c - 1; d < c + 2; d++) {
          if (d < 0 || 9 < d) {
            break;
          }
          for (int e = d - 1; e < d + 2; e++) {
            if (e < 0 || 9 < e) {
              break;
            }
            for (int f = e - 1; f < e + 2; f++) {
              if (f < 0 || 9 < f) {
                break;
              }
              for (int g = f - 1; g < f + 2; g++) {
                if (g < 0 || 9 < g) {
                  break;
                }
                for (int h = g - 1; h < g + 2; h++) {
                  if (h < 0 || 9 < h) {
                    break;
                  }
                  for (int i = h - 1; i < h + 2; i++) {
                    if (i < 0 || 9 < i) {
                      break;
                    }
                    for (int j = i - 1; j < i + 2; j++) {
                      if (j < 0 || 9 < j) {
                        break;
                      }
                      n = j + 10 * i + 100 * h + 1000 * g + 10000 * f +
                          100000 * e + 1000000 * d + 10000000 * c +
                          100000000 * b + 1000000000 * a;
                      vec.push_back(n);
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  sort(vec.begin(), vec.end());
  cout << vec.at(kk);
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author lynmisakura
 */

#include <fstream>
#include <iostream>

/*
 *  author : lynmisakura
 *  stay hungry, stay foolish, stay home.
 */
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>

#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

class DLunlunNumber {
public:
  void solve(std::istream &cin, std::ostream &cout) {
    int k;
    cin >> k;
    queue<long long> Q;
    for (int i = 1; i < 10; ++i) {
      Q.push(i);
    }
    for (int i = 0; i < k - 1; i++) {
      ll x = Q.front();
      Q.pop();
      // if(i < 10)cerr << x << endl;
      ll d = x % 10;
      x *= 10;
      if (d != 0)
        Q.push(x + d - 1);
      Q.push(x + d);
      if (d != 9)
        Q.push(x + d + 1);
    }
    long long ans = Q.front();
    cout << ans << endl;
  }
};

int main() {
  DLunlunNumber solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


Error: TLE

Fixed submission:

/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <fstream>
#include <iostream>

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>

#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

class DLunlunNumber {
public:
  void solve(std::istream &cin, std::ostream &cout) {
    int k;
    cin >> k;
    priority_queue<ll, vector<ll>, greater<ll>> Q;
    for (int i = 1; i < 10; ++i) {
      Q.push(i);
    }
    for (int i = 0; i < k - 1; k++) {
      ll x = Q.top();
      Q.pop();
      ll d = x % 10;
      x *= 10;
      if (d != 0)
        Q.push(x + d - 1);
      Q.push(x + d);
      if (d != 9)
        Q.push(x + d + 1);
    }
    cout << Q.top() << endl;
  }
};

int main() {
  DLunlunNumber solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long
using namespace std;
int k, head = 99;
int a[10003];
inline void change() {
  int j = 101;
  for (int k = j - 1; k >= head + 1; k--) {
    if (a[k] != a[k - 1] + 1 && a[k] != 9) {
      j = k;
      break;
    }
  }
  if (j != 101) {
    a[j]++;
    for (int k = j + 1; k <= 100; k++) {
      if (a[k - 1] - 1 >= 0)
        a[k] = a[k - 1] - 1;
      else
        a[k] = a[k - 1];
    }
    return;
  }
  if (j == 101 && a[head] != 9) {
    a[head]++;
    for (int k = head + 1; k <= 100; k++)
      if (a[k - 1] - 1 >= 0)
        a[k] = a[k - 1] - 1;
      else
        a[k] = a[k - 1];
    return;
  } else if (a[head] == 9 && j == 101) {
    head--, a[head] = 1;
    for (int k = head + 1; k <= 100; k++)
      a[k] = 0;
  }
}

signed main() {
  cin >> k;

  if (k <= 9)
    return cout << k << endl, 0;
  k -= 10;
  a[head] = 1, a[head + 1] = 0;

  for (int i = 1; i <= k; i++)
    change();
  for (int i = head; i <= 100; i++)
    cout << a[i];
  return 0;
}

Error: -8

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
long long n, k;
int main() {
  cin >> n >> k;
  cout << min(n % k, k - (n % k)) << endl;
  return 0;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int k;
  cin >> k;
  vector<ll> a;
  for (int i = 1; i <= 9; ++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);
      }
    }
  }
}

Error: TLE

Fixed submission:

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

bool lun(int X) {
  vector<int> A;
  int i = 0;
  if (X < 10)
    return true;
  else {
    while (X != 0) {
      A.push_back(X % 10);
      X /= 10;
      i++;
    }
  }
  for (int i = 1; i < A.size(); i++) {
    if (abs(A.at(i) - A.at(i - 1)) > 1)
      return false;
  }
  return true;
}

int main() {
  int K;
  cin >> K;
  int i = 1;
  int count = 0;
  while (true) {
    if (lun(i))
      count++;
    if (count == K) {
      cout << i << endl;
      return 0;
    }
    i++;
  }
}
Problem p02720 (C++) — buggy submission, verdict: Runtime Error

//
//  lunlun.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>

int main(int argc, const char *argv[]) {
  int k;
  std::cin >> k;
  long long a[100000];
  int i = 0;
  for (i = 0; i < 9; i++) {
    a[i] = i + 1;
  }
  int index = 0;
  while (i < k) {
    // if (a[index]%10 == 9) {
    //   a[i] = a[index]*10 + (a[index]%10 - 1);
    //   a[i+1] = a[index]*10 + (a[index]%10);
    //   i=i+2;
    // }
    // else if (a[index]%10 == 0) {
    //   a[i] = a[index]*10 + (a[index]%10);
    //   a[i+1] = a[index]*10 + (a[index]%10 + 1);
    //   i=i+2;
    // }
    // else {
    //   a[i] = a[index]*10 + (a[index]%10 - 1);
    //   a[i+1] = a[index]*10 + (a[index]%10);
    //   a[i+2] = a[index]*10 + (a[index]%10 + 1);
    //   i=i+3;
    // }
    if (a[index] % 10 != 0) {
      a[i] = a[index] * 10 + (a[index] % 10 - 1);
      i++;
    }
    a[i] = a[index] * 10 + (a[index] % 10);
    i++;
    if (a[index] % 10 != 9) {
      a[i] = a[index] * 10 + (a[index] % 10 + 1);
      i++;
    }
    index++;
  }

  // for (int i=0; i<k; i++) {
  //   std::cout << a[i] << " ";
  // }
  // std::cout << std::endl;
  // std::cout << "index " << index << std::endl;
  std::cout << a[k - 1] << std::endl;
}

Error: 0

Fixed submission:

//
//  lunlun.cpp
//  learningCplusplus
//
//  Created by Tran Duc Chinh on 2020/04/04.
//  Copyright © 2020 Tran Duc Chinh. All rights reserved.
//

#include <iostream>

int main(int argc, const char *argv[]) {
  int k;
  std::cin >> k;
  long long a[k];
  int i = 0;
  for (i = 0; i < 9; i++) {
    a[i] = i + 1;
  }
  int index = 0;
  while (i < k) {
    // if (a[index]%10 == 9) {
    //   a[i] = a[index]*10 + (a[index]%10 - 1);
    //   a[i+1] = a[index]*10 + (a[index]%10);
    //   i=i+2;
    // }
    // else if (a[index]%10 == 0) {
    //   a[i] = a[index]*10 + (a[index]%10);
    //   a[i+1] = a[index]*10 + (a[index]%10 + 1);
    //   i=i+2;
    // }
    // else {
    //   a[i] = a[index]*10 + (a[index]%10 - 1);
    //   a[i+1] = a[index]*10 + (a[index]%10);
    //   a[i+2] = a[index]*10 + (a[index]%10 + 1);
    //   i=i+3;
    // }
    if (a[index] % 10 != 0) {
      a[i] = a[index] * 10 + (a[index] % 10 - 1);
      i++;
    }
    a[i] = a[index] * 10 + (a[index] % 10);
    i++;
    if (a[index] % 10 != 9) {
      a[i] = a[index] * 10 + (a[index] % 10 + 1);
      i++;
    }
    index++;
  }

  // for (int i=0; i<k; i++) {
  //   std::cout << a[i] << " ";
  // }
  // std::cout << std::endl;
  // std::cout << "index " << index << std::endl;
  std::cout << a[k - 1] << std::endl;
}
Problem p02720 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll k;
  cin >> k;
  if (k < 10) {
    cout << k << endl;
    return 0;
  }
  queue<ll> ans;
  ans.push(1);
  ans.push(2);
  ans.push(3);
  ans.push(4);
  ans.push(5);
  ans.push(6);
  ans.push(7);
  ans.push(8);
  ans.push(9);
  ll i = 0, now = 1;
  while (i != k) {
    // cout<<now<<endl;
    i++;
    now = ans.front();
    ans.pop();
    if (now % 10 != 0 && now % 10 != 9) {
      int m = now % 10;
      ans.push(now * 10 + m - 1);
      ans.push(now * 10 + m);
      ans.push(now * 10 + m + 1);
    } else if (now % 10 == 0) {
      ans.push(now * 10);
      ans.push(now * 10 + 1);
    } else if (now % 10 == 9) {
      ans.push(now * 10 + 8);
      ans.push(now * 10 + 9);
    }
  }
  cout << now << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

bool Ans(ll ans) {
  string s = to_string(ans);
  for (int i = 0; i < s.length() - 1; ++i) {
    if (abs(stoi(s.substr(i, 1)) - stoi(s.substr(i + 1, 1))) > 1) {
      return false;
    }
  }
  return true;
}

int main() {
  ll k, ans = 1;
  cin >> k;
  if (k <= 9) {
    cout << k << endl;
    return 0;
  }
  ans = 10;
  ll i = 10;
  while (i != k) {
    ans++;
    if (Ans(ans))
      i++;
  }
  cout << ans << endl;
  return 0;
}