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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long s64;

const int ONE = 100005;

int get() {
  int res = 1, Q = 1;
  char c;
  while ((c = getchar()) < 48 || c > 57)
    if (c == '-')
      Q = -1;
  if (Q)
    res = c - 48;
  while ((c = getchar()) >= 48 && c <= 57)
    res = res * 10 + c - 48;
  return res * Q;
}

int n, k;
int a[ONE];

#include <map>
map<int, int> times, f;

#include <vector>

int A[ONE];

int main() {
  n = get(), k = get();

  int now = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = get(), times[a[i]]++;
    if (times[a[i]] == 1)
      now++;
  }

  int total = 0;
  for (int i = 1; i <= n; i++)
    if (!f[a[i]])
      A[++total] = times[a[i]], f[a[i]] = 1;

  sort(A + 1, A + total + 1);

  int ans = 0;
  for (int i = 1; i <= total; i++) {
    if (now <= k)
      break;
    ans += A[i], now--;
  }

  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long s64;

const int ONE = 2000005;

int get() {
  int res = 1, Q = 1;
  char c;
  while ((c = getchar()) < 48 || c > 57)
    if (c == '-')
      Q = -1;
  if (Q)
    res = c - 48;
  while ((c = getchar()) >= 48 && c <= 57)
    res = res * 10 + c - 48;
  return res * Q;
}

int n, k;
int a[ONE];

#include <map>
map<int, int> times, f;

#include <vector>

int A[ONE];

int main() {
  n = get(), k = get();

  int now = 0;
  for (int i = 1; i <= n; i++) {
    a[i] = get(), times[a[i]]++;
    if (times[a[i]] == 1)
      now++;
  }

  int total = 0;
  for (int i = 1; i <= n; i++)
    if (!f[a[i]])
      A[++total] = times[a[i]], f[a[i]] = 1;

  sort(A + 1, A + total + 1);

  int ans = 0;
  for (int i = 1; i <= total; i++) {
    if (now <= k)
      break;
    ans += A[i], now--;
  }

  cout << ans << endl;
}
Problem p03497 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

map<int, int> M;
signed main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    M[a]++;
  }
  vector<int> V;
  for (pair<int, int> i : M) {
    V.push_back(i.second);
  }
  sort(V.begin(), V.end());
  int ans = 0;
  for (int i = 0; i < V.size() - k; i++) {
    ans += V[i];
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

map<int, int> M;
signed main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    M[a]++;
  }
  vector<int> V;
  for (pair<int, int> i : M) {
    V.push_back(i.second);
  }
  sort(V.begin(), V.end());
  int ans = 0;
  for (int i = 0; i < (int)V.size() - k; i++) {
    ans += V[i];
  }
  cout << ans << endl;
}
Problem p03498 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  int absmax = 0;
  int pos = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (absmax < abs(a[i] - 0)) {
      pos = i;
      absmax = abs(a[i] - 0);
    }
  }

  int cand = a[pos];
  cout << 2 * n - 1 << endl;
  if (cand >= 0) {
    for (int i = 0; i < n; i++) {
      a[i] += cand;
      cout << pos + 1 << " " << i + 1 << endl;
    }
    for (int i = 0; i < n - 1; i++) {
      a[i + 1] += a[i];
      cout << i + 1 << " " << i + 2 << endl;
    }
  } else {
    for (int i = 0; i < n; i++) {
      a[i] += cand;
      cout << pos + 1 << " " << i + 1 << endl;
    }
    for (int i = n - 1; i >= 1; i++) {
      a[i - 1] += a[i];
      cout << i + 1 << " " << i << endl;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  int absmax = 0;
  int pos = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (absmax < abs(a[i] - 0)) {
      pos = i;
      absmax = abs(a[i] - 0);
    }
  }

  int cand = a[pos];
  cout << 2 * n - 1 << endl;
  if (cand >= 0) {
    for (int i = 0; i < n; i++) {
      a[i] += cand;
      cout << pos + 1 << " " << i + 1 << endl;
    }
    for (int i = 0; i < n - 1; i++) {
      a[i + 1] += a[i];
      cout << i + 1 << " " << i + 2 << endl;
    }
  } else {
    for (int i = 0; i < n; i++) {
      a[i] += cand;
      cout << pos + 1 << " " << i + 1 << endl;
    }
    for (int i = n - 1; i >= 1; i--) {
      a[i - 1] += a[i];
      cout << i + 1 << " " << i << endl;
    }
  }
}
Problem p03498 (C++)

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

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

  vi a(N);
  for (ll i = 0; i < N; i++) {
    cin >> a[i];
  }

  pii ma = make_pair(0, a[0]);
  pii mi = make_pair(0, a[0]);

  for (ll i = 0; i < N; i++) {
    if (a[i] > ma.second) {
      ma = make_pair(i, a[i]);
    }
    if (a[i] < mi.second) {
      mi = make_pair(i, a[i]);
    }
  }

  vpii ans;

  if (ma.second + mi.second >= 0) {
    for (ll i = 0; i < N; i++) {
      if (i != ma.first) {
        ans.push_back(make_pair(ma.first, i));
      }
    }
    for (ll i = 0; i < N - 1; i++) {
      ans.push_back(make_pair(i, i + 1));
    }
  } else {
    for (ll i = 0; i < N; i++) {
      if (i != mi.first) {
        ans.push_back(make_pair(mi.first, i));
      }
    }
    for (ll i = N - 2; i >= 0; i++) {
      ans.push_back(make_pair(i + 1, i));
    }
  }

  cout << ans.size() << endl;

  for (auto p : ans) {
    cout << p.first + 1 << ' ' << p.second + 1 << endl;
  }
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

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

  vi a(N);
  for (ll i = 0; i < N; i++) {
    cin >> a[i];
  }

  pii ma = make_pair(0, a[0]);
  pii mi = make_pair(0, a[0]);

  for (ll i = 0; i < N; i++) {
    if (a[i] > ma.second) {
      ma = make_pair(i, a[i]);
    }
    if (a[i] < mi.second) {
      mi = make_pair(i, a[i]);
    }
  }

  vpii ans;

  if (ma.second + mi.second >= 0) {
    for (ll i = 0; i < N; i++) {
      if (i != ma.first) {
        ans.push_back(make_pair(ma.first, i));
      }
    }
    for (ll i = 0; i < N - 1; i++) {
      ans.push_back(make_pair(i, i + 1));
    }
  } else {
    for (ll i = 0; i < N; i++) {
      if (i != mi.first) {
        ans.push_back(make_pair(mi.first, i));
      }
    }
    for (ll i = N - 2; i >= 0; i--) {
      ans.push_back(make_pair(i + 1, i));
    }
  }

  cout << ans.size() << endl;

  for (auto p : ans) {
    cout << p.first + 1 << ' ' << p.second + 1 << endl;
  }
}
Problem p03498 (C++)

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

using namespace std;

#define rep(i, a, b) for (ll i = a; i < ll(b); ++i)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define trav(a, c) for (auto a : c)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;

int main() {
  cin.sync_with_stdio(false);
  ll n;
  cin >> n;
  vi a(n);
  ll mxInd = 0;
  rep(i, 0, n) {
    cin >> a[i];
    if (abs(a[i]) > abs(a[mxInd]))
      mxInd = i;
  }
  bool rev = (a[mxInd] < 0);
  if (a[mxInd] < 0) {
    rep(i, 0, n) a[i] *= -1;
    reverse(all(a));
  }
  cout << 2 * n << endl;
  a[0] += a[mxInd] * 2;
  cout << mxInd + 1 << " " << (rev ? n : 1ll) << endl;
  cout << mxInd + 1 << " " << (rev ? n : 1ll) << endl;
  rep(i, 1, n) {
    a[i] += a[i - 1] * 2;
    cout << (rev ? (n - i + 1) : (i)) << " " << (rev ? (n - i) : (i + 1))
         << endl;
    cout << (rev ? (n - i + 1) : (i)) << " " << (rev ? (n - i) : (i + 1))
         << endl;
  }
  rep(i, 0, n - 1) assert(a[i] <= a[i + 1]);
}


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

using namespace std;

#define rep(i, a, b) for (ll i = a; i < ll(b); ++i)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define trav(a, c) for (auto a : c)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pii;

int main() {
  cin.sync_with_stdio(false);
  ll n;
  cin >> n;
  vi a(n);
  ll mxInd = 0;
  rep(i, 0, n) {
    cin >> a[i];
    if (abs(a[i]) > abs(a[mxInd]))
      mxInd = i;
  }
  bool rev = (a[mxInd] < 0);
  if (a[mxInd] < 0) {
    rep(i, 0, n) a[i] *= -1;
    reverse(all(a));
  }
  cout << 2 * n << endl;
  a[0] += a[mxInd] * 2;
  cout << mxInd + 1 << " " << (rev ? n : 1ll) << endl;
  cout << mxInd + 1 << " " << (rev ? n : 1ll) << endl;
  rep(i, 1, n) {
    a[i] += a[i - 1] * 2;
    cout << (rev ? (n - i + 1) : (i)) << " " << (rev ? (n - i) : (i + 1))
         << endl;
    cout << (rev ? (n - i + 1) : (i)) << " " << (rev ? (n - i) : (i + 1))
         << endl;
  }
  // rep(i,0,n-1) assert(a[i]<=a[i+1]);
}
Problem p03498 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define double long double
#define P pair<long long, long long>
#define all(a) a.begin(), a.end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

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

  int n;
  cin >> n;
  vector<int> a(n);

  int abs_max = 0, use;
  rep(i, n) {
    cin >> a[i];
    if (chmax(abs_max, abs(a[i]))) {
      use = i;
    }
  }

  vector<P> ans;
  rep(i, n) if (i != use) {
    a[i] += a[use];
    ans.push_back(P(use + 1, i + 1));
  }
  if (a[use] >= 0) {
    rep(i, n - 1) {
      if (a[i] > a[i + 1]) {
        a[i + 1] += a[i];
        ans.push_back(P(i + 1, i + 2));
      }
    }
  } else {
    for (int i = n - 1; i > 0; i--) {
      if (a[i - 1] > a[i]) {
        a[i - 1] += a[i];
        ans.push_back(P(i + 1, i));
      }
    }
  }

  cout << ans.size() << endl;
  rep(i, ans.size()) { cout << ans[i].first << ' ' << ans[i].second << endl; }
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define double long double
#define P pair<long long, long long>
#define all(a) a.begin(), a.end()
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using namespace std;

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

  int n;
  cin >> n;
  vector<int> a(n);

  int abs_max = -1, use;
  rep(i, n) {
    cin >> a[i];
    if (chmax(abs_max, abs(a[i]))) {
      use = i;
    }
  }

  vector<P> ans;
  rep(i, n) if (i != use) {
    a[i] += a[use];
    ans.push_back(P(use + 1, i + 1));
  }
  if (a[use] >= 0) {
    rep(i, n - 1) {
      if (a[i] > a[i + 1]) {
        a[i + 1] += a[i];
        ans.push_back(P(i + 1, i + 2));
      }
    }
  } else {
    for (int i = n - 1; i > 0; i--) {
      if (a[i - 1] > a[i]) {
        a[i - 1] += a[i];
        ans.push_back(P(i + 1, i));
      }
    }
  }

  cout << ans.size() << endl;
  rep(i, ans.size()) { cout << ans[i].first << ' ' << ans[i].second << endl; }
}
Problem p03498 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>  // minmax, sort, swap
#include <cstdio>     // printf, scanf
#include <deque>      // deque
#include <functional> // function<void(int)>
#include <iomanip>    // cout<<setprecision(n)
#include <iostream>   // cin, cout, cerr
#include <map>        // key-value pairs sorted by keys
#include <numeric>    // iota
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <string>     // string, stoi, to_string
#include <vector>     // vector

#define rep(i, n) for (int i = 0; i < (n); i++)
#define ENDL '\n'
#define print1(i) std::cout << (i) << '\n'
#define print(i, j) std::cout << (i) << ' ' << (j) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  rep(i, n) std::cin >> a[i];
  int maxi;
  int max = 0;
  rep(i, n) {
    if (std::abs(a[i]) > max) {
      max = std::abs(a[i]);
      maxi = i;
    }
  }
  print1(2 * n);
  if (a[maxi] >= 0) {
    print(maxi + 1, n);
    print(maxi + 1, n);
    rep(i, n - 1) {
      print(n, i + 1);
      print(i + 1, n);
    }
  } else {
    print(maxi + 1, 1);
    print(maxi + 1, 1);
    rep(i, n - 1) {
      print(1, n - i);
      print(n - i, 1);
    }
  }

  return 0;
}


Fixed submission:
#include <algorithm>  // minmax, sort, swap
#include <cstdio>     // printf, scanf
#include <deque>      // deque
#include <functional> // function<void(int)>
#include <iomanip>    // cout<<setprecision(n)
#include <iostream>   // cin, cout, cerr
#include <map>        // key-value pairs sorted by keys
#include <numeric>    // iota
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <string>     // string, stoi, to_string
#include <vector>     // vector

#define rep(i, n) for (int i = 0; i < (n); i++)
#define ENDL '\n'
#define print1(i) std::cout << (i) << '\n'
#define print(i, j) std::cout << (i) << ' ' << (j) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
  int n;
  std::cin >> n;
  std::vector<int> a(n);
  rep(i, n) std::cin >> a[i];
  int maxi = 0;
  int max = 0;
  rep(i, n) {
    if (std::abs(a[i]) > max) {
      max = std::abs(a[i]);
      maxi = i;
    }
  }
  print1(2 * n);
  if (a[maxi] >= 0) {
    print(maxi + 1, n);
    print(maxi + 1, n);
    rep(i, n - 1) {
      print(n, i + 1);
      print(i + 1, n);
    }
  } else {
    print(maxi + 1, 1);
    print(maxi + 1, 1);
    rep(i, n - 1) {
      print(1, n - i);
      print(n - i, 1);
    }
  }

  return 0;
}
Problem p03498 (C++)

Buggy submission (status: Time Limit Exceeded):
// A,Elebereth Gilthoniel mantae!
// For Temeria!
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int n;
int a[80];
int xabs(int x) { return max(x, -x); }
int main() {
  // freopen("","r",stdin);
  // freopen("","w",stdout);
  int ma = -1, mi = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (xabs(a[i]) > ma)
      ma = xabs(a[i]), mi = i;
  }
  cout << n * 2 << "\n";
  if (a[mi] > 0) {
    cout << mi << " " << n << "\n";
    cout << n << " " << n << "\n";
    for (int i = 2; i <= n; i++) {
      cout << n << " " << n << "\n";
      cout << n << " " << i << "\n";
    }
  } else {
    cout << mi << " " << 1 << "\n";
    cout << 1 << " " << 1 << "\n";
    for (int i = n - 1; i >= 1; i++) {
      cout << 1 << " " << 1 << "\n";
      cout << 1 << " " << i << "\n";
    }
  }
  return 0;
}

Fixed submission:
// A,Elebereth Gilthoniel mantae!
// For Temeria!
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
int n;
int a[80];
int xabs(int x) { return max(x, -x); }
int main() {
  // freopen("","r",stdin);
  // freopen("","w",stdout);
  int ma = -1, mi = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    if (xabs(a[i]) > ma)
      ma = xabs(a[i]), mi = i;
  }
  cout << n * 2 << "\n";
  if (a[mi] > 0) {
    cout << mi << " " << n << "\n";
    cout << n << " " << n << "\n";
    for (int i = 2; i <= n; i++) {
      cout << n << " " << n << "\n";
      cout << n << " " << i << "\n";
    }
  } else {
    cout << mi << " " << 1 << "\n";
    cout << 1 << " " << 1 << "\n";
    for (int i = n - 1; i >= 1; i--) {
      cout << 1 << " " << 1 << "\n";
      cout << 1 << " " << i << "\n";
    }
  }
  return 0;
}
Problem p03498 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  ll arr[n + 5];
  ll mini = 1e16, maxi = -1e16;
  int idxmin = -1, idxmax = -1;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (maxi < arr[i])
      maxi = arr[i], idxmax = i;
    if (mini > arr[i])
      mini = arr[i], idxmin = i;
  }
  vector<pair<int, int>> v;
  if (mini < 0 && maxi > 0) {
    ll tmp, idx;
    if (abs(maxi) >= abs(mini)) {
      tmp = maxi;
      idx = idxmax;
    } else {
      tmp = mini;
      idx = idxmin;
    }
    maxi = -1e16;
    mini = 1e16;
    for (int i = 1; i <= n; i++) {
      arr[i] += tmp;
      v.push_back({idx, i});
      maxi = max(maxi, arr[i]);
      mini = min(mini, arr[i]);
    }
  }
  if (maxi >= 0 && mini >= 0) {
    for (int i = 2; i <= n; i++)
      v.push_back({i - 1, i});
  } else if (maxi < 0 && mini < 0) {
    for (int i = n - 1; i >= 1; i--)
      v.push_back({i + 1, i});
  } else
    assert(0);
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++)
    cout << v[i].first << " " << v[i].second << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  ll arr[n + 5];
  ll mini = 1e16, maxi = -1e16;
  int idxmin = -1, idxmax = -1;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
    if (maxi < arr[i])
      maxi = arr[i], idxmax = i;
    if (mini > arr[i])
      mini = arr[i], idxmin = i;
  }
  vector<pair<int, int>> v;
  if (mini < 0 && maxi > 0) {
    ll tmp, idx;
    if (abs(maxi) >= abs(mini)) {
      tmp = maxi;
      idx = idxmax;
    } else {
      tmp = mini;
      idx = idxmin;
    }
    maxi = -1e16;
    mini = 1e16;
    for (int i = 1; i <= n; i++) {
      arr[i] += tmp;
      v.push_back({idx, i});
      maxi = max(maxi, arr[i]);
      mini = min(mini, arr[i]);
    }
  }
  if (maxi >= 0 && mini >= 0) {
    for (int i = 2; i <= n; i++)
      v.push_back({i - 1, i});
  } else if (maxi <= 0 && mini <= 0) {
    for (int i = n - 1; i >= 1; i--)
      v.push_back({i + 1, i});
  } else
    assert(0);
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++)
    cout << v[i].first << " " << v[i].second << endl;
}
Problem p03498 (C++)

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

int main() {
  ll n;
  std::cin >> n;
  vector<ll> a(n);
  ll ma, mi, mai, mii;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    if (i == 0) {
      ma = a[i];
      mai = i;
      mi = a[i];
      mii = i;
    } else {
      if (a[i] > ma) {
        ma = a[i];
        mai = i;
      }
      if (a[i] < mi) {
        mi = a[i];
        mii = i;
      }
    }
  }

  std::cout << 2 * n - 1 << std::endl;
  for (int i = 0; i < n; i++) {
    if (abs(ma) >= abs(mi)) {
      std::cout << mai + 1 << " " << i + 1 << std::endl;
    } else {
      std::cout << mii + 1 << " " << i + 1 << std::endl;
    }
  }

  if (abs(ma) >= abs(mi)) {
    for (int i = 0; i < n - 1; i++) {
      std::cout << i + 1 << " " << i + 2 << std::endl;
    }
  } else {
    for (int i = n - 1; i > 0; i++) {
      std::cout << i + 1 << " " << i << std::endl;
    }
  }
}


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

int main() {
  ll n;
  std::cin >> n;
  vector<ll> a(n);
  ll ma, mi, mai, mii;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    if (i == 0) {
      ma = a[i];
      mai = i;
      mi = a[i];
      mii = i;
    } else {
      if (a[i] > ma) {
        ma = a[i];
        mai = i;
      }
      if (a[i] < mi) {
        mi = a[i];
        mii = i;
      }
    }
  }

  std::cout << 2 * n - 1 << std::endl;
  for (int i = 0; i < n; i++) {
    if (abs(ma) >= abs(mi)) {
      std::cout << mai + 1 << " " << i + 1 << std::endl;
    } else {
      std::cout << mii + 1 << " " << i + 1 << std::endl;
    }
  }

  if (abs(ma) >= abs(mi)) {
    for (int i = 0; i < n - 1; i++) {
      std::cout << i + 1 << " " << i + 2 << std::endl;
    }
  } else {
    for (int i = n - 1; i > 0; i--) {
      std::cout << i + 1 << " " << i << std::endl;
    }
  }
}
Problem p03498 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
ll a[111];
int i, j, k, n, m, b[211][2];
int av(int x) { return (x >= 0) ? x : -x; }
void add(int x, int y) {
  b[++m][0] = x;
  b[m][1] = y;
  a[y] += a[x];
}
int main() {
  scanf("%d", &n);
  m = 0;
  for (i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  for (i = 1, k = 1; i <= n; i++)
    if (av(a[k]) < av(a[i]))
      k = i;
  if (!a[k]) {
    puts("0");
    return 0;
  }
  if (a[k] > 0) {
    while (a[n] < a[k])
      add(k, n);
    for (i = 2; i < n; i++) {
      while (a[i] + a[n] < a[i - 1])
        add(n, n);
      if (a[i] < a[i - 1])
        add(n, i);
    }
    while (a[n] < a[n - 1])
      add(n, n);
  } else {
    while (a[1] > a[k])
      add(k, 1);
    for (i = n - 1; i > 1; i++) {
      while (a[i] + a[1] > a[i + 1])
        add(1, 1);
      if (a[i] > a[i + 1])
        add(1, i);
    }
    while (a[1] > a[2])
      add(1, 1);
  }
  assert(m <= 2 * n);
  printf("%d\n", m);
  for (i = 1; i <= m; i++)
    printf("%d %d\n", b[i][0], b[i][1]);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
ll a[111];
int i, j, k, n, m, b[211][2];
int av(int x) { return (x >= 0) ? x : -x; }
void add(int x, int y) {
  b[++m][0] = x;
  b[m][1] = y;
  a[y] += a[x];
}
int main() {
  scanf("%d", &n);
  m = 0;
  for (i = 1; i <= n; i++)
    scanf("%lld", &a[i]);
  for (i = 1, k = 1; i <= n; i++)
    if (av(a[k]) < av(a[i]))
      k = i;
  if (!a[k]) {
    puts("0");
    return 0;
  }
  if (a[k] > 0) {
    while (a[n] < a[k])
      add(k, n);
    for (i = 2; i < n; i++) {
      while (a[i] + a[n] < a[i - 1])
        add(n, n);
      if (a[i] < a[i - 1])
        add(n, i);
    }
    while (a[n] < a[n - 1])
      add(n, n);
  } else {
    while (a[1] > a[k])
      add(k, 1);
    for (i = n - 1; i > 1; i--) {
      while (a[i] + a[1] > a[i + 1])
        add(1, 1);
      if (a[i] > a[i + 1])
        add(1, i);
    }
    while (a[1] > a[2])
      add(1, 1);
  }
  assert(m <= 2 * n);
  printf("%d\n", m);
  for (i = 1; i <= m; i++)
    printf("%d %d\n", b[i][0], b[i][1]);
  return 0;
}
Problem p03498 (C++)

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

using namespace std;

struct Pair {
  int a;
  int b;
  Pair(int a, int b) {
    this->a = a;
    this->b = b;
  }
};

int main() {
  int n;
  cin >> n;
  vector<long long> v;
  long long tmp;
  vector<Pair> vp;
  long long min = 1000001, max = -1000001;
  int index_min, index_max;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    v.push_back(tmp);
    if (min > tmp) {
      min = tmp;
      index_min = i;
    }
    if (max < tmp) {
      max = tmp;
      index_max = i;
    }
  }
  if (max < -min) {
    for (int i = 0; i < n; i++) {
      v[i] += v[index_min];
      vp.push_back(Pair(index_min, i));
    }
    for (int i = n - 1; i >= 0; i--) {
      while (v[i - 1] > v[i]) {
        v[i - 1] += v[i];
        vp.push_back(Pair(i, i - 1));
        // cout << i << endl;
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      v[i] += v[index_max];
      vp.push_back(Pair(index_max, i));
    }
    for (int i = 0; i < n - 1; i++) {
      while (v[i] > v[i + 1]) {
        v[i + 1] += v[i];
        vp.push_back(Pair(i, i + 1));
      }
    }
  }
  cout << vp.size() << endl;
  for (auto it = vp.begin(); it != vp.end(); it++)
    cout << it->a + 1 << " " << it->b + 1 << endl;
}


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

using namespace std;

struct Pair {
  int a;
  int b;
  Pair(int a, int b) {
    this->a = a;
    this->b = b;
  }
};

int main() {
  int n;
  cin >> n;
  vector<long long> v;
  long long tmp;
  vector<Pair> vp;
  long long min = 1000001, max = -1000001;
  int index_min, index_max;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    v.push_back(tmp);
    if (min > tmp) {
      min = tmp;
      index_min = i;
    }
    if (max < tmp) {
      max = tmp;
      index_max = i;
    }
  }
  if (max < -min) {
    for (int i = 0; i < n; i++) {
      v[i] += v[index_min];
      vp.push_back(Pair(index_min, i));
    }
    for (int i = n - 1; i > 0; i--) {
      while (v[i - 1] > v[i]) {
        v[i - 1] += v[i];
        vp.push_back(Pair(i, i - 1));
        // cout << i << endl;
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      v[i] += v[index_max];
      vp.push_back(Pair(index_max, i));
    }
    for (int i = 0; i < n - 1; i++) {
      while (v[i] > v[i + 1]) {
        v[i + 1] += v[i];
        vp.push_back(Pair(i, i + 1));
      }
    }
  }
  cout << vp.size() << endl;
  for (auto it = vp.begin(); it != vp.end(); it++)
    cout << it->a + 1 << " " << it->b + 1 << endl;
}
Problem p03498 (Python)

Buggy submission (status: Runtime Error):
N = int(input())
A = list(map(int, input().split()))

ans = []
mx = max(A)
mi = min(A)

if mx * mi < 0:
    if abs(mi) > abs(mx):
        x = A.index(mi)
        for y in range(N):
            if y == x:
                continue
            A[y] += mi
            ans.append((x, y))
    else:
        x = A.index(mx)
        for y in range(N):
            if x == y:
                continue
            A[y] += mx
            ans.append((x, y))

for i in range(N - 1)[:: (-1) ** (max(A) < 0)]:
    l, r = A[i], A[i + 1]

    if l > r:
        if r >= 0:
            A[i + 1] += l
            ans.append((i, i + 1))
        elif l <= 0:
            A[i] += r
            ans.append((i + 1, i))

print(len(ans))
for x, y in ans:
    print(x + 1, y + 1)

if list(sorted(A)) != A:
    print(A)
    1 / 0


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

ans = []
mx = max(A)
mi = min(A)

if mx * mi < 0:
    if abs(mi) > abs(mx):
        x = A.index(mi)
        for y in range(N):
            if y == x:
                continue
            A[y] += mi
            ans.append((x, y))
    else:
        x = A.index(mx)
        for y in range(N):
            if x == y:
                continue
            A[y] += mx
            ans.append((x, y))

for i in range(N - 1)[:: (-1) ** (min(A) < 0)]:
    l, r = A[i], A[i + 1]

    if l > r:
        if r >= 0:
            A[i + 1] += l
            ans.append((i, i + 1))
        elif l <= 0:
            A[i] += r
            ans.append((i + 1, i))

print(len(ans))
for x, y in ans:
    print(x + 1, y + 1)

if list(sorted(A)) != A:
    print(A)
    1 / 0
Problem p03499 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
const int MX = 35, MOD = 1e9 + 7, H = 5e8 + 4;
int n, p, len[MX], id[MX];
ll a;
vector<int> G[MX];
struct P {
  ll z, o;
};
deque<P> qu[MX];
void merge(P &a, P &b) {
  a.o = (a.o * b.z + a.z * b.o) % MOD;
  a.z = a.z * b.z % MOD;
}
void rev(P &a) { a.z = (MOD - a.o + 1) % MOD; }
void dfs(int u) {
  int f = id[u] = u, s = 0;
  for (int &nx : G[u]) {
    dfs(nx);
    if (len[f] < len[nx]) {
      s = len[f];
      swap(f, nx);
    } else if (s < len[nx])
      s = len[nx];
    rep(i, len[nx]) merge(qu[id[f]][i], qu[id[nx]][i]);
  }
  rep(i, s) rev(qu[id[f]][i]);
  qu[id[f]].push_front({H, H});
  id[u] = id[f];
  len[u] = len[f] + 1;
}
int main() {
  scanf("%d", &n);
  rep(i, n) {
    scanf("%d", &p);
    G[p].push_back(i + 1);
  }
  dfs(0);
  for (P t : qu[id[0]])
    a += t.o;
  a %= MOD;
  for (ll k = n + 1, b = 2; k; k /= 2, (b *= b) %= MOD)
    if (k & 1)
      (a *= b) %= MOD;
  printf("%lld\n", a);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
const int MX = 200005, MOD = 1e9 + 7, H = 5e8 + 4;
int n, p, len[MX], id[MX];
ll a;
vector<int> G[MX];
struct P {
  ll z, o;
};
deque<P> qu[MX];
void merge(P &a, P &b) {
  a.o = (a.o * b.z + a.z * b.o) % MOD;
  a.z = a.z * b.z % MOD;
}
void rev(P &a) { a.z = (MOD - a.o + 1) % MOD; }
void dfs(int u) {
  int f = id[u] = u, s = 0;
  for (int &nx : G[u]) {
    dfs(nx);
    if (len[f] < len[nx]) {
      s = len[f];
      swap(f, nx);
    } else if (s < len[nx])
      s = len[nx];
    rep(i, len[nx]) merge(qu[id[f]][i], qu[id[nx]][i]);
  }
  rep(i, s) rev(qu[id[f]][i]);
  qu[id[f]].push_front({H, H});
  id[u] = id[f];
  len[u] = len[f] + 1;
}
int main() {
  scanf("%d", &n);
  rep(i, n) {
    scanf("%d", &p);
    G[p].push_back(i + 1);
  }
  dfs(0);
  for (P t : qu[id[0]])
    a += t.o;
  a %= MOD;
  for (ll k = n + 1, b = 2; k; k /= 2, (b *= b) %= MOD)
    if (k & 1)
      (a *= b) %= MOD;
  printf("%lld\n", a);
}
Problem p03499 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <vector>
using namespace std;

int N, P[100100];
vector<int> G[100100];

const long long mod = 1000000007;
struct Data {
  long long s, a, l;
  bool d;
  Data operator*(Data t) {
    Data r;
    r.s = s * t.s % mod;
    r.a = (a * t.l + t.a * l) % mod;
    r.l = l * t.l % mod;
    r.d = true;
    return r;
  }
};

vector<Data> go(int x) {
  vector<Data> ret;
  for (auto y : G[x]) {
    vector<Data> nxt = go(y);
    if (ret.size() < nxt.size())
      swap(ret, nxt);
    for (int i = (int)ret.size() - 1, j = (int)nxt.size() - 1; j >= 0;
         i--, j--) {
      ret[i] = ret[i] * nxt[j];
    }
  }

  for (int i = (int)ret.size() - 1; i >= 0; i--) {
    if (!ret[i].d)
      break;
    ret[i].l = (ret[i].s + mod - ret[i].a) % mod;
    ret[i].d = false;
  }
  ret.push_back({2, 1, 1, false});
  return move(ret);
}

long long fpow(long long a, long long p) {
  long long r = 1;
  while (p) {
    if (p & 1)
      r = r * a % mod;
    a = a * a % mod;
    p /= 2;
  }
  return r;
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &P[i]);
    G[P[i]].push_back(i);
  }

  auto p = go(0);

  long long ans = 0, all = fpow(2, N + 1);
  for (auto &d : p)
    ans = (ans + d.a * fpow(d.s, mod - 2)) % mod;
  ans = ans * all % mod;
  printf("%lld\n", ans);
  return 0;
}

Fixed submission:
#include <stdio.h>
#include <vector>
using namespace std;

int N, P[200200];
vector<int> G[200200];

const long long mod = 1000000007;
struct Data {
  long long s, a, l;
  bool d;
  Data operator*(Data t) {
    Data r;
    r.s = s * t.s % mod;
    r.a = (a * t.l + t.a * l) % mod;
    r.l = l * t.l % mod;
    r.d = true;
    return r;
  }
};

vector<Data> go(int x) {
  vector<Data> ret;
  for (auto y : G[x]) {
    vector<Data> nxt = go(y);
    if (ret.size() < nxt.size())
      swap(ret, nxt);
    for (int i = (int)ret.size() - 1, j = (int)nxt.size() - 1; j >= 0;
         i--, j--) {
      ret[i] = ret[i] * nxt[j];
    }
  }

  for (int i = (int)ret.size() - 1; i >= 0; i--) {
    if (!ret[i].d)
      break;
    ret[i].l = (ret[i].s + mod - ret[i].a) % mod;
    ret[i].d = false;
  }
  ret.push_back({2, 1, 1, false});
  return move(ret);
}

long long fpow(long long a, long long p) {
  long long r = 1;
  while (p) {
    if (p & 1)
      r = r * a % mod;
    a = a * a % mod;
    p /= 2;
  }
  return r;
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &P[i]);
    G[P[i]].push_back(i);
  }

  auto p = go(0);

  long long ans = 0, all = fpow(2, N + 1);
  for (auto &d : p)
    ans = (ans + d.a * fpow(d.s, mod - 2)) % mod;
  ans = ans * all % mod;
  printf("%lld\n", ans);
  return 0;
}
Problem p03499 (C++)

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

using namespace std;

vector<int> ch[222222];
typedef deque<pair<pair<long long, long long>, long long>> D;
const int mod = 1000000007;

void f(int v, D &d) {
  D t;
  for (auto i : ch[v])
    f(i, t);
  for (auto &p : t) {
    p.first.first += p.second;
    p.first.first %= mod;
    p.second = 0;
  }
  t.push_front(make_pair(make_pair(1, 1), 0));
  if (d.size() < t.size())
    d.swap(t);
  auto it = d.begin();
  for (auto &p : t) {
    it->second += it->first.first + it->first.second;
    it->second *= p.first.first + p.first.second + p.second;
    it->second %= mod;
    it->first.second *= p.first.first;
    it->first.second += it->first.first * p.first.second;
    it->first.second %= mod;
    it->first.first *= p.first.first;
    it->first.first %= mod;
    it->second += mod + mod;
    it->second -= it->first.first + it->first.second;
    it->second %= mod;
    ++it;
  }
}
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int p;
    scanf("%d", &p);
    ch[p].push_back(i + 1);
  }
  D d;
  f(0, d);
  long long a = 0, b = 1;
  for (auto &p : d) {
    a *= p.first.first + p.first.second;
    a += b * p.first.second;
    a %= mod;
    b *= p.first.first + p.first.second;
    b %= mod;
  }
  cout << a << endl;
  return 0;
}


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

using namespace std;

vector<int> ch[222222];
typedef deque<pair<pair<long long, long long>, long long>> D;
const int mod = 1000000007;

void f(int v, D &d) {
  D t;
  for (auto i : ch[v])
    f(i, t);
  if (ch[v].size() > 1)
    for (auto &p : t) {
      p.first.first += p.second;
      p.first.first %= mod;
      p.second = 0;
    }
  t.push_front(make_pair(make_pair(1, 1), 0));
  if (d.size() < t.size())
    d.swap(t);
  auto it = d.begin();
  for (auto &p : t) {
    it->second += it->first.first + it->first.second;
    it->second *= p.first.first + p.first.second + p.second;
    it->second %= mod;
    it->first.second *= p.first.first;
    it->first.second += it->first.first * p.first.second;
    it->first.second %= mod;
    it->first.first *= p.first.first;
    it->first.first %= mod;
    it->second += mod + mod;
    it->second -= it->first.first + it->first.second;
    it->second %= mod;
    ++it;
  }
}
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int p;
    scanf("%d", &p);
    ch[p].push_back(i + 1);
  }
  D d;
  f(0, d);
  long long a = 0, b = 1;
  for (auto &p : d) {
    a *= p.first.first + p.first.second;
    a += b * p.first.second;
    a %= mod;
    b *= p.first.first + p.first.second;
    b %= mod;
  }
  cout << a << endl;
  return 0;
}
Problem p03501 (Python)

Buggy submission (status: Runtime Error):
n, a, b = map(int, input())
print(min(b, a * n))


Fixed submission:
n, a, b = map(int, input().split())
print(min(b, a * n))
Problem p03501 (Python)

Buggy submission (status: Runtime Error):
N, A, B = map(int, input().split())

print(min(N * A), B)


Fixed submission:
N, A, B = map(int, input().split())

print(min(N * A, B))
Problem p03501 (C++)

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

using namespace std;

typedef long long int ll;
typedef long double ld;

inline void debugMode() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

#ifndef ONLINE_JUDGE
  freopen("date.in", "r", stdin);
  freopen("date.out", "w", stdout);
#endif // ONLINE_JUDGE
}
inline void PrintYes() { cout << "YES\n"; }
inline void PrintNo() { cout << "NO\n"; }

const double eps = 1e-7;

int main() {
  debugMode();

  int n, a, b;

  cin >> n >> a >> b;
  int x = n * a;
  cout << min(x, b);

  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef long double ld;

inline void debugMode() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  // #ifndef ONLINE_JUDGE
  // freopen("date.in", "r", stdin);
  // freopen("date.out", "w", stdout);
  // #endif // ONLINE_JUDGE
}
inline void PrintYes() { cout << "YES\n"; }
inline void PrintNo() { cout << "NO\n"; }

const double eps = 1e-7;

int main() {
  debugMode();

  int n, a, b;

  cin >> n >> a >> b;
  int x = n * a;
  cout << min(x, b);

  return 0;
}
Problem p03501 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

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

  int Acost = n * a;
  int Bcost = b;

  if (Acost < Bcost) {
    printf("%d", Acost);
  } else {
    printf("%d", Bcost);
  }
  while (1)
    ;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

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

  int Acost = n * a;
  int Bcost = b;

  if (Acost < Bcost) {
    printf("%d", Acost);
  } else {
    printf("%d", Bcost);
  }
}
Problem p03502 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define HAIRETU(N, A)                                                          \
  for (int i = 0; i < N; i++)                                                  \
  cin >> A[i]
using namespace std;

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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

  int a;
  for (int i = 0; i <= N; i++) {
    a = findSumOfDigits(i);
    if (N % a == 0) {
      cout << "Yes" << endl;
    } else
      cout << "No" << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define HAIRETU(N, A)                                                          \
  for (int i = 0; i < N; i++)                                                  \
  cin >> A[i]
using namespace std;

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

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

  int a;
  a = findSumOfDigits(N);
  if (N % a == 0) {
    cout << "Yes" << endl;
  } else
    cout << "No" << endl;

  return 0;
}
Problem p03502 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int N = 0, A = 0, B = 0;
  cin >> N;
  A = N;
  while (A > 0) {
    B += A % 10;
    A /= 10;
  }
  if (N % A)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int N = 0, A = 0, B = 0;
  cin >> N;
  A = N;
  while (A > 0) {
    B += A % 10;
    A /= 10;
  }
  if (N % B)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}
Problem p03502 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <queue>         //キュー
#include <unordered_map> //ハッシュ連想配列
#include <vector>        //可変長配列
#define ll long long int
#define INFTY (1 << 21)

using namespace std;

int main(void) {
  cin.sync_with_stdio(false);
  ll N, n, a = 0;
  cin >> N;
  n = N;
  do {
    a += n / 10;
    n = n % 10;
  } while (n % 10 >= 10);
  cout << ((N % a == 0) ? "Yes" : "No") << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <queue>         //キュー
#include <unordered_map> //ハッシュ連想配列
#include <vector>        //可変長配列
#define ll long long int
#define INFTY (1 << 21)

using namespace std;

int main(void) {
  cin.sync_with_stdio(false);
  ll N, n, a = 0;
  cin >> N;
  n = N;
  while (n % 10 != 0) {
    a += n % 10;
    n /= 10;
  }
  cout << ((N % a == 0) ? "Yes" : "No") << endl;
  return 0;
}
Problem p03502 (Python)

Buggy submission (status: Runtime Error):
N = input()
x = sum(int(i) for i in N)
print("Yes" if N % x == 0 else "No")


Fixed submission:
N = input()
x = sum(int(i) for i in N)
print("Yes" if int(N) % x == 0 else "No")
Problem p03502 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-
N = int, input()
num = str(N[1])
char_list = list(num)
sum = 0
for i in range(len(char_list)):
    sum += int(char_list[i])

if N[1] % sum == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
# -*- coding: utf-8 -*-
N = int, input()
num = str(N[1])
char_list = list(num)
sum = 0
for i in range(len(char_list)):
    sum += int(char_list[i])

if int(N[1]) % sum == 0:
    print("Yes")
else:
    print("No")
Problem p03502 (C++)

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

int main(void) {
  int n = 0;
  int x = 0;
  int sum = 0;

  scanf("%d", &n);
  x = n;

  while (n > 10) {
    sum += n % 10;
    n /= 10;
  }

  if (x % sum == 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


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

int main(void) {
  int n = 0;
  int x = 0;
  int sum = 0;

  scanf("%d", &n);
  x = n;

  while (n > 10) {
    sum += n % 10;
    n /= 10;
  }
  sum += n;

  if (x % sum == 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}
Problem p03502 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, n;
  cin >> N;
  n = N;
  int s;
  if (N != 0) {
    while (N > 0) {
      s == s + N % 10;
      N = (N - N % 10) / 10;
      if (N == 0) {
        if (n % s == 0)
          cout << "Yes";
        else
          cout << "No";
      }
    }
  } else
    cout << "No";
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, n;
  cin >> N;
  n = N;
  int s;
  if (N != 0) {
    while (N > 0) {
      s = s + N % 10;
      N = (N - N % 10) / 10;
      if (N == 0) {
        if (n % s == 0)
          cout << "Yes";
        else
          cout << "No";
      }
    }
  } else
    cout << "No";
}
Problem p03502 (C++)

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

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

  for (int i = 0; i < 9; i++) {
    f += (N % (10 ^ (i + 1))) / (10 ^ i);
  }
  if (N % f == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

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

  for (int i = 0; i < 9; i++) {
    int j = 1;
    for (int k = 0; k < i; k++) {
      j *= 10;
    }

    f += (N % (10 * j)) / j;
  }
  if (N % f == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03502 (Python)

Buggy submission (status: Runtime Error):
N = input()
sum = 0

for i in N:
    sum += i
if N % sum == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
N = input()
sum = 0

for i in N:
    sum += int(i)
if int(N) % sum == 0:
    print("Yes")
else:
    print("No")
Problem p03502 (Python)

Buggy submission (status: Runtime Error):
# python template for atcoder1
import sys

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = input()[:-1]
dig = 0
for c in N:
    dig += int(c)
if N % dig == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
# python template for atcoder1
import sys

sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = input()[:-1]
dig = 0
for c in N:
    dig += int(c)
if int(N) % dig == 0:
    print("Yes")
else:
    print("No")
Problem p03502 (Python)

Buggy submission (status: Runtime Error):
N = str(input())
ans = 0
for i in N:
    ans += int(i)
if N % ans == 0:
    print("Yes")
else:
    print("No")


Fixed submission:
N = str(input())
ans = 0
for i in N:
    ans += int(i)
if int(N) % ans == 0:
    print("Yes")
else:
    print("No")
Problem p03502 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int X, tmp, fx = 0;
  cin >> X;
  tmp = X;
  while ((tmp / 10) >= 1) {
    fx += tmp % 10;
    tmp /= 10;
  }
  if (X % fx == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


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

int main() {
  int X, tmp, fx = 0;
  cin >> X;
  tmp = X;
  while ((tmp / 10) >= 1 || (tmp >= 1 && tmp <= 9)) {
    fx += tmp % 10;
    tmp /= 10;
  }
  if (X % fx == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p03502 (C++)

Buggy submission (status: Runtime Error):
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i, a, b) for (Int i = a; i < b; ++i)
#define rrep(i, a, b) for (Int i = a; i >= b; --i)
using namespace std;

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

  int N, _N;
  cin >> N;
  int digitSum = 0;
  while (_N > 0) {
    digitSum += _N % 10;
    _N /= 10;
  }

  cout << (N % digitSum == 0 ? "Yes" : "No") << endl;
}


Fixed submission:
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i, a, b) for (Int i = a; i < b; ++i)
#define rrep(i, a, b) for (Int i = a; i >= b; --i)
using namespace std;

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

  int N, _N;
  cin >> N;
  _N = N;
  int digitSum = 0;
  while (_N > 0) {
    digitSum += _N % 10;
    _N /= 10;
  }

  cout << (N % digitSum == 0 ? "Yes" : "No") << endl;
}
Problem p03502 (C++)

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

int main() {
  int N;
  cin >> N;
  int d_sum = 0;

  for (int i = 10; i <= N; i *= 10) {
    int x;
    x = (N % i) - (N % (i / 10));
    d_sum += x / (i / 10);
    if ((N / i) <= 9)
      d_sum += N / i;
  }

  if (N % d_sum == 0)
    cout << "Yes" << endl;

  else {
    cout << "No" << endl;
  }
}

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

int main() {
  int N;
  cin >> N;
  int d_sum = 0;

  for (int i = 10; i <= N; i *= 10) {
    int x;
    x = (N % i) - (N % (i / 10));
    d_sum += x / (i / 10);
    if ((N / i) <= 9)
      d_sum += N / i;
  }

  if (N <= 9)
    d_sum += N;

  if (N % d_sum == 0)
    cout << "Yes" << endl;

  else {
    cout << "No" << endl;
  }
}
Problem p03502 (C++)

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

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

int ctoi(const char c) {
  switch (c) {
  case '0':
    return 0;
  case '1':
    return 1;
  case '2':
    return 2;
  case '3':
    return 3;
  case '4':
    return 4;
  case '5':
    return 5;
  case '6':
    return 6;
  case '7':
    return 7;
  case '8':
    return 8;
  case '9':
    return 9;
  default:
    return -1;
  }
}

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

  int n = atoi(N.c_str());
  int x = 0;

  rep(i, n) { x += ctoi(N[i]); }

  if (x == 0)
    return 0;

  if (n % x == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

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

int ctoi(const char c) {
  switch (c) {
  case '0':
    return 0;
  case '1':
    return 1;
  case '2':
    return 2;
  case '3':
    return 3;
  case '4':
    return 4;
  case '5':
    return 5;
  case '6':
    return 6;
  case '7':
    return 7;
  case '8':
    return 8;
  case '9':
    return 9;
  default:
    return -1;
  }
}

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

  int n = atoi(N.c_str());
  int x = 0;

  rep(i, N.length()) { x += ctoi(N[i]); }

  if (x == 0)
    return 0;

  if (n % x == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p03502 (C++)

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

using namespace std;
#define BUF (1000)
#define ll long long

int n;

int main(void) {
  cin >> n;
  int n_ = n;
  int ans = 0;
  while (n > 10) {
    int a = n % 10;
    ans += a;
    n /= 10;
  }

  if (n_ % ans == 0) {
    cout << "Yes";
  } else
    cout << "No";

  return 0;
}


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

using namespace std;
#define BUF (1000)
#define ll long long

int n;

int main(void) {
  cin >> n;
  int n_ = n;
  int ans = 0;
  while (n > 10) {
    int a = n % 10;
    ans += a;
    n /= 10;
  }

  ans += n;

  //	cout << ans;
  if (n_ % ans == 0) {
    cout << "Yes";
  } else
    cout << "No";

  return 0;
}