prithivMLmods/Coder-Stat huggingface dataset:
Problem p02627 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(), A.end()
#define MEM(a, b) memset(a, b, sizeof(a))
#define FOR(n) for (int i = 0; i < n; ++i)
#define FOR_(n) for (int i = 1; i <= n; ++i)
#define FOR_J(n) for (int j = 0; j < n; ++j)
#define FOR_J_(n) for (int j = 1; j <= n; ++j)
#define IT_FOR(A) for (auto i = A.begin(); i != A.end(); ++i)
#define INF 0x3f3f3f3f
#define N ((int)1e6)
// #define max(_a,_b) (((_a) > (_b)) ? (_a) : (_b))
// #define min(_a,_b) (((_a) < (_b)) ? (_a) : (_b))
const int mod = 1000000007;
typedef long long ll;

inline int read() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * w;
}

int main() {
  // freopen("in.txt", "r", stdin);
  // freopen("wa4.txt","w",stdout);
  int _ = 1;
  _ = read();
  while (_--) {
    char c;
    cin >> c;
    char t = tolower(c);
    if (c == t)
      cout << "a\n";
    else
      cout << "A\n";
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) A.begin(), A.end()
#define MEM(a, b) memset(a, b, sizeof(a))
#define FOR(n) for (int i = 0; i < n; ++i)
#define FOR_(n) for (int i = 1; i <= n; ++i)
#define FOR_J(n) for (int j = 0; j < n; ++j)
#define FOR_J_(n) for (int j = 1; j <= n; ++j)
#define IT_FOR(A) for (auto i = A.begin(); i != A.end(); ++i)
#define INF 0x3f3f3f3f
#define N ((int)1e6)
// #define max(_a,_b) (((_a) > (_b)) ? (_a) : (_b))
// #define min(_a,_b) (((_a) < (_b)) ? (_a) : (_b))
const int mod = 1000000007;
typedef long long ll;

inline int read() {
  int x = 0, w = 1;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-')
      w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * w;
}

int main() {
  // freopen("in.txt", "r", stdin);
  // freopen("wa4.txt","w",stdout);
  int _ = 1;
  //_ = read();
  while (_--) {
    char c;
    cin >> c;
    char t = tolower(c);
    if (c == t)
      cout << "a\n";
    else
      cout << "A\n";
  }
  return 0;
}
Problem p02627 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define pii pair<int, int>
#define vvi vector<vector<int>>
#define vi vector<int>
#define f first
#define s second
using namespace std;
const int mod = 1e9 + 7;
int logi(int n) {
  int p = 0;
  while (n / 2) {
    n = n / 2;
    p++;
  }
  return p;
}
int poww(int x, int y) {
  int pro = 1;
  while (y) {
    if (y & 1)
      pro = ((pro % mod) * (x % mod) % mod);
    y = y >> 1;
    x = ((x % mod) * (x % mod) % mod);
  }
  return pro;
}
int poww2(int x, int y) {
  int pro = 1;
  while (y) {
    if (y & 1)
      pro = pro * x;
    y = y >> 1;
    x = x * x;
  }
  return pro;
}
bool isprime(int n) {
  if (n == 1)
    return false;
  for (int i = 2; i <= sqrt(n); i++)
    if (n % i == 0)
      return false;
  return true;
}

/*

*/

int solve() {
  char c;
  cin >> c;
  if (c >= 'A' && c <= 'Z')
    cout << 'A';
  else
    cout << 'a';
}

int32_t main() {
  fast;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define pii pair<int, int>
#define vvi vector<vector<int>>
#define vi vector<int>
#define f first
#define s second
using namespace std;
const int mod = 1e9 + 7;
int logi(int n) {
  int p = 0;
  while (n / 2) {
    n = n / 2;
    p++;
  }
  return p;
}
int poww(int x, int y) {
  int pro = 1;
  while (y) {
    if (y & 1)
      pro = ((pro % mod) * (x % mod) % mod);
    y = y >> 1;
    x = ((x % mod) * (x % mod) % mod);
  }
  return pro;
}
int poww2(int x, int y) {
  int pro = 1;
  while (y) {
    if (y & 1)
      pro = pro * x;
    y = y >> 1;
    x = x * x;
  }
  return pro;
}
bool isprime(int n) {
  if (n == 1)
    return false;
  for (int i = 2; i <= sqrt(n); i++)
    if (n % i == 0)
      return false;
  return true;
}

/*

*/

int solve() {
  char c;
  cin >> c;
  if (c >= 'A' && c <= 'Z')
    cout << 'A';
  else
    cout << 'a';
  return 0;
}

int32_t main() {
  fast;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}
Problem p02628 (Python)

Buggy submission (status: Runtime Error):
N, K = map(int, input().split())
P = list(map(int, input().split())).sort()
print(sum(P[:K]))


Fixed submission:
N, K = map(int, input().split())
P = sorted(list(map(int, input().split())))
print(sum(P[:K]))
Problem p02628 (Python)

Buggy submission (status: Runtime Error):
N, K = (int(i) for i in input().split())
p = [input().split()]

sp = sorted(p)
print(sum(sp[:K]))


Fixed submission:
N, K = (int(i) for i in input().split())
p = [int(i) for i in input().split()]

sp = sorted(p)
print(sum(sp[:K]))
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K, sum = 0;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  for (int i = 0; i, K; i++) {
    sum += A.at(i);
  }
  cout << sum << endl;
}

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

int main() {
  int N, K, sum = 0;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < K; i++) {
    sum += A.at(i);
  }
  cout << sum << endl;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>

#define int long long

using namespace std;

const int N = 2e5 + 10;

int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> v;
  for (int i = 0; i < n; ++i)
    cin >> v[i];
  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = 0; i < k; ++i)
    ans += v[i];
  cout << ans;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>

#define int long long

using namespace std;

const int N = 2e5 + 10;

int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; ++i)
    cin >> v[i];
  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = 0; i < k; ++i)
    ans += v[i];
  cout << ans;
  return 0;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main(void) {
  int n, k;

  scanf("%d", &n);
  scanf("%d", &k);

  int p[n];

  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }

  int min, tmp;

  for (int i = 0; i < n - 1; i++) {
    min = p[i];
    for (int j = i + 1; j < n; j++) {
      if (min > p[j]) {
        min = p[j];
        tmp = j;
      }
    }
    p[tmp] = p[i];
    p[i] = min;
  }

  int sum = 0;

  for (int i = 0; i < k; i++) {
    sum += p[i];
  }

  printf("%d", sum);

  return 0;
}

Fixed submission:
#include <stdio.h>

int main(void) {
  int n, k;

  scanf("%d", &n);
  scanf("%d", &k);

  int p[n];

  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }

  int min, tmp;

  for (int i = 0; i < n - 1; i++) {
    min = p[i];
    tmp = i;
    for (int j = i + 1; j < n; j++) {
      if (min > p[j]) {
        min = p[j];
        tmp = j;
      }
    }
    p[tmp] = p[i];
    p[i] = min;
  }

  int sum = 0;

  for (int i = 0; i < k; i++) {
    sum += p[i];
  }

  printf("%d", sum);

  return 0;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define input1                                                                 \
  freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout);
const ll nax = 1e9 + 7;

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < k; i++) {
    ans += a[i];
  }
  cout << ans;
}

int main() {
  input1;

  solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define input1                                                                 \
  freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout);
const ll nax = 1e9 + 7;

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < k; i++) {
    ans += a[i];
  }
  cout << ans;
}

int main() {
  // input1;

  solve();
  return 0;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>

using namespace std;

int N, K, p[100];

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; ++i)
    cin >> p[i];
  sort(p, p + N);
  int ans = 0;
  for (int i = 0; i < K; ++i)
    ans += p[i];
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>

using namespace std;

int N, K, p[1010];

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; ++i)
    cin >> p[i];
  sort(p, p + N);
  int ans = 0;
  for (int i = 0; i < K; ++i)
    ans += p[i];
  cout << ans << endl;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
  int N, K, Only1;
  cin >> N >> K;
  if (N == 1) {
    cin >> Only1;
    cout << Only1 << endl;
  } else {

    vector<int> nedan(N);
    for (int i = 0; i < N; i++) {
      cin >> nedan.at(i);
    }

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

    int goukei;
    goukei = nedan.at(0) + nedan.at(1) + nedan.at(2);
    cout << goukei << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
  int N, K, Only1;
  cin >> N >> K;
  if (N == 1) {
    cin >> Only1;
    cout << Only1 << endl;
  } else {

    vector<int> nedan(N);
    for (int i = 0; i < N; i++) {
      cin >> nedan.at(i);
    }

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

    int goukei = 0;
    for (int i = 0; i < K; i++) {
      goukei = goukei + nedan.at(i);
    }

    cout << goukei << endl;
  }
}
Problem p02628 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int sum = 0, min = 1001;
  while (k != 0) {
    for (int i = 0; i < n; i++) {
      if (min > arr[i]) {
        min = arr[i];
      }
    }
    sum += min;
    for (int i = 0; i < n; i++) {
      if (min == arr[i]) {
        arr[i] = 1001;
        break;
      }
    }
  }
  cout << sum;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int sum = 0, min = 1001;
  while (k != 0) {
    for (int i = 0; i < n; i++) {
      if (min > arr[i]) {
        min = arr[i];
      }
    }
    sum += min;
    for (int i = 0; i < n; i++) {
      if (min == arr[i]) {
        arr[i] = 1001;
        break;
      }
    }
    k--;
    min = 1002;
  }
  cout << sum;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#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<int,int>;

int main() {
  int n, k, sum = 0;
  cin >> n >> k;
  vector<int> p;
  rep(i, n) cin >> p.at(i);
  sort(p.begin(), p.end());
  rep(i, k) { sum += p.at(i); }
  cout << sum << endl;
}

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<int,int>;

int main() {
  int n, k, sum = 0;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p.at(i);
  sort(p.begin(), p.end());
  rep(i, k) { sum += p.at(i); }
  cout << sum << endl;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
// #define ll long long
using namespace std;
#define SPEED                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define fileio                                                                 \
  freopen("http://in.in", "r", stdin), freopen("out.out", "w", stdout);
#define ll long long
#define pb push_back
#define pll pair<ll, ll>
#define ff first
#define ss second

#define N 2000001
#define M 998244353
#define INF 1000000000000000
std::vector<ll> v;

int main() {
  SPEED;
  ll t;
  cin >> t;

  while (t-- > 0) {
    ll n, k;
    cin >> n >> k;
    ll a[n];
    ll i;
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    ll sum = 0;
    for (i = 0; i < k; i++) {
      sum += a[i];
    }
    cout << sum;
  }
}

Fixed submission:
#include <bits/stdc++.h>
// #define ll long long
using namespace std;
#define SPEED                                                                  \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define fileio                                                                 \
  freopen("http://in.in", "r", stdin), freopen("out.out", "w", stdout);
#define ll long long
#define pb push_back
#define pll pair<ll, ll>
#define ff first
#define ss second

#define N 2000001
#define M 998244353
#define INF 1000000000000000
std::vector<ll> v;

int main() {
  SPEED;
  ll t;
  t = 1;

  while (t-- > 0) {
    ll n, k;
    cin >> n >> k;
    ll a[n];
    ll i;
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    ll sum = 0;
    for (i = 0; i < k; i++) {
      sum += a[i];
    }
    cout << sum;
  }
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <map>
#include <set>
#include <utility>
#include <vector>
using namespace std;
using P = pair<int, int>;
using ll = long long;
constexpr int MOD = 998244353;
constexpr int MAX = 510000;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  ll ret = 0;
  for (int i = 0; i < k; i++)
    ret += a[i];
  cout << ret << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <map>
#include <set>
#include <utility>
#include <vector>
using namespace std;
using P = pair<int, int>;
using ll = long long;
constexpr int MOD = 998244353;
constexpr int MAX = 510000;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  ll ret = 0;
  for (int i = 0; i < k; i++)
    ret += a[i];
  cout << ret << endl;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[50], k, t, i, s = 0, j;
  cin >> t >> k;
  for (i = 0; i < t; i++) {
    cin >> a[i];
  }
  sort(a, a + t);
  for (j = 0; j < k; j++) {
    s = s + a[j];
  }
  cout << s << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[1001], k, t, i, s = 0, j;
  cin >> t >> k;
  for (i = 0; i < t; i++) {
    cin >> a[i];
  }
  sort(a, a + t);
  for (j = 0; j < k; j++) {
    s = s + a[j];
  }
  cout << s << endl;
  return 0;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main(void) {
  int i, n, k, p[1000], sum = 0;
  scanf("%d %d", n, k);
  for (i = 0; i < n; i++)
    scanf("%d", &p[i]);
  sort(p, p + n);
  for (i = 0; i < k; i++)
    sum += p[i];
  printf("%d\n", sum);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main(void) {
  int i, n, k, p[1000], sum = 0;
  scanf("%d %d", &n, &k);
  for (i = 0; i < n; i++)
    scanf("%d", &p[i]);
  sort(p, p + n);
  for (i = 0; i < k; i++)
    sum += p[i];
  printf("%d\n", sum);
  return 0;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> vec(N);
  int money = 0;
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < K; i++) {
    money += vec.at(i);
  }
  cout << money << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);
  int money = 0;
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < K; i++) {
    money += vec.at(i);
  }
  cout << money << endl;
}
Problem p02628 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

typedef long long int llint;

unsigned int min(unsigned int A, unsigned int B) {
  if (A < B) {
    return A;
  } else {
    return B;
  }
}

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

  vector<int> P;
  P.push_back(0);
  for (int i = 0; i < N; i++) {
    int p;
    cin >> p;
    P.push_back(p);
  }

  int dp[N + 1][K + 1]; // dp[i][j]=i番目までj個選んだ時の最小の金額
  dp[0][0] = 0;
  for (int i = 1; i <= K; i++) {
    dp[0][i] = 0x0FFFFFFF;
  }
  for (int i = 1; i <= N; i++) {
    dp[i][0] = 0;
    for (int k = 1; k <= K; k++) {
      dp[i][k] = min(dp[i - 1][k - 1] + P[i], dp[i - 1][k]);
    }
  }

  for (int i = 0; i <= N; i++) {
    for (int k = 0; k <= K; k++) {
      clog << dp[i][k] << " ";
    }
    clog << endl;
  }

  cout << dp[N][K] << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

typedef long long int llint;

unsigned int min(unsigned int A, unsigned int B) {
  if (A < B) {
    return A;
  } else {
    return B;
  }
}

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

  vector<int> P;
  P.push_back(0);
  for (int i = 0; i < N; i++) {
    int p;
    cin >> p;
    P.push_back(p);
  }

  int dp[N + 1][K + 1]; // dp[i][j]=i番目までj個選んだ時の最小の金額
  dp[0][0] = 0;
  for (int i = 1; i <= K; i++) {
    dp[0][i] = 0x0FFFFFFF;
  }
  for (int i = 1; i <= N; i++) {
    dp[i][0] = 0;
    for (int k = 1; k <= K; k++) {
      dp[i][k] = min(dp[i - 1][k - 1] + P[i], dp[i - 1][k]);
    }
  }

  /*
          for(int i=0;i<=N;i++){
                  for(int k=0;k<=K;k++){
                          clog << dp[i][k] << " ";
                  }
                  clog << endl;
          }
          */

  cout << dp[N][K] << endl;
  return 0;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);

  // 100個の入力を受け取る
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int X = 0;
  for (int i = 0; i <= K + 2; i++) {
    X += vec.at(i);
  }
  cout << X << endl;
}

Fixed submission:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> vec(N);

  // 100個の入力を受け取る
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int X = 0;
  for (int i = 0; i < K; i++) {
    X += vec.at(i);
  }
  cout << X << endl;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
using namespace std;
#define endl '\n'

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int K, N;
  cin >> N >> K;
  int a[K];
  for (int i = 0; i < N; i++) {
    int n;
    cin >> n;
    a[i] = n;
  }
  sort(a, a + N);
  int num = 0;
  for (int j = 0; j < K; j++) {
    num = num + a[j];
  }
  cout << num << endl;
}

Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
#define endl '\n'

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int K, N;
  cin >> N >> K;
  int a[N];
  for (int i = 0; i < N; i++) {
    int n;
    cin >> n;
    a[i] = n;
  }
  sort(a, a + N);
  int num = 0;
  for (int j = 0; j < K; j++) {
    num = num + a[j];
  }
  cout << num << endl;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
/**********************************************************************************************
******************************AUTHOR:**********************************************************
****************************ASHISH
*RANJAN******************************************************
***********************************************************************************************/
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start);

    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast()                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i, n) for (int i = 0; i < n; i++)
#define frs(i, a, b) for (int i = a; i < b; i++)
#define meme(a, b) memset(a, b, sizeof(a)); // works only for 0 and -1
int main() {
  fast();
  int n, k;
  cin >> n >> k;
  int arr[k];
  fr(i, n) cin >> arr[i];
  sort(arr, arr + n);
  ll sum = 0;
  fr(i, k) sum += arr[i];
  cout << sum;
  return 0;
}


Fixed submission:
/**********************************************************************************************
******************************AUTHOR:**********************************************************
****************************ASHISH
*RANJAN******************************************************
***********************************************************************************************/
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start);

    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast()                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i, n) for (int i = 0; i < n; i++)
#define frs(i, a, b) for (int i = a; i < b; i++)
#define meme(a, b) memset(a, b, sizeof(a)); // works only for 0 and -1
int main() {
  fast();
  int n, k;
  cin >> n >> k;
  int arr[n];
  fr(i, n) cin >> arr[i];
  sort(arr, arr + n);
  ll sum = 0;
  fr(i, k) sum += arr[i];
  cout << sum;
  return 0;
}
Problem p02628 (Python)

Buggy submission (status: Time Limit Exceeded):
import itertools

N, K = map(int, input().split())
p = list(map(int, input().split()))

ans = sum(p)
for v in itertools.permutations(p, K):
    ans = min(ans, sum(v))

print(ans)


Fixed submission:
import itertools

N, K = map(int, input().split())
p = list(map(int, input().split()))

ans = 0
for _ in range(K):
    min_index = p.index(min(p))
    minv = p.pop(min_index)
    ans += minv

print(ans)
Problem p02628 (Python)

Buggy submission (status: Time Limit Exceeded):
N, K = map(int, input().split())
P = list(map(int, input().split()))

ans = float("inf")
for i in range(1 << len(P)):
    sum = 0
    cnt = 0
    for j in range(len(P)):
        if (i >> j) & 1 == 1:
            sum += P[j]
            cnt += 1
            if cnt == K:
                ans = min(ans, sum)
print(ans)


Fixed submission:
N, K = map(int, input().split())
P = list(map(int, input().split()))

P = sorted(P)

print(sum(P[:K]))
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PB push_back
#define in insert
#define MP make_pair
#define F first
#define S second
void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void inout() {
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
}
void solve() {
  ll n, k;
  cin >> n >> k;
  ll ara[n + 10];
  for (int i = 1; i <= n; i++) {
    cin >> ara[i];
  }
  sort(ara + 1, ara + n + 1);
  ll sum = 0;
  for (int i = 1; i <= k; i++) {
    sum += ara[i];
  }
  cout << sum;
}
int main() {
  faster();
  inout();
  solve();
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PB push_back
#define in insert
#define MP make_pair
#define F first
#define S second
void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void inout() {
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
}
void solve() {
  ll n, k;
  cin >> n >> k;
  ll ara[n + 10];
  for (int i = 1; i <= n; i++) {
    cin >> ara[i];
  }
  sort(ara + 1, ara + n + 1);
  ll sum = 0;
  for (int i = 1; i <= k; i++) {
    sum += ara[i];
  }
  cout << sum;
}
int main() {
  faster();
  // inout();
  solve();
  return 0;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> wage;
  for (int i = 0; i < N; i++) {
    cin >> wage.at(i);
  }
  sort(wage.begin(), wage.end());
  int answer = 0;

  for (int i = 0; i < K; i++) {
    answer = answer + wage.at(i);
  }
  cout << answer << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> wage(N);
  for (int i = 0; i < N; i++) {
    cin >> wage.at(i);
  }
  sort(wage.begin(), wage.end());
  int answer = 0;

  for (int i = 0; i < K; i++) {
    answer = answer + wage.at(i);
  }
  cout << answer << endl;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  int p[100];
  int i;

  for (i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }

  sort(p, p + n);

  int sum = 0;
  for (i = 0; i < k; i++) {
    sum += p[i];
  }
  printf("%d\n", sum);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  int p[1001];
  int i;

  for (i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }

  sort(p, p + n);

  int sum = 0;
  for (i = 0; i < k; i++) {
    sum += p[i];
  }
  printf("%d\n", sum);

  return 0;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>

int arr[1030];
int N, K;
int answer;

int main() {
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%d", arr[i]);
  }
  std::sort(arr, arr + N);
  for (int i = 0; i < K; i++) {
    answer += arr[i];
  }
  printf("%d", answer);
}

Fixed submission:
#include <algorithm>
#include <iostream>

int arr[1030];
int N, K;
int answer;

int main() {
  scanf("%d %d", &N, &K);
  for (int i = 0; i < N; i++) {
    scanf("%d", &arr[i]);
  }
  std::sort(arr, arr + N);
  for (int i = 0; i < K; i++) {
    answer += arr[i];
  }
  printf("%d", answer);
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (int &i : p)
    cin >> i;
  sort(p.begin(), p.end());
  int ans = 0;
  for (int i = 0; i < 3; i++)
    ans += p.at(i);
  cout << ans << endl;
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (int &i : p)
    cin >> i;
  sort(p.begin(), p.end());
  int ans = 0;
  for (int i = 0; i < K; i++)
    ans += p.at(i);
  cout << ans << endl;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
int p[100];

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);

  int n, k, sum = 0;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  sort(p, p + n);
  for (int i = 0; i < k; ++i) {
    sum += p[i];
  }
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;
int p[10000];

int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);

  int n, k, sum = 0;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  sort(p, p + n);
  for (int i = 0; i < k; ++i) {
    sum += p[i];
  }
  cout << sum << endl;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
  int n, k, price[n + 1], total = 0;

  cin >> n >> k;

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

  sort(price, price + n);

  for (int i = 0; i < k; i++)
    total = total + price[i];

  cout << total;
}

Fixed submission:
#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
  int n, k, price[1001], total = 0;

  cin >> n >> k;

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

  sort(price, price + n);

  for (int i = 0; i < k; i++)
    total = total + price[i];

  cout << total;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define pii pair<int, int>
#define vvi vector<vector<int>>
#define vi vector<int>
#define f first
#define s second
using namespace std;
const int mod = 1e9 + 7;
int logi(int n) {
  int p = 0;
  while (n / 2) {
    n = n / 2;
    p++;
  }
  return p;
}
int poww(int x, int y) {
  int pro = 1;
  while (y) {
    if (y & 1)
      pro = ((pro % mod) * (x % mod) % mod);
    y = y >> 1;
    x = ((x % mod) * (x % mod) % mod);
  }
  return pro;
}
int poww2(int x, int y) {
  int pro = 1;
  while (y) {
    if (y & 1)
      pro = pro * x;
    y = y >> 1;
    x = x * x;
  }
  return pro;
}
bool isprime(int n) {
  if (n == 1)
    return false;
  for (int i = 2; i <= sqrt(n); i++)
    if (n % i == 0)
      return false;
  return true;
}

/*

*/

int solve() {
  int n, k;
  cin >> n >> k;
  vi v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += v[i];
  }
  cout << sum;
}

int32_t main() {
  fast;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);
#define pii pair<int, int>
#define vvi vector<vector<int>>
#define vi vector<int>
#define f first
#define s second
using namespace std;
const int mod = 1e9 + 7;
int logi(int n) {
  int p = 0;
  while (n / 2) {
    n = n / 2;
    p++;
  }
  return p;
}
int poww(int x, int y) {
  int pro = 1;
  while (y) {
    if (y & 1)
      pro = ((pro % mod) * (x % mod) % mod);
    y = y >> 1;
    x = ((x % mod) * (x % mod) % mod);
  }
  return pro;
}
int poww2(int x, int y) {
  int pro = 1;
  while (y) {
    if (y & 1)
      pro = pro * x;
    y = y >> 1;
    x = x * x;
  }
  return pro;
}
bool isprime(int n) {
  if (n == 1)
    return false;
  for (int i = 2; i <= sqrt(n); i++)
    if (n % i == 0)
      return false;
  return true;
}

/*

*/

void solve() {
  int n, k;
  cin >> n >> k;
  vi v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += v[i];
  }
  cout << sum;
}

int32_t main() {
  fast;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> lol;
  for (int i = 0; i < n; i++) {
    cin >> lol[i];
  }
  sort(lol.begin(), lol.end());
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += lol[i];
  }
  cout << sum;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> lol(n);
  for (int i = 0; i < n; i++) {
    cin >> lol[i];
  }
  sort(lol.begin(), lol.end());
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += lol[i];
  }
  cout << sum;
}
Problem p02628 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <iostream>
int main() {
  int n, k, sum, vec[n];
  sum = 0;
  std::cin >> n >> k;
  for (int i = 0; i < n; i++) {
    std::cin >> vec[i];
  }
  std::sort(vec, vec + n);
  for (int i = 0; i < k; i++) {
    sum = sum + vec[i];
  }
  std::cout << sum;
}


Fixed submission:
#include <bits/stdc++.h>
#include <iostream>
int main() {
  int n, k, sum, vec[1000];
  sum = 0;
  std::cin >> n >> k;
  for (int i = 0; i < n; i++) {
    std::cin >> vec[i];
  }
  std::sort(vec, vec + n);
  for (int i = 0; i < k; i++) {
    sum = sum + vec[i];
  }
  std::cout << sum;
}
Problem p02629 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

#define MAX 500000000

// Function to print Excel column name for a given column number
void printString(long long int n) {
  char str[MAX];       // To store result (Excel column name)
  long long int i = 0; // To store current index in str which is result

  while (n > 0) {
    // Find remainder
    long long int rem = n % 26;

    // If remainder is 0, then a 'Z' must be there in output
    if (rem == 0) {
      str[i++] = 'z';
      n = (n / 26) - 1;
    } else // If remainder is non-zero
    {
      str[i++] = (rem - 1) + 'a';
      n = n / 26;
    }
  }
  str[i] = '\0';

  // Reverse the string and print result
  reverse(str, str + strlen(str));
  cout << str;

  return;
}

int main() {

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

  long long int n, num = 0, num1 = 0;
  cin >> n;
  printString(n);

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define MAX 50

// Function to print Excel column name for a given column number
void printString(long long int n) {
  char str[MAX];       // To store result (Excel column name)
  long long int i = 0; // To store current index in str which is result

  while (n > 0) {
    // Find remainder
    long long int rem = n % 26;

    // If remainder is 0, then a 'Z' must be there in output
    if (rem == 0) {
      str[i++] = 'z';
      n = (n / 26) - 1;
    } else // If remainder is non-zero
    {
      str[i++] = (rem - 1) + 'a';
      n = n / 26;
    }
  }
  str[i] = '\0';

  // Reverse the string and print result
  reverse(str, str + strlen(str));
  cout << str;

  return;
}

int main() {

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

  long long int n, num = 0, num1 = 0;
  cin >> n;
  printString(n);

  return 0;
}
Problem p02629 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
int main() {
  long n;
  cin >> n;
  int digit[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  int idx = 0;
  while (n > 0) {
    digit[idx] = n % 26;
    if (digit[idx] == 0) {
      digit[idx] = 26;
      n -= 26;
    }
    n /= 26;
    idx++;
  }

  for (; digit[idx] == 0; idx--)
    ;
  for (; idx >= 0; idx--) {
    cout << (char)('a' + digit[idx] - 1);
  }

  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  long n;
  cin >> n;
  int digit[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  int idx = 0;
  while (n > 0) {
    digit[idx] = n % 26;
    if (digit[idx] == 0) {
      digit[idx] = 26;
      n -= 26;
    }
    n /= 26;
    idx++;
  }

  for (; digit[idx] == 0; idx--)
    ;
  for (; idx >= 0; idx--) {
    cout << (char)('a' + digit[idx] - 1);
  }

  return 0;
}
Problem p02629 (C++)

Buggy submission (status: Runtime Error):
#include <cassert>
#include <cmath>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long N;
  cin >> N;
  assert(N >= 1);

  const string alphabets = "abcdefghijklmnopqrstuvwxyz";
  const long long MAX_N = 1000000000000001;
  const int M = 26;

  int j = 1000000000;
  long long th = 0;
  vector<long long> ths = {0};
  for (int i = 1; i < log(MAX_N) / log(M); i++) {
    th += pow(M, i);
    ths.push_back(th);
    if (N <= th)
      j = min(j, i);
  }

  // cout << "length: " << j << endl;

  string ans = "";
  N -= 1;
  for (; j > 0; j--) {
    int x = (N - ths[j - 1]) / pow(M, j - 1);
    N -= (x + 1) * pow(M, j - 1);
    cout << alphabets[x];
  }

  cout << endl;

  return 0;
}


Fixed submission:
#include <cassert>
#include <cmath>
#include <iostream>
#include <stdexcept>
#include <string>
#include <vector>
using namespace std;

int main() {
  long long N;
  cin >> N;
  assert(N >= 1);

  const string alphabets = "abcdefghijklmnopqrstuvwxyz";
  const long long MAX_N = 1000000000000001;
  const int M = 26;

  int j = 1000000000;
  long long th = 0;
  vector<long long> ths = {0};
  for (int i = 1; i < log(MAX_N) / log(M) + 1; i++) {
    th += pow(M, i);
    ths.push_back(th);
    if (N <= th)
      j = min(j, i);
  }

  // cout << "length: " << j << endl;

  string ans = "";
  N -= 1;
  for (; j > 0; j--) {
    int x = (N - ths[j - 1]) / pow(M, j - 1);
    N -= (x + 1) * pow(M, j - 1);
    cout << alphabets[x];
  }

  cout << endl;

  return 0;
}
Problem p02629 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
string ans;
int n, now = 1, cnt = 26, num = 26;
int main() {
  cin >> n;
  while (cnt < n) {
    num *= 26;
    cnt += num, now++;
  }
  cnt -= num, num /= 26, n -= cnt + 1;
  //	cout<<n<<" "<<num<<"\n";

  for (int i = 0; i < now; i++) {
    putchar(n / num + 'a');
    n %= num, num /= 26;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
long long n, now = 1, cnt = 26, num = 26;
int main() {
  cin >> n;
  while (cnt < n) {
    num *= 26;
    cnt += num, now++;
  }
  cnt -= num, num /= 26, n -= cnt + 1;
  //	cout<<n<<" "<<num<<"\n";

  for (int i = 0; i < now; i++) {
    putchar(n / num + 'a');
    n %= num, num /= 26;
  }
}
Problem p02629 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
ans = ""
while N > 0:
    N -= 1
    ans += chr(ord("a" + N % 26))
    N //= 26
print(ans[::-1])


Fixed submission:
N = int(input())
ans = ""
while N > 0:
    N -= 1
    ans += chr(ord("a") + N % 26)
    N //= 26
print(ans[::-1])
Problem p02629 (Python)

Buggy submission (status: Runtime Error):
import string

s = string.ascii_lowercase


def f(x, tmp):
    if x == 0:
        return ""
    x -= 1
    if x <= 26:
        return s[x] + tmp
    else:
        return f(x // 26, s[x % 26] + tmp)


n = int(input())
r = f(n, "")
print(r)


Fixed submission:
import string

s = string.ascii_lowercase


def f(x, tmp):
    if x == 0:
        return ""
    x -= 1
    if x < 26:
        return s[x] + tmp
    else:
        return f(x // 26, s[x % 26] + tmp)


n = int(input())
r = f(n, "")
print(r)
Problem p02629 (Python)

Buggy submission (status: Runtime Error):
a = int(input())
c = ""
while a >= 26:
    b = a % 26
    c += chr(ord("a") + b - 1)
    a /= 26
c += chr(ord("a") + int(a) - 1)
print(c[::-1])


Fixed submission:
a = int(input())
c = ""
while a > 26:
    b = int(a) % 26
    c += chr(ord("a") + (25 if b == 0 else int(b) - 1))
    a = int(a / 26 - 1 if a % 26 == 0 else a / 26)
c += chr(ord("a") + int(a) - 1)
print(c[::-1])
Problem p02629 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<int> bits(n);
  int p = 0;
  while (n > 0) {
    bits[p++] = (--n) % 26;
    n /= 26;
  }
  for (int i = p - 1; i >= 0; i--) {
    cout << char(bits[i] + 'a');
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main() {
  ll n;
  cin >> n;
  vector<int> bits(100);
  int p = 0;
  while (n > 0) {
    bits[p++] = (--n) % 26;
    n /= 26;
  }
  for (int i = p - 1; i >= 0; i--) {
    cout << char(bits[i] + 'a');
  }
  return 0;
}
Problem p02629 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

int main() {
  string s;
  long long N;
  long long d = 1;
  int result[7] = {0};
  int i = 0;
  int l;
  cin >> N;
  while (N >= 0) {
    N -= d;
    d *= 26;
    result[i]++;
    i++;
  }
  i--;
  l = i;
  d /= 26;
  N += d;
  while (d >= 1) {
    result[i] += N / d;
    N %= d;
    d /= 26;
    i--;
  }
  for (int m = l - 1; m >= 0; m--) {
    s += (result[m] + 'a' - 1);
  }
  cout << s;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

int main() {
  string s;
  long long N;
  long long d = 1;
  int result[15] = {0};
  int i = 0;
  int l;
  cin >> N;
  while (N >= 0) {
    N -= d;
    d *= 26;
    result[i]++;
    i++;
  }
  i--;
  l = i;
  d /= 26;
  N += d;
  while (d >= 1) {
    result[i] += N / d;
    N %= d;
    d /= 26;
    i--;
  }
  for (int m = l - 1; m >= 0; m--) {
    s += (result[m] + 'a' - 1);
  }
  cout << s;
}
Problem p02629 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

void solve() {
  long long n, x = 26, pre = 1;
  cin >> n;
  string s;
  while (n > 0) {
    int c = n % x;
    if (!c)
      c = x;
    n -= c;
    s += ((c / pre - 1) + 'a');
    x *= 26;
    pre *= 26;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
}

int main() {
  int tt = 1;
  // cin >> tt;
  while (tt--)
    solve();
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

void solve() {
  long long n, x = 26, pre = 1;
  cin >> n;
  string s;
  while (n > 0) {
    long long c = n % x;
    if (!c)
      c = x;
    n -= c;
    s += ((c / pre - 1) + 'a');
    x *= 26;
    pre *= 26;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
}

int main() {
  int tt = 1;
  // cin >> tt;
  while (tt--)
    solve();
}
Problem p02629 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
// cout << fixed << setprecision(8) << a << endl;
#define Fast_Input                                                             \
  ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a))
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type, greater<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
/*sort(v.begin(), v.end(),
     [](const pair<int, int>& x, const pair<int, int>& y)
{
    if (x.first != y.first)
        return x.first < y.first;
    return x.second < y.second;
});
*/
int const fx[] = {+1, +0, -1, +1};
int const fy[] = {-1, +1, +0, +0};
const int inf = numeric_limits<int>::max();
const int mx = 2e5;
const ll mod = 1e9 + 7;
ll pow(ll x, ll n) {
  ll res = 1;
  while (n) {
    if (n % 2) {
      res = res * x;
      n--;
    }
    x = x * x;
    n /= 2;
  }
  return res;
}
int main() {
  string s = "aabcdefghijklmnopqrstuvwxyz";
  ll n, i, sum = 0;
  cin >> n;
  i = 0;
  while (sum < n) {
    i++;
    sum += pow(ll(26), i);
  }
  i--;
  vector<char> v(i);
  int j;
  for (j = i; j >= 0; j--) {
    int y = n % 26;
    if (y == 0)
      y = 26;
    v[j] = s[y];
    n -= y;
    n /= 26;
  }
  for (j = 0; j <= i; j++)
    cout << v[j];
  cout << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
// cout << fixed << setprecision(8) << a << endl;
#define Fast_Input                                                             \
  ios_base ::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define pb push_back
#define mem(a, b) memset(a, b, sizeof(a))
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type, greater<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
/*sort(v.begin(), v.end(),
     [](const pair<int, int>& x, const pair<int, int>& y)
{
    if (x.first != y.first)
        return x.first < y.first;
    return x.second < y.second;
});
*/
int const fx[] = {+1, +0, -1, +1};
int const fy[] = {-1, +1, +0, +0};
const int inf = numeric_limits<int>::max();
const int mx = 2e5;
const ll mod = 1e9 + 7;
ll pow(ll x, ll n) {
  ll res = 1;
  while (n) {
    if (n % 2) {
      res = res * x;
      n--;
    }
    x = x * x;
    n /= 2;
  }
  return res;
}
int main() {
  string s = "aabcdefghijklmnopqrstuvwxyz";
  ll n, i, sum = 0;
  cin >> n;
  i = 0;
  while (sum < n) {
    i++;
    sum += pow(ll(26), i);
  }
  i--;
  vector<char> v(20);
  int j;
  for (j = i; j >= 0; j--) {
    int y = n % 26;
    if (y == 0)
      y = 26;
    v[j] = s[y];
    n -= y;
    n /= 26;
  }
  for (j = 0; j <= i; j++)
    cout << v[j];
  cout << endl;
  return 0;
}
Problem p02629 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long n;
  cin >> n;
  string ans = "";
  string abc = "abcdefghijklmnopqrstuvwxyz";
  int rem;
  while (n >= 0) {
    n -= 1;
    rem = n % 26;
    ans += abc[rem];
    n /= 26;
  }

  reverse(ans.begin(), ans.end());
  cout << ans;

  return 0;
}


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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  long long n;
  cin >> n;
  string ans = "";
  string abc = "abcdefghijklmnopqrstuvwxyz";
  int rem;
  while (n > 0) {
    n -= 1;
    rem = n % 26;
    ans += abc[rem];
    n /= 26;
  }

  reverse(ans.begin(), ans.end());
  cout << ans;

  return 0;
}