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

Buggy submission (status: Runtime Error):
// by The_One_Solver
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
long long n, m, f = 1, c = 1, h = 1, odd = 1;
int main() {

  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    c *= i;
    if (i <= (n - 2))
      f *= i;
  }
  for (int i = 1; i <= m; i++) {
    odd *= i;
    if (i <= m - 2)
      h *= i;
  }
  cout << (c / (f * 2)) + (odd / (h * 2));
  return 0;
}


Fixed submission:
// by The_One_Solver
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
long long n, m, f = 1, c = 1, h = 1, odd = 1;
int main() {

  cin >> n >> m;

  cout << (n > 1 ? (n * (n - 1)) / 2 : 0) + (m > 1 ? (m * (m - 1)) / 2 : 0)
       << endl;
}
Problem p02729 (C++)

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

int main() {
  int N, M;
  cin >> N >> M;

  int all = 1;
  int A = 1;

  for (int i = 1; i <= N + M; i++) {
    all *= i;
  }

  if (N + M == 2) {
    A = 1;
  } else {
    for (int i = 1; i <= N + M - 2; i++) {
      A *= i;
    }
  }

  cout << all / 2 / A - N * M << endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  cout << (N * N + M * M - N - M) / 2 << endl;
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define pb push_back
#define endl "\n"
ll fact(int a) {
  if (a == 0)
    return 1;
  return a * fact(a - 1);
}
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, m;
  cin >> n >> m;
  ll ans = 0;
  cout << fact(n) / (2 * fact(n - 2)) + fact(m) / (2 * fact(m - 2));

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define pb push_back
#define endl "\n"
ll fact(int a) {
  if (a == 0)
    return 1;
  return a * fact(a - 1);
}
using namespace std;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll n, m;
  cin >> n >> m;

  cout << (n * (n - 1)) / 2 + (m * (m - 1)) / 2;

  return 0;
}
Problem p02729 (C++)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, cnt, a[100];
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    a[i] = i * 2;
  }
  for (int j = n; j < n + m; j++) {
    a[j] = j * 2 + 1;
  }
  for (int k = 0; k < n + m; k++) {
    for (int l = k + 1; l < n + m; l++) {
      if ((a[k] + a[l]) % 2 != 0) {
        continue;
      } else {
        cnt++;
      };
    }
  }
  cout << cnt << "\n";
  return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, cnt, a[n + m];
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    a[i] = i * 2;
  }
  for (int j = n; j < n + m; j++) {
    a[j] = j * 2 + 1;
  }
  for (int k = 0; k < n + m; k++) {
    for (int l = k + 1; l < n + m; l++) {
      if ((a[k] + a[l]) % 2 != 0) {
        continue;
      } else {
        cnt++;
      };
    }
  }
  cout << cnt << "\n";
  return 0;
}
Problem p02729 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main() {
  int N; // even
  int M; // odd
  unsigned sum;
  while (scanf("%d%d", &N, &M)) {
    sum = (N * N + M * M - M - N) >> 1;
    printf("%d\n", sum);
  }
}

Fixed submission:
#include <stdio.h>
int main() {
  int N; // even
  int M; // odd
  unsigned sum;
  scanf("%d%d", &N, &M);
  sum = (N * N + M * M - M - N) >> 1;
  printf("%d\n", sum);
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int a = 1, b = 1, c = 1, d = 1;
  for (int i = 1; i < N + 1; i++)
    a *= i;
  for (int i = N; i > 0; i--) {
    if (N <= 1)
      b = 0;
    else
      b *= i;
  }
  for (int j = 1; j < M + 1; j++)
    c *= j;
  for (int j = M; j > 0; j--) {
    if (M <= 1)
      d = 0;
    else
      d *= j;
  }
  cout << b / a + d / c << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

#define int long long
#define val(x) cout << #x << " equals to " << x << endl
#define F first
#define S second
#define pb push_back

const int N = 2e6 + 7;
const int INF = 1e18;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

#ifndef ONLINE_JUDGE
  freopen("/home/emrey/Coding/IO/in.txt", "r", stdin);
  // freopen("/home/emrey/Coding/IO/out.txt", "w", stdout);
#endif

  int n, m;
  cin >> n >> m;
  cout << ((n * (n - 1) / 2) + (m * (m - 1) / 2)) << endl;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

#define int long long
#define val(x) cout << #x << " equals to " << x << endl
#define F first
#define S second
#define pb push_back

const int N = 2e6 + 7;
const int INF = 1e18;

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

#ifndef ONLINE_JUDGE
  // freopen("/home/emrey/Coding/IO/in.txt", "r", stdin);
  // freopen("/home/emrey/Coding/IO/out.txt", "w", stdout);
#endif

  int n, m;
  cin >> n >> m;
  cout << ((n * (n - 1) / 2) + (m * (m - 1) / 2)) << endl;
}
Problem p02729 (Python)

Buggy submission (status: Runtime Error):
import math


def f(x):
    return math.factorial(x)


arr = list(map(int, input().split()))
n = arr[0]
m = arr[1]
cnt = 0
cnt += int(f(n) / (2 * f(n - 2)))
if m > 1:
    cnt += int(f(m) / (2 * f(m - 2)))
print(int(cnt))


Fixed submission:
n, m = map(int, input().split())
print((n * (n - 1)) // 2 + (m * (m - 1)) // 2)
Problem p02729 (Python)

Buggy submission (status: Runtime Error):
N, M = map(int, input().split())

print(N(N - 1) // 2 + M(M - 1) // 2)


Fixed submission:
N, M = map(int, input().split())

print(N * (N - 1) // 2 + M * (M - 1) // 2)
Problem p02729 (Python)

Buggy submission (status: Runtime Error):
import math

n, m = map(int, input().split())


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


ans = combinations_count(m, 2) + combinations_count(n, 2)

print(ans)


Fixed submission:
import math

n, m = map(int, input().split())


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


if n >= 2 and m >= 2:
    ans = combinations_count(m, 2) + combinations_count(n, 2)
elif n < 2 and m < 2:
    ans = 0
elif n < 2:
    ans = combinations_count(m, 2)
elif m < 2:
    ans = combinations_count(n, 2)


print(ans)
Problem p02729 (Python)

Buggy submission (status: Runtime Error):
from scipy.special import comb

n, m = map(int, input().split())
# nC2+mC2を求めればよい
print(comb(n, 2, exact=True) + comb(m, 2, exact=True))


Fixed submission:
from scipy.misc import comb

n, m = map(int, input().split())
# nC2+mC2を求めればよい
print(comb(n, 2, exact=True) + comb(m, 2, exact=True))
Problem p02729 (Python)

Buggy submission (status: Runtime Error):
import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def main():
    n, m = map(int, input().split())
    print(combinations_count(n, 2) + combinations_count(m, 2))


if __name__ == "__main__":
    main()


Fixed submission:
import math


def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def main():
    n, m = map(int, input().split())
    if n < 2:
        even = 0
    else:
        even = combinations_count(n, 2)
    if m < 2:
        odd = 0
    else:
        odd = combinations_count(m, 2)
    print(even + odd)


if __name__ == "__main__":
    main()
Problem p02729 (Python)

Buggy submission (status: Runtime Error):
N, M = list(int, input().split())

print(int(N * (N - 1) / 2 + M * (M - 1) / 2))


Fixed submission:
N, M = map(int, input().split())

print(int(N * (N - 1) / 2 + M * (M - 1) / 2))
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
/*
Author- Aasav Badera
Time- Sun Mar 22 17:30:45 2020
*/
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define s second
#define mii map<ll, ll>
#define dbg(x)                                                                 \
  { cerr << #x << ": " << x << endl; }
#define dbg2(x, y)                                                             \
  { cerr << #x << ": " << x << " , " << #y << ": " << y << endl; }
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define pii pair<ll, ll>
#define ppb pop_back
#define f first
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define si set<ll>
#define all(a) (a).begin(), (a).end()
#define sz(x) (ll) x.size()
#define hell 1000000007
#define mp make_pair
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define inf 1e18L + 1
#define endl '\n'
using namespace std;
#define N 300005

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("output.txt", "w", stdout);
#endif
  ll tests = 1;
  // cin >> tests;
  while (tests--) {
    ll n, m;
    cin >> n >> m;
    ll ans = n * (n - 1) + m * (m - 1);
    ans /= 2;
    cout << ans;
  }
  return 0;
}

Fixed submission:
/*
Author- Aasav Badera
Time- Sun Mar 22 17:30:45 2020
*/
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define s second
#define mii map<ll, ll>
#define dbg(x)                                                                 \
  { cerr << #x << ": " << x << endl; }
#define dbg2(x, y)                                                             \
  { cerr << #x << ": " << x << " , " << #y << ": " << y << endl; }
#define rep(i, a, b) for (ll i = a; i < b; i++)
#define pii pair<ll, ll>
#define ppb pop_back
#define f first
#define vi vector<ll>
#define vii vector<pair<ll, ll>>
#define si set<ll>
#define all(a) (a).begin(), (a).end()
#define sz(x) (ll) x.size()
#define hell 1000000007
#define mp make_pair
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define inf 1e18L + 1
#define endl '\n'
using namespace std;
#define N 300005

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ll tests = 1;
  // cin >> tests;
  while (tests--) {
    ll n, m;
    cin >> n >> m;
    ll ans = n * (n - 1) + m * (m - 1);
    ans /= 2;
    cout << ans;
  }
  return 0;
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>

int main() {
  int N, M;
  int Ball[201];

  freopen("input.txt", "r", stdin);

  scanf("%d %d", &N, &M);

  int BallCnt = 0;
  for (int n = 1; n <= N; n++) // even
    Ball[BallCnt++] = 2 * n;

  for (int m = 0; m < M; m++) // odd
    Ball[BallCnt++] = 2 * m + 1;

  int ResultCnt = 0;
  for (int b = 0; b < BallCnt; b++)
    for (int t = 0; t < BallCnt; t++)
      if (b != t)
        if ((Ball[b] + Ball[t]) % 2 == 0)
          ResultCnt++;

  printf("%d", ResultCnt / 2);
  return 0;
}

Fixed submission:
#include <stdio.h>

int main() {
  int N, M;
  int Ball[201];

  scanf("%d %d", &N, &M);

  int BallCnt = 0;
  for (int n = 1; n <= N; n++) // even
    Ball[BallCnt++] = 2 * n;

  for (int m = 0; m < M; m++) // odd
    Ball[BallCnt++] = 2 * m + 1;

  int ResultCnt = 0;
  for (int b = 0; b < BallCnt; b++)
    for (int t = 0; t < BallCnt; t++)
      if (b != t)
        if ((Ball[b] + Ball[t]) % 2 == 0)
          ResultCnt++;

  printf("%d", ResultCnt / 2);
  return 0;
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n, m) for (int i = n; i >= m; i--)
#define mod 1000000007
#define float long double
#define pb push_back
#define mp make_pair
using namespace std;

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
int binomialCoeff(int n, int k) {
  // Base Cases
  if (k == 0 || k == n)
    return 1;

  // Recur
  return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k);
}
void solve() {
  int n, m, total = 0;
  cin >> n >> m;
  if (n > 1)
    total += binomialCoeff(n, 2);
  if (m > 1)
    total += binomialCoeff(m, 2);
  cout << total;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n, m) for (int i = n; i >= m; i--)
#define mod 1000000007
#define float long double
#define pb push_back
#define mp make_pair
using namespace std;

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
int binomialCoeff(int n, int k) {
  // Base Cases
  if (k == 0 || k == n)
    return 1;

  // Recur
  return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k);
}
void solve() {
  int n, m, total = 0;
  cin >> n >> m;
  if (n > 1)
    total += binomialCoeff(n, 2);
  if (m > 1)
    total += binomialCoeff(m, 2);
  cout << total;
}
signed main() {

  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, m, a, ans;
  cin >> n >> m;
  if (n == 1 && m == 1)
    cout << "0" << endl;
  else if ((n + m) % 2 != 0) {
    a = n / m + 1;
    ans = pow(m, a);
    cout << ans << endl;
  } else {
    a = n / m;
    ans = pow(m, a);
    cout << ans << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M, ans;
  cin >> N >> M;
  ans = N * (N - 1) / 2 + M * (M - 1) / 2;
  cout << ans << endl;
  return 0;
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(p, a, b) for (int p = a; p < b; p++)
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define INF 0x3f3f3f3f

int C(int n, int r) {
  int ans = 1;
  if (r > n - r)
    r = n - r;

  for (int i = 0; i < r; i++) {
    ans *= ((n - i) / (i + 1));
  }

  return ans;
}

int main() {

#ifndef ONLINE_JUDGE
  // for getting input from input.txt
  freopen("input.txt", "r", stdin);
  // for writing output to output.txt
  freopen("o2.txt", "w", stdout);
#endif

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, k, i, t, ans = 0;
  cin >> n >> k;

  if (n)
    ans = n * (n - 1) / 2;
  if (k)
    ans += k * (k - 1) / 2;
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(p, a, b) for (int p = a; p < b; p++)
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define INF 0x3f3f3f3f

int C(int n, int r) {
  int ans = 1;
  if (r > n - r)
    r = n - r;

  for (int i = 0; i < r; i++) {
    ans *= ((n - i) / (i + 1));
  }

  return ans;
}

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

  ll n, k, i, t, ans = 0;
  cin >> n >> k;

  if (n)
    ans = n * (n - 1) / 2;
  if (k)
    ans += k * (k - 1) / 2;
  cout << ans;
  return 0;
}
Problem p02729 (Python)

Buggy submission (status: Runtime Error):
while True:
    m, n = list(map(int, input().split()))
    print(m * (m - 1) / 2 + n * (n - 1) / 2)


Fixed submission:
m, n = list(map(int, input().split()))
print(int(m * (m - 1) / 2 + n * (n - 1) / 2))
Problem p02729 (C++)

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

// Returns value of Binomial Coefficient C(n, k)
int binomialCoeff(int n, int k) {
  // Base Cases
  if (k == 0 || k == n)
    return 1;

  // Recur
  return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k);
}

/* Driver code*/
int main() {
  int n, m;
  cin >> n >> m;
  int x;
  x = binomialCoeff(n, 2) + binomialCoeff(m, 2);
  cout << x << endl;
  return 0;
}


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

// Returns value of Binomial Coefficient C(n, k)
int binomialCoeff(int n, int k) {
  // Base Cases
  if (k == 0 || k == n)
    return 1;

  // Recur
  return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k);
}

/* Driver code*/
int main() {
  int n, m;
  cin >> n >> m;
  int x;
  if ((n == 0 || n == 1) && (m == 0 || m == 1))
    x = 0;
  else if (n == 0 || n == 1)
    x = binomialCoeff(m, 2);
  else if (m == 0 || m == 1)
    x = binomialCoeff(n, 2);
  else
    x = binomialCoeff(n, 2) + binomialCoeff(m, 2);
  cout << x << endl;
  return 0;
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
long long fact(int x) {
  if (x == 0)
    return 1;
  else
    return x * fact(x - 1);
}
long long permu(int x, int r) { return (fact(x) / ((fact(x - r)) * fact(r))); }
int main() {
  fast;
  int n, m;
  long long p, q;
  cin >> n >> m;
  if (n >= 2)
    p = permu(n, 2);
  else
    p = n / 2;
  if (m >= 2)
    q = permu(m, 2);
  else
    q = m / 2;
  cout << p + q;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
long long fact(int x) {
  if (x == 0)
    return 1;
  else
    return x * fact(x - 1);
}
long long permu(int x, int r) { return (fact(x) / ((fact(x - r)) * fact(r))); }
int main() {
  fast;
  int n, m;
  long long p, q;
  cin >> n >> m;
  cout << ((n - 1) * n) / 2 + (m * (m - 1)) / 2;
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define lh long double
#define f(a, b, i) for (ll i = a; i < b; i++)

int main() {

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, m;
  cin >> n >> m;
  cout << (n * (n - 1) + m * (m - 1)) / 2;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define lh long double
#define f(a, b, i) for (ll i = a; i < b; i++)

int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, m;
  cin >> n >> m;
  cout << (n * (n - 1) + m * (m - 1)) / 2;
  return 0;
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int m;
  cin >> n;
  cin >> m;
  int res;
  res = (n * (n - 1)) / (m * (m - 1));
  cout << res << '\n';
}

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

signed main(void) {
  int n, m;
  cin >> n >> m;
  cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;
  return 0;
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define speedrap                                                               \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
int be(int a, int b, int mod) {
  if (b == 0)
    return 1;
  if (b % 2 == 1)
    return (a * be(a, b - 1, mod)) % mod;
  else
    return (be(a, b / 2, mod) * be(a, b / 2, mod)) % mod;
}
const int mod = 998244353;
#define PI 3.1415926535
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
const int siz = 2 * (1e6 + 1);
const int logi = 21;
const double epsilon = 1e-6;
int fact[siz];
int ifact[siz];
int bit[siz];
bool cmp(const int &a, const int &b) { return (abs(a - b) > 1); }

signed main() {
#ifndef ONLINE_JUDGE2

  freopen("in.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  speedrap int n, m;
  cin >> n >> m;
  int sum = n * (n - 1) + m * (m - 1);
  sum /= 2;
  cout << sum << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define speedrap                                                               \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
int be(int a, int b, int mod) {
  if (b == 0)
    return 1;
  if (b % 2 == 1)
    return (a * be(a, b - 1, mod)) % mod;
  else
    return (be(a, b / 2, mod) * be(a, b / 2, mod)) % mod;
}
const int mod = 998244353;
#define PI 3.1415926535
#define pf push_front
#define pb push_back
#define bitcount __builtin_popcount
#define sc(a) scanf("%d", &a);
#define sz(s) (int)s.size()
#define eb emplace_back
#define pf push_front
const int siz = 2 * (1e6 + 1);
const int logi = 21;
const double epsilon = 1e-6;
int fact[siz];
int ifact[siz];
int bit[siz];
bool cmp(const int &a, const int &b) { return (abs(a - b) > 1); }

signed main() {
  // #ifndef ONLINE_JUDGE2
  // freopen("in.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // #endif
  speedrap int n, m;
  cin >> n >> m;
  int sum = n * (n - 1) + m * (m - 1);
  sum /= 2;
  cout << sum << "\n";
}
Problem p02729 (C++)

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

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> data(n + m);

  if (n == 0 & m == 0) {
    cout << "0" << endl;
    return 0;
  }

  for (int i = 0; i < n + 1; i++) {
    data.at(i) = (i + 1) * 2;
  }

  int index = 0;
  for (int i = n; i < n + m; i++) {
    data.at(i) = index * 2 + 1;
  }

  int counter = 0;
  rep(i, n + m) {
    for (int j = i; j < n + m; j++) {
      if (i != j & (data.at(i) + data.at(j)) % 2 == 0)
        counter++;
    }

    // cout << data.at(i) << endl;
  }

  cout << counter << endl;
}

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

int main() {

  int n, m;
  cin >> n >> m;
  vector<int> data(n + m);

  if (n == 0 & m == 0) {
    cout << "0" << endl;
    return 0;
  }

  for (int i = 0; i < n; i++) {
    data.at(i) = (i + 1) * 2;
  }

  int index = 0;
  for (int i = n; i < n + m; i++) {
    data.at(i) = index * 2 + 1;
  }

  int counter = 0;
  rep(i, n + m) {
    for (int j = i; j < n + m; j++) {
      if (i != j & (data.at(i) + data.at(j)) % 2 == 0)
        counter++;
    }

    // cout << data.at(i) << endl;
  }

  cout << counter << endl;
}
Problem p02729 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define test                                                                   \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define fast                                                                   \
  ios::sync_with_stdio(NULL);                                                  \
  cin.tie(NULL)
#define mod 1000000007
#define endl "\n"
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define ALL(v) v.begin(), v.end()
#define ll long long
typedef vector<ll> vecll;
typedef vector<int> veci;
typedef vector<char> vecc;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define time 1.0 * clock() / CLOCKS_PER_SEC

int main() {
  fast;

#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  // freopen("output.txt","w",stdout);
  cout << "TIME ESCAPED: " << time << endl;
#endif

  // test{}
  ll m, n;
  cin >> m >> n;
  cout << ((m * (m - 1)) / 2) + ((n * (n - 1)) / 2);
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define test                                                                   \
  int t;                                                                       \
  cin >> t;                                                                    \
  while (t--)
#define fast                                                                   \
  ios::sync_with_stdio(NULL);                                                  \
  cin.tie(NULL)
#define mod 1000000007
#define endl "\n"
#define GCD(m, n) __gcd(m, n)
#define LCM(m, n) m *(n / GCD(m, n))
#define ALL(v) v.begin(), v.end()
#define ll long long
typedef vector<ll> vecll;
typedef vector<int> veci;
typedef vector<char> vecc;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define time 1.0 * clock() / CLOCKS_PER_SEC

int main() {
  fast;

  // test{}
  ll m, n;
  cin >> m >> n;
  cout << ((m * (m - 1)) / 2) + ((n * (n - 1)) / 2);
  return 0;
}
Problem p02729 (C++)

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

int main() {
  string n;
  string m;

  cin >> n >> m;

  int iN = atoi(n.c_str());
  int iM = atoi(m.c_str());

  int retVal = 0;

  // 偶数から2個とる場合の数
  if (iN > 1) {
    retVal += iN * (iN - 1) / 2;
  }
  // 奇数から2個とる場合の数
  if (iM > 1) {
    retVal += iM * (iM - 1) / 2;
  }

  return retVal;
}

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

int main() {
  string n;
  string m;

  cin >> n >> m;

  int iN = atoi(n.c_str());
  int iM = atoi(m.c_str());

  int retVal = 0;

  // 偶数から2個とる場合の数
  if (iN > 1) {
    retVal += iN * (iN - 1) / 2;
  }
  // 奇数から2個とる場合の数
  if (iM > 1) {
    retVal += iM * (iM - 1) / 2;
  }

  cout << retVal << endl;

  return 0;
}
Problem p02729 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
long long fun(long long a) {
  if (a == 1)
    return 1;
  return a + fun(a - 1);
}
int main() {
  long long n, m;
  cin >> n >> m;
  cout << fun(n - 1) + fun(m - 1);
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;
long long fun(long long a) { return (a + 1) * a / 2; }
int main() {
  long long n, m;
  cin >> n >> m;
  cout << fun(n - 1) + fun(m - 1);
  return 0;
}
Problem p02729 (C++)

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

using namespace std;

long long int f(int num) {

  if (num <= 1) {
    return 1;
  } else {
    return (num * f(num - 1));
  }
}

int combine(int n, int m) { return f(n) / (2 * f(n - 2)); }

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  int n = 0, m = 0;
  cin >> n >> m;

  // cout << combine(13,2)<<endl;
  if (n <= 1 || m <= 1) {
    if (n <= 1 && m <= 1)
      cout << "0";
    else if (n <= 1) {
      cout << combine(m, 2);
    } else if (m <= 1) {
      cout << combine(n, 2);
    }
  } else {
    // cout <<"nnn="<<n<<"m="<<m<<endl;
    // cout <<"re="<< combine(n,2)<<" " <<combine(m,2)<<endl;
    cout << combine(n, 2) + combine(m, 2);
  }

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

long long int f(int num) {

  if (num <= 1) {
    return 1;
  } else {
    return (num * f(num - 1));
  }
}

int combine(int n, int m) { return (n * (n - 1)) / 2; }

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);

  int n = 0, m = 0;
  cin >> n >> m;

  // cout << combine(13,2)<<endl;
  if (n <= 1 || m <= 1) {
    if (n <= 1 && m <= 1)
      cout << "0";
    else if (n <= 1) {
      cout << combine(m, 2);
    } else if (m <= 1) {
      cout << combine(n, 2);
    }
  } else {
    // cout <<"nnn="<<n<<"m="<<m<<endl;
    // cout <<"re="<< combine(n,2)<<" " <<combine(m,2)<<endl;
    cout << combine(n, 2) + combine(m, 2);
  }

  return 0;
}
Problem p02730 (C++)

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

int main() {
  string S;
  cin >> S;
  int n = (S.size() - 1) / 2;
  bool ans = 1;
  for (int i = 0; i < (n + 1) / 2; i++) {
    if (S.at(i) != S.at(n - 1 - i) || S.at(i) != S.at(n + 1 + 1) ||
        S.at(i) != S.at(S.size() - 1 - i)) {
      ans = 0;
      break;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
}

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

int main() {
  string S;
  cin >> S;
  int n = (S.size() - 1) / 2;
  bool ans = 1;
  for (int i = 0; i < (n + 1) / 2; i++) {
    if (S.at(i) != S.at(n - 1 - i) || S.at(i) != S.at(n + 1 + i) ||
        S.at(i) != S.at(S.size() - 1 - i)) {
      ans = 0;
      break;
    }
  }
  cout << (ans ? "Yes" : "No") << endl;
}
Problem p02730 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(k, a, b) for (int k = (a); k < (b); k++)
#define FORE(k, a, b) for (int k = (a); k <= (b); k++)
#define REP(k, a) for (int k = 0; k < (a); k++)

#define ALL(c) (c).begin(), (c).end()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define RANGE(lb, x, ub) ((lb) <= (x) && (x) < (ub))

#define dump(x) cerr << #x << ": " << (x) << endl;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INF = 1000000000;
const double EPS = 1e-10;
const double PI = acos(-1.0);

bool is_palind(string s) {
  if (s.size() == 1)
    return true;
  return (s[0] != s[s.size() - 1]) ? false
                                   : is_palind(s.substr(1, s.size() - 2));
}

int main(void) {
  string s;
  cin >> s;
  int n = s.size();
  cout << ((is_palind(s) && is_palind(s.substr(0, n / 2)) &&
            is_palind(s.substr((n + 3) / 2 - 1, n / 2)))
               ? "Yes"
               : "No")
       << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(k, a, b) for (int k = (a); k < (b); k++)
#define FORE(k, a, b) for (int k = (a); k <= (b); k++)
#define REP(k, a) for (int k = 0; k < (a); k++)

#define ALL(c) (c).begin(), (c).end()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define RANGE(lb, x, ub) ((lb) <= (x) && (x) < (ub))

#define dump(x) cerr << #x << ": " << (x) << endl;

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INF = 1000000000;
const double EPS = 1e-10;
const double PI = acos(-1.0);

bool is_palind(string s) {
  if (s.size() <= 1)
    return true;
  return (s[0] != s[s.size() - 1]) ? false
                                   : is_palind(s.substr(1, s.size() - 2));
}

int main(void) {
  string s;
  cin >> s;
  int n = s.size();
  cout << ((is_palind(s) && is_palind(s.substr(0, n / 2)) &&
            is_palind(s.substr((n + 3) / 2 - 1, n / 2)))
               ? "Yes"
               : "No")
       << endl;

  return 0;
}
Problem p02730 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  int N;
  int M = 0;
  cin >> S;
  N = S.size();
  for (int i = 0; i < (N - 1) / 2; i++) {
    if (S.at(i) != S.at((N + 3) / 2 + i)) {
      M = 1;
    }
  }
  if (M == 1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  int N;
  int M = 0;
  cin >> S;
  N = S.size();
  for (int i = 0; i < (N - 1) / 2; i++) {
    if (S.at(i) != S.at((N - 1) / 2 + 1 + i)) {
      M = 1;
    }
  }
  if (M == 1) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}
Problem p02730 (Python)

Buggy submission (status: Runtime Error):
S = input()
a = len(S)
if S[: (a - 1) / 2] == S[(a + 1) / 2 :]:
    print("Yes")
else:
    print("No")


Fixed submission:
S = input()
n = len(S)
a = S[: int((n - 1) / 2)]
b = S[int((n + 1) / 2) :]
if a == b:
    print("Yes")
else:
    print("No")
Problem p02730 (C++)

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

#define REP(i, s, N) for (int i = s; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

bool judge(string str) {
  bool a = true;
  int h = str.length() / 2;

  if (str.length() == 1) {
    a = true;
    //}else if(str.length()%2==0){
    //  a = false;
  } else {
    int k = 1;
    while (h - k >= 0) {
      if (str.at(h - k) == str.at(h + k)) {
        k++;
        // continue;
      } else {
        a = false;
        break;
      }
    }
  }
  return a;
}

int main() {
  string S;
  cin >> S;
  int N = S.length();
  string S2 = S.substr(0, (N - 1) / 2);
  string S3 = S.substr((N + 3) / 2 - 1);

  if (judge(S) && judge(S2) && judge(S3)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

#define REP(i, s, N) for (int i = s; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

bool judge(string str) {
  string str1 = str;
  reverse(str.begin(), str.end());
  return str == str1;
}

int main() {
  string S;
  cin >> S;
  int N = S.length();
  string S2 = S.substr(0, (N - 1) / 2);
  string S3 = S.substr((N + 3) / 2 - 1);

  if (judge(S) && judge(S2) && judge(S3)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02730 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  char S[100];
  char mae[50] = {};
  char ato[50] = {};
  char mae_mae[25] = {};
  char mae_ato[25] = {};
  char ato_mae[25] = {};
  char ato_ato[25] = {};

  scanf("%s", &S);

  strncpy(mae, S, (strlen(S) - 1) / 2);
  for (int i = 0; i < (strlen(S) - 1) / 2; ++i) {
    ato[i] = S[(strlen(S) - 1 - i)];
  }
  if (strcmp(mae, ato) != 0) {
    printf("No");
    return 0;
  }

  if (strlen(mae) % 2 == 1) {
    strncpy(mae_mae, mae, (strlen(mae) - 1) / 2);
    strncpy(ato_mae, ato, (strlen(ato) - 1) / 2);
    for (int i = 0; i < (strlen(mae) - 1) / 2; ++i) {
      mae_ato[i] = S[(strlen(mae) - 1 - i)];
      ato_ato[i] = S[(strlen(mae) - 1 - i)];
    }

  } else {
    strncpy(mae_mae, mae, strlen(mae) / 2);
    strncpy(ato_mae, ato, strlen(ato) / 2);
    for (int i = 0; i < (strlen(mae)) / 2; ++i) {
      strncpy(mae_ato, mae + strlen(mae) / 2 + 1, strlen(mae));
      strncpy(ato_ato, ato + strlen(ato) / 2 + 1, strlen(ato));
    }
  }

  if (strcmp(mae_mae, mae_ato) != 0 || strcmp(ato_mae, ato_ato) != 0) {
    printf("No");
    return 0;
  } else {
    printf("Yes");
    return 0;
  }
}

int A() {
  int N, M;
  int ans;
  scanf("%d %d", &N, &M);

  ans = (N - 1) * N / 2 + (M - 1) * M / 2;
  printf("%d", ans);

  return 0;
}


Fixed submission:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  char S[100];
  char mae[50] = {};
  char ato[50] = {};
  char mae_mae[25] = {};
  char mae_ato[25] = {};
  char ato_mae[25] = {};
  char ato_ato[25] = {};

  scanf("%s", &S);

  strncpy(mae, S, (strlen(S) - 1) / 2);
  for (int i = 0; i < (strlen(S) - 1) / 2; ++i) {
    ato[i] = S[(strlen(S) - 1 - i)];
  }
  if (strcmp(mae, ato) != 0) {
    printf("No");
    return 0;
  }

  if (strlen(mae) % 2 == 1) {
    strncpy(mae_mae, mae, (strlen(mae) - 1) / 2);
    strncpy(ato_mae, ato, (strlen(ato) - 1) / 2);
    for (int i = 0; i < (strlen(mae) - 1) / 2; ++i) {
      mae_ato[i] = S[(strlen(mae) - 1 - i)];
      ato_ato[i] = S[(strlen(mae) - 1 - i)];
    }

  } else {
    strncpy(mae_mae, mae, strlen(mae) / 2);
    strncpy(ato_mae, ato, strlen(ato) / 2);
    for (int i = 0; i < (strlen(mae)) / 2; ++i) {
      mae_ato[i] = S[(strlen(mae) - 1 - i)];
      ato_ato[i] = S[(strlen(mae) - 1 - i)];
    }
  }

  if (strcmp(mae_mae, mae_ato) != 0 || strcmp(ato_mae, ato_ato) != 0) {
    printf("No");
    return 0;
  } else {
    printf("Yes");
    return 0;
  }
}

int A() {
  int N, M;
  int ans;
  scanf("%d %d", &N, &M);

  ans = (N - 1) * N / 2 + (M - 1) * M / 2;
  printf("%d", ans);

  return 0;
}
Problem p02730 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647; // int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  string re_s = s;
  reverse(re_s.begin(), re_s.end());
  if (s == re_s) {
    int n = s.length();
    string b = s.substr(0, (n - 1) / 2);
    string re_b = b;
    reverse(re_b.begin(), re_b.end());
    if (b == re_b) {
      string f = s.substr((n + 3) / 2 + 1);
      string re_f = f;
      reverse(re_f.begin(), re_f.end());
      if (f == re_f) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
  return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
const int INF = 2147483647; // int max
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  int n = s.length();
  string r = "";
  for (int i = n - 1; i >= 0; i--)
    r += s[i];
  if (s == r) {
    string f = "";
    for (int i = (n - 1) / 2 - 1; i >= 0; i--)
      f += s[i];
    if (f == s.substr(0, (n - 1) / 2)) {
      string b = "";
      for (int i = n - 1; i >= (n + 3) / 2 - 1; i--)
        b += s[i];
      string c = s.substr((n + 3) / 2 - 1);
      if (b == c) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
  return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/
Problem p02730 (C++)

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

string S;

bool check(string str) {
  int len = str.length();
  int af = len / 2;
  for (int i = 0; i < af; i++) {
    if (str[i] != str[len - i - 1]) {
      return false;
    }
  }
  return true;
}

void Main() {
  int len = S.length();
  int af = len / 2;
  if (check(S) && check(S.substr(0, af))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return;
}

int main() {

  cin >> S;
  Main();
  return 1;
}

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

string S;

bool check(string str) {
  int len = str.length();
  int af = len / 2;
  for (int i = 0; i < af; i++) {
    if (str[i] != str[len - i - 1]) {
      return false;
    }
  }
  return true;
}

void Main() {
  int len = S.length();
  int af = len / 2;
  if (check(S) && check(S.substr(0, af))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return;
}

int main() {

  cin >> S;
  Main();
  return 0;
}
Problem p02730 (C++)

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

bool kaibun(string s) {
  int n = s.length();
  for (int i = 0; i < n; i++) {
    if (s[i] != s[n - i - 1]) {
      return false;
    }
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  int n = s.length();
  if (kaibun(s) && kaibun(s.substr(0, (n - 1) / 2)) &&
      kaibun(s.substr(((n + 3) / 2) + 1))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

bool kaibun(string s) {
  int n = s.length();
  for (int i = 0; i < n; i++) {
    if (s[i] != s[n - i - 1]) {
      return false;
    }
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  int n = s.length();
  if (kaibun(s) && kaibun(s.substr(0, (n - 1) / 2)) &&
      kaibun(s.substr(((n + 3) / 2) - 1))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02730 (C++)

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

bool check(string s) {
  bool res = true;
  int n = s.size();
  for (int i = 0; i < n / 2; ++i) {
    if (s[i] != s[n - 1 - i])
      res = false;
  }
  return res;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  string ans = "No";
  if (check(s) && check(s.substr(0, n / 2)) && check(s.substr((n + 3) / 2 + 1)))
    ans = "Yes";
  cout << ans << endl;
}

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

bool check(string s) {
  bool res = true;
  int n = s.size();
  for (int i = 0; i < n / 2; ++i) {
    if (s[i] != s[n - 1 - i])
      res = false;
  }
  return res;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  string ans = "No";
  if (check(s) && check(s.substr(0, n / 2)) && check(s.substr((n + 3) / 2 - 1)))
    ans = "Yes";
  cout << ans << endl;
}
Problem p02730 (C++)

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

bool round_word(string s) {
  int n = s.length();
  for (int i = 0; i < n / 2; i++) {
    if (s.at(i) != s.at(n - 1 - i)) {
      return false;
    }
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  int n = s.length();
  if (round_word(s) && round_word(s.substr(0, (n - 1) / 2)) &&
      round_word(s.substr((n + 3) / 2 + 1))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

bool round_word(string s) {
  int n = s.length();
  for (int i = 0; i < n / 2; i++) {
    if (s.at(i) != s.at(n - 1 - i)) {
      return false;
    }
  }
  return true;
}

int main() {
  string s;
  cin >> s;
  int n = s.length();
  if (round_word(s) && round_word(s.substr(0, (n - 1) / 2)) &&
      round_word(s.substr((n + 3) / 2 - 1))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}
Problem p02730 (C++)

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

int main() {
  string s;
  cin >> s;
  int n = s.size();

  bool judge = true;
  for (int i = 0; i < (n - 1) / 2; i++) {
    if (s.at(i) != s.at(n - 1 - i)) {
      judge = false;
      break;
    }
  }

  if (judge) {
    for (int i = 0; i < (n - 1) / 4; i++) {
      if (s.at(i) != s.at((n - 1) / 2 - 1 - n)) {
        judge = false;
        break;
      }
    }
  }

  if (judge) {
    int j = 0;
    for (int i = (n + 3) / 2 - 1; i < n; i++) {
      if (s.at(i) != s.at(n - 1 - j)) {
        judge = false;
        break;
      }
      j++;
    }
  }
  if (judge) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main() {
  string s;
  cin >> s;
  int n = s.size();

  bool judge = true;
  for (int i = 0; i < (n - 1) / 2; i++) {
    if (s.at(i) != s.at(n - 1 - i)) {
      judge = false;
      break;
    }
  }

  if (judge) {
    for (int i = 0; i < n / 2; i++) {
      if (s.at(i) != s.at((n - 1) / 2 - 1 - i)) {
        judge = false;
        break;
      }
    }
  }

  if (judge) {
    int j = 0;
    for (int i = (n + 3) / 2 - 1; i < n; i++) {
      if (s.at(i) != s.at(n - 1 - j)) {
        judge = false;
        break;
      }
      j++;
    }
  }
  if (judge) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02730 (C++)

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

bool kaibun(string S, int A, int B) {
  // Sの文字数は3以上の奇数
  // SのA文字目からB文字目までが回文かどうかを判定する関数
  int i = A - 1;
  int j = B - 1;
  while (i != j) {
    if (S.at(i) != S.at(j))
      return false;
    i += 1;
    j += -1;
  }
  return true;
}

int main() {
  string S;
  cin >> S;
  int N = S.size();
  if (kaibun(S, 1, N) && kaibun(S, 1, (N - 1) / 2) && kaibun(S, (N + 3) / 2, N))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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

bool kaibun(string S, int A, int B) {
  // Sの文字数は3以上の奇数
  // SのA文字目からB文字目までが回文かどうかを判定する関数
  int i = A - 1;
  int j = B - 1;
  while (i <= j) {
    if (S.at(i) != S.at(j))
      return false;
    i += 1;
    j += -1;
  }
  return true;
}

int main() {
  string S;
  cin >> S;
  int N = S.size();
  if (kaibun(S, 1, N) && kaibun(S, 1, (N - 1) / 2) && kaibun(S, (N + 3) / 2, N))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
Problem p02730 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()    // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

bool isPalindrome(string s) {
  int si = 0, ei = s.size() - 1;
  while (si != ei) {
    if (s.at(si) != s.at(ei))
      return false;
    si++;
    ei--;
  }
  return true;
}

int main() {
  string S;
  cin >> S;
  int i1 = (S.size() - 1) / 2, i2 = (S.size() + 3) / 2;
  string s1 = S.substr(0, i1), s2 = S.substr(i2 - 1, S.size());
  cout << (isPalindrome(S) && isPalindrome(s1) && isPalindrome(s2) ? "Yes"
                                                                   : "No")
       << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()    // 昇順ソート
#define rall(v) (v).rbegin(), (v).rend() // 降順ソート
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

bool isPalindrome(string s) {
  string es = s;
  reverse(all(es));
  return s == es;
}

int main() {
  string S;
  cin >> S;
  int i1 = (S.size() - 1) / 2, i2 = (S.size() + 3) / 2;
  string s1 = S.substr(0, i1), s2 = S.substr(i2 - 1, S.size());
  cout << (isPalindrome(S) && isPalindrome(s1) && isPalindrome(s2) ? "Yes"
                                                                   : "No")
       << endl;
}
Problem p02730 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  string ans = "Yes";
  for (int i = 0; i <= (N - 3) / 4; i++) {
    if (S.at(i) != S.at(N - i) || S.at(i) != S.at((N - 3) / 2)) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  string ans = "Yes";
  for (int i = 0; i <= (N - 3) / 2; i++) {
    if (S.at(i) != S.at(N - i - 1) || S.at(i) != S.at((N - 3) / 2 - i)) {
      ans = "No";
      break;
    }
  }
  cout << ans << endl;

  return 0;
}