Problem p03140 (C++)

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

using namespace std;

#define REP(var, n) for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)                                                           \
  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b) for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b) for (auto var = b - 1; var != a; var--)

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

#define all(c) begin(c), end(c)

#define D(x)                                                                   \
  do {                                                                         \
    std::cerr << x;                                                            \
  } while (0)
#define D2(x)                                                                  \
  do {                                                                         \
    std::cerr << #x << ": " << x << std::endl;                                 \
  } while (0)

template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  if (!v.empty()) {
    out << '[';
    std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
    out << "\b\b]";
  }
  return out;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << '(' << p.first << ',' << p.second << ')';
}

auto solve() {
  int n;
  cin >> n;
  vector<string> st(n);
  for (auto &&e : st)
    cin >> e;
  int res = 0;
  REP(j, n) {
    set<char> diff;
    REP(i, 3) { diff.insert(st[i][j]); }

    res += diff.size() - 1;
  }

  return res;
}

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

  //    cout << (solve() ? "Yes" : "No") << endl;
  //    cout << (solve() ? "YES" : "NO") << endl;
  cout << solve() << endl;
  //    solve();

  return 0;
}


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

using namespace std;

#define REP(var, n) for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)                                                           \
  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b) for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b) for (auto var = b - 1; var != a; var--)

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

#define all(c) begin(c), end(c)

#define D(x)                                                                   \
  do {                                                                         \
    std::cerr << x;                                                            \
  } while (0)
#define D2(x)                                                                  \
  do {                                                                         \
    std::cerr << #x << ": " << x << std::endl;                                 \
  } while (0)

template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
  if (!v.empty()) {
    out << '[';
    std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
    out << "\b\b]";
  }
  return out;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << '(' << p.first << ',' << p.second << ')';
}

auto solve() {
  int n;
  cin >> n;
  vector<string> st(3);
  for (auto &&e : st)
    cin >> e;
  int res = 0;
  REP(j, n) {
    set<char> diff;
    REP(i, 3) { diff.insert(st[i][j]); }

    res += diff.size() - 1;
  }

  return res;
}

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

  //    cout << (solve() ? "Yes" : "No") << endl;
  //    cout << (solve() ? "YES" : "NO") << endl;
  cout << solve() << endl;
  //    solve();

  return 0;
}