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

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
bool p[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
long long res = 0;
string a;
int n;
long long turn() {
  long long num1 = 0, num2 = a[0] - '0';
  for (int i = 0; i < n - 1; i++) {
    if (p[i] == 0) {
      //			cout<<i<<" "<<a[i+1]<<endl;
      num2 = num2 * 10 + a[i + 1] - '0';
    } else {
      num1 += num2;
      num2 = a[i + 1] - '0';
    }
  }
  num1 += num2;
  //	cout<<" "<<num1<<endl;
  return num1;
}
long long k(int i) {
  if (i == 0) {
    for (int j = 0; j < 2; j++) {
      p[i] = j;
      res += turn();
    }
    return 0;
  }
  for (int j = 0; j < 2; j++) {
    p[i] = j;
    k(i - 1);
  }
  return 0;
}
int main() {
  cin >> a;
  n = a.size();
  k(n - 2);
  cout << res;
  //	cout<<turn();
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
bool p[9] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
long long res = 0;
string a;
int n;
long long turn() {
  long long num1 = 0, num2 = a[0] - '0';
  for (int i = 0; i < n - 1; i++) {
    if (p[i] == 0) {
      //			cout<<i<<" "<<a[i+1]<<endl;
      num2 = num2 * 10 + a[i + 1] - '0';
    } else {
      num1 += num2;
      num2 = a[i + 1] - '0';
    }
  }
  num1 += num2;
  //	cout<<" "<<num1<<endl;
  return num1;
}
long long k(int i) {
  if (i == 0) {
    for (int j = 0; j < 2; j++) {
      p[i] = j;
      res += turn();
    }
    return 0;
  }
  for (int j = 0; j < 2; j++) {
    p[i] = j;
    k(i - 1);
  }
  return 0;
}
int main() {
  cin >> a;
  n = a.size();
  if (n == 1) {
    cout << a;
    return 0;
  }
  k(n - 2);
  cout << res;
  //	cout<<turn();
  return 0;
}
Problem p03999 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
const int N = 200005;

ll modulo(ll num, ll MOD = mod) {
  return ((num % MOD) + MOD) % MOD;
} // for negative integer
ll power(ll b, ll e, ll MOD = mod) {
  ll ans = 1;
  while (e) {
    if (e % 2)
      ans = (ans * b) % MOD;
    b = (b * b) % MOD;
    e /= 2;
  }
  return ans;
}
ll inv(ll num, ll MOD = mod) { return power(modulo(num), MOD - 2, MOD); }

ll ans = 0;

void go(int ind, string s, int n, vector<int> vec) {
  if (ind == n - 1) {
    int pr = -1;
    ll tmp = 0;
    for (auto it : vec) {
      string sr = "";
      for (int j = pr + 1; j <= it; j++) {
        sr += s[j];
      }
      pr = it;
      tmp += stoll(sr);
    }
    string sr = "";
    for (int j = pr + 1; j < n; j++) {
      sr += s[j];
    }
    tmp += stoll(sr);
    ans += tmp;
    return;
  }
  vec.pb(ind);
  go(ind + 1, s, n, vec);
  vec.pop_back();
  go(ind + 1, s, n, vec);
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
  cout << fixed << setprecision(15);

  string s;

  cin >> s;

  int n = s.length();

  vector<int> vec;

  go(0, s, n, vec);

  cout << ans;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mod 1000000007
const int N = 200005;

ll modulo(ll num, ll MOD = mod) {
  return ((num % MOD) + MOD) % MOD;
} // for negative integer
ll power(ll b, ll e, ll MOD = mod) {
  ll ans = 1;
  while (e) {
    if (e % 2)
      ans = (ans * b) % MOD;
    b = (b * b) % MOD;
    e /= 2;
  }
  return ans;
}
ll inv(ll num, ll MOD = mod) { return power(modulo(num), MOD - 2, MOD); }

ll ans = 0;

void go(int ind, string s, int n, vector<int> vec) {
  if (ind == n - 1) {
    int pr = -1;
    ll tmp = 0;
    for (auto it : vec) {
      string sr = "";
      for (int j = pr + 1; j <= it; j++) {
        sr += s[j];
      }
      pr = it;
      tmp += stoll(sr);
    }
    string sr = "";
    for (int j = pr + 1; j < n; j++) {
      sr += s[j];
    }
    tmp += stoll(sr);
    ans += tmp;
    return;
  }
  vec.pb(ind);
  go(ind + 1, s, n, vec);
  vec.pop_back();
  go(ind + 1, s, n, vec);
}

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

  cout << fixed << setprecision(15);

  string s;

  cin >> s;

  int n = s.length();

  vector<int> vec;

  go(0, s, n, vec);

  cout << ans;

  return 0;
}
Problem p03999 (Python)

Buggy submission (status: Runtime Error):
S = input()

N = len(S)
ans = 0
for i in range(2 ** (N - 1)):
    bit = ("{:0" + str(N - 1) + "b}").format(i)
    formula = S[0]
    for j in range(len(bit)):
        if bit[j] == "1":
            formula += "+"
        formula += S[j + 1]
    ans += eval(formula)
print(ans)


Fixed submission:
S = input()

N = len(S)
ans = 0
for i in range(2 ** (N - 1)):
    bit = "{:010b}".format(i)[11 - N :]
    formula = S[0]
    for j in range(len(bit)):
        if bit[j] == "1":
            formula += "+"
        formula += S[j + 1]
    ans += eval(formula)
print(ans)
Problem p03999 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define itrfor(itr, A) for (auto itr = A.begin(); itr != A.end(); itr++)
typedef long long llong;
char moji[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char moji2[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
                  'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
                  'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
char moji3[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
#define Sort(a) sort(a.begin(), a.end());
#define Reverse(a) reverse(a.begin(), a.end());

int main() {

  vector<llong> A[int(1e9)];
  llong s;
  cin >> s;
  if (s < 10) {
    cout << s << endl;
    return 0;
  }
  int keta = 0;
  llong tmp = 1;
  while (1) {
    tmp *= 10;
    keta += 1;
    if (s < tmp)
      break;
  }
  llong ans = 0;
  int bit = 1;
  while (1) {
    int ind = -1;
    REP(i, keta) {
      if (bit & 1 << i) {
        if (ind == -1) {
          ans += s / int(pow(10, keta - i - 1));
          ind = i;
        } else {
          int x = s / int(pow(10, keta - i - 1));
          ans += x % int(pow(10, i - ind));
          ind = i;
        }
      }
    }
    ans += s % int(pow(10, keta - ind - 1));
    bit += 1;
    if (bit >= int(pow(2, keta - 1)))
      break;
  }
  cout << ans + s << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define itrfor(itr, A) for (auto itr = A.begin(); itr != A.end(); itr++)
typedef long long llong;
char moji[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
char moji2[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
                  'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
                  'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
char moji3[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
#define Sort(a) sort(a.begin(), a.end());
#define Reverse(a) reverse(a.begin(), a.end());

int main() {

  vector<llong> A[int(1e5)];
  llong s;
  cin >> s;
  if (s < 10) {
    cout << s << endl;
    return 0;
  }
  int keta = 0;
  llong tmp = 1;
  while (1) {
    tmp *= 10;
    keta += 1;
    if (s < tmp)
      break;
  }
  llong ans = 0;
  int bit = 1;
  while (1) {
    int ind = -1;
    REP(i, keta) {
      if (bit & 1 << i) {
        if (ind == -1) {
          ans += s / int(pow(10, keta - i - 1));
          ind = i;
        } else {
          int x = s / int(pow(10, keta - i - 1));
          ans += x % int(pow(10, i - ind));
          ind = i;
        }
      }
    }
    ans += s % int(pow(10, keta - ind - 1));
    bit += 1;
    if (bit >= int(pow(2, keta - 1)))
      break;
  }
  cout << ans + s << endl;
}
Problem p03999 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll>;
#define all(v) v.begin(), v.end()

ll calc_sum(vector<ll> v, string S) {
  vector<ll> n;
  ll res = 0, tmp = 0;
  for (ll i = 0; i < S.size(); ++i) {
    if (v[i] == 1) {
      string s = S.substr(tmp, i + 1 - tmp);
      n.push_back(stoll(s));
      tmp = i + 1ll;
    }
  }
  string s = S.substr(tmp, S.size() + 1 - tmp);
  n.push_back(stoll(s));
  res = accumulate(all(n), 0ll);
  return res;
}

int main() {
  string S;
  cin >> S;
  ll ans = 0;
  for (ll i = 0; i < S.size(); ++i) {
    vector<ll> v(S.size() - 1, 1);
    for (ll j = 0; j < i; ++j)
      v[j] = 0;
    do {
      ans += calc_sum(v, S);
    } while (next_permutation(all(v)));
  }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll>;
#define all(v) v.begin(), v.end()

ll calc_sum(vector<ll> v, string S) {
  vector<ll> n;
  ll res = 0, tmp = 0;
  for (ll i = 0; i < S.size(); ++i) {
    if (v[i] == 1) {
      string s = S.substr(tmp, i + 1 - tmp);
      n.push_back(stoll(s));
      tmp = i + 1ll;
    }
  }
  string s = S.substr(tmp, S.size() + 1 - tmp);
  n.push_back(stoll(s));
  res = accumulate(all(n), 0ll);
  return res;
}

int main() {
  string S;
  cin >> S;
  ll ans = 0;
  for (ll i = 0; i < S.size(); ++i) {
    if (S.size() == 1) {
      ans = stoi(S);
      break;
    }
    vector<ll> v(S.size() - 1, 1);
    for (ll j = 0; j < i; ++j)
      v[j] = 0;
    do {
      ans += calc_sum(v, S);
    } while (next_permutation(all(v)));
  }
  cout << ans << endl;
}
Problem p03999 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, double> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, 1, 0, -1};

int main() {

  string s;
  cin >> s;
  int len = s.size();
  ll sum = 0;
  for (int tmp = 0; tmp < (1 << (len - 1)); tmp++) {
    bitset<9> sb(tmp);
    int num = 0;
    for (int i = 0; i < (len - 1); i++) {
      if (sb.test(i)) {
        sum += stoi(s.substr(num, i + 1 - num));
        num = i + 1;
      }
      if (i == len - 2) {
        sum += stoll(s.substr(num, i + 2 - num));
      }
    }
  }
  if (len = 1) {
    sum = stoi(s);
  }
  cout << sum << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long ll;
typedef pair<int, double> P;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, 1, 0, -1};

int main() {

  string s;
  cin >> s;
  int len = s.size();
  ll sum = 0;
  for (int tmp = 0; tmp < (1 << (len - 1)); tmp++) {
    bitset<9> sb(tmp);
    int num = 0;
    for (int i = 0; i < (len - 1); i++) {
      if (sb.test(i)) {
        sum += stoi(s.substr(num, i + 1 - num));
        num = i + 1;
      }
      if (i == len - 2) {
        sum += stoll(s.substr(num, i + 2 - num));
      }
    }
  }
  if (len == 1) {
    sum = stoi(s);
  }
  cout << sum << endl;

  return 0;
}
Problem p03999 (C++)

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

inline std::string to_binString(int val) {
  if (!val)
    return std::string("0");
  std::string str;
  while (val != 0) {
    if ((val & 1) == 0)             // val は偶数か？
      str.insert(str.begin(), '0'); //  偶数の場合
    else
      str.insert(str.begin(), '1'); //  奇数の場合
    val >>= 1;
  }
  return str;
}

std::vector<std::string> my_split(const std::string &str, char sep) {
  std::vector<std::string> v;
  std::stringstream ss(str);
  std::string buffer;
  while (std::getline(ss, buffer, sep)) {
    v.push_back(buffer);
  }
  return v;
}

int main() {

  string s;

  cin >> s;

  long long int ans = 0;

  for (int loop = 0; loop < (1 << s.size() - 1); loop++) {

    string split_point = "";

    string bin_str = to_binString(loop);

    for (int i = 0; i < (s.size() - 1) - bin_str.size(); i++) {
      split_point += '0';
    }

    split_point += bin_str;

    string culc = "";

    for (int i = 0; i < s.size(); i++) {
      culc += s[i];
      if (split_point[i] == '1') {
        culc += '.';
      }
    }

    vector<string> formulas = my_split(culc, '.');

    long long int sum = 0;

    for (int i = 0; i < formulas.size(); i++) {
      stringstream ss;
      ss << formulas[i];
      long long int tmp = 0;
      ss >> tmp;
      sum += tmp;
    }

    ans += sum;
  }

  cout << ans << endl;

  return 0;
}

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

inline std::string to_binString(int val) {
  if (!val)
    return std::string("0");
  std::string str;
  while (val != 0) {
    if ((val & 1) == 0)             // val は偶数か？
      str.insert(str.begin(), '0'); //  偶数の場合
    else
      str.insert(str.begin(), '1'); //  奇数の場合
    val >>= 1;
  }
  return str;
}

std::vector<std::string> my_split(const std::string &str, char sep) {
  std::vector<std::string> v;
  std::stringstream ss(str);
  std::string buffer;
  while (std::getline(ss, buffer, sep)) {
    v.push_back(buffer);
  }
  return v;
}

int main() {

  string s;

  cin >> s;

  long long int ans = 0;

  for (int loop = 0; loop < (1 << s.size() - 1); loop++) {

    string split_point = "";

    string bin_str = to_binString(loop);

    for (int i = 0;
         i < static_cast<int>(s.size()) - 1 - static_cast<int>(bin_str.size());
         i++) {
      split_point += '0';
    }

    split_point += bin_str;

    string culc = "";

    for (int i = 0; i < s.size(); i++) {
      culc += s[i];
      if (split_point[i] == '1') {
        culc += '.';
      }
    }

    vector<string> formulas = my_split(culc, '.');

    long long int sum = 0;

    for (int i = 0; i < formulas.size(); i++) {
      stringstream ss;
      ss << formulas[i];
      long long int tmp = 0;
      ss >> tmp;
      sum += tmp;
    }

    ans += sum;
  }

  cout << ans << endl;

  return 0;
}
Problem p03999 (Python)

Buggy submission (status: Runtime Error):
# all_split("abc") -> [['abc'], ['ab', 'c'], ['a', 'bc'], ['a', 'b', 'c']]
def all_split(s):
    ans = []
    for i in range(2 ** (len(s) - 1)):
        b = list(map(int, format(i, "0" + str(len(s) - 1) + "b")))
        ans.append(split(s, b))
    return ans


def split(s, split_positions):
    assert len(s) - 1 == len(split_positions)

    ans = []
    pre = 0
    for i, is_split in enumerate(split_positions, start=1):
        if is_split:
            ans.append(s[pre:i])
            pre = i

    ans.append(s[pre:])
    return ans


def main():
    s = input()
    ans = 0
    for a in all_split(s):
        ans += eval("+".join(a))
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
# all_split("abc") -> [['abc'], ['ab', 'c'], ['a', 'bc'], ['a', 'b', 'c']]
def all_split(s):
    if len(s) == 1:
        return [s]

    ans = []
    for i in range(2 ** (len(s) - 1)):
        b = list(map(int, format(i, "0" + str(len(s) - 1) + "b")))
        ans.append(split(s, b))
    return ans


def split(s, split_positions):
    assert len(s) - 1 == len(split_positions)

    ans = []
    pre = 0
    for i, is_split in enumerate(split_positions, start=1):
        if is_split:
            ans.append(s[pre:i])
            pre = i

    ans.append(s[pre:])
    return ans


def main():
    s = input()
    ans = 0
    for a in all_split(s):
        ans += eval("+".join(a))
    print(ans)


if __name__ == "__main__":
    main()
Problem p04000 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
using namespace std;
typedef long long ll;
const long long N = 1e9 + 7;
ll h, w, n, x, y;
ll ans[20], a[500005];
ll fir = 0, cnt = 0;
int main() {
  ios::sync_with_stdio(false);
  // freopen("D:\\in.txt","r",stdin);
  // freopen("D:\\out.txt","w",stdout);
  cin >> h >> w >> n;
  fir = (h - 2) * (w - 2);
  while (n--) {
    cin >> x >> y;
    for (int i = 0; i <= 2; i++) {
      for (int j = 0; j <= 2; j++) {
        if (x - i >= 1 && x - i <= h - 2 && y - j <= w - 2 && y - j >= 1) {
          a[cnt++] = N * (x - i) + (y - j);
        }
      }
    }
  }
  sort(a, a + cnt);
  ll t = 1;
  for (ll i = 0; i < cnt; i++) {
    if (a[i] == a[i + 1])
      t++;
    else {
      ans[t]++;
      t = 1;
      fir--;
    }
  }
  cout << fir << endl;
  for (int i = 1; i < 10; i++) {
    cout << ans[i] << endl;
  }
  // system("pause");
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
using namespace std;
typedef long long ll;
const long long N = 1e9 + 7;
ll h, w, n, x, y;
ll ans[20], a[1000005];
ll fir = 0, cnt = 0;
int main() {
  ios::sync_with_stdio(false);
  // freopen("D:\\in.txt","r",stdin);
  // freopen("D:\\out.txt","w",stdout);
  cin >> h >> w >> n;
  fir = (h - 2) * (w - 2);
  while (n--) {
    cin >> x >> y;
    for (int i = 0; i <= 2; i++) {
      for (int j = 0; j <= 2; j++) {
        if (x - i >= 1 && x - i <= h - 2 && y - j <= w - 2 && y - j >= 1) {
          a[cnt++] = N * (x - i) + (y - j);
        }
      }
    }
  }
  sort(a, a + cnt);
  ll t = 1;
  for (ll i = 0; i < cnt; i++) {
    if (a[i] == a[i + 1])
      t++;
    else {
      ans[t]++;
      t = 1;
      fir--;
    }
  }
  cout << fir << endl;
  for (int i = 1; i < 10; i++) {
    cout << ans[i] << endl;
  }
  // system("pause");
  return 0;
}
Problem p04000 (C++)

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

ll H, W, N;
int a[10010];
int b[10010];

int main() {
  cin >> H >> W >> N;
  for (int i = 0; i < N; ++i)
    cin >> a[i] >> b[i];
  map<pair<int, int>, int> m;
  for (int i = 0; i < N; ++i) {
    for (auto dx : {-1, 0, 1}) {
      for (auto dy : {-1, 0, 1}) {
        auto x = b[i] + dx, y = a[i] + dy;
        if (2 <= x && x < W && 2 <= y && y < H) {
          auto k = make_pair(x, y);
          if (!m.count(k)) {
            m[k] = 1;
          } else {
            m[k]++;
          }
        }
      }
    }
  }
  ll ans[10] = {};
  for (auto &kv : m) {
    ans[kv.second]++;
  }
  auto s = accumulate(begin(ans), end(ans), 0ll);
  ans[0] = (H - 2) * (W - 2) - s;
  for (auto v : ans) {
    cout << v << endl;
  }
  return 0;
}

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

ll H, W, N;
int a[100010];
int b[100010];

int main() {
  cin >> H >> W >> N;
  for (int i = 0; i < N; ++i)
    cin >> a[i] >> b[i];
  map<pair<int, int>, int> m;
  for (int i = 0; i < N; ++i) {
    for (auto dx : {-1, 0, 1}) {
      for (auto dy : {-1, 0, 1}) {
        auto x = b[i] + dx, y = a[i] + dy;
        if (2 <= x && x < W && 2 <= y && y < H) {
          auto k = make_pair(x, y);
          if (!m.count(k)) {
            m[k] = 1;
          } else {
            m[k]++;
          }
        }
      }
    }
  }
  ll ans[10] = {};
  for (auto &kv : m) {
    ans[kv.second]++;
  }
  auto s = accumulate(begin(ans), end(ans), 0ll);
  ans[0] = (H - 2) * (W - 2) - s;
  for (auto v : ans) {
    cout << v << endl;
  }
  return 0;
}
Problem p04000 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;

#define all(x) x.begin(), x.end()

const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main() {
  ll n, h, w;
  cin >> h >> w >> n;
  vector<P> p(n), q(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  map<P, ll> mp;
  for (int i = 0; i < n; i++) {
    ll above = max(1, p[i].first - 2), below = p[i].first;
    if (p[i].first == h)
      below = p[i].first - 2;
    else if (p[i].first + 1 == h)
      below = p[i].first - 1;
    ll left = max(1, p[i].second - 2), right = p[i].second;
    if (p[i].second == w)
      right = p[i].second - 2;
    else if (p[i].second + 1 == w)
      right = p[i].second - 1;
    for (ll k = above; k <= below; i++) {
      for (ll j = left; j <= right; j++) {
        mp[P(k, j)]++;
      }
    }
  }
  vector<ll> cnt(10);
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    cnt[itr->second]++;
    // cout << itr->first.first << " " << itr->first.second << " " <<
    // itr->second << endl;
  }
  ll sum = 0;
  for (int i = 1; i < 10; i++) {
    sum += cnt[i];
  }
  cnt[0] = (h - 2) * (w - 2) - sum;
  for (int i = 0; i < 10; i++) {
    cout << cnt[i] << endl;
  }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;

#define all(x) x.begin(), x.end()

const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main() {
  ll n, h, w;
  cin >> h >> w >> n;
  vector<P> p(n), q(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  map<P, ll> mp;
  for (int i = 0; i < n; i++) {
    ll above = max(1, p[i].first - 2), below = p[i].first;
    if (p[i].first == h)
      below = p[i].first - 2;
    else if (p[i].first + 1 == h)
      below = p[i].first - 1;
    ll left = max(1, p[i].second - 2), right = p[i].second;
    if (p[i].second == w)
      right = p[i].second - 2;
    else if (p[i].second + 1 == w)
      right = p[i].second - 1;
    for (ll k = above; k <= below; k++) {
      for (ll j = left; j <= right; j++) {
        mp[P(k, j)]++;
      }
    }
  }
  vector<ll> cnt(10);
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    cnt[itr->second]++;
    // cout << itr->first.first << " " << itr->first.second << " " <<
    // itr->second << endl;
  }
  ll sum = 0;
  for (int i = 1; i < 10; i++) {
    sum += cnt[i];
  }
  cnt[0] = (h - 2) * (w - 2) - sum;
  for (int i = 0; i < 10; i++) {
    cout << cnt[i] << endl;
  }

  return 0;
}
Problem p04000 (C++)

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

int count(map<pair<long long, long long>, bool> x, int start_idx_h,
          int start_idx_w, long long H, long long W) {
  if (start_idx_h < 0 || H <= start_idx_h + 2) {
    return -1;
  }

  if (start_idx_w < 0 || W <= start_idx_w + 2) {
    return -1;
  }

  int ret = 0;
  for (long long i = start_idx_h; i < start_idx_h + 3; i++) {
    for (long long j = start_idx_w; j < start_idx_w + 3; j++) {
      if (x[make_pair(i, j)]) {
        ret++;
      }
    }
  }
  return ret;
}

int main() {
  long long H, W;
  cin >> H >> W;

  int N;
  cin >> N;

  map<pair<long long, long long>, bool> x;
  long long a, b;
  vector<long long> ans(10, 0);
  ans[0] = (H - 3 + 1) * (W - 3 + 1);
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    a--;
    b--;
    x[make_pair(a, b)] = true;
    for (int j = a - 2; j <= a; j++) {
      for (int k = b - 2; k <= b; k++) {
        int num = count(x, j, k, H, W);
        if (num > 0) {
          ans[num]++;
          ans[num - 1]--;
        }
      }
    }
  }
  for (int i = 0; i < 10; i++) {
    cout << ans[i] << endl;
  }
}


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

int count(map<pair<long long, long long>, bool> &x, int start_idx_h,
          int start_idx_w, long long H, long long W) {
  if (start_idx_h < 0 || H <= start_idx_h + 2) {
    return -1;
  }

  if (start_idx_w < 0 || W <= start_idx_w + 2) {
    return -1;
  }

  int ret = 0;
  for (long long i = start_idx_h; i < start_idx_h + 3; i++) {
    for (long long j = start_idx_w; j < start_idx_w + 3; j++) {
      if (x[make_pair(i, j)]) {
        ret++;
      }
    }
  }
  return ret;
}

int main() {
  long long H, W;
  cin >> H >> W;

  int N;
  cin >> N;

  map<pair<long long, long long>, bool> x;
  long long a, b;
  vector<long long> ans(10, 0);
  ans[0] = (H - 3 + 1) * (W - 3 + 1);
  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    a--;
    b--;
    x[make_pair(a, b)] = true;
    for (int j = a - 2; j <= a; j++) {
      for (int k = b - 2; k <= b; k++) {
        int num = count(x, j, k, H, W);
        if (num > 0) {
          ans[num]++;
          ans[num - 1]--;
        }
      }
    }
  }
  for (int i = 0; i < 10; i++) {
    cout << ans[i] << endl;
  }
}
Problem p04000 (Python)

Buggy submission (status: Runtime Error):
from collections import defaultdict

h, w, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

d = defaultdict(int)

for a, b in ab:
    for hi in range(a - 2, a + 1):
        for wi in range(b - 2, b + 1):
            if 1 <= hi <= h - 2 and 1 <= wi <= w - 2:
                d[(hi, wi)] += 1

cnt = [0] * 9
for v in d.values():
    cnt[v] += 1

cnt[0] = (h - 2) * (w - 2) - sum(cnt[1:])
print(*cnt, sep="\n")


Fixed submission:
from collections import defaultdict

h, w, n = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

d = defaultdict(int)

for a, b in ab:
    for hi in range(a - 2, a + 1):
        for wi in range(b - 2, b + 1):
            if 1 <= hi <= h - 2 and 1 <= wi <= w - 2:
                d[(hi, wi)] += 1

cnt = [0] * 10
for v in d.values():
    cnt[v] += 1

cnt[0] = (h - 2) * (w - 2) - sum(cnt[1:])
print(*cnt, sep="\n")
Problem p04000 (C++)

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

int main() {
  ll H, W, N;
  cin >> H >> W >> N;
  vector<ll> ans(10, 0);

  multiset<pair<ll, ll>> q;
  for (int i = 0; i < N; i++) {
    ll s, t;
    cin >> s >> t;
    for (int j = -1; j <= 1; j++) {
      for (int k = -1; k <= 1; k++) {
        if (s + j >= 2 && s + j <= H - 1 && t + k >= 2 && t + k <= W - 1) {
          q.insert({s + j, t + k});
        }
      }
    }
  }
  auto it = q.begin();
  auto u = *it;
  ll x = u.first, y = u.second;
  it++;
  int cnt = 1;
  while (true) {
    auto sq = *it;
    if (sq.first == x && sq.second == y)
      cnt++;
    else {
      ans[cnt]++;
      cnt = 1;
    }
    x = sq.first;
    y = sq.second;
    it++;
    if (it == q.end()) {
      ans[cnt]++;
      break;
    }
  }

  ans[0] = (H - 2) * (W - 2);
  for (int i = 1; i <= 9; i++)
    ans[0] -= ans[i];
  for (int i = 0; i <= 9; i++) {
    cout << ans[i] << endl;
  }
}


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

int main() {
  ll H, W, N;
  cin >> H >> W >> N;
  vector<ll> ans(10, 0);

  if (N == 0) {
    cout << (H - 2) * (W - 2) << endl;
    for (int i = 1; i <= 9; i++) {
      cout << 0 << endl;
    }
    return 0;
  }

  multiset<pair<ll, ll>> q;
  for (int i = 0; i < N; i++) {
    ll s, t;
    cin >> s >> t;
    for (int j = -1; j <= 1; j++) {
      for (int k = -1; k <= 1; k++) {
        if (s + j >= 2 && s + j <= H - 1 && t + k >= 2 && t + k <= W - 1) {
          q.insert({s + j, t + k});
        }
      }
    }
  }
  auto it = q.begin();
  auto u = *it;
  ll x = u.first, y = u.second;
  it++;
  int cnt = 1;
  while (true) {
    auto sq = *it;
    if (sq.first == x && sq.second == y)
      cnt++;
    else {
      ans[cnt]++;
      cnt = 1;
    }
    x = sq.first;
    y = sq.second;
    it++;
    if (it == q.end()) {
      ans[cnt]++;
      break;
    }
  }

  ans[0] = (H - 2) * (W - 2);
  for (int i = 1; i <= 9; i++)
    ans[0] -= ans[i];
  for (int i = 0; i <= 9; i++) {
    cout << ans[i] << endl;
  }
}
Problem p04000 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> M;
vector<pair<long long, long long>> vec, vec2;
long long H, W, n, a, b;
long long cnt1[10];
bool valid(int x, int y) {
  if (x < 0 || x >= H - 2 || y < 0 || y >= W - 2) {
    return false;
  }
  return true;
}
int main() {
  cin >> H >> W >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    a--;
    b--;
    M[make_pair(a, b)] = 1;
    for (int j = -2; j <= 2; j++) {
      for (int k = -2; k <= 2; k++)
        vec.push_back(make_pair(a + j, b + k));
    }
  }
  if (n >= 1) {
    sort(vec.begin(), vec.end());
    if (valid(vec[0].first, vec[0].second) == true)
      vec2.push_back(vec[0]);
    for (int i = 1; i < vec.size(); i++) {
      if (vec[i - 1] != vec[i]) {
        if (valid(vec[i].first, vec[i].second) == true)
          vec2.push_back(vec[i]);
      }
    }
    for (int i = 0; i < vec2.size(); i++) {
      int cnts = 0;
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++)
          cnts += M[make_pair(vec2[i].first + j, vec2[i].second + k)];
      }
      cnt1[cnts]++;
    }
  }
  long long sums = 0;
  for (int i = 1; i <= 9; i++) {
    sums += cnt1[i];
  }
  cnt1[0] = 1LL * (H - 2) * (W - 2) - sums;
  for (int i = 0; i <= 9; i++)
    cout << cnt1[i] << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> M;
vector<pair<long long, long long>> vec, vec2;
long long H, W, n, a, b;
long long cnt1[10];
bool valid(int x, int y) {
  if (x < 0 || x >= H - 2 || y < 0 || y >= W - 2) {
    return false;
  }
  return true;
}
int main() {
  cin >> H >> W >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    a--;
    b--;
    M[make_pair(a, b)] = 1;
    for (int j = -2; j <= 0; j++) {
      for (int k = -2; k <= 0; k++)
        vec.push_back(make_pair(a + j, b + k));
    }
  }
  if (n >= 1) {
    sort(vec.begin(), vec.end());
    if (valid(vec[0].first, vec[0].second) == true)
      vec2.push_back(vec[0]);
    for (int i = 1; i < vec.size(); i++) {
      if (vec[i - 1] != vec[i]) {
        if (valid(vec[i].first, vec[i].second) == true)
          vec2.push_back(vec[i]);
      }
    }
    for (int i = 0; i < vec2.size(); i++) {
      int cnts = 0;
      for (int j = 0; j < 3; j++) {
        for (int k = 0; k < 3; k++)
          cnts += M[make_pair(vec2[i].first + j, vec2[i].second + k)];
      }
      cnt1[cnts]++;
    }
  }
  long long sums = 0;
  for (int i = 1; i <= 9; i++) {
    sums += cnt1[i];
  }
  cnt1[0] = 1LL * (H - 2) * (W - 2) - sums;
  for (int i = 0; i <= 9; i++)
    cout << cnt1[i] << endl;
  return 0;
}
Problem p04000 (C++)

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y)                                                            \
  cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define BINARY(x) static_cast<bitset<16>>(x)

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

#define in_range(x, y, w, h)                                                   \
  (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) && (int)(y) < (int)(h))
#define ALL(a) (a).begin(), (a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};

int main() {
  int H, W, N;
  cin >> H >> W >> N;

  map<PII, ll> cnt;
  rep(i, N) {
    int X, Y;
    cin >> Y >> X;
    X--, Y--;

    for (int y = Y - 2; y <= Y; y++) {
      for (int x = X - 2; x <= X; x++) {
        if (in_range(x, y, W - 2, H - 2)) {
          cnt[PII(x, y)]++;
        }
      }
    }
  }

  map<int, ll> ans;
  ll tmp = 0;
  for (auto &p : cnt) {
    cerr << p.first.first << " " << p.first.second << " " << p.second << endl;
    ans[p.second]++;
    tmp++;
  }

  ans[0] = (ll)(H - 2) * (W - 2) - tmp;
  for (int i = 0; i <= 9; i++) {
    cout << ans[i] << endl;
  }
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y)                                                            \
  cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define BINARY(x) static_cast<bitset<16>>(x)

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

#define in_range(x, y, w, h)                                                   \
  (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) && (int)(y) < (int)(h))
#define ALL(a) (a).begin(), (a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};

int main() {
  int H, W, N;
  cin >> H >> W >> N;

  map<PII, ll> cnt;
  rep(i, N) {
    int X, Y;
    cin >> Y >> X;
    X--, Y--;

    for (int y = Y - 2; y <= Y; y++) {
      for (int x = X - 2; x <= X; x++) {
        if (in_range(x, y, W - 2, H - 2)) {
          cnt[PII(x, y)]++;
        }
      }
    }
  }

  map<int, ll> ans;
  ll tmp = 0;
  for (auto &p : cnt) {
    // cerr << p.first.first << " " << p.first.second << " " << p.second <<
    // endl;
    ans[p.second]++;
    tmp++;
  }

  ans[0] = (ll)(H - 2) * (W - 2) - tmp;
  for (int i = 0; i <= 9; i++) {
    cout << ans[i] << endl;
  }
}
Problem p04000 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

ll ans[9];
int main() {
  ll h, w, n;
  cin >> h >> w >> n;
  h--;
  w--;
  map<pair<ll, ll>, ll> a;
  for (ll i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    for (ll j = -2; j <= 0; j++) {
      for (ll k = -2; k <= 0; k++) {
        ll nowx = x + j;
        ll nowy = y + k;
        if (nowx < 0 || nowx > h - 2 || nowy < 0 || nowy > w - 2) {
          continue;
        }
        a[make_pair(nowx, nowy)]++;
      }
    }
  }
  for (auto itr = a.begin(); itr != a.end(); itr++) {
    ll val = itr->second;
    ans[val]++;
  }
  ll sum = 0;
  for (ll i = 0; i < 10; i++) {
    sum += ans[i];
  }
  ans[0] = (h - 1) * (w - 1) - sum;
  for (ll i = 0; i < 10; i++) {
    cout << ans[i] << endl;
  }
  // your code goes here
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL << 62
#define inf 1000000007

ll ans[10];
int main() {
  ll h, w, n;
  cin >> h >> w >> n;
  h--;
  w--;
  map<pair<ll, ll>, ll> a;
  for (ll i = 0; i < n; i++) {
    ll x, y;
    cin >> x >> y;
    x--;
    y--;
    for (ll j = -2; j <= 0; j++) {
      for (ll k = -2; k <= 0; k++) {
        ll nowx = x + j;
        ll nowy = y + k;
        if (nowx < 0 || nowx > h - 2 || nowy < 0 || nowy > w - 2) {
          continue;
        }
        a[make_pair(nowx, nowy)]++;
      }
    }
  }
  for (auto itr = a.begin(); itr != a.end(); itr++) {
    ll val = itr->second;
    ans[val]++;
  }
  ll sum = 0;
  for (ll i = 0; i < 10; i++) {
    sum += ans[i];
  }
  ans[0] = (h - 1) * (w - 1) - sum;
  for (ll i = 0; i < 10; i++) {
    cout << ans[i] << endl;
  }
  // your code goes here
  return 0;
}
Problem p04000 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <map>
#include <utility>

using namespace std;

int main() {

  long long H, W, N;
  cin >> H >> W >> N;

  std::map<pair<int, int>, long> m;

  // Create grid mappings
  for (long h = 1; h <= H - 2; h++) {
    for (long w = 1; w <= W - 2; w++) {
      m[make_pair(h, w)] = 0;
    }
  }

  long x, y;
  for (long i = 0; i < N; i++) {
    cin >> x >> y;
    for (int x_offset = -1; x_offset <= 1; x_offset++) {
      for (int y_offset = -1; y_offset <= 1; y_offset++) {
        if (x + x_offset < 2 || y + y_offset < 2 || x + x_offset > H - 1 ||
            y + y_offset > W - 1)
          continue;
        m[make_pair(x + x_offset, y + y_offset)] += 1;
      }
    }
  }

  long count[10] = {0};
  count[0] = (H - 2) * (W - 2);

  for (auto elem : m) {
    count[elem.second]++;
    count[0]--;
  }

  for (int i = 0; i < 10; i++) {
    cout << count[i] << endl;
  }
}


Fixed submission:
#include <iostream>
#include <map>
#include <utility>

using namespace std;

int main() {

  long long H, W, N;
  cin >> H >> W >> N;

  std::map<pair<int, int>, long> m;

  long x, y;
  for (long i = 0; i < N; i++) {
    cin >> x >> y;
    for (int x_offset = -1; x_offset <= 1; x_offset++) {
      for (int y_offset = -1; y_offset <= 1; y_offset++) {
        if (x + x_offset < 2 || y + y_offset < 2 || x + x_offset > H - 1 ||
            y + y_offset > W - 1)
          continue;
        m[make_pair(x + x_offset, y + y_offset)] += 1;
      }
    }
  }

  long count[10] = {0};
  count[0] = (H - 2) * (W - 2);

  for (auto elem : m) {
    count[elem.second]++;
    count[0]--;
  }

  for (int i = 0; i < 10; i++) {
    cout << count[i] << endl;
  }
}
Problem p04001 (C++)

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

void func1(int64_t nd, int64_t current_num, int64_t current_total,
           int64_t &all_total, int ketasuu, vector<int> kakuketa) {
  if (nd == ketasuu - 1) {
    all_total = current_total + current_num + all_total;
  } else {
    int64_t current_num1 = current_num;
    int64_t current_total1 = current_total;
    for (int i = 0; i < 2; i++) {
      if (i == 0) {

        func1(nd + 1, kakuketa.at(nd + 1), current_total1 + current_num1,
              all_total, ketasuu, kakuketa);
      }

      else {
        func1(nd + 1, current_num1 * 10 + kakuketa.at(nd + 1), current_total1,
              all_total, ketasuu, kakuketa);
      }
    }
  }
}

int main() {
  int64_t N;
  cin >> N;
  if (N < 10) {
    cout << N << endl;
  } else {
    int ketasuu = 0;
    vector<int> kakuketa;
    int H = N;

    while (H > 0) {
      kakuketa.push_back(H % 10);
      H /= 10;
      ketasuu++;
    };
    reverse(kakuketa.begin(), kakuketa.end());
    if (N < 10) {
      cout << N << endl;
    }
    int64_t all_total = 0;
    func1(0, kakuketa.at(0), 0, all_total, ketasuu, kakuketa);
    cout << all_total << endl;
  }
}


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

void func1(int64_t nd, int64_t current_num, int64_t current_total,
           int64_t &all_total, int ketasuu, vector<int> kakuketa) {
  if (nd == ketasuu - 1) {
    all_total = current_total + current_num + all_total;
  } else {
    int64_t current_num1 = current_num;
    int64_t current_total1 = current_total;
    for (int i = 0; i < 2; i++) {
      if (i == 0) {

        func1(nd + 1, kakuketa.at(nd + 1), current_total1 + current_num1,
              all_total, ketasuu, kakuketa);
      }

      else {
        func1(nd + 1, current_num1 * 10 + kakuketa.at(nd + 1), current_total1,
              all_total, ketasuu, kakuketa);
      }
    }
  }
}

int main() {
  int64_t N;
  cin >> N;
  if (N < 10) {
    cout << N << endl;
  } else {
    int ketasuu = 0;
    vector<int> kakuketa;
    int64_t H = N;

    while (H > 0) {
      kakuketa.push_back(H % 10);
      H /= 10;
      ketasuu++;
    };
    reverse(kakuketa.begin(), kakuketa.end());
    if (N < 10) {
      cout << N << endl;
    }
    int64_t all_total = 0;
    func1(0, kakuketa.at(0), 0, all_total, ketasuu, kakuketa);
    cout << all_total << endl;
  }
}
Problem p04001 (C++)

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

int main() {
  string S;
  cin >> S;
  int number[S.size()];
  long S_int = stoi(S);

  for (int i = 0; i < S.size(); i++) {
    number[i] = S_int % 10;
    S_int /= 10;
  }

  long ans = 0;

  for (long i = 0; i < (1 << (S.size() - 1)); i++) {
    long temp = i;
    long factor = 1;
    ans += (number[0]);
    for (int j = 1; j < S.size(); j++) {

      if (temp & 0b1) {
        factor = 1;
      } else {
        factor *= 10;
      }

      temp >>= 1;

      ans += (number[j] * factor);
    }
  }

  cout << ans << endl;
}


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

int main() {
  string S;
  cin >> S;
  int number[S.size()];
  long S_int = stol(S);

  for (int i = 0; i < S.size(); i++) {
    number[i] = S_int % 10;
    S_int /= 10;
  }

  long ans = 0;

  for (long i = 0; i < (1 << (S.size() - 1)); i++) {
    long temp = i;
    long factor = 1;
    ans += (number[0]);
    for (int j = 1; j < S.size(); j++) {

      if (temp & 0b1) {
        factor = 1;
      } else {
        factor *= 10;
      }

      temp >>= 1;

      ans += (number[j] * factor);
    }
  }

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<int, vector<int>, greater<int>> que;

string s;
llint a[9];
llint n;

llint calc(int bit) {
  llint ret = 0;
  llint tmp = a[0];
  for (int i = 0; i < n - 1; i++) {
    if (bit & (1 << i)) {
      ret += tmp;
      tmp = 0;
    } else {
      tmp *= 10;
    }
    tmp += a[i + 1];
  }
  return ret + tmp;
}

void solve() {
  cin >> s;
  n = s.size();
  for (int i = 0; i < n; i++)
    a[i] = s[i] - '0';
  llint r = 0;
  for (int b = 0; b < (1 << (n - 1)); b++) {
    r += calc(b);
  }
  cout << r << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<int, vector<int>, greater<int>> que;

string s;
llint a[10];
llint n;

llint calc(int bit) {
  llint ret = 0;
  llint tmp = a[0];
  for (int i = 0; i < n - 1; i++) {
    if (bit & (1 << i)) {
      ret += tmp;
      tmp = 0;
    } else {
      tmp *= 10;
    }
    tmp += a[i + 1];
  }
  return ret + tmp;
}

void solve() {
  cin >> s;
  n = s.size();
  for (int i = 0; i < n; i++)
    a[i] = s[i] - '0';
  llint r = 0;
  for (int b = 0; b < (1 << (n - 1)); b++) {
    r += calc(b);
  }
  cout << r << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}
Problem p04001 (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++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

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

  int n = s.size();
  ll sum = 0;
  rep(tmp, 1 << (n - 1)) {
    bitset<9> bs(tmp);
    int cnt = 0;
    rep(i, n) {
      sum += (ll)(s[n - 1 - i] - '0') * (ll)pow(10, cnt);
      if (bs.test(i))
        cnt = 0;
      else
        cnt++;
    }
  }

  cout << sum << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define INF 1e9
#define all(v) v.begin(), v.end()
typedef long long ll;

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

  int n = s.size();
  ll sum = 0;
  rep(tmp, 1 << (n - 1)) {
    bitset<10> bs(tmp);
    int cnt = 0;
    rep(i, n) {
      sum += (ll)(s[n - 1 - i] - '0') * (ll)pow(10, cnt);
      if (bs.test(i))
        cnt = 0;
      else
        cnt++;
    }
  }

  cout << sum << endl;

  return 0;
}
Problem p04001 (C++)

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

int main() {
  string ABCD;
  cin >> ABCD;
  int A = ABCD.at(0) - '0', B = ABCD.at(1) - '0', C = ABCD.at(2) - '0',
      D = ABCD.at(3) - '0';
  if (A + B + C + D == 7)
    cout << A << "+" << B << "+" << C << "+" << D << "=7" << endl;
  else if (A - B + C + D == 7)
    cout << A << "-" << B << "+" << C << "+" << D << "=7" << endl;
  else if (A + B - C + D == 7)
    cout << A << "+" << B << "-" << C << "+" << D << "=7" << endl;
  else if (A + B + C - D == 7)
    cout << A << "+" << B << "+" << C << "-" << D << "=7" << endl;
  else if (A + B - C - D == 7)
    cout << A << "+" << B << "-" << C << "-" << D << "=7" << endl;
  else if (A - B + C - D == 7)
    cout << A << "-" << B << "+" << C << "-" << D << "=7" << endl;
  else if (A - B - C + D == 7)
    cout << A << "-" << B << "-" << C << "+" << D << "=7" << endl;
  else if (A - B - C - D == 7)
    cout << A << "-" << B << "-" << C << "-" << D << "=7" << endl;
}


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

int main() {
  string s;
  cin >> s;
  string A;
  long long ans = 0;
  for (int i = 0; i < (1 << (s.size() - 1)); i++) {
    bitset<11> p(i);
    A = s[0];
    for (int j = 0; j < (s.size() - 1); j++) {
      if (p[j]) {
        ans += stoll(A);
        A = s[j + 1];
      } else {
        A += s[j + 1];
      }
    }
    ans += stoll(A);
  }
  cout << ans << endl;
}
Problem p04001 (C++)

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

string s;

ll sum(int l, bool plus, ll tmp, ll sm) {
  ll ans = 0;
  if (plus) {
    sm += tmp + s[l] - '0';
    tmp = 0;
  } else {
    tmp += s[l] - '0';
    tmp *= 10;
  }
  if (l == s.size() - 2) {
    ans = sm + tmp + s[s.size() - 1] - '0';
  } else {
    ans += sum(l + 1, true, tmp, sm);
    ans += sum(l + 1, false, tmp, sm);
  }
  return ans;
}

int main() {
  cin >> s;
  ll ans = sum(0, true, 0, 0) + sum(0, false, 0, 0);
  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

string s;

ll sum(int l, bool plus, ll tmp, ll sm) {
  ll ans = 0;
  if (plus) {
    sm += tmp + s[l] - '0';
    tmp = 0;
  } else {
    tmp += s[l] - '0';
    tmp *= 10;
  }
  if (l == s.size() - 2) {
    ans = sm + tmp + s[s.size() - 1] - '0';
  } else {
    ans += sum(l + 1, true, tmp, sm);
    ans += sum(l + 1, false, tmp, sm);
  }
  return ans;
}

int main() {
  cin >> s;
  ll ans;
  if (s.size() == 1)
    ans = s[0] - '0';
  else
    ans = sum(0, true, 0, 0) + sum(0, false, 0, 0);
  cout << ans << endl;
}
Problem p04001 (C++)

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

int main() {
  string S;
  cin >> S;
  long long ans = 0;
  int N = S.size();

  for (int bit = 0; bit < (1 << (N - 1)); bit++) {
    string s = "";
    for (int i = 0; i < N; i++) {
      s += S.at(i);
      if (bit >> i & 1) {
        ans += stoll(s);
        s = "";
      }
    }
    ans += stoi(s);
    s = "";
  }
  cout << ans << endl;
}


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

int main() {
  string S;
  cin >> S;
  long long ans = 0;
  int N = S.size();

  for (int bit = 0; bit < (1 << (N - 1)); bit++) {
    string s = "";
    for (int i = 0; i < N; i++) {
      s += S.at(i);
      if (bit >> i & 1) {
        ans += stoll(s);
        s = "";
      }
    }
    ans += stoll(s);
    s = "";
  }
  cout << ans << endl;
}