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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;

ll topnum(ll x) {
  ll ret = 0;

  ll a = 1;
  ll b = 10;
  while (b <= x) {
    ret += (b - 1LL - b / 10LL + 1LL) * a;
    a++;
    b *= 10LL;
  }
  b /= 10LL;

  ret += (x - b) * a + 1;

  return ret;
}

int main() {
  /*cout << topnum(1) << endl;
  cout << topnum(10) << endl;
  cout << topnum(11) << endl;
  cout << topnum(1000000) << endl;
  cout << topnum(1000001) << endl;
  cout << topnum(1000001) << endl;
  return 0;*/

  while (1) {
    ll K, N;
    cin >> N >> K;
    if (K == 0)
      return 0;

    ll l = 1, r = 1;
    rep(i, 0, 10) r *= 10;
    while (l + 1 != r) {
      ll mid = (l + r) / 2LL;
      if (N < topnum(mid))
        r = mid;
      else
        l = mid;
    }

    ll top = topnum(l);
    bool init = true;
    string ans = "";
    while (ans.length() < K) {
      string s = to_string(l);
      if (init) {
        ans += s.substr(N - top);
        init = false;
      } else {
        ans += s;
      }
      l++;
    }

    rep(i, 0, K) cout << ans[i];
    cout << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;

ll topnum(ll num) {
  ll ret = 0;

  ll a = 1;
  ll b = 10;
  while (b <= num) {
    ret += (b - 1 - b / 10 + 1) * a;
    a++;
    b *= 10;
  }
  b /= 10;

  ret += (num - b) * a + 1;

  return ret;
}

int main() {
  while (1) {
    ll K, N;
    cin >> N >> K;
    if (K == 0)
      return 0;

    int l = 0, r = 10000000;
    while (l + 1 != r) {
      ll mid = (l + r) / 2;
      if (N <= topnum(mid))
        r = mid;
      else
        l = mid;
    }

    ll top = topnum(r);
    bool init = true;
    string ans = "";
    while (ans.length() < K) {
      string s = to_string(r);
      if (init) {
        ans += s.substr(N - top);
        init = false;
      } else {
        ans += s;
      }
      r++;
    }

    rep(i, 0, K) cout << ans[i];
    cout << endl;
  }
}
Problem p01295 (C++) — buggy submission, verdict: Runtime Error

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

ll check(int x) {
  ll num = x, cnt = 0;
  while (x)
    x /= 10, cnt++;
  ll sum = 0, a = 9, add = 1, b = 0;
  while (--cnt > 0) {
    sum += a * add;
    a *= 10;
    add++;
    b = b * 10 + 9;
  }
  sum += (num - b) * add;
  return sum;
}

ll bynary_search() {
  ll l = 0, r = (1e9);
  while (l < r) {
    ll m = (l + r) / 2;
    if (check(m) >= n)
      r = m;
    else
      l = m + 1;
  }
  return l - 1;
}

string itos(ll x) {
  string res;
  while (x)
    res += (x % 10 + '0'), x /= 10;
  reverse(res.begin(), res.end());
  return res;
}

void solve() {
  ll r = bynary_search(), x = r + 1;
  string s;
  rep(i, k) s += itos(x++);
  cout << s.substr(n - check(r) - 1, k) << endl;
}

int main() {
  while (1) {
    cin >> n >> k;
    if (!n && !k)
      break;
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

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

int check(int x) {
  int num = x, cnt = 0;
  while (x)
    x /= 10, cnt++;
  int sum = 0, a = 9, add = 1, b = 0;
  while (--cnt > 0) {
    sum += a * add;
    a *= 10;
    add++;
    b = b * 10 + 9;
  }
  sum += (num - b) * add;
  return sum;
}

int bynary_search() {
  int l = 0, r = (1e9);
  while (l < r) {
    int m = (l + r) / 2;
    if (check(m) >= n)
      r = m;
    else
      l = m + 1;
  }
  return l - 1;
}

string itos(int x) {
  string res;
  while (x)
    res += (x % 10 + '0'), x /= 10;
  reverse(res.begin(), res.end());
  return res;
}

void solve() {
  int r = bynary_search(), x = r + 1;
  string s;
  rep(i, k) s += itos(x++);
  cout << s.substr(n - check(r) - 1, k) << endl;
}

int main() {
  while (1) {
    cin >> n >> k;
    if (!n && !k)
      break;
    solve();
  }
  return 0;
}
Problem p01295 (C++) — buggy submission, verdict: Runtime Error

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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define each(it, v)                                                            \\
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define pb push_back
#define fi first
#define se second
template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

int N, K;

void solve() {
  N--;
  int d = 1, t = 1;
  while (true) {
    if (N < t * 9 * d)
      break;
    N -= t * 9 * d;
    d++;
    t *= 10;
  }

  int tmp = N / d;
  N %= d;
  t += tmp;
  stringstream ss;
  while (ss.str().size() < 120) {
    ss << t;
    t++;
  }
  string s = ss.str();
  cout << s.substr(N, K) << endl;
}

signed main() {
  while (cin >> N >> K, N || K)
    solve();
  return 0;
}

Error: 0

Fixed submission:

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

#define int long long
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<pint> vpint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define each(it, v)                                                            \\
  for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define pb push_back
#define fi first
#define se second
template <typename A, typename B> inline void chmin(A &a, B b) {
  if (a > b)
    a = b;
}
template <typename A, typename B> inline void chmax(A &a, B b) {
  if (a < b)
    a = b;
}

int N, K;

void solve() {
  N--;
  int d = 1, t = 1;
  while (true) {
    if (N < t * 9)
      break;
    N -= t * 9 * d;
    d++;
    t *= 10;
  }

  int tmp = N / d;
  N %= d;
  t += tmp;
  stringstream ss;
  while (ss.str().size() < 120) {
    ss << t;
    t++;
  }
  string s = ss.str();
  cout << s.substr(N, K) << endl;
}

signed main() {
  while (cin >> N >> K, N || K)
    solve();
  return 0;
}
Problem p01295 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <sstream>
#include <vector>
using namespace std;

string stest;

void test(int N, int K) {
  for (int i = N; i < N + K; i++)
    cout << stest[i];
  cout << endl;
}
string itos(int a) {
  stringstream ss;
  ss << a;
  return ss.str();
}
long long d[] = {0,      10,      90,       900,       9000,       90000,
                 900000, 9000000, 90000000, 900000000, 9000000000, 90000000000};
int getD(int g) { return !g ? 1 : (int)log10(g) + 1; }

void print(int now, int K, int dif) {
  string s;
  for (int i = now; s.size() <= K + dif; i++)
    s += itos(i);

  for (int i = dif; i < dif + K; i++)
    cout << s[i];
  cout << endl;
}

void DO(int N, int K) {
  long long total = 0;
  int now = 0;
  for (int kt = getD(now); total + kt < N; kt = getD(now)) {
    if (kt <= 10 && total + kt * d[kt] <= N) {
      total += kt * d[kt];
      now += d[kt];
      continue;
    }
    int use = (N - total) / kt;
    if (use > d[kt])
      use = d[kt];
    total += kt * use;
    now += use;
  }

  print(now, K, N - total);
}

int main() {
  /*
  for(int i=0;i<=10000;i++)
    stest += itos(i);
  */
  int N, K;
  while (cin >> N >> K, N | K)
    DO(N, K);

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <sstream>
#include <vector>
using namespace std;

string stest;

void test(int N, int K) {
  for (int i = N; i < N + K; i++)
    cout << stest[i];
  cout << endl;
}
string itos(int a) {
  stringstream ss;
  ss << a;
  return ss.str();
}
long long d[] = {0,      10,      90,       900,       9000,      90000,
                 900000, 9000000, 90000000, 900000000, 9000000000};
int getD(int g) { return !g ? 1 : (int)log10(g) + 1; }

void print(int now, int K, int dif) {
  string s;
  for (int i = now; s.size() <= K + dif; i++)
    s += itos(i);

  for (int i = dif; i < dif + K; i++)
    cout << s[i];
  cout << endl;
}

void DO(int N, int K) {
  long long total = 0;
  int now = 0;
  for (int kt = getD(now); total + kt < N; kt = getD(now)) {
    if (kt <= 10 && total + kt * d[kt] <= N) {
      total += kt * d[kt];
      now += d[kt];
      continue;
    }
    total += kt;
    now++;
  }

  print(now, K, N - total);
}

int main() {
  /*
  for(int i=0;i<=10000;i++)
    stest += itos(i);
  */
  int N, K;
  while (cin >> N >> K, N | K) {
    assert(N <= 1000000000);
    DO(N, K);
  }

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

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {
  long long int N, K;
  while (1) {
    scanf("%lld%lld", &N, &K);
    if (!N)
      break;
    long long int base = 9;
    for (int d = 1; d < 10; d++) {
      long long int sum = d * base;
      if (N > sum) {
        N -= sum;
        base *= 10;
      } else {
        long long int div = (N - 1) / d + base / 9, mo = (N - 1 + d) % d;
        string s = "";
        for (int i = 0; s.length() < K + 10; i++) {
          s += to_string(div + i);
        }
        cout << s.substr(mo, K) << endl;
        break;
      }
    }
  }
}


Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main() {
  long long int N, K;
  while (1) {
    scanf("%lld%lld", &N, &K);
    long long int base = 9;
    for (int d = 1; d < 10; d++) {
      long long int sum = d * base;
      if (N > sum) {
        N -= sum;
        base *= 10;
      } else {
        long long int div = (N - 1) / d + base / 9, mo = (N - 1 + d) % d;
        string s = "";
        for (int i = 0; s.length() < K + 10; i++) {
          s += to_string(div + i);
        }
        cout << s.substr(mo, K) << endl;
        break;
      }
    }
  }
}
Problem p01295 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;

ll pow10_[20], t[20];

string toString(ll x) {
  stringstream ss;
  ss << x;
  return ss.str();
}

ll calc(ll x) {
  ll len = toString(x).size();
  return t[len - 1] + len * (x - pow10_[len - 1]);
}

int main() {
  ll n, k;
  pow10_[0] = 1, t[0] = 1;
  for (int i = 1; i < 20; i++) {
    pow10_[i] = pow10_[i - 1] * 10;
    t[i] = (pow10_[i] - pow10_[i - 1]) * i + t[i - 1];
  }
  while (cin >> n >> k, n | k) {
    ll lb = 1, ub = 10000000000ll;
    while (lb + 1 < ub) {
      ll md = (lb + ub) / 2;
      if (calc(md) > n)
        ub = md;
      else
        lb = md;
    }
    string res;
    for (ll i = lb; i < lb + 200; i++) {
      res += toString(i);
    }
    cout << string(res, n - calc(lb), k) << endl;
  }
}

Error: 0

Fixed submission:

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

typedef long long ll;

string toString(ll x) {
  stringstream ss;
  ss << x;
  return ss.str();
}

int main() {
  ll n, k;
  ll pow10[20], t[20];
  pow10[0] = 1, t[0] = 1;
  for (int i = 1; i < 20; i++) {
    pow10[i] = pow10[i - 1] * 10;
    t[i] = (pow10[i] - pow10[i - 1]) * i + t[i - 1];
  }
  while (cin >> n >> k, n | k) {
    ll lb = 1, ub = 10000000000ll;
    ll y;
    while (lb + 1 < ub) {
      ll md = (lb + ub) / 2;
      ll len = toString(md).size();
      ll x = t[len - 1] + len * (md - pow10[len - 1]);
      if (x > n)
        ub = md;
      else {
        lb = md;
        y = x;
      }
    }
    string res;
    for (ll i = lb; i < lb + 200; i++) {
      res += toString(i);
    }
    cout << string(res, n - y, k) << endl;
  }
}
Problem p01295 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll len(ll x) {
  ll a = 1, k = 0, j = 1;
  while (a * 10 <= x)
    k += 9 * a * j, a *= 10, j++;
  k += (x - a + 1) * j;
  return k;
}
int main() {
  ll n, k;
  while (cin >> n >> k, n || k) {
    ll l = 0, r = 1000000000LL, m, i;
    string s;
    while (l + 1 < r)
      (len(m = (l + r) / 2) < n) ? l = m : r = m;
    for (i = 1; i < 10000; i++)
      s += to_string(l + i);
    for (i = 0; i < k; i++)
      cout << s[n - len(l) - 1 + i];
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll len(ll x) {
  ll a = 1, k = 0, j = 1;
  while (a * 10 <= x)
    k += 9 * a * j, a *= 10, j++;
  k += (x - a + 1) * j;
  return k;
}
int main() {
  ll n, k;
  while (cin >> n >> k, n || k) {
    ll l = 0, r = 100000000LL, m, i;
    string s;
    while (l + 1 < r)
      (len(m = (l + r) / 2) < n) ? l = m : r = m;
    for (i = 1; i < 10000; i++)
      s += to_string(l + i);
    for (i = 0; i < k; i++)
      cout << s[n - len(l) - 1 + i];
    cout << endl;
  }
  return 0;
}
Problem p01295 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int main() {
  while (1) {
    long long n, m;
    cin >> n >> m;
    if (!n && !m)
      break;
    string ans;
    long long c = 1, d = 1;
    n--;
    while (n - 9 * c * d >= 0)
      n -= 9 * c * d, c++, d *= 10;

    d = n / c + d;
    while ((int)ans.size() < m + n % c + 10) {
      long long t = d;
      string a;
      while (t)
        a += (t % 10 + '0'), t /= 10;
      reverse(a.begin(), a.end());
      ans += a;
      d++;
    }
    for (int i = n % c; i < m + n % c; i++)
      cout << ans[i];
    cout << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

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

int main() {
  while (1) {
    int n, m;
    cin >> n >> m;
    if (!n && !m)
      break;
    string ans;
    int c = 1, d = 1;
    while (n - 9 * c * d >= 0)
      n -= 9 * c * d, c++, d *= 10;

    while ((int)ans.size() - n < m) {
      int t = d;
      string a;
      while (t)
        a += (t % 10 + '0'), t /= 10;
      reverse(a.begin(), a.end());
      ans += a;
      d++;
    }

    for (int i = n; i < m + n; i++)
      cout << ans[i];
    cout << endl;
  }
  return 0;
}
Problem p01295 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-10;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

ll solve(ll n) {
  ll t = 1, d = 1, cnt = 0;
  while (t * 10 < n) {
    cnt += (t * 10 - t) * d;
    t *= 10;
    d++;
  }
  cnt += d * (n - t);
  return cnt;
}
int main() {
  int n, k;
  while (cin >> n >> k, n) {
    ll lb = 0, ub = INT_MAX;
    ll cnt;
    while (ub - lb > 1) {
      ll mid = (lb + ub) / 2;
      cnt = solve(mid);
      if (cnt >= n)
        ub = mid;
      else
        lb = mid;
    }
    string s;
    cnt = solve(lb);
    REP(i, 100) s += to_string(lb + i);
    cout << s.substr(n - cnt - 1, k) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define MS(m, v) memset(m, v, sizeof(m))
#define D10 fixed << setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-10;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

ll solve(ll n) {
  ll t = 1, d = 1, cnt = 0;
  while (t * 10 < n) {
    cnt += (t * 10 - t) * d;
    t *= 10;
    d++;
  }
  cnt += d * (n - t);
  return cnt;
}
int main() {
  int n, k;
  while (cin >> n >> k, n) {
    ll lb = 0, ub = INT_MAX;
    ll cnt;
    while (ub - lb > 1) {
      ll mid = (lb + ub) / 2;
      cnt = solve(mid);
      if (cnt >= n)
        ub = mid;
      else
        lb = mid;
    }
    string s;
    REP(i, 100) s += to_string(lb + i);
    cout << s.substr(n - cnt - 1, k) << endl;
  }
  return 0;
}
Problem p01295 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

long long a, b;

int digit(long long n) { return to_string(n).size(); }

long long sumsize(long long n) {
  long long t = 1, sum = 0;

  while (t <= n) {
    if (t * 10 > n) {
      sum += (n - t + 1) * digit(t);
    } else {
      sum += t * 9 * digit(t);
    }

    t *= 10;
  }

  return sum;
}

string solve() {
  // 1. Binary Search

  int rep = 40;

  long long l = 0;
  long long r = (1LL << rep);
  long long m;

  for (int i = 0; i <= rep; i++) {
    m = (l + r) / 2;

    if (sumsize(m) >= a) {
      r = m;
    } else {
      l = m;
    }
  }

  // 2. Solve

  string S;

  for (long long i = m + 1; S.size() < b; i++) {
    if (i == m + 1) {
      int r = a - sumsize(m) - 1;

      S += to_string(i).substr(r, digit(i) - r);
    } else {
      S += to_string(i);
    }
  }

  return S.substr(0, b);
}

int main() {
  while (true) {
    cin >> a >> b;

    if (a == 0 && b == 0) {
      break;
    }

    cout << solve() << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

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

using namespace std;

long long a, b;

int digit(long long n) { return to_string(n).size(); }

long long sumsize(long long n) {
  long long t = 1, sum = 0;

  while (t <= n) {
    if (t * 10 > n) {
      sum += (n - t + 1) * digit(t);
    } else {
      sum += t * 9 * digit(t);
    }

    t *= 10;
  }

  return sum;
}

string solve() {
  // 1. Binary Search

  int rep = 40;

  long long l = 0;
  long long r = (1LL << rep);
  long long m;

  for (int i = 0; i <= rep; i++) {
    m = (l + r) / 2;

    if (sumsize(m) >= a) {
      r = m;
    } else {
      l = m;
    }
  }

  // 2. Solve

  string S;

  for (long long i = m + 1; S.size() < b; i++) {
    if (i == m + 1) {
      int r = sumsize(m + 1) - a;

      S += to_string(i).substr(r, digit(i) - r);
    } else {
      S += to_string(i);
    }
  }

  return S.substr(0, b);
}

int main() {
  while (true) {
    cin >> a >> b;

    cout << solve() << endl;
  }

  return 0;
}
Problem p01295 (C++) — buggy submission, verdict: Runtime Error

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge {
  int u, v;
  ll w;
};

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

ll f(ll x) {
  ll d = 1, cnt = 0;
  for (ll y = 9; x > 0; y *= 10) {
    ll z = min(x, y);
    x -= z;
    cnt += d * z;
    d++;
  }
  return cnt;
}

int main() {
  for (;;) {
    ll N, K;
    cin >> N >> K;
    if (N == 0 && K == 0)
      break;
    N--;
    ll lb = 0, ub = N + 1;
    while (ub - lb > 1) {
      ll mid = (lb + ub) / 2;
      if (f(mid) <= N)
        lb = mid;
      else
        ub = mid;
    }
    N -= f(lb);
    stringstream ss;
    for (int i = 1; i <= 100; i++)
      ss << (lb + i);
    cout << ss.str().substr(N, K) << endl;
  }
}

Error: 0

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge {
  int u, v;
  ll w;
};

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

ll f(ll x) {
  ll d = 1, cnt = 0;
  for (ll y = 9; x > 0; y *= 10) {
    ll z = min(x, y);
    x -= z;
    cnt += d * z;
    d++;
  }
  return cnt;
}

int main() {
  for (;;) {
    ll N, K;
    cin >> N >> K;
    if (N == 0 && K == 0)
      break;
    N--;
    ll lb = 0, ub = N + 1;
    while (ub - lb > 1) {
      ll mid = (lb + ub) / 2;
      if (f(mid) <= N)
        lb = mid;
      ub = mid;
    }
    N -= f(lb);
    string s;
    for (int i = 1; i <= 100; i++) {
      stringstream ss;
      ss << lb + i;
      s += ss.str();
    }
    cout << s.substr(N, K) << endl;
  }
}
Problem p01295 (C++) — buggy submission, verdict: Runtime Error

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX / 3

ll n, k;

ll f(ll x) {
  if (x == 0)
    return 0;
  ll cnt = 1, res = 0;
  for (ll i = 10; i < 1000000000000000; i *= 10, cnt++) {
    if (x < i) {
      res += cnt * (x - (i / 10) + 1);
      break;
    } else {
      res += cnt * (i - (i / 10));
    }
  }
  return res;
}

int main() {
  cin.sync_with_stdio(false);
  while (1) {
    cin >> n >> k;
    if (n == 0)
      break;
    ll lb = 0, ub = 100000000000000000;
    while (ub - lb > 1) {
      ll mid = (ub + lb) / 2;
      if (f(mid) < n)
        lb = mid;
      else
        ub = mid;
    }
    string s;
    for (ll i = 1; s.length() < 200; i++) {
      s += to_string(lb + i);
    }
    cout << s.substr(n - f(lb) - 1, k) << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define rep(i, n) repl(i, 0, n)
#define each(itr, v) for (auto itr : v)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define dbg(x) cout << #x "=" << x << endl
#define mmax(x, y) (x > y ? x : y)
#define mmin(x, y) (x < y ? x : y)
#define maxch(x, y) x = mmax(x, y)
#define minch(x, y) x = mmin(x, y)
#define uni(x) x.erase(unique(all(x)), x.end())
#define exist(x, y) (find(all(x), y) != x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX / 3

ll n, k;

ll f(ll x) {
  if (x == 0)
    return 0;
  ll cnt = 1;
  ll res = 0;
  for (ll i = 10; i < 100000000; i *= 10, cnt++) {
    if (x < i) {
      res += cnt * (x - (i / 10) + 1);
      break;
    } else {
      res += cnt * (i - (i / 10));
    }
  }
  return res;
}

int main() {
  cin.sync_with_stdio(false);
  while (1) {
    cin >> n >> k;
    if (n == 0)
      break;
    ll lb = 0, ub = 10000000000;
    while (ub - lb > 1) {
      ll mid = (ub + lb) / 2;
      if (f(mid) < n)
        lb = mid;
      else
        ub = mid;
    }
    string s;
    for (ll i = 0; s.length() < 200; i++) {
      s += to_string(lb + i);
    }
    cout << s.substr(n - f(lb), k) << endl;
  }
  return 0;
}