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

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

llong cast(string s) {
  llong sum = 0;
  string t = "";
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '+') {
      sum += stoi(t);
      t = "";
    } else {
      t += s[i];
    }
  }
  sum += stoi(t);
  return sum;
}

llong f(string s, llong n, llong i) {
  if (n == 1)
    return cast(s);
  return f(s, n - 1, i + 1) +
         f(s.insert(s.length() - i - 1, "+"), n - 1, i + 2);
}

int main() {
  string s;
  cin >> s;
  cout << f(s, s.length(), 0) << endl;
  return 0;
}

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

llong cast(string s) {
  llong sum = 0;
  string t = "";
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '+') {
      sum += stoi(t);
      t = "";
    } else {
      t += s[i];
    }
  }
  sum += stol(t);
  return sum;
}

llong f(string s, llong n, llong i) {
  if (n == 1)
    return cast(s);
  return f(s, n - 1, i + 1) +
         f(s.insert(s.length() - i - 1, "+"), n - 1, i + 2);
}

int main() {
  string s;
  cin >> s;
  cout << f(s, s.length(), 0) << endl;
  return 0;
}
Problem p04001 (C++)

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

using namespace std;

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

  string s;
  cin >> s;

  long long rez = 0;
  for (int i = 0; i < (1 << (s.size() - 1)); i++) {
    long long cr = 0;
    for (int j = 0; j <= s.size() - 2; j++) {
      cr = cr * 10 + s[j] - '0';
      if ((1 << j) & i) {
        rez = rez + cr;
        cr = 0;
      }
    }

    cr = cr * 10 + s[s.size() - 1] - '0';
    rez = rez + cr;
  }
  cout << rez << "\n";
  return 0;
}


Fixed submission:
#include <iostream>

using namespace std;

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

  string s;
  cin >> s;

  long long rez = 0;
  for (int i = 0; i < (1 << (s.size() - 1)); i++) {
    long long cr = 0;
    for (int j = 0; j <= (int)s.size() - 2; j++) {
      cr = cr * 10 + s[j] - '0';
      if ((1 << j) & i) {
        rez = rez + cr;
        cr = 0;
      }
    }

    cr = cr * 10 + s[s.size() - 1] - '0';
    rez = rez + cr;
  }
  cout << rez << "\n";
  return 0;
}
Problem p04001 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <sstream>
#include <stdlib.h>
#include <string>
typedef long long ll;
using namespace std;

int binary(int bina) {
  int ans = 0;
  for (int i = 0; bina > 0; i++) {
    ans = ans + (bina % 2) * pow(10, i);
    bina = bina / 2;
  }
  return ans;
}

template <typename T> std::string to_bin_str(T n, std::size_t digit_num) {
  std::string str;
  while (n > 0) {
    str.push_back('0' + (n & 1));
    n >>= 1;
  }
  str.resize(digit_num, '0');
  std::reverse(str.begin(), str.end());
  return str;
}

int main() {
  string N;
  cin >> N;
  int k = N.length();
  ll result = 0;
  string str;
  ll num = 0;
  int count = 0;
  for (int i = 0; i < pow(2, k - 1); i++) {
    num = binary(i);
    str = to_bin_str(num, k - 1);
    count = 0;
    for (int j = 0; j < k - 2; j++) {
      if (str[j] == '1') {
        result = result + stoll(N.substr(j - count, count + 1).c_str());
        count = 0;
      } else {
        count++;
      }
    }
    if (str[k - 2] == '1') {
      result = result + stoll(N.substr(k - 2 - count, count + 1).c_str()) +
               stoll(N.substr(k - 1).c_str());
    } else {
      result = result + stoll(N.substr(k - 2 - count).c_str());
    }
  }
  cout << result << endl;
}

Fixed submission:
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <math.h>
#include <sstream>
#include <stdlib.h>
#include <string>
typedef long long ll;
using namespace std;

int binary(int bina) {
  int ans = 0;
  for (int i = 0; bina > 0; i++) {
    ans = ans + (bina % 2) * pow(10, i);
    bina = bina / 2;
  }
  return ans;
}

template <typename T> std::string to_bin_str(T n, std::size_t digit_num) {
  std::string str;
  while (n > 0) {
    str.push_back('0' + (n & 1));
    n >>= 1;
  }
  str.resize(digit_num, '0');
  std::reverse(str.begin(), str.end());
  return str;
}

int main() {
  string N;
  cin >> N;
  int k = N.length();
  ll result = 0;
  string str;
  ll num = 0;
  int count = 0;
  result = stoll(N.c_str());
  /*for (int i=0; i<k;i++){
          result=result+N[i]-'0';
  }*/
  for (int i = 1; i < 1 << (k - 1); i++) {
    num = binary(i);
    str = to_bin_str(num, k - 1);
    count = 0;
    for (int j = 0; j < k - 2; j++) {
      if (str[j] == '1') {
        result = result + stoll(N.substr(j - count, count + 1).c_str());
        count = 0;
      } else {
        count++;
      }
    }
    if (str[k - 2] == '1') {
      result = result + stoll(N.substr(k - 2 - count, count + 1).c_str()) +
               stoll(N.substr(k - 1).c_str());
    } else {
      result = result + stoll(N.substr(k - 2 - count).c_str());
    }
  }
  cout << result << endl;
}
Problem p04001 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
long long ans = 0;
bool pl[100] = {0};
string s;
void cal(int l) {
  long long a1 = 0;
  for (int i = 0; i < l + 1; i++) {
    a1 = a1 * 10 + s[i] - '0';

    if (pl[i] && i < l + 1) {
      ans += a1;
      a1 = 0;
    }
  }
  ans += a1;
}

void ba(int d, int l) {

  if (d == l - 1) {
    pl[d] = 0;

    cal(l);
    pl[d] = 1;

    cal(l);
    return;
  }

  else {
    pl[d] = 0;
    ba(d + 1, l);
    pl[d] = 1;
    ba(d + 1, l);
    return;
  }
}

int main() {
  cin >> s;
  ba(0, s.length() - 1);
  cout << ans;
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
long long ans = 0;
bool pl[100] = {0};
string s;
void cal(int l) {
  long long a1 = 0;
  for (int i = 0; i < l + 1; i++) {
    a1 = a1 * 10 + s[i] - '0';

    if (pl[i] && i < l + 1) {
      ans += a1;
      a1 = 0;
    }
  }
  ans += a1;
}

void ba(int d, int l) {

  if (d == l - 1) {
    pl[d] = 0;

    cal(l);
    pl[d] = 1;

    cal(l);
    return;
  }

  else {
    pl[d] = 0;
    ba(d + 1, l);
    pl[d] = 1;
    ba(d + 1, l);
    return;
  }
}

int main() {
  cin >> s;
  if (s.length() == 1) {
    cout << s[0] - '0';
  } else {

    ba(0, s.length() - 1);

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

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;
int main() {
  string n;
  cin >> n;
  long long int nn = n.size();
  long long int ans = 0;
  for (int bit = 0; bit < (1 << nn - 1); bit++) {
    long long int sum = 0;
    string s;
    s += n[0];
    long long int f = 0;
    for (long long int i = 0; i < nn - 1; i++) {
      if (bit & (1 << i)) {
        s += "+";
        f++;
      }
      s += n[i + 1];
    }
    vector<string> h(nn);
    long long int k = 0;
    long long int d = 0;

    for (long long int i = 0; i < nn + f; i++) {

      if (s.at(i) != '+') {

        h[k] += s.at(i);

      } else {

        k++;
      }
    }
    for (long long int i = 0; i < k + 1; i++) {

      ans += stoi(h[i]);
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;
int main() {
  string n;
  cin >> n;
  long long int nn = n.size();
  long long int ans = 0;
  for (int bit = 0; bit < (1 << nn - 1); bit++) {
    long long int sum = 0;
    string s;
    s += n[0];
    long long int f = 0;
    for (long long int i = 0; i < nn - 1; i++) {
      if (bit & (1 << i)) {
        s += "+";
        f++;
      }
      s += n[i + 1];
    }
    vector<string> h(nn);
    long long int k = 0;
    long long int d = 0;

    for (long long int i = 0; i < nn + f; i++) {

      if (s.at(i) != '+') {

        h[k] += s.at(i);

      } else {

        k++;
      }
    }
    for (long long int i = 0; i < k + 1; i++) {

      long long int g = stoll(h[i]);
      ans += g;
    }
  }
  cout << ans << endl;
}
Problem p04001 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end)                                                     \
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
const lint mod = 1e9 + 7;

// 適当な区切りを入れて足したものを返す
// vector<string>& _sで参照渡ししてたせいで3日躓いてた
lint cut_sum(vector<string> _s, int _at) {
  lint sum = 0;
  if (_at < _s.back().size()) {
    //_atで区切らない場合
    sum += cut_sum(_s, _at + 1);
    //_atで区切る場合
    string tmp = _s.back().substr(_at);
    _s.back().erase(_s.back().begin() + _at, _s.back().end());
    _s.push_back(tmp);
    sum += cut_sum(_s, 1);
  } else {
    for (int i = 0; i < _s.size(); i++) {
      sum += stoi(_s[i]);
    }
  }
  return sum;
}

int main() {
  std::vector<string> v(1);
  cin >> v[0];

  cout << cut_sum(v, 1) << "\n";
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end)                                                     \
  for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end)                                                    \
  for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
const lint mod = 1e9 + 7;

// 適当な区切りを入れて足したものを返す
// vector<string>& _sで参照渡ししてたせいで3日躓いてた
lint cut_sum(vector<string> _s, int _at) {
  lint sum = 0;
  if (_at < _s.back().size()) {
    //_atで区切らない場合
    sum += cut_sum(_s, _at + 1);
    //_atで区切る場合
    string tmp = _s.back().substr(_at);
    _s.back().erase(_s.back().begin() + _at, _s.back().end());
    _s.push_back(tmp);
    sum += cut_sum(_s, 1);
  } else {
    for (int i = 0; i < _s.size(); i++) {
      // stoi(),stol()では数が大きくなった時に対応できない
      sum += stoll(_s[i]);
    }
  }
  return sum;
}

int main() {
  std::vector<string> v(1);
  cin >> v[0];

  cout << cut_sum(v, 1) << "\n";
  return 0;
}
Problem p04001 (C++)

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

int pow2(int l) {
  if (l > 0) {
    return 2 * pow2(l - 1);
  }
  return 1;
}

vector<bool> inttobool(int n, int l) {
  vector<bool> rep;
  for (int i = 0; i < l; i++) {
    rep.push_back(n % 2);
    n /= 2;
  }
  return rep;
}

int main() {
  string S;
  cin >> S;
  int l = S.size();
  long sum = 0;

  vector<bool> positionofplus(11);
  string T;
  for (int i = 0; i < (pow2(l - 1)); i++) {
    positionofplus = inttobool(i, l - 1);
    positionofplus.push_back(1);
    T += S.at(0);
    for (int j = 0; j <= l - 1; j++) {
      if (positionofplus.at(j)) {
        sum += stoi(T);
        T = "";
        if (j != l - 1) {
          T += S.at(j + 1);
        }
      } else {
        T += S.at(j + 1);
      }
    }
  }
  cout << sum << endl;
}

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

int pow2(int l) {
  if (l > 0) {
    return 2 * pow2(l - 1);
  }
  return 1;
}

vector<bool> inttobool(int n, int l) {
  vector<bool> rep;
  for (int i = 0; i < l; i++) {
    rep.push_back(n % 2);
    n /= 2;
  }
  return rep;
}

int main() {
  string S;
  cin >> S;
  int l = S.size();
  long sum = 0;

  vector<bool> positionofplus(11);
  string T;
  for (int i = 0; i < (pow2(l - 1)); i++) {
    positionofplus = inttobool(i, l - 1);
    positionofplus.push_back(1);
    T += S.at(0);
    for (int j = 0; j <= l - 1; j++) {
      if (positionofplus.at(j)) {
        sum += stol(T);
        T = "";
        if (j != l - 1) {
          T += S.at(j + 1);
        }
      } else {
        T += S.at(j + 1);
      }
    }
  }
  cout << sum << endl;
}
Problem p04001 (C++)

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

long long ans(string S) {
  S.push_back('+');
  string l;
  long long sum = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] != '+') {
      l.push_back(S[i]);
    } else {
      sum += stoi(l);
      l = " ";
    }
  }
  return sum;
}

int main() {
  string S;
  cin >> S;
  string c = S;
  long long ANS = 0;
  for (int bit = 0; bit < (1 << S.size() - 1); bit++) {
    int d = 0;
    for (int i = 0; i < S.size() - 1; i++) {
      if (bit & (1 << i)) {
        S.insert(i + 1 + d, "+");
        d++;
      }
    }
    ANS += ans(S);
    S = c;
  }
  cout << ANS << endl;
}

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

long long ans(string S) {
  S.push_back('+');
  string l;
  long long sum = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] != '+') {
      l.push_back(S[i]);
    } else {
      sum += stoll(l);
      l = " ";
    }
  }
  return sum;
}

int main() {
  string S;
  cin >> S;
  string c = S;
  long long ANS = 0;
  for (int bit = 0; bit < (1 << S.size() - 1); bit++) {
    int d = 0;
    for (int i = 0; i < S.size() - 1; i++) {
      if (bit & (1 << i)) {
        S.insert(i + 1 + d, "+");
        d++;
      }
    }
    ANS += ans(S);
    S = c;
  }
  cout << ANS << endl;
}
Problem p04001 (C++)

Buggy submission (status: Runtime Error):
#define _XCODE_DEBUG

#include <iostream>
#include <math.h>
#include <string>
#include <vector>

#ifdef _XCODE_DEBUG
#include <fstream>
#endif

int main() {
#ifdef _XCODE_DEBUG
  std::ifstream in("input.txt");
  std::cin.rdbuf(in.rdbuf());
#endif

  std::string s;
  std::cin >> s;
  int length = (int)s.length() - 1;

  long long ans = 0;
  for (int i = 0; i < pow(2, length); ++i) {
    long long sum_v = 0;
    int ind = 0;
    for (int j = 0; j < length; ++j) {
      if ((1 << j) & i) {
        sum_v += std::stoi(s.substr(ind, j + 1 - ind));
        ind = j + 1;
      }
    }
    sum_v += std::stoll(s.substr(ind, length + 1 - ind));
    ans += sum_v;
  }
  std::cout << ans << "\n";
  return 0;
}

Fixed submission:
// #define _XCODE_DEBUG

#include <iostream>
#include <math.h>
#include <string>
#include <vector>

#ifdef _XCODE_DEBUG
#include <fstream>
#endif

int main() {
#ifdef _XCODE_DEBUG
  std::ifstream in("input.txt");
  std::cin.rdbuf(in.rdbuf());
#endif

  std::string s;
  std::cin >> s;
  int length = (int)s.length() - 1;

  long long ans = 0;
  for (int i = 0; i < pow(2, length); ++i) {
    long long sum_v = 0;
    int ind = 0;
    for (int j = 0; j < length; ++j) {
      if ((1 << j) & i) {
        sum_v += std::stoi(s.substr(ind, j + 1 - ind));
        ind = j + 1;
      }
    }
    sum_v += std::stoll(s.substr(ind, length + 1 - ind));
    ans += sum_v;
  }
  std::cout << ans << "\n";
  return 0;
}
Problem p04001 (C++)

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

#define MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;

string S;
ll total = 0;
vector<string> split(const string &str, char sep) {
  std::vector<std::string> v;  // 分割結果を格納するベクター
  auto first = str.begin();    // テキストの最初を指すイテレータ
  while (first != str.end()) { // テキストが残っている間ループ
    auto last = first;         // 分割文字列末尾へのイテレータ
    while (last != str.end() &&
           *last != sep) // 末尾 or セパレータ文字まで進める
      ++last;
    v.push_back(std::string(first, last)); // 分割文字を出力
    if (last != str.end())
      ++last;
    first = last; // 次の処理のためにイテレータを設定
  }
  return v;
}

void count(string s) {
  vector<string> v = split(s, '+');
  for (vector<string>::iterator it = v.begin(); it != v.end(); it++) {
    total += stoi(*it);
  }
}

void setPlus(int d, string s, int p) {
  if (d == S.size() - 1) {
    count(s);
    return;
  }
  d++;
  string t = string(s);
  setPlus(d, t.insert(p, "+"), p + 2);
  setPlus(d, s, p + 1);
  d--;
}

int main() {
  cin >> S;

  setPlus(0, S, 1);

  cout << total << endl;
  return 0;
}

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

#define MOD 1000000007;
#define PI 3.14159265358979323846;
using namespace std;
typedef long long ll;
ll mod = 1000000007;

string S;
ll total = 0;
vector<string> split(const string &str, char sep) {
  std::vector<std::string> v;  // 分割結果を格納するベクター
  auto first = str.begin();    // テキストの最初を指すイテレータ
  while (first != str.end()) { // テキストが残っている間ループ
    auto last = first;         // 分割文字列末尾へのイテレータ
    while (last != str.end() &&
           *last != sep) // 末尾 or セパレータ文字まで進める
      ++last;
    v.push_back(std::string(first, last)); // 分割文字を出力
    if (last != str.end())
      ++last;
    first = last; // 次の処理のためにイテレータを設定
  }
  return v;
}

void count(string s) {
  vector<string> v = split(s, '+');
  for (vector<string>::iterator it = v.begin(); it != v.end(); it++) {
    total += stoll(*it);
  }
}

void setPlus(int d, string s, int p) {
  if (d == S.size() - 1) {
    count(s);
    return;
  }
  d++;
  string t = string(s);
  setPlus(d, t.insert(p, "+"), p + 2);
  setPlus(d, s, p + 1);
  d--;
}

int main() {
  cin >> S;

  setPlus(0, S, 1);

  cout << total << endl;
  return 0;
}
Problem p04001 (C++)

Buggy submission (status: Runtime Error):
// 递归
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000
typedef long long ll;
string s;
ll sum;
void dfs(vector<bool> b) {
  if (b.size() == s.size() - 1) {
    ll tmp = 0;
    // for(int i=0;i<b.size();++i)cout<<b[i];cout<<endl;
    for (int i = 0; i < s.size(); ++i) {
      tmp = tmp * 10 + s[i] - '0';
      if (b[i] && i != s.size() - 1) { /*cout<<tmp<<endl;*/
        sum += tmp;
        tmp = 0;
      }
    }
    sum += tmp;
    return;
  }
  b.push_back(0);
  dfs(b);
  b.pop_back();
  b.push_back(1);
  dfs(b);
}
int main() {
  cin >> s;
  vector<bool> b;
  dfs(b);
  cout << sum << endl;
  return 0;
}


Fixed submission:
// 递归
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000
typedef long long ll;
string s;
ll sum;
void dfs(vector<bool> b) {
  if (b.size() == s.size() - 1) {
    ll tmp = 0;
    // for(int i=0;i<b.size();++i)cout<<b[i];cout<<endl;
    for (int i = 0; i < s.size(); ++i) {
      tmp = tmp * 10 + s[i] - '0';
      if (i != s.size() - 1 && b[i]) { /*cout<<tmp<<endl;*/
        sum += tmp;
        tmp = 0;
      }
    }
    sum += tmp;
    return;
  }
  b.push_back(0);
  dfs(b);
  b.pop_back();
  b.push_back(1);
  dfs(b);
}
int main() {
  cin >> s;
  vector<bool> b;
  dfs(b);
  cout << sum << endl;
  return 0;
}
Problem p04001 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
// https://atcoder.jp/contests/arc061/tasks/arc061_a
typedef long long ll;
int main() {
  string input;
  cin >> input;
  ll len = (input.length() - 1);
  ll res = stoi(input);
  for (int bit = 1; bit < (1 << len); bit++) {
    ll temp = 0;
    for (ll i = 0; i < len; i++) {
      temp *= 10;
      temp += input.at(i) - '0';
      if (bit & (1 << i)) {
        res += temp;
        temp = 0;
      }
    }
    temp *= 10;
    temp += input.at(len) - '0';
    res += temp;
  }
  cout << res << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
// https://atcoder.jp/contests/arc061/tasks/arc061_a
typedef long long ll;
int main() {
  string input;
  cin >> input;
  ll len = (input.length() - 1);
  ll res = stol(input);
  for (int bit = 1; bit < (1 << len); bit++) {
    ll temp = 0;
    for (ll i = 0; i < len; i++) {
      temp *= 10;
      temp += input.at(i) - '0';
      if (bit & (1 << i)) {
        res += temp;
        temp = 0;
      }
    }
    temp *= 10;
    temp += input.at(len) - '0';
    res += temp;
  }
  cout << res << endl;
}
Problem p04001 (Python)

Buggy submission (status: Runtime Error):
import sys

input = sys.stdin.readline

s = input()
n = len(s)

total_sum = 0
# +を挿入する事象は
# sが2文字なら2通り，3文字なら4通り，n文字なら2^(n-1)通りある
for i in range(2 ** (n - 1)):
    # iは各桁に+を挿入するかどうかを決定する
    # 例えば s=12345, i=0b0111, ss=1+2+3+45
    now_sum = 0
    reg = int(s[0])
    for j in range(n - 1):
        if i & 1 << j:
            now_sum += reg
            reg = 0
        reg *= 10
        reg += int(s[j + 1])
    now_sum += reg

    total_sum += now_sum

print(total_sum)


Fixed submission:
import sys


def input():
    return sys.stdin.readline().strip()


s = input()
n = len(s)

total_sum = 0
# +を挿入する事象は
# sが2文字なら2通り，3文字なら4通り，n文字なら2^(n-1)通りある
for i in range(2 ** (n - 1)):
    # iは各桁に+を挿入するかどうかを決定する
    # 例えば s=12345, i=0b0111, ss=1+2+3+45
    now_sum = 0
    reg = int(s[0])
    for j in range(n - 1):
        if i & 1 << j:
            now_sum += reg
            reg = 0
        reg *= 10
        reg += int(s[j + 1])
    now_sum += reg

    total_sum += now_sum

print(total_sum)
Problem p04001 (Python)

Buggy submission (status: Runtime Error):
S = int(input())
N = len(S) - 1
ans = 0

for i in range(2**N):
    k = 0
    for j in range(N):
        if (i >> j) & 1:
            ans += int(S[k : j + 1])
            k = j + 1
    ans += int(S[k:])
print(ans)


Fixed submission:
S = input()
N = len(S) - 1
ans = 0

for i in range(2**N):
    k = 0
    for j in range(N):
        if (i >> j) & 1:
            ans += int(S[k : j + 1])
            k = j + 1
    ans += int(S[k:])
print(ans)
Problem p04001 (Python)

Buggy submission (status: Runtime Error):
S = input()
N = len(S)
ans = 0
for i in range(2 ** (N - 1)):
    signs = bin(i)[2:].zfill(N - 1).replace("0", "+").replace("1", " ")

    tmp_s = S[0]
    for j, sign in enumerate(signs):
        tmp_s += sign + S[j + 1]

    ans += eval(tmp_s.replace(" ", ""))

print(ans)


Fixed submission:
S = input()
N = len(S)

if N == 1:
    print(S)
    exit()

ans = 0
for i in range(2 ** (N - 1)):
    signs = bin(i)[2:].zfill(N - 1).replace("0", "+").replace("1", " ")

    tmp_s = S[0]
    for j, sign in enumerate(signs):
        tmp_s += sign + S[j + 1]

    ans += eval(tmp_s.replace(" ", ""))

print(ans)
Problem p04002 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
// #include <ext/numeric>
#define oo 0x3f3f3f3f
#define long long long

using namespace std;
// using namespace __gnu_cxx;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9),
      cout << fixed;

  int h, w, n;
  cin >> h >> w >> n;
  vector<pair<int, int>> arr(n);
  set<pair<int, int>> isBlack;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i].first >> arr[i].second;
    isBlack.insert({arr[i].first, arr[i].second});
  }

  map<int, long> ans;
  ans[0] = 1ll * (h - 2) * (w - 2);
  set<pair<int, int>> vis[3][3];
  for (int i = 0; i < n; ++i) {
    for (int x = max(1, arr[i].first - 2); x <= arr[i].first; ++x) {
      for (int y = max(1, arr[i].second - 2); y <= arr[i].second; ++y) {
        if (x + 2 > h || y + 2 > w)
          continue;
        bool ok = true;
        int cnt = 0;
        for (int a = x; a <= x + 2; ++a) {
          for (int b = y; b <= y + 2; ++b) {
            cnt += isBlack.count({a, b});
            ok &= vis[a - x][b - y].insert({a, b}).second;
          }
        }
        //                cout << x << ' ' << y << ' ' << cnt << '\n';
        if (ok) {
          ++ans[cnt];
          --ans[0];
        }
      }
    }
  }

  for (int i = 0; i < 10; ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
// #include <ext/numeric>
#define oo 0x3f3f3f3f
#define long long long

using namespace std;
// using namespace __gnu_cxx;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
#endif
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9),
      cout << fixed;

  int h, w, n;
  cin >> h >> w >> n;
  vector<pair<int, int>> arr(n);
  set<pair<int, int>> isBlack;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i].first >> arr[i].second;
    isBlack.insert({arr[i].first, arr[i].second});
  }

  map<int, long> ans;
  ans[0] = 1ll * (h - 2) * (w - 2);
  set<pair<int, int>> vis[3][3];
  for (int i = 0; i < n; ++i) {
    for (int x = max(1, arr[i].first - 2); x <= arr[i].first; ++x) {
      for (int y = max(1, arr[i].second - 2); y <= arr[i].second; ++y) {
        if (x + 2 > h || y + 2 > w)
          continue;
        bool ok = true;
        int cnt = 0;
        for (int a = x; a <= x + 2; ++a) {
          for (int b = y; b <= y + 2; ++b) {
            if (isBlack.count({a, b})) {
              ++cnt;
              ok &= vis[a - x][b - y].insert({a, b}).second;
            }
          }
        }
        //                cout << x << ' ' << y << ' ' << cnt << '\n';
        if (ok) {
          ++ans[cnt];
          --ans[0];
        }
      }
    }
  }

  for (int i = 0; i < 10; ++i) {
    cout << ans[i] << '\n';
  }

  return 0;
}
Problem p04002 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

ll H, W, N;
ll dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
ll dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  cin >> H >> W >> N;
  set<pair<ll, ll>> st;
  set<pair<ll, ll>> br;
  vector<ll> ans(11);
  ans[0] = (H - 2) * (W - 2);
  for (int i = 0; i < N; i++) {
    ll y, x;
    cin >> y >> x;
    y--, x--;
    pair<ll, ll> p = make_pair(y, x);
    br.insert(p);
    st.insert(p);
    for (ll i = 0; i < 9; i++) {
      ll ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || ny >= H)
        continue;
      if (nx < 0 || nx >= W)
        continue;
      pair<ll, ll> q = make_pair(ny, nx);
      st.insert(q);
    }
  }
  for (auto &p : st) {
    ll y = p.first, x = p.second, cnt = 0;
    if (br.find(p) != br.end())
      cnt++;
    for (ll i = 0; i < 8; i++) {
      ll ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || ny >= H || nx < 0 || nx >= W) {
        cnt = -1;
        break;
      }
      pair<ll, ll> q = make_pair(ny, nx);
      if (br.find(q) != br.end())
        cnt++;
    }
    if (cnt != -1) {
      ans[cnt]++, ans[0]--;
    }
  }
  for (int i = 0; i <= 9; i++) {
    cout << ans[i] << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

ll H, W, N;
ll dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
ll dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  cin >> H >> W >> N;
  set<pair<ll, ll>> st;
  set<pair<ll, ll>> br;
  vector<ll> ans(11);
  ans[0] = (H - 2) * (W - 2);
  for (int i = 0; i < N; i++) {
    ll y, x;
    cin >> y >> x;
    y--, x--;
    pair<ll, ll> p = make_pair(y, x);
    br.insert(p);
    st.insert(p);
    for (ll i = 0; i < 8; i++) {
      ll ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || ny >= H)
        continue;
      if (nx < 0 || nx >= W)
        continue;
      pair<ll, ll> q = make_pair(ny, nx);
      st.insert(q);
    }
  }
  for (auto &p : st) {
    ll y = p.first, x = p.second, cnt = 0;
    if (br.find(p) != br.end())
      cnt++;
    for (ll i = 0; i < 8; i++) {
      ll ny = y + dy[i], nx = x + dx[i];
      if (ny < 0 || ny >= H || nx < 0 || nx >= W) {
        cnt = -1;
        break;
      }
      pair<ll, ll> q = make_pair(ny, nx);
      if (br.find(q) != br.end())
        cnt++;
    }
    if (cnt != -1) {
      ans[cnt]++, ans[0]--;
    }
  }
  for (int i = 0; i <= 9; i++) {
    cout << ans[i] << endl;
  }
}
Problem p04002 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)
#define rep_r(i, s, n) for (ll i = n - 1; i >= s; i--)
#define repe_r(i, s, n) for (ll i = s; i <= n; i++)
static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;
static const ll MAX_L = (ll)1 << 62;

map<pair<ll, ll>, ll> mp;

int main() {
  ll Y[9] = {0, 0, 0, -1, -1, -1, -2, -2, -2};
  ll X[9] = {0, -1, -2, 0, -1, -2, 0, -1, -2};

  ll h, w, n;
  cin >> h >> w >> n;
  rep(i, 0, n) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    rep(j, 0, 9) {
      ll ny = a + Y[j];
      ll nx = b + X[j];
      if (ny >= 0 && nx >= 0 && ny + 2 < h && nx + 2 < w) {
        mp[{ny, nx}]++;
      }
    }
  }

  ll ans[9] = {};

  for (map<pair<ll, ll>, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
    ans[it->second]++;
  }

  cout << (h - 2) * (w - 2) - mp.size() << endl;
  repe(i, 1, 9) { cout << ans[i] << endl; }

  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
using namespace std;
typedef long long ll;
#define rep(i, s, n) for (ll i = s; i < n; i++)
#define repe(i, s, n) for (ll i = s; i <= n; i++)
#define rep_r(i, s, n) for (ll i = n - 1; i >= s; i--)
#define repe_r(i, s, n) for (ll i = s; i <= n; i++)
static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;
static const ll MAX_L = (ll)1 << 62;

map<pair<ll, ll>, ll> mp;

int main() {
  ll Y[9] = {0, 0, 0, -1, -1, -1, -2, -2, -2};
  ll X[9] = {0, -1, -2, 0, -1, -2, 0, -1, -2};

  ll h, w, n;
  cin >> h >> w >> n;
  rep(i, 0, n) {
    ll a, b;
    cin >> a >> b;
    a--, b--;
    rep(j, 0, 9) {
      ll ny = a + Y[j];
      ll nx = b + X[j];
      if (ny >= 0 && nx >= 0 && ny + 2 < h && nx + 2 < w) {
        mp[{ny, nx}]++;
      }
    }
  }

  ll ans[10] = {};

  for (map<pair<ll, ll>, ll>::iterator it = mp.begin(); it != mp.end(); it++) {
    ans[it->second]++;
  }

  cout << (h - 2) * (w - 2) - mp.size() << endl;
  repe(i, 1, 9) { cout << ans[i] << endl; }

  return 0;
}
Problem p04002 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define int long long
#define inf 1145141919
#define rep(i, n) for (int i = 0; i < n; i++)
typedef pair<int, int> P;
typedef pair<int, P> PP;
struct edge {
  int to, cost;
};
const long long mod = 10000000;
int a[114514], b[114514];
int ans[15];
vector<P> V;
map<P, int> M;
signed main() {
  int h, w, n;
  cin >> h >> w >> n;
  rep(i, n) {
    cin >> a[i] >> b[i];
    M[P(a[i], b[i])] = 1;
    for (int j = -2; j <= 2; j++) {
      for (int k = -2; k <= 2; k++) {
        if (1 <= a[i] + j && a[i] + j <= h - 2 && 1 <= b[i] + k &&
            b[i] + k <= w - 2)
          V.push_back(P(a[i] + j, b[i] + k));
      }
    }
  }
  sort(V.begin(), V.end());
  V.erase(unique(V.begin(), V.end()), V.end());

  rep(i, V.size()) {
    int cnt = 0;
    rep(j, 3) {
      rep(k, 3) {
        if (M[P(V[i].first + j, V[i].second + k)])
          cnt++;
      }
    }
    ans[cnt]++;
  }
  ans[0] += (h - 2) * (w - 2) - V.size();
  rep(i, 10) cout << ans[i] << endl;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define int long long
#define inf 1145141919
#define rep(i, n) for (int i = 0; i < n; i++)
typedef pair<int, int> P;
typedef pair<int, P> PP;
struct edge {
  int to, cost;
};
const long long mod = 10000000;
int a[114514], b[114514];
int ans[15];
vector<P> V;
map<P, int> M;
signed main() {
  int h, w, n;
  cin >> h >> w >> n;
  rep(i, n) {
    cin >> a[i] >> b[i];
    M[P(a[i], b[i])] = 1;
    for (int j = -2; j <= 0; j++) {
      for (int k = -2; k <= 0; k++) {
        if (1 <= a[i] + j && a[i] + j <= h - 2 && 1 <= b[i] + k &&
            b[i] + k <= w - 2)
          V.push_back(P(a[i] + j, b[i] + k));
      }
    }
  }
  sort(V.begin(), V.end());
  V.erase(unique(V.begin(), V.end()), V.end());

  rep(i, V.size()) {
    int cnt = 0;
    rep(j, 3) {
      rep(k, 3) {
        if (M[P(V[i].first + j, V[i].second + k)])
          cnt++;
      }
    }
    ans[cnt]++;
  }
  ans[0] += (h - 2) * (w - 2) - V.size();
  rep(i, 10) cout << ans[i] << endl;
}
Problem p04002 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
typedef long long int ll;
int main() {
  ll H, W;
  int N;
  map<ll, int> mpa;
  ll num[10];
  fill(num, num + 10, 0);
  cin >> H >> W >> N;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    for (ll j = 0; j < 3; j++) {
      for (ll k = 0; k < 3; k++) {
        ll na = a + j;
        ll nb = b + k;
        if (na < 2 || nb < 2 || na >= H || nb >= W)
          continue;
        mpa[na * H + nb]++;
      }
    }
  }
  num[0] = (H - 2) * (W - 2);
  for (auto e : mpa) {
    num[e.second]++;
    num[0]--;
  }
  for (int i = 0; i <= 9; i++) {
    cout << num[i] << endl;
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
using namespace std;
typedef long long int ll;
int main() {
  ll H, W;
  int N;
  map<ll, int> mpa;
  ll num[10];
  fill(num, num + 10, 0);
  cin >> H >> W >> N;
  for (int i = 0; i < N; i++) {
    ll a, b;
    cin >> a >> b;
    a--;
    b--;
    for (ll j = 0; j < 3; j++) {
      for (ll k = 0; k < 3; k++) {
        ll na = a + j;
        ll nb = b + k;
        if (na < 2 || nb < 2 || na >= H || nb >= W)
          continue;
        mpa[na * W + nb]++;
      }
    }
  }
  num[0] = (H - 2) * (W - 2);
  for (auto e : mpa) {
    num[e.second]++;
    num[0]--;
  }
  for (int i = 0; i <= 9; i++) {
    cout << num[i] << endl;
  }
  return 0;
}
Problem p04002 (C++)

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

/*
http://arc061.contest.atcoder.jp/tasks/arc061_b
题意：
H行W列的矩阵中，然后挖了n个洞，输出j(0-9)行，对于第i行输出，有多少个3*3区域中有i个洞；

思路：
对于一个黑色的格子，只有9个3*3的矩阵才能包含他。
所以只有处理m个黑格子就行了。
对于每个黑格子，我默认把3*3的左上角代表这个矩阵。
这样还不够，因为没有那么大的矩阵表示方法，所以换一个表示就是把矩阵中每个格子标记；
处理一下，最后输出就好了；

*/
LL h, w, n;
map<LL, LL> mp;
LL ans[10];
LL dx[9] = {-2, -2, -2, -1, -1, -1, 0, 0, 0};
LL dy[9] = {-2, -1, 0, -2, -1, 0, -2, -1, 0};

void Add(LL x, LL y) {
  LL a, b;
  LL temp;
  for (int i = 0; i < 9; i++) {
    a = x + dx[i];
    b = y + dy[i];
    if (a < 1 || b < 1 || a > h - 2 || b > w - 2)
      continue;
    temp = (h - 2) * (a - 1) + b;
    mp[temp]++;
  }
}

int main() {
  LL x, y;
  scanf("%lld%lld%lld", &h, &w, &n);
  for (LL i = 0; i < n; i++) {
    scanf("%lld%lld", &x, &y);
    Add(x, y);
  }
  memset(ans, 0, sizeof(ans));
  ans[0] = (h - 3) * (w - 2) + w - 2;
  LL temp;
  map<LL, LL>::iterator it;
  for (it = mp.begin(); it != mp.end(); it++) {
    temp = it->second;
    ans[temp]++;
    ans[0]--;
  }
  for (LL i = 0; i <= 9; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}


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

/*
http://arc061.contest.atcoder.jp/tasks/arc061_b
题意：
H行W列的矩阵中，然后挖了n个洞，输出j(0-9)行，对于第i行输出，有多少个3*3区域中有i个洞；

思路：
对于一个黑色的格子，只有9个3*3的矩阵才能包含他。
所以只有处理m个黑格子就行了。
对于每个黑格子，我默认把3*3的左上角代表这个矩阵。
这样还不够，因为没有那么大的矩阵表示方法，所以换一个表示就是把矩阵中每个格子标记；
处理一下，最后输出就好了；

*/
LL h, w, n;
map<LL, LL> mp;
LL ans[10];
LL dx[9] = {-2, -2, -2, -1, -1, -1, 0, 0, 0};
LL dy[9] = {-2, -1, 0, -2, -1, 0, -2, -1, 0};

void Add(LL x, LL y) {
  LL a, b;
  LL temp;
  for (int i = 0; i < 9; i++) {
    a = x + dx[i];
    b = y + dy[i];
    if (a < 1 || b < 1 || a > h - 2 || b > w - 2)
      continue;
    temp = (h - 2) * (b - 1) + a;
    mp[temp]++;
  }
}

int main() {
  LL x, y;
  scanf("%lld%lld%lld", &h, &w, &n);
  for (LL i = 0; i < n; i++) {
    scanf("%lld%lld", &x, &y);
    Add(x, y);
  }
  memset(ans, 0, sizeof(ans));
  ans[0] = (h - 3) * (w - 2) + w - 2;
  LL temp;
  map<LL, LL>::iterator it;
  for (it = mp.begin(); it != mp.end(); it++) {
    temp = it->second;
    ans[temp]++;
    ans[0]--;
  }
  for (LL i = 0; i <= 9; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}
Problem p04002 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define erep(i, a, b) for (int i = a; i <= (int)(b); ++i)
#define per(i, a, b) for (int i = (b); i > (a); --i)
#define eper(i, a, b) for (int i = ((int)(a)); i >= b; --i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int h, w, n;
ll ans[10];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w >> n;
  map<P, int> p;
  rep(i, 0, n) {
    int x, y;
    cin >> x >> y;
    rep(j, 0, 3) rep(k, 0, 3) {
      int va = x - j, vb = y - k;
      if (va <= 0 || h < va + 2 || vb <= 0 || w < vb + 2)
        continue;
      p[mp(va, vb)]++;
    }
  }
  fill(ans, ans + n, 0);
  ans[0] = (ll)(h - 2) * (w - 2);
  for (auto itr = p.begin(); itr != p.end(); itr++) {
    ans[itr->second]++;
    ans[0]--;
  }
  rep(i, 0, 10) cout << ans[i] << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define erep(i, a, b) for (int i = a; i <= (int)(b); ++i)
#define per(i, a, b) for (int i = (b); i > (a); --i)
#define eper(i, a, b) for (int i = ((int)(a)); i >= b; --i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int h, w, n;
ll ans[10];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> h >> w >> n;
  map<P, int> p;
  rep(i, 0, n) {
    int x, y;
    cin >> x >> y;
    rep(j, 0, 3) rep(k, 0, 3) {
      int va = x - j, vb = y - k;
      if (va <= 0 || h < va + 2 || vb <= 0 || w < vb + 2)
        continue;
      p[mp(va, vb)]++;
    }
  }
  fill(ans, ans + 10, 0);
  ans[0] = (ll)(h - 2) * (w - 2);
  for (auto itr = p.begin(); itr != p.end(); itr++) {
    ans[itr->second]++;
    ans[0]--;
  }
  rep(i, 0, 10) cout << ans[i] << endl;
  return 0;
}
Problem p04002 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll H, W;
int N;
vector<pair<int, int>> mass;
vector<pair<int, int>> zero;
int a[10001];
int b[10001];
ll ans[10];

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

  for (int i = 0; i < N; i++)
    cin >> a[i] >> b[i];

  for (int i = 0; i < N; i++) {
    for (int j = a[i] - 2; j <= a[i]; j++) {
      for (int k = b[i] - 2; k <= b[i]; k++) {
        pair<int, int> p(j, k);
        mass.push_back(p);
      }
    }
  }
  sort(mass.begin(), mass.end());

  for (int i = 0; i < mass.size(); i++) {
    if (mass[i].first > 0 && mass[i].second > 0 && mass[i].first <= H - 2 &&
        mass[i].second <= W - 2) {
      int j = 0;
      pair<int, int> p(mass[i]);
      zero.push_back(p);
      while (true) {
        if (p == mass[i]) {
          j++;
          i++;
        } else {
          ans[j]++;
          i--;
          break;
        }
      }
    }
  }

  ans[0] = ((W - 2) * (H - 2)) - zero.size();

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


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
ll H, W;
int N;
vector<pair<int, int>> mass;
vector<pair<int, int>> zero;
int a[100001];
int b[100001];
ll ans[10];

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

  for (int i = 0; i < N; i++)
    cin >> a[i] >> b[i];

  for (int i = 0; i < N; i++) {
    for (int j = a[i] - 2; j <= a[i]; j++) {
      for (int k = b[i] - 2; k <= b[i]; k++) {
        pair<int, int> p(j, k);
        mass.push_back(p);
      }
    }
  }
  sort(mass.begin(), mass.end());

  for (int i = 0; i < mass.size(); i++) {
    if (mass[i].first > 0 && mass[i].second > 0 && mass[i].first <= H - 2 &&
        mass[i].second <= W - 2) {
      int j = 0;
      pair<int, int> p(mass[i]);
      zero.push_back(p);
      while (true) {
        if (p == mass[i]) {
          j++;
          i++;
        } else {
          ans[j]++;
          i--;
          break;
        }
      }
    }
  }

  ans[0] = ((W - 2) * (H - 2)) - zero.size();

  for (int i = 0; i < 10; i++)
    cout << ans[i] << endl;
}
Problem p04002 (C++)

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

long long ans[9];
const int N = 1e6;

int main() {
  long long h, w, node[N], inf = 1e9 + 7, n, a, b, cnt = 0;
  cin >> h >> w >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    for (int i = -2; i <= 0; i++) {
      for (int j = -2; j <= 0; j++) {
        if (a + i >= 1 && b + j >= 1 && a + i <= h - 2 && b + j <= w - 2) {
          node[cnt] = inf * (a + i) + (b + j);
          cnt++;
        }
      }
    }
  }
  sort(node, node + cnt);
  long long tmp = 1, zero = (h - 2) * (w - 2);
  for (int i = 0; i <= cnt - 1; i++) {
    if (node[i + 1] == node[i])
      tmp++;
    else {
      ans[tmp]++;
      tmp = 1;
      zero--;
    }
  }
  cout << zero << endl;
  for (int i = 1; i <= 9; i++)
    cout << ans[i] << endl;
}

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

long long ans[15];
const int N = 1e6 + 10;

int main() {
  long long h, w, node[N], inf = 1e9 + 7, n, a, b, cnt = 0;
  cin >> h >> w >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    for (int i = -2; i <= 0; i++) {
      for (int j = -2; j <= 0; j++) {
        if (a + i >= 1 && b + j >= 1 && a + i <= h - 2 && b + j <= w - 2) {
          node[cnt] = inf * (a + i) + (b + j);
          cnt++;
        }
      }
    }
  }
  sort(node, node + cnt);
  long long tmp = 1, zero = (h - 2) * (w - 2);
  for (int i = 0; i <= cnt - 1; i++) {
    if (node[i + 1] == node[i])
      tmp++;
    else {
      ans[tmp]++;
      tmp = 1;
      zero--;
    }
  }
  cout << zero << endl;
  for (int i = 1; i <= 9; i++)
    cout << ans[i] << endl;
}
Problem p04002 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define forr(i, p, n) for (ll i = p; i < n; i++)
#define tam 10010
#define tamlog 12
#define offset 50000
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<string, ll> si;
typedef pair<ll, ii> iii;
const ll INF = 1e11;
ll H, W, N;
set<ii> resp[12];
set<ii> s;
ll hay(ll xx, ll yy) {
  if (s.find(mp(xx, yy)) == s.end())
    return 0;
  return 1;
}
bool valid(ll xx, ll yy) {
  if (xx <= 0 || yy <= 0 || xx > H || yy > W)
    return 0;
  return 1;
}
ll calc(ll xx, ll yy) {
  ll tot = 0;
  for (ll i = 0; i >= -2; i--) {
    for (ll j = 0; j >= -2; j--) {
      if (valid(xx + i, yy + j) == false)
        return 10;
      tot += hay(xx + i, yy + j);
    }
  }
  return tot;
}
ll vx[tam], vy[tam];
int main() {

  cin >> H >> W >> N;
  forr(i, 0, N) {
    cin >> vx[i] >> vy[i];
    s.insert(ii(vx[i], vy[i]));
  }
  ll xx, yy;
  forr(i, 0, N) {
    forr(j, 0, 3) {
      forr(k, 0, 3) {
        xx = vx[i] + j;
        yy = vy[i] + k;
        resp[calc(xx, yy)].insert(ii(xx, yy));
      }
    }
  }
  ll atot = 0;
  forr(i, 1, 10) atot += resp[i].size();
  cout << (H - 2) * (W - 2) - atot << endl;
  forr(i, 1, 10) {
    cout << resp[i].size() << endl;
    /*for(set<ii>::iterator ite=resp[i].begin();ite!=resp[i].end();ite++)
    {
        //cout<<(*ite).fi<<" "<<(*ite).se<<endl;
    }*/
  }
}


Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define forr(i, p, n) for (ll i = p; i < n; i++)
#define tam 200010
#define tamlog 12
#define offset 50000
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<string, ll> si;
typedef pair<ll, ii> iii;
const ll INF = 1e11;
ll H, W, N;
set<ii> resp[12];
set<ii> s;
ll hay(ll xx, ll yy) {
  if (s.find(mp(xx, yy)) == s.end())
    return 0;
  return 1;
}
bool valid(ll xx, ll yy) {
  if (xx <= 0 || yy <= 0 || xx > H || yy > W)
    return 0;
  return 1;
}
ll calc(ll xx, ll yy) {
  ll tot = 0;
  for (ll i = 0; i >= -2; i--) {
    for (ll j = 0; j >= -2; j--) {
      if (valid(xx + i, yy + j) == false)
        return 10;
      tot += hay(xx + i, yy + j);
    }
  }
  return tot;
}
ll vx[tam], vy[tam];
int main() {

  cin >> H >> W >> N;
  forr(i, 0, N) {
    cin >> vx[i] >> vy[i];
    s.insert(ii(vx[i], vy[i]));
  }
  ll xx, yy;
  forr(i, 0, N) {
    forr(j, 0, 3) {
      forr(k, 0, 3) {
        xx = vx[i] + j;
        yy = vy[i] + k;
        resp[calc(xx, yy)].insert(ii(xx, yy));
      }
    }
  }
  ll atot = 0;
  forr(i, 1, 10) atot += resp[i].size();
  cout << (H - 2) * (W - 2) - atot << endl;
  forr(i, 1, 10) {
    cout << resp[i].size() << endl;
    /*for(set<ii>::iterator ite=resp[i].begin();ite!=resp[i].end();ite++)
    {
        //cout<<(*ite).fi<<" "<<(*ite).se<<endl;
    }*/
  }
}
Problem p04003 (C++)

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

typedef std::pair<int, int> pr;
typedef std::map<int, int> map;
const int N = 500054, M = 1000054, INF = 0x3f3f3f3f;

struct edge {
  int u, v, w;
  edge(int u0 = 0, int v0 = 0, int w0 = 0) : u(u0), v(v0), w(w0) {}
} e[M];

int n, m, V, E = 0;
int first[N], next[M];
int d[N];
map g[M];
std::priority_queue<pr, std::vector<pr>, std::greater<pr>> pq;

inline void addedge(int u, int v, int w1, int w2) {
  e[++E] = edge(u, v, w1), next[E] = first[u], first[u] = E;
  e[++E] = edge(v, u, w2), next[E] = first[v], first[v] = E;
}

inline int get(int ty, int id) {
  map::iterator it;
  bool ret;
  std::tie(it, ret) = g[ty].emplace(id, V + 1);
  return ret ? ++V : it->second;
}

void Dijkstra(int s) {
  int i, x, y, di;
  memset(d, 63, (V + 1) << 2);
  for (pq.emplace(d[s] = 0, s); !pq.empty();) {
    std::tie(di, x) = pq.top(), pq.pop();
    if (d[x] != di)
      continue;
    for (i = first[x]; i; i = next[i])
      if (di + e[i].w < d[y = e[i].v])
        pq.emplace(d[y] = di + e[i].w, y);
  }
}

int main() {
  int i, u, v, w;
  scanf("%d%d", &n, &m), V = n;
  for (i = 0; i < m; ++i)
    scanf("%d%d%d", &u, &v, &w), addedge(get(w, u), get(w, v), 0, 0);
  for (i = 0; i < M; ++i)
    for (const pr &p : g[i])
      addedge(p.first, p.second, 1, 0);
  Dijkstra(1), printf("%d\n", d[n] >= INF ? -1 : d[n]);
  return 0;
}

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

typedef std::pair<int, int> pr;
typedef std::map<int, int> map;
const int N = 500054, M = 2000054, INF = 0x3f3f3f3f;

struct edge {
  int u, v, w;
  edge(int u0 = 0, int v0 = 0, int w0 = 0) : u(u0), v(v0), w(w0) {}
} e[M];

int n, m, V, E = 0;
int first[N], next[M];
int d[N];
map g[M];
std::priority_queue<pr, std::vector<pr>, std::greater<pr>> pq;

inline void addedge(int u, int v, int w1, int w2) {
  e[++E] = edge(u, v, w1), next[E] = first[u], first[u] = E;
  e[++E] = edge(v, u, w2), next[E] = first[v], first[v] = E;
}

inline int get(int ty, int id) {
  map::iterator it;
  bool ret;
  std::tie(it, ret) = g[ty].emplace(id, V + 1);
  return ret ? ++V : it->second;
}

void Dijkstra(int s) {
  int i, x, y, di;
  memset(d, 63, (V + 1) << 2);
  for (pq.emplace(d[s] = 0, s); !pq.empty();) {
    std::tie(di, x) = pq.top(), pq.pop();
    if (d[x] != di)
      continue;
    for (i = first[x]; i; i = next[i])
      if (di + e[i].w < d[y = e[i].v])
        pq.emplace(d[y] = di + e[i].w, y);
  }
}

int main() {
  int i, u, v, w;
  scanf("%d%d", &n, &m), V = n;
  for (i = 0; i < m; ++i)
    scanf("%d%d%d", &u, &v, &w), addedge(get(w, u), get(w, v), 0, 0);
  for (i = 0; i < M; ++i)
    for (const pr &p : g[i])
      addedge(p.first, p.second, 1, 0);
  Dijkstra(1), printf("%d\n", d[n] >= INF ? -1 : d[n]);
  return 0;
}