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

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

#define int long long

using namespace std;
const int inf = 1e18;
int x[111111], dp[111111], st[444444] = {inf};
int upd(int l, int r, int cur, int ind, int val) {
  if (ind < l or r < ind or r < l)
    return inf;
  if (l == r)
    return st[cur] = val;
  int mid = (l + r) / 2;
  upd(mid + 1, r, cur * 2 + 2, ind, val);
  upd(l, mid, cur * 2 + 1, ind, val);
  return st[cur] = min(st[cur * 2 + 1], st[cur * 2 + 2]);
}
int mn(int l, int r, int sl, int sr, int cur) {
  if (sr < l or r < sl or r < l or sr < sl)
    return inf;
  if (l == r)
    return st[cur];
  int mid = (l + r) / 2;
  return min(mn(l, mid, sl, sr, cur * 2 + 1),
             mn(mid + 1, r, sl, sr, cur * 2 + 2));
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, t, e;
  cin >> n >> e >> t;
  for (int i = 1; i <= n; i++)
    cin >> x[i];

  upd(0, n, 0, 0, -2 * x[1]);

  for (int i = 1; i <= n; i++) {
    int j = lower_bound(x + 1, x + n + 1, x[i] - t / 2.0) - x;
    if ((x[i] - x[j]) * 2 < t)
      j--;
    dp[i] = min(dp[j] + t, mn(0, n, 0, j - 1, 0) + 2 * x[i]);
    // cout << i << ' ' << j << ' ' << dp[i] << endl;

    upd(0, n, 0, i, dp[i] - 2 * x[i + 1]);
  }
  cout << dp[n] + e << endl;
  return 0;
}


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

#define int long long

using namespace std;
const int inf = 1e18;
int x[111111], dp[111111], st[444444] = {inf};
int upd(int l, int r, int cur, int ind, int val) {
  if (ind < l or r < ind or r < l)
    return inf;
  if (l == r)
    return st[cur] = val;
  int mid = (l + r) / 2;
  upd(mid + 1, r, cur * 2 + 2, ind, val);
  upd(l, mid, cur * 2 + 1, ind, val);
  return st[cur] = min(st[cur * 2 + 1], st[cur * 2 + 2]);
}
int mn(int l, int r, int sl, int sr, int cur) {
  if (sr < l or r < sl or r < l or sr < sl)
    return inf;
  if (sl <= l and r <= sr)
    return st[cur];
  if (l == r)
    return st[cur];
  int mid = (l + r) / 2;
  return min(mn(l, mid, sl, sr, cur * 2 + 1),
             mn(mid + 1, r, sl, sr, cur * 2 + 2));
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, t, e;
  cin >> n >> e >> t;
  for (int i = 1; i <= n; i++)
    cin >> x[i];

  upd(0, n, 0, 0, -2 * x[1]);

  for (int i = 1; i <= n; i++) {
    int j = lower_bound(x + 1, x + n + 1, x[i] - t / 2.0) - x;
    if ((x[i] - x[j]) * 2 < t)
      j--;
    dp[i] = min(dp[j] + t, mn(0, n, 0, j - 1, 0) + 2 * x[i]);
    // cout << i << ' ' << j << ' ' << dp[i] << endl;

    upd(0, n, 0, i, dp[i] - 2 * x[i + 1]);
  }
  cout << dp[n] + e << endl;
  return 0;
}
Problem p03941 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int p[150010], q[150010], fa[150010], len[150010];
vector<pair<long long, long long>> vec[150010], ls;
void dfs(int s, long long lim) {
  if (!p[s]) {
    vec[s].push_back(make_pair(len[s], len[s]));
    return;
  }
  dfs(p[s], lim);
  dfs(q[s], lim);
  if (vec[p[s]].size() > vec[q[s]].size())
    swap(p[s], q[s]);
  ls.clear();
  for (int k = 0; k < vec[p[s]].size(); k++) {
    int w = lower_bound(vec[q[s]].begin(), vec[q[s]].end(),
                        make_pair(lim - vec[p[s]][k].second + 1, 0ll)) -
            vec[q[s]].begin();
    if (w > 0) {
      w--;
      ls.push_back(
          make_pair(vec[p[s]][k].first + len[s], vec[q[s]][w].second + len[s]));
      ls.push_back(
          make_pair(vec[q[s]][w].second + len[s], vec[p[s]][k].first + len[s]));
    }
  }
  sort(ls.begin(), ls.end());
  long long mx = 1e18;
  for (int i = 0; i < ls.size(); i++)
    if (ls[i].second < mx) {
      mx = ls[i].second;
      vec[s].push_back(ls[i]);
    }
}
int n;
bool check(long long x) {
  for (int i = 1; i <= n; i++)
    vec[i].clear();
  dfs(1, x);
  return vec[1].size();
}
int main() {
  long long l = 0, r = 0;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d%d", &fa[i], &len[i]);
    if (!p[fa[i]])
      p[fa[i]] = i;
    else
      q[fa[i]] = i;
    r += len[i];
  }
  // cerr<<check(4)<<endl;
  while (l + 1 != r) {
    long long mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  printf("%lld", r);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int p[150010], q[150010], fa[150010], len[150010];
vector<pair<long long, long long>> vec[150010], ls;
void dfs(int s, long long lim) {
  if (!p[s]) {
    vec[s].push_back(make_pair(len[s], len[s]));
    return;
  }
  dfs(p[s], lim);
  dfs(q[s], lim);
  if (vec[p[s]].size() > vec[q[s]].size())
    swap(p[s], q[s]);
  ls.clear();
  for (int k = 0; k < vec[p[s]].size(); k++) {
    int w = lower_bound(vec[q[s]].begin(), vec[q[s]].end(),
                        make_pair(lim - vec[p[s]][k].second + 1, 0ll)) -
            vec[q[s]].begin();
    if (w > 0) {
      w--;
      ls.push_back(
          make_pair(vec[p[s]][k].first + len[s], vec[q[s]][w].second + len[s]));
      ls.push_back(
          make_pair(vec[q[s]][w].second + len[s], vec[p[s]][k].first + len[s]));
    }
  }
  sort(ls.begin(), ls.end());
  long long mx = 1e18;
  for (int i = 0; i < ls.size(); i++)
    if (ls[i].second < mx) {
      mx = ls[i].second;
      vec[s].push_back(ls[i]);
    }
}
int n;
bool check(long long x) {
  for (int i = 1; i <= n; i++)
    vec[i].clear();
  dfs(1, x);
  return vec[1].size();
}
int main() {
  long long l = -1, r = 0;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d%d", &fa[i], &len[i]);
    if (!p[fa[i]])
      p[fa[i]] = i;
    else
      q[fa[i]] = i;
    r += len[i];
  }
  // cerr<<check(4)<<endl;
  while (l + 1 != r) {
    long long mid = (l + r) >> 1;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  printf("%lld", r);
}
Problem p03942 (C++)

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

typedef long long ll;
const int maxn = 1000005;

inline int gi() {
  char c = getchar();
  while (c < '0' || c > '9')
    c = getchar();
  int sum = 0;
  while ('0' <= c && c <= '9')
    sum = sum * 10 + c - 48, c = getchar();
  return sum;
}

int n;
char s[maxn], t[maxn];
int ans, l, r, q[maxn];

int main() {
  scanf("%d\n%s%s", &n, s + 1, t + 1);

  int i;
  for (i = 1; i <= n; ++i)
    if (s[i] != t[i])
      break;
  if (i > n)
    return puts("0");

  int up = n, down = n;
  l = 1;
  r = 0;
  while (down) {
    while (down && t[down - 1] == t[down])
      --down;
    while (up && (up > down || s[up] != t[down]))
      --up;
    if (!up)
      return puts("-1"), 0;
    while (l < r && q[l] - (r - l + 1) >= down)
      ++l;
    if (up != down)
      q[++r] = up;
    ans = max(ans, r - l + 2);
    --down;
  }

  printf("%d\n", ans);

  return 0;
}


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

typedef long long ll;
const int maxn = 1000005;

inline int gi() {
  char c = getchar();
  while (c < '0' || c > '9')
    c = getchar();
  int sum = 0;
  while ('0' <= c && c <= '9')
    sum = sum * 10 + c - 48, c = getchar();
  return sum;
}

int n;
char s[maxn], t[maxn];
int ans, l, r, q[maxn];

int main() {
  scanf("%d\n%s%s", &n, s + 1, t + 1);

  int i;
  for (i = 1; i <= n; ++i)
    if (s[i] != t[i])
      break;
  if (i > n)
    return puts("0"), 0;

  int up = n, down = n;
  l = 1;
  r = 0;
  while (down) {
    while (down && t[down - 1] == t[down])
      --down;
    while (up && (up > down || s[up] != t[down]))
      --up;
    if (!up)
      return puts("-1"), 0;
    while (l < r && q[l] - (r - l + 1) >= down)
      ++l;
    if (up != down)
      q[++r] = up;
    ans = max(ans, r - l + 2);
    --down;
  }

  printf("%d\n", ans);

  return 0;
}
Problem p03942 (C++)

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

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;

struct ad_set {
  int tag;
  deque<int> que;

  void subt(int x) { tag += x; }

  void push_front(int x) { que.push_front(x + tag); }
  void push_back(int x) { que.push_back(x + tag); }
  int back() { return que.back() - tag; }
  void pop_back() { que.pop_back(); }
  int size() { return que.size(); }
} tre;

int n;
char s[1000005], t[1000005];
int term[1000005], dest[1000005];
vector<int> occ[26];

int main() {
  scanf("%d%s%s", &n, s, t);
  rep(i, n) {
    s[i] -= 'a';
    t[i] -= 'a';
  }
  rep(i, n) occ[s[i]].push_back(i);
  int maxt = n - 1;
  for (int i = n - 1; i >= 0; i--) {
    maxt = min(maxt, i);
    vector<int>::iterator pos =
        upper_bound(occ[t[i]].begin(), occ[t[i]].end(), maxt);
    if (pos == occ[t[i]].begin()) {
      printf("-1\n");
      return 0;
    } else
      maxt = term[i] = *(--pos);
  }

  rep(i, n) dest[i] = -1;
  term[n] = -1;
  for (int i = n - 1; i >= 0; i--)
    if (term[i] != term[i + 1])
      dest[term[i]] = i;

  int ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (dest[i] == -1)
      continue;
    tre.subt(1);
    tre.push_front(i);
    while (tre.back() >= dest[i])
      tre.pop_back();
    tre.push_back(dest[i]);
    ans = max(ans, tre.size());
  }
  printf("%d\n", ans - 1);
  return 0;
}

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

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int INF = 1e9 + 7;

struct ad_set {
  int tag;
  deque<int> que;

  void subt(int x) { tag += x; }

  void push_front(int x) { que.push_front(x + tag); }
  void push_back(int x) { que.push_back(x + tag); }
  int back() { return que.back() - tag; }
  void pop_back() { que.pop_back(); }
  int size() { return que.size(); }
} tre;

int n;
char s[1000005], t[1000005];
int term[1000005], dest[1000005];
vector<int> occ[26];

int main() {
  scanf("%d%s%s", &n, s, t);
  rep(i, n) {
    s[i] -= 'a';
    t[i] -= 'a';
  }
  rep(i, n) occ[s[i]].push_back(i);
  int maxt = n - 1;
  for (int i = n - 1; i >= 0; i--) {
    maxt = min(maxt, i);
    vector<int>::iterator pos =
        upper_bound(occ[t[i]].begin(), occ[t[i]].end(), maxt);
    if (pos == occ[t[i]].begin()) {
      printf("-1\n");
      return 0;
    } else
      maxt = term[i] = *(--pos);
  }

  rep(i, n) dest[i] = -1;
  term[n] = -1;
  for (int i = n - 1; i >= 0; i--)
    if (term[i] != term[i + 1])
      dest[term[i]] = i;

  int ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (dest[i] == -1)
      continue;
    tre.subt(1);
    tre.push_front(i);
    while (tre.size() > 0 && tre.back() >= dest[i])
      tre.pop_back();
    tre.push_back(dest[i]);
    ans = max(ans, tre.size());
  }
  printf("%d\n", ans - 1);
  return 0;
}
Problem p03942 (C++)

Buggy submission (status: Runtime Error):
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template <class T> inline T next_num() {
  T i = 0;
  char c;
  while (!isdigit(c = getchar()) && c != '-')
    ;
  bool flag = c == '-';
  flag ? c = getchar() : 0;
  while (i = i * 10 - '0' + c, isdigit(c = getchar()))
    ;
  return flag ? -i : i;
}
template <class T1, class T2> inline void apmax(T1 &a, const T2 &b) {
  if (a < b)
    a = b;
}
template <class T1, class T2> inline void apmin(T1 &a, const T2 &b) {
  if (b < a)
    a = b;
}
const int N = 1000010;
char a[N], b[N];
deque<int> q;
inline int Main() {
  int n = ni;
  scanf("%s%s", a + 1, b + 1);
  q.push_back(n + 1);
  int delta = 0;
  int ans = 0;
  for (int i = n, j = n + 1; i >= 1; i--) {
    int last = j;
    for (; j >= 1 && (i < j || b[i] != a[j]); j--)
      ;
    if (j < 1)
      return -1;
    if (last == j) {
      for (; q.back() + delta >= i; q.pop_back())
        ;
      q.push_back(i - delta);
    } else {
      delta--;
      if (i != j) {
        apmax(ans, (int)q.size());
        q.push_front(j - delta);
      }
    }
  }
  return ans;
}
int main() {
  printf("%d\n", Main());
  return 0;
}

Fixed submission:
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template <class T> inline T next_num() {
  T i = 0;
  char c;
  while (!isdigit(c = getchar()) && c != '-')
    ;
  bool flag = c == '-';
  flag ? c = getchar() : 0;
  while (i = i * 10 - '0' + c, isdigit(c = getchar()))
    ;
  return flag ? -i : i;
}
template <class T1, class T2> inline void apmax(T1 &a, const T2 &b) {
  if (a < b)
    a = b;
}
template <class T1, class T2> inline void apmin(T1 &a, const T2 &b) {
  if (b < a)
    a = b;
}
const int N = 1000010;
char a[N], b[N];
deque<int> q;
inline int Main() {
  int n = ni;
  scanf("%s%s", a + 1, b + 1);
  q.push_back(n + 1);
  int delta = 0;
  int ans = 0;
  for (int i = n, j = n + 1; i >= 1; i--) {
    int last = j;
    for (; j >= 1 && (i < j || b[i] != a[j]); j--)
      ;
    if (j < 1)
      return -1;
    if (last == j) {
      for (; !q.empty() && q.back() + delta >= i; q.pop_back())
        ;
      q.push_back(i - delta);
    } else {
      delta--;
      if (i != j) {
        apmax(ans, (int)q.size());
        q.push_front(j - delta);
      }
    }
  }
  return ans;
}
int main() {
  printf("%d\n", Main());
  return 0;
}
Problem p03942 (C++)

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

const int N = 1e6 + 9;
int n, ans = 1, mx, q[N], he = 1, ta, tag;
char s[N], t[N];
deque<int> Q;

int main() {
  scanf("%d", &n);
  scanf("%s%s", s + 1, t + 1);
  if (strcmp(s + 1, t + 1) == 0)
    return puts("0"), 0;
  for (int i = n, la = 1e9, j = n; i; --i) {
    if (i > 1 && t[i] == t[i - 1])
      continue;
    if (j > i)
      j = i;
    while (j && s[j] != t[i])
      --j;
    if (!j)
      return puts("-1"), 0;
    --tag;
    Q.push_front(j - tag);
    while (Q.back() + tag >= la)
      Q.pop_back();
    //		if (he <= ta && i >= q[ta]) q[ta + 1] = q[ta] - 1, ++ta;
    //		ans = j == i ? 0 : ans + 1;
    //		if (ans > mx) mx = ans;
    if (Q.size() > mx)
      mx = Q.size();
    la = i - 1;
  }
  printf("%d\n", mx);
  return 0;
}
/*
8
asdfadsa
aadffdsa
*/

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

const int N = 1e6 + 9;
int n, ans = 1, mx, q[N], he = 1, ta, tag;
char s[N], t[N];
deque<int> Q;

int main() {
  scanf("%d", &n);
  scanf("%s%s", s + 1, t + 1);
  if (strcmp(s + 1, t + 1) == 0)
    return puts("0"), 0;
  for (int i = n, la = 1e9, j = n; i; --i) {
    if (i > 1 && t[i] == t[i - 1])
      continue;
    if (j > i)
      j = i;
    while (j && s[j] != t[i])
      --j;
    if (!j)
      return puts("-1"), 0;
    --tag;
    Q.push_front(j - tag);
    while (!Q.empty() && Q.back() + tag >= la)
      Q.pop_back();
    //		if (he <= ta && i >= q[ta]) q[ta + 1] = q[ta] - 1, ++ta;
    //		ans = j == i ? 0 : ans + 1;
    //		if (ans > mx) mx = ans;
    if (Q.size() > mx)
      mx = Q.size();
    la = i - 1;
  }
  printf("%d\n", mx);
  return 0;
}
/*
8
asdfadsa
aadffdsa
*/
Problem p03942 (C++)

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

using namespace std;

#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)
#define fi first
#define se second
#define mkp make_pair

typedef long long ll;

const int N = 1100000;

int n, ans, flag, s[N], t[N], pos[N], a[N], b[N];

int read() {
  int ret = 0, sig = 1;
  char c;
  while (c = getchar(), (c < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    sig = -1;
  else
    ret = c - '0';
  while (c = getchar(), c >= '0' && c <= '9')
    ret = ret * 10 + c - '0';
  return ret * sig;
}

int main() {
  n = read();
  fo(i, 1, n) {
    char c;
    while (c = getchar(), c < 'a' || c > 'z')
      ;
    s[i] = c - 'a' + 1;
  }
  fo(i, 1, n) {
    char c;
    while (c = getchar(), c < 'a' || c > 'z')
      ;
    t[i] = c - 'a' + 1;
    if (s[i] != t[i])
      flag = 1;
  }
  if (!flag) {
    printf("0\n");
    return 0;
  }
  int w = n + 1;
  b[0] = 1;
  fd(i, n + 1, 1) if (t[i] != t[i - 1]) {
    b[++b[0]] = i - 1;
    while (w && (w > i || s[w] != t[i]))
      w--;
    if (!w) {
      printf("-1\n");
      return 0;
    }
    a[++a[0]] = w;
  }
  int tail = 1;
  fo(i, 2, a[0]) {
    while (a[tail + 1] - (i - tail - 1) >= b[i])
      tail++;
    ans = max(ans, i - tail);
  }
  printf("%d\n", ans);
  return 0;
}

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

using namespace std;

#define fo(i, a, b) for (int i = a; i <= b; i++)
#define fd(i, a, b) for (int i = a; i >= b; i--)
#define fi first
#define se second
#define mkp make_pair

typedef long long ll;

const int N = 1100000;

int n, ans, flag, s[N], t[N], pos[N], a[N], b[N];

int read() {
  int ret = 0, sig = 1;
  char c;
  while (c = getchar(), (c < '0' || c > '9') && c != '-')
    ;
  if (c == '-')
    sig = -1;
  else
    ret = c - '0';
  while (c = getchar(), c >= '0' && c <= '9')
    ret = ret * 10 + c - '0';
  return ret * sig;
}

int main() {
  n = read();
  fo(i, 1, n) {
    char c;
    while (c = getchar(), c < 'a' || c > 'z')
      ;
    s[i] = c - 'a' + 1;
  }
  fo(i, 1, n) {
    char c;
    while (c = getchar(), c < 'a' || c > 'z')
      ;
    t[i] = c - 'a' + 1;
    if (s[i] != t[i])
      flag = 1;
  }
  if (!flag) {
    printf("0\n");
    return 0;
  }
  int w = n + 1;
  b[0] = 1;
  fd(i, n + 1, 1) if (t[i] != t[i - 1]) {
    b[++b[0]] = i - 1;
    while (w && (w > i || s[w] != t[i]))
      w--;
    if (!w) {
      printf("-1\n");
      return 0;
    }
    a[++a[0]] = w;
  }
  int tail = 1;
  fo(i, 2, a[0]) {
    while (tail < a[0] && a[tail + 1] - (i - tail - 1) >= b[i])
      tail++;
    ans = max(ans, i - tail);
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03943 (C++)

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

int main() {

  int a, b, c;
  cin >> a >> b >> c;

  vector<int> L(3);
  L = {a, b, c};

  sort(L.begin(), L.end());

  if (L.at(0) + L.at(1) == L.at(3)) {
    cout << "Yes" << endl;
  }

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


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

int main() {

  int a, b, c;
  cin >> a >> b >> c;

  vector<int> L(3);
  L = {a, b, c};

  sort(L.begin(), L.end());

  if (L.at(0) + L.at(1) == L.at(2)) {
    cout << "Yes" << endl;
  }

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

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

int main() {
  vector<int> v;
  for (int i = 0; i < 3; i++) {
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  if (v[0] + v[1] == v[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

int main() {
  vector<int> v;
  for (int i = 0; i < 3; i++) {
    int n;
    cin >> n;
    v.push_back(n);
  }
  sort(v.begin(), v.end());
  if (v[0] + v[1] == v[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
Problem p03943 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T> T sq(T x) { return x * x; }

signed main() {
  vector<ll> a;
  rep(i, 3) { cin >> a.at(i); }
  sort(all(a));

  if (a.at(0) + a.at(1) == a.at(2)) {
    cout << "Yes" << endl;
    return 0;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep2(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using ll = long long;
template <typename T> T sq(T x) { return x * x; }

signed main() {
  vector<ll> a(3);
  rep(i, 3) { cin >> a.at(i); }
  sort(all(a));

  if (a.at(0) + a.at(1) == a.at(2)) {
    cout << "Yes" << endl;
    return 0;
  } else {
    cout << "No" << endl;
  }
  return 0;
}
Problem p03943 (Python)

Buggy submission (status: Runtime Error):
packs = list(map(int, input().split())).sort()
if packs[2] - packs[1] == packs[0]:
    print("Yes")
else:
    print("No")


Fixed submission:
packs = sorted(list(map(int, input().split())))
if packs[2] - packs[1] == packs[0]:
    print("Yes")
else:
    print("No")
Problem p03943 (Python)

Buggy submission (status: Runtime Error):
from functools import reduce
from operator import add

A = list(map(int, input().split()))
print("Yes" if max(A) == reduce(add, [i for i in A if i != max(A)]) else "No")


Fixed submission:
from functools import reduce
from operator import add

A = list(map(int, input().split()))
M = max(A)
T = [i for i in A if i != M]
if len(T) == 0:
    print("No")
else:
    print("Yes" if M == reduce(add, T) else "No")
Problem p03943 (Python)

Buggy submission (status: Runtime Error):
a, b, c = map(int, input().split())

if sum(a, b, c) == max(a, b, c) * 2:
    print("Yes")
else:
    print("No")


Fixed submission:
a, b, c = map(int, input().split())

if a + b + c == max(a, b, c) * 2:
    print("Yes")
else:
    print("No")
Problem p03943 (Python)

Buggy submission (status: Runtime Error):
# 3個のパックにそれぞれ、a,b,c個のキャンディーが入っている
# キャンディーを2人に分ける際、個数が等しくなるか判定

# 入力
a = int(input())
b = int(input())
c = int(input())

# 処理
if a == b + c or b == a + c or c == a + b:
    print("Yes")
else:
    print("No")


Fixed submission:
# 3個のパックにそれぞれ、a,b,c個のキャンディーが入っている
# キャンディーを2人に分ける際、個数が等しくなるか判定

# 入力
a, b, c = map(int, input().split())

# 処理
if a == b + c or b == a + c or c == a + b:
    print("Yes")
else:
    print("No")
Problem p03943 (Python)

Buggy submission (status: Runtime Error):
a, b, c = map(int, input().split())

if a + b == c or b + c == a or c + a == b:
    print("Yes")
else:
    print("No")
a, b, c = map(int, input().split())

if a + b == c or b + c == a or c + a == b:
    print("Yes")
else:
    print("No")


Fixed submission:
a, b, c = map(int, input().split())

if a + b == c or b + c == a or c + a == b:
    print("Yes")
else:
    print("No")
Problem p03943 (C++)

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

int main(void) {
  vector<int> a;
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  if (a[0] + a[1] == a[2])
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}


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

int main(void) {
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(), a.end());
  if (a[0] + a[1] == a[2])
    cout << "Yes\n";
  else
    cout << "No\n";

  return 0;
}
Problem p03944 (C++)

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

int main(void) {
  int w, h, n;
  cin >> w >> h >> n;
  vector<vector<int>> rect(w, vector<int>(h, false));
  int x, y, a;
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> a;
    if (a == 1 || a == 2) {
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (a == 1) {
            rect[j][i] |= (j < x);
          } else {
            rect[j][i] |= (j >= x);
          }
        }
      }
    } else {
      for (int i = 0; i < w; i++) {
        for (int j = 0; j < h; j++) {
          if (a == 3) {
            rect[i][j] |= (j < y);
          } else {
            rect[i][j] |= (j >= y);
          }
        }
      }
    }
  }

  int area = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (!rect[i][j])
        area++;
    }
  }

  cout << area << endl;
  return 0;
}

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

int main(void) {
  int w, h, n;
  cin >> w >> h >> n;
  vector<vector<int>> rect(w, vector<int>(h, false));
  int x, y, a;
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> a;
    if (a == 1 || a == 2) {
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
          if (a == 1) {
            rect[j][i] |= (j < x);
          } else {
            rect[j][i] |= (j >= x);
          }
        }
      }
    } else {
      for (int i = 0; i < w; i++) {
        for (int j = 0; j < h; j++) {
          if (a == 3) {
            rect[i][j] |= (j < y);
          } else {
            rect[i][j] |= (j >= y);
          }
        }
      }
    }
  }

  int area = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (!rect[j][i])
        area++;
    }
  }

  cout << area << endl;
  return 0;
}
Problem p03944 (C++)

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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  vector<vector<int>> color(H, vector<int>(W, 0));
  int x, y, a;
  int area = 0;
  for (int i = 0; i < N; i++) {
    cin >> x >> y >> a;
    if (a == 1) {
      for (int j = 0; j < x; j++) {
        for (int k = 0; k < H; k++) {
          color.at(k).at(j) = 1;
        }
      }
    } else if (a == 2) {
      for (int j = x; j < W; j++) {
        for (int k = 0; k < H; k++) {
          color.at(k).at(j) = 1;
        }
      }
    } else if (a == 3) {
      for (int j = 0; j < W; j++) {
        for (int k = 0; k < y; k++) {
          color.at(k).at(j) = 1;
        }
      }
    } else if (a == 4) {
      for (int j = 0; j < W; j++) {
        for (int k = y; k < H; k++) {
          color.at(k).at(j) = 1;
        }
      }
    } else {
      cout << "error" << endl;
    }
  }
  for (int j = 0; j < W; j++) {
    for (int k = 0; k < H; k++) {
      if (color.at(j).at(k) == 1) {
        area++;
      }
    }
  }
  cout << area << endl;
}

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

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  vector<vector<int>> color(H, vector<int>(W, 0));
  int x, y, a;
  int area = 0;
  for (int i = 0; i < N; i++) {
    cin >> x >> y >> a;
    if (a == 1) {
      for (int j = 0; j < x; j++) {
        for (int k = 0; k < H; k++) {
          color.at(k).at(j) = 1;
        }
      }
    } else if (a == 2) {
      for (int j = x; j < W; j++) {
        for (int k = 0; k < H; k++) {
          color.at(k).at(j) = 1;
        }
      }
    } else if (a == 3) {
      for (int j = 0; j < W; j++) {
        for (int k = 0; k < y; k++) {
          color.at(k).at(j) = 1;
        }
      }
    } else if (a == 4) {
      for (int j = 0; j < W; j++) {
        for (int k = y; k < H; k++) {
          color.at(k).at(j) = 1;
        }
      }
    } else {
      cout << "error" << endl;
    }
  }
  for (int j = 0; j < W; j++) {
    for (int k = 0; k < H; k++) {
      if (color.at(k).at(j) == 0) {
        area++;
      }
    }
  }
  cout << area << endl;
}
Problem p03944 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INCANT                                                                 \
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(0),                            \
      cout << fixed << setprecision(20);
#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7LL;
const int INF = 2e9;
int W, H, N;
bool A[101][101];

int main() {
  INCANT;
  cin >> W >> H >> N;
  int a, x, y;
  rep(i, N) {
    cin >> x >> y >> a;
    if (a == 1) {
      rep(j, x) {
        rep(k, H) { A[k][j] = true; }
      }
    } else if (a == 2) {
      rep(j, W - x) {
        rep(k, H) { A[k][j + x] = true; }
      }
    } else if (a == 3) {
      rep(j, y) {
        rep(k, W) { A[j][k] = true; }
      }
    } else {
      rep(j, H - y) {
        rep(k, W) { A[j + x][k] = true; }
      }
    }
  }
  int cnt = 0;
  rep(i, H) rep(j, W) cnt += !A[i][j];
  cout << cnt << "\n";
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
#define INCANT                                                                 \
  cin.tie(0), cout.tie(0), ios::sync_with_stdio(0),                            \
      cout << fixed << setprecision(20);
#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7LL;
const int INF = 2e9;
int W, H, N;
bool A[101][101];

int main() {
  INCANT;
  cin >> W >> H >> N;
  int a, x, y;
  rep(i, N) {
    cin >> x >> y >> a;
    if (a == 1) {
      rep(j, x) {
        rep(k, H) { A[k][j] = true; }
      }
    } else if (a == 2) {
      rep(j, W - x) {
        rep(k, H) { A[k][j + x] = true; }
      }
    } else if (a == 3) {
      rep(j, y) {
        rep(k, W) { A[j][k] = true; }
      }
    } else {
      rep(j, H - y) {
        rep(k, W) { A[j + y][k] = true; }
      }
    }
  }
  int cnt = 0;
  rep(i, H) rep(j, W) cnt += !A[i][j];
  cout << cnt << "\n";
  return 0;
}
Problem p03944 (C++)

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

void set_right(vector<vector<int>> &P, uint xBase) {
  if (xBase >= P[0].size())
    return;
  for (uint x = xBase; x < P[0].size(); ++x) {
    for (uint y = 0; y < P.size(); ++y) {
      P[y][x] = 0;
    }
  }
};

void set_left(vector<vector<int>> &P, uint xBase) {
  for (uint x = 0; x < xBase; ++x) {
    for (uint y = 0; y < P.size(); ++y) {
      P[y][x] = 0;
    }
  }
};

void set_bottom(vector<vector<int>> &P, uint yBase) {
  for (uint y = 0; y < yBase; ++y) {
    for (uint x = 0; x < P[y].size(); ++x) {
      P[y][x] = 0;
    }
  }
};

void set_top(vector<vector<int>> &P, uint yBase) {
  if (yBase >= P.size())
    return;
  for (uint y = yBase; y < P.size(); ++y) {
    for (uint x = 0; x < P[y].size(); ++x) {
      P[y][x] = 0;
    }
  }
};

int main() {
  uint W, H, N;
  cin >> W >> H >> N;
  vector<vector<int>> P(W, vector<int>(W, 1));

  for (size_t i = 0; i < N; ++i) {
    uint x, y, a;
    cin >> x >> y >> a;

    if (a == 1) {
      set_left(P, x);
    } else if (a == 2) {
      set_right(P, x);
    } else if (a == 3) {
      set_bottom(P, y);
    } else if (a == 4) {
      set_top(P, y);
    }
  }

  int area = 0;
  for (uint y = 0; y < P.size(); ++y) {
    for (uint x = 0; x < P[0].size(); ++x) {
      area += P[y][x];
    }
  }
  cout << area << endl;
}

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

void set_right(vector<vector<int>> &P, uint xBase) {
  if (xBase >= P[0].size())
    return;
  for (uint x = xBase; x < P[0].size(); ++x) {
    for (uint y = 0; y < P.size(); ++y) {
      P[y][x] = 0;
    }
  }
};

void set_left(vector<vector<int>> &P, uint xBase) {
  for (uint x = 0; x < xBase; ++x) {
    for (uint y = 0; y < P.size(); ++y) {
      P[y][x] = 0;
    }
  }
};

void set_bottom(vector<vector<int>> &P, uint yBase) {
  for (uint y = 0; y < yBase; ++y) {
    for (uint x = 0; x < P[y].size(); ++x) {
      P[y][x] = 0;
    }
  }
};

void set_top(vector<vector<int>> &P, uint yBase) {
  if (yBase >= P.size())
    return;
  for (uint y = yBase; y < P.size(); ++y) {
    for (uint x = 0; x < P[y].size(); ++x) {
      P[y][x] = 0;
    }
  }
};

int main() {
  uint W, H, N;
  cin >> W >> H >> N;
  vector<vector<int>> P(H, vector<int>(W, 1));

  for (size_t i = 0; i < N; ++i) {
    uint x, y, a;
    cin >> x >> y >> a;

    if (a == 1) {
      set_left(P, x);
    } else if (a == 2) {
      set_right(P, x);
    } else if (a == 3) {
      set_bottom(P, y);
    } else if (a == 4) {
      set_top(P, y);
    }
  }

  int area = 0;
  for (uint y = 0; y < P.size(); ++y) {
    for (uint x = 0; x < P[0].size(); ++x) {
      area += P[y][x];
    }
  }
  cout << area << endl;
}
Problem p03944 (C++)

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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> array1;
  vector<int> array2;
  vector<int> array3;
  vector<int> array4;
  int x, y, a;
  int i;
  for (i = 0; i < n; ++i) {
    cin >> x >> y >> a;
    if (a == 1) {
      array1.push_back(x);
    } else if (a == 2) {
      array2.push_back(x);
    } else if (a == 3) {
      array3.push_back(y);
    } else if (a == 4) {
      array4.push_back(y);
    }
  }
  int maxx, minx, maxy, miny;
  if (array1.size() != 0) {
    maxx = array1.at(0);
    for (i = 0; i < array1.size(); ++i) {
      if (maxx < array1.at(i)) {
        maxx = array1.at(i);
      }
    }
  } else {
    maxx = 0;
  }
  if (array2.size() != 0) {
    minx = array2.at(0);
    for (i = 0; i < array2.size(); ++i) {
      if (minx > array2.at(i)) {
        minx = array2.at(i);
      }
    }
  } else {
    minx = w;
  }
  if (array3.size() != 0) {
    maxy = array1.at(0);
    for (i = 0; i < array3.size(); ++i) {
      if (maxy < array3.at(i)) {
        maxy = array3.at(i);
      }
    }
  } else {
    maxy = 0;
  }
  if (array4.size() != 0) {
    miny = array4.at(0);
    for (i = 0; i < array4.size(); ++i) {
      if (miny > array4.at(i)) {
        miny = array4.at(i);
      }
    }
  } else {
    miny = h;
  }
  if (maxx > minx || maxy > miny) {
    cout << 0 << endl;
  } else {
    cout << (minx - maxx) * (miny - maxy) << endl;
  }
  return 0;
}

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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> array1;
  vector<int> array2;
  vector<int> array3;
  vector<int> array4;
  int x, y, a;
  int i;
  for (i = 0; i < n; ++i) {
    cin >> x >> y >> a;
    if (a == 1) {
      array1.push_back(x);
    } else if (a == 2) {
      array2.push_back(x);
    } else if (a == 3) {
      array3.push_back(y);
    } else if (a == 4) {
      array4.push_back(y);
    }
  }
  int maxx, minx, maxy, miny;
  if (array1.size() != 0) {
    maxx = array1.at(0);
    for (i = 0; i < array1.size(); ++i) {
      if (maxx < array1.at(i)) {
        maxx = array1.at(i);
      }
    }
  } else {
    maxx = 0;
  }
  if (array2.size() != 0) {
    minx = array2.at(0);
    for (i = 0; i < array2.size(); ++i) {
      if (minx > array2.at(i)) {
        minx = array2.at(i);
      }
    }
  } else {
    minx = w;
  }
  if (array3.size() != 0) {
    maxy = array3.at(0);
    for (i = 0; i < array3.size(); ++i) {
      if (maxy < array3.at(i)) {
        maxy = array3.at(i);
      }
    }
  } else {
    maxy = 0;
  }
  if (array4.size() != 0) {
    miny = array4.at(0);
    for (i = 0; i < array4.size(); ++i) {
      if (miny > array4.at(i)) {
        miny = array4.at(i);
      }
    }
  } else {
    miny = h;
  }
  if (maxx > minx || maxy > miny) {
    cout << 0 << endl;
  } else {
    cout << (minx - maxx) * (miny - maxy) << endl;
  }
  return 0;
}
Problem p03944 (C++)

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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<vector<int>> s(h, vector<int>(w, 1));
  vector<int> x(n);
  vector<int> y(n);
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> x[i] >> y[i] >> a[i];
  for (int k = 0; k < n; k++) {
    if (a[k] == 1) {
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < x[k]; i++)
          s[i][j] = 0;
      }
    } else if (a[k] == 2) {
      for (int i = 0; i < h; i++) {
        for (int j = x[k]; j < w; j++)
          s[i][j] = 0;
      }
    } else if (a[k] == 3) {
      for (int i = 0; i < y[k]; i++) {
        for (int j = 0; j < w; j++)
          s[i][j] = 0;
      }
    } else {
      for (int i = y[k]; i < h; i++) {
        for (int j = 0; j < w; j++)
          s[i][j] = 0;
      }
    }
  }
  int sum = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++)
      sum += s[i][j];
  }
  cout << sum << endl;
  return 0;
}


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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<vector<int>> s(h, vector<int>(w, 1));
  vector<int> x(n);
  vector<int> y(n);
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> x[i] >> y[i] >> a[i];
  for (int k = 0; k < n; k++) {
    if (a[k] == 1) {
      for (int i = 0; i < h; i++) {
        for (int j = 0; j < x[k]; j++)
          s[i][j] = 0;
      }
    } else if (a[k] == 2) {
      for (int i = 0; i < h; i++) {
        for (int j = x[k]; j < w; j++)
          s[i][j] = 0;
      }
    } else if (a[k] == 3) {
      for (int i = 0; i < y[k]; i++) {
        for (int j = 0; j < w; j++)
          s[i][j] = 0;
      }
    } else {
      for (int i = y[k]; i < h; i++) {
        for (int j = 0; j < w; j++)
          s[i][j] = 0;
      }
    }
  }
  int sum = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++)
      sum += s[i][j];
  }
  cout << sum << endl;
  return 0;
}
Problem p03944 (C++)

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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<vector<int>> x(n, vector<int>(2));
  vector<int> k(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i).at(0) >> x.at(i).at(1) >> k.at(i);
  }

  vector<vector<int>> b(w, vector<int>(h));
  for (int i = 0; i < n; i++) {
    if (k.at(i) == 1) {
      for (int j = 0; j < x.at(i).at(0); j++) {
        for (int g = 0; g < h; g++) {
          b.at(j).at(g) = 1;
        }
      }
    } else if (k.at(i) == 2) {
      for (int j = x.at(i).at(0); j < w; j++) {
        for (int g = 0; g < h; g++) {
          b.at(j).at(g) = 1;
        }
      }
    } else if (k.at(i) == 3) {
      for (int j = 0; j < x.at(i).at(1); j++) {
        for (int g = 0; g < w; g++) {
          b.at(g).at(j) = 1;
        }
      }
    } else {
      for (int j = x.at(i).at(1); j < h; j++) {
        for (int g = 0; g < w; g++) {
          b.at(g).at(j) = 1;
        }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (b.at(i).at(j) == 0) {
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<vector<int>> x(n, vector<int>(2));
  vector<int> k(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i).at(0) >> x.at(i).at(1) >> k.at(i);
  }

  vector<vector<int>> b(w, vector<int>(h));
  for (int i = 0; i < n; i++) {
    if (k.at(i) == 1) {
      for (int j = 0; j < x.at(i).at(0); j++) {
        for (int g = 0; g < h; g++) {
          b.at(j).at(g) = 1;
        }
      }
    } else if (k.at(i) == 2) {
      for (int j = x.at(i).at(0); j < w; j++) {
        for (int g = 0; g < h; g++) {
          b.at(j).at(g) = 1;
        }
      }
    } else if (k.at(i) == 3) {
      for (int j = 0; j < x.at(i).at(1); j++) {
        for (int g = 0; g < w; g++) {
          b.at(g).at(j) = 1;
        }
      }
    } else {
      for (int j = x.at(i).at(1); j < h; j++) {
        for (int g = 0; g < w; g++) {
          b.at(g).at(j) = 1;
        }
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (b.at(j).at(i) == 0) {
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p03944 (C++)

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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> x(w);
  vector<int> y(h);
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i);
    cin >> y.at(i);
    cin >> A.at(i);
  }
  int x1 = 0, x2 = w, y1 = 0, y2 = h;
  for (int i = 0; i < n; i++) {
    if (A.at(i) == 1) {
      if (x1 < x.at(i))
        x1 = x.at(i);
    } else if (A.at(i) == 2) {
      if (x2 > x.at(i))
        x2 = x.at(i);
    } else if (A.at(i) == 3) {
      if (y1 < y.at(i))
        y1 = y.at(i);
    } else if (A.at(i) == 4) {
      if (y2 > y.at(i))
        y2 = y.at(i);
    }
  }
  int S = (x2 - x1) * (y2 - y1);
  if (x2 - x1 < 0 || y2 - y1 < 0)
    cout << 0 << endl;
  else
    cout << S << endl;
}

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

int main() {
  int w, h, n;
  cin >> w >> h >> n;
  vector<int> x(n);
  vector<int> y(n);
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> x.at(i);
    cin >> y.at(i);
    cin >> A.at(i);
  }
  int x1 = 0, x2 = w, y1 = 0, y2 = h;
  for (int i = 0; i < n; i++) {
    if (A.at(i) == 1) {
      if (x1 < x.at(i))
        x1 = x.at(i);
    } else if (A.at(i) == 2) {
      if (x2 > x.at(i))
        x2 = x.at(i);
    } else if (A.at(i) == 3) {
      if (y1 < y.at(i))
        y1 = y.at(i);
    } else if (A.at(i) == 4) {
      if (y2 > y.at(i))
        y2 = y.at(i);
    }
  }
  int S = (x2 - x1) * (y2 - y1);
  if (x2 - x1 < 0 || y2 - y1 < 0)
    cout << 0 << endl;
  else
    cout << S << endl;
}
Problem p03944 (C++)

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

int main() {
  int x, y, n;
  cin >> x >> y >> n;
  vector<vector<int>> data(n, vector<int>(3));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> data[i][j];
    }
  }
  set<int> a, b, c, d;
  for (int i = 0; i < n; i++) {
    if (data[i][2] == 1)
      a.insert(data[i][0]);
    if (data[i][2] == 2)
      b.insert(data[i][0]);
    if (data[i][2] == 3)
      c.insert(data[i][1]);
    if (data[i][2] == 4)
      d.insert(data[i][1]);
  }
  int minx = *rbegin(a);
  int maxx = *begin(b);
  int miny = *rbegin(c);
  int maxy = *begin(d);
  int S;
  if (minx >= maxx)
    S = 0;
  if (minx < maxx) {
    if (miny >= maxy) {
      S = 0;
    }
    if (miny < maxy) {
      S = (maxx - minx) * (maxy - miny);
    }
  }

  cout << S << endl;
  return 0;
}

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

int main() {
  int x, y, n;
  cin >> x >> y >> n;
  vector<vector<int>> data(n, vector<int>(3));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> data[i][j];
    }
  }
  set<int> a, b, c, d;
  for (int i = 0; i < n; i++) {
    if (data[i][2] == 1)
      a.insert(data[i][0]);
    if (data[i][2] == 2)
      b.insert(data[i][0]);
    if (data[i][2] == 3)
      c.insert(data[i][1]);
    if (data[i][2] == 4)
      d.insert(data[i][1]);
  }
  int minx;
  if (!a.empty())
    minx = *rbegin(a);
  else
    minx = 0;
  int maxx;
  if (!b.empty())
    maxx = *begin(b);
  else
    maxx = x;

  int miny;
  if (!c.empty())
    miny = *rbegin(c);
  else
    miny = 0;

  int maxy;
  if (!d.empty())
    maxy = *begin(d);
  else
    maxy = y;

  int S;
  if (minx >= maxx)
    S = 0;
  if (minx < maxx) {
    if (miny >= maxy) {
      S = 0;
    }
    if (miny < maxy) {
      S = (maxx - minx) * (maxy - miny);
    }
  }

  cout << S << endl;
  return 0;
}
Problem p03944 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
#define NtoM(N, M) for (int i = N; i < M; i++)
#define Nfor(N) for (int j = 0; j < N; j++)

using namespace std;

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  vector<vector<int>> board(H, vector<int>(W));
  for (int i = 0; i < N; i++) {
    int x, y, a;
    cin >> x >> y >> a;
    switch (a) {
    case 1:
      NtoM(0, x) { Nfor(H) board[i][j] = 1; }
      break;
    case 2:
      NtoM(x, W) { Nfor(H) board[i][j] = 1; }
      break;
    case 3:
      NtoM(0, y) { Nfor(W) board[j][i] = 1; }
      break;
    case 4:
      NtoM(y, H) { Nfor(W) board[j][i] = 1; }
      break;
    }
  }
  int sum = 0;
  NtoM(0, W) {
    Nfor(H) {
      if (board[i][j] == 0)
        sum++;
    }
  }
  cout << sum << endl;
}

Fixed submission:
#include <iostream>
#include <vector>
#define NtoM(N, M) for (int i = N; i < M; i++)
#define Nfor(N) for (int j = 0; j < N; j++)

using namespace std;

int main() {
  int W, H, N;
  cin >> W >> H >> N;
  vector<vector<int>> board(W, vector<int>(H));
  for (int k = 0; k < N; k++) {
    int x, y, a;
    cin >> x >> y >> a;
    switch (a) {
    case 1:
      NtoM(0, x) { Nfor(H) board[i][j] = 1; }
      break;
    case 2:
      NtoM(x, W) { Nfor(H) board[i][j] = 1; }
      break;
    case 3:
      NtoM(0, y) { Nfor(W) board[j][i] = 1; }
      break;
    case 4:
      NtoM(y, H) { Nfor(W) board[j][i] = 1; }
      break;
    }
  }
  int sum = 0;
  NtoM(0, W) {
    Nfor(H) {
      if (board[i][j] == 0)
        sum++;
    }
  }
  cout << sum << endl;
}
Problem p03945 (C++)

Buggy submission (status: Time Limit Exceeded):
//
#include <iostream>
#include <string>

using namespace std;

#define REP(i, m, n) for (int i = m; i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) (x).begin(), (x).end()

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

void op(string &str) {
  while (1) {
    auto pos = str.find("BBB");
    if (pos != -1)
      str.replace(pos, 2, "B");
    pos = str.find("BB");
    if (pos != -1)
      str.replace(pos, 2, "B");
    else
      break;
  }
  while (1) {
    auto pos = str.find("WWW");
    if (pos != -1)
      str.replace(pos, 2, "W");
    pos = str.find("WW");
    if (pos != -1)
      str.replace(pos, 2, "W");
    else
      break;
  }
  return;
}

int main() {
  string str;
  cin >> str;
  op(str);
  printf("%lu\n", str.size() - 1);
  return 0;
}


Fixed submission:
//
#include <iostream>
#include <string>

using namespace std;

#define REP(i, m, n) for (int i = m; i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define ALL(x) (x).begin(), (x).end()

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

void op(string &str) {
  while (1) {
    auto pos = str.find("BBB");
    if (pos != -1)
      str.replace(pos, 2, "B");
    pos = str.find("BB");
    if (pos != -1)
      str.replace(pos, 2, "B");
    else
      break;
  }
  while (1) {
    auto pos = str.find("WWW");
    if (pos != -1)
      str.replace(pos, 2, "W");
    pos = str.find("WW");
    if (pos != -1)
      str.replace(pos, 2, "W");
    else
      break;
  }
  return;
}

int main() {
  string str;
  cin >> str;
  // op(str);
  // printf("%lu\n", str.size()-1);
  int counter = 0;
  char before = str[0], after;
  REP(i, 1, str.size()) {
    after = str[i];
    if (after != before)
      counter++;
    before = after;
  }
  printf("%d\n", counter);

  return 0;
}
Problem p03945 (C++)

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

using namespace std;

char a[10010];
int main() {
  scanf("%s", a);
  int ans = 0;
  int len = strlen(a);
  for (int i = 1; i < len; i++) {
    if (a[i] != a[i - 1])
      ans++;
  }
  cout << ans;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

char a[1000010];
int main() {
  scanf("%s", a);
  int ans = 0;
  int len = strlen(a);
  for (int i = 1; i < len; i++) {
    if (a[i] != a[i - 1])
      ans++;
  }
  cout << ans;
}
Problem p03945 (C++)

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

typedef long long ll;
string S;

int main() {
  cin >> S;

  int ans = 0;
  for (int i = 0; i <= S.size() - 2; i++) {
    if (S[i] != S[i + 1])
      ans++;
  }
  cout << ans << endl;
}

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

typedef long long ll;
string S;

int main() {
  cin >> S;

  if (S.size() == 1) {
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i <= S.size() - 2; i++) {
    if (S[i] != S[i + 1])
      ans++;
  }
  cout << ans << endl;
}