Problem p00544 (C++)

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

#define int long long int
#define rep(a, b, c) for (int a = b; a < c; a++)
#define repm(a, b, c) for (int a = (b - 1); a >= c; a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d", &a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int strnum(str s) {
  double ans = 0;
  rep(i, 0, s.length()) { ans += (s[i] - '0') * pow(10, s.length() - i - 1); }
  return (int)ans;
}
inline string numstr(int m) {
  str s = "";
  while (m > 0) {
    char c;
    int a = m / 10;
    if (a > 0)
      a = m % (a * 10);
    else
      a = m;
    c = (char)('0' + a);
    s += c;
    m /= 10;
  }
  str st = "";
  for (int i = s.size() - 1; i >= 0; i--) {
    st += s[i];
  }
  return st;
}
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  str s[21];
  rep(i, 0, n) { cin >> s[i]; }
  int a, b, c, ans = INF, num = 0;
  rep(i, 0, n - 2) {
    a = 0;
    // a=i;
    rep(u, 0, i + 1) {
      rep(l, 0, m) {
        if (s[u][l] != 'W')
          a++;
      }
    }
    rep(j, i + 1, n - 1) {
      b = 0;
      rep(u, i + 1, j + 1) {
        rep(l, 0, m) {
          if (s[u][l] != 'B')
            b++;
        }
      }
      c = 0;
      rep(k, j + 1, n) {
        rep(l, 0, m) {
          if (s[k][l] != 'R')
            c++;
        }
      }
      if (ans > (a + b + c)) {
        // cout << a <<" "<< b <<" "<<c << endl;
        // cout << i <<j<<(n-j) << endl;
        ans = (a + b + c);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define int long long int
#define rep(a, b, c) for (int a = b; a < c; a++)
#define repm(a, b, c) for (int a = (b - 1); a >= c; a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d", &a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int strnum(str s) {
  double ans = 0;
  rep(i, 0, s.length()) { ans += (s[i] - '0') * pow(10, s.length() - i - 1); }
  return (int)ans;
}
inline string numstr(int m) {
  str s = "";
  while (m > 0) {
    char c;
    int a = m / 10;
    if (a > 0)
      a = m % (a * 10);
    else
      a = m;
    c = (char)('0' + a);
    s += c;
    m /= 10;
  }
  str st = "";
  for (int i = s.size() - 1; i >= 0; i--) {
    st += s[i];
  }
  return st;
}
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  str s[51];
  rep(i, 0, n) { cin >> s[i]; }
  int a, b, c, ans = INF, num = 0;
  rep(i, 0, n - 2) {
    a = 0;
    // a=i;
    rep(u, 0, i + 1) {
      rep(l, 0, m) {
        if (s[u][l] != 'W')
          a++;
      }
    }
    rep(j, i + 1, n - 1) {
      b = 0;
      rep(u, i + 1, j + 1) {
        rep(l, 0, m) {
          if (s[u][l] != 'B')
            b++;
        }
      }
      c = 0;
      rep(k, j + 1, n) {
        rep(l, 0, m) {
          if (s[k][l] != 'R')
            c++;
        }
      }
      if (ans > (a + b + c)) {
        // cout << a <<" "<< b <<" "<<c << endl;
        // cout << i <<j<<(n-j) << endl;
        ans = (a + b + c);
      }
    }
  }
  cout << ans << endl;
  return 0;
}