alexjercan/bugnet huggingface dataset:
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

/* SANDEEP YADAv*/
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
lld gcd(lld a, lld b) {
  if (a < b) {
    a = a + b;
    b = a - b;
    a = a - b;
  }
  while (b != 0) {
    lld r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long power(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
void judge() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
}

int main() {
  fastio;
  // judge();

  lld n, m;
  cin >> n >> m;

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

Error: WA

Fixed submission:

/* SANDEEP YADAv*/
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio                                                                 \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
lld gcd(lld a, lld b) {
  if (a < b) {
    a = a + b;
    b = a - b;
    a = a - b;
  }
  while (b != 0) {
    lld r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long power(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
void judge() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif
}

int main() {
  fastio;
  judge();

  lld n, m;
  cin >> n >> m;

  cout << n * (n - 1) / 2 + m * (m - 1) / 2;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main() {
  long long int n, m, a, b, c, d, e, f, g, sum;
  cin >> n >> m;
  a = n * (n - 1) / 2;
  b = m * (m - 1) / 2;
  sum = a + b;
  cout << sum << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
unsigned long long int factorial(unsigned int a) {
  if (a == 0)
    return 1;
  return a * factorial(a - 1);
}

int main() {
  long long int n, m, a, b, c, d, e, f, g, sum;
  cin >> n >> m;
  b = factorial(n);
  //	cout<<b<<endl;
  c = factorial(n - 2);
  //	cout<<c<<endl;
  d = factorial(m);
  e = factorial(m - 2);

  f = b / (c * 2);
  //	cout<<f<<endl;

  g = d / (e * 2);
  //	cout<<g<<endl;
  sum = f + g;
  cout << sum << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

// #include<iostream>
#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;
  return 0;
}


Error: 0

Fixed submission:

// #include<iostream>
#include <bits/stdc++.h>
using namespace std;

int combinations(int s, int t) {
  int r = s - t;
  if (r < 0)
    return 0;
  long int m = 1, c = 1;
  for (int i = 0; i < r; i++) {
    m *= (s - i);
    c *= (i + 1);
  }
  return m / c;
}

int main() {
  int N, M;
  cin >> N >> M;
  cout << combinations(N, 2) + combinations(M, 2) << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

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

  cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;

int factorial(int n) {
  int answer = 1;
  while (n > 1) {
    answer *= n;
    n--;
  }
  return answer;
}

int calcNumOfCombination(int n, int r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

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

  cout << calcNumOfCombination(N, 2) + calcNumOfCombination(M, 2) << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  printf("%d", n * (n - 1) / 2 + m * (m - 1) / 2);
}


Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", n, m);
  printf("%d", n * (n - 1) / 2 + m * (m - 1) / 2);
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  cout << N * (N - 1) / 2 + M * (M - 1) / 2;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

long long int fact(long long int K) {
  if (K == 0)
    return 1;
  if (K < 0)
    return 0;
  return K * fact(K - 1);
}

long long int combi2(long long int L) {
  if (L == 0)
    return 0;
  if (L == 1)
    return 0;
  return fact(L) / (2 * fact(L - 2));
}

int main() {
  int N, M;
  cin >> N >> M;
  cout << combi2(N) + combi2(M);
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

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

  int n, m;

  cin >> n >> m;

  long long int x1 = n * (n - 1) / 2, x2 = m * (m - 1) / 2;

  cout << (x1 + x2) << endl;

  return 0;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::substr: __pos (which is 4) > this->size() (which is 1)


Fixed submission:

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

bool pal(string str) {
  int i = 0, j = str.size() - 1;

  while (i < j) {
    if (str[i] != str[j])
      return false;

    i++;
    j--;
  }

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

  string str;

  cin >> str;

  int f1 = 0, f2 = 0, f3 = 0;

  f1 = pal(str);

  f2 = pal(str.substr(0, 3));

  f3 = pal(str.substr(4, 7));

  if (f1 && f2 && f3)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

const int MAX = 1e6;
const int INF = 2e9;
typedef long long ll;

int comb(int n, int r) {

  if (n < r) {
    return 0;
  }

  if (n == r || r == 0) {
    return 1;
  }

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

  return x / y;
}

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

  int n, m;
  cin >> n >> m;

  cout << comb(n, 2) + comb(m, 2);

  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

const int MAX = 1e6;
const int INF = 2e9;
typedef long long ll;

int comb(int n, int r) {

  if (n < r) {
    return 0;
  }

  if (n == r || r == 0) {
    return 1;
  }

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

  return x / y;
}

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

  int n, m;
  cin >> n >> m;

  cout << comb(n, 2) + comb(m, 2);

  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, n, t, m, ans, npr1, npr2, ncr1, ncr2;
  // int minirow=INT_MAX,minicol=INT_MAX,maxrow=INT_MIN,maxcol=INT_MIN;
  // int i,j;
  // string s[100],p;
  // char ch;
  cin >> n >> m;
  npr1 = n * (n - 1);
  ncr1 = npr1 / 2;
  npr2 = m * (m - 1);
  ncr2 = npr2 / 2;
  // cout<<npr1<<endl;
  // cout<<ncr1<<" "<<ncr2<<endl;
  ans = ncr1 + ncr2;
  cout << ans << endl;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int fact(int x) {
  int i, f = 1;
  for (i = 2; i <= x; i++) {
    f = f * i;
  }
  return f;
}
int main() {
  int a, b, c, d, n, t, m, ans, npr1, npr2, ncr1, ncr2;
  // int minirow=INT_MAX,minicol=INT_MAX,maxrow=INT_MIN,maxcol=INT_MIN;
  // int i,j;
  // string s[100],p;
  // char ch;
  cin >> n >> m;
  npr1 = fact(n) / fact(n - 2);
  ncr1 = npr1 / 2;
  npr2 = fact(m) / fact(m - 2);
  ncr2 = npr2 / 2;
  // cout<<npr1<<endl;
  // cout<<ncr1<<" "<<ncr2<<endl;
  ans = ncr1 + ncr2;
  cout << ans << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  ll n, m;
  cin >> n >> m;
  ll res = 0;
  if (n > 1)
    res += n * (n - 1) * 0.5;
  if (m > 1)
    res += m * (m - 1) * 0.5;
  cout << res << endl;
  return 0;
}

Error: 0

Fixed submission:

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

ll fact(int x) { return (x > 1) ? x * fact(x - 1) : 1; }

ll comb(int n, int r) { return fact(n) / (fact(n - r) * fact(r)); }

int main() {
  int n, m;
  cin >> n >> m;
  ll res = 0;
  if (n > 1)
    res += comb(n, 2);
  if (m > 1)
    res += comb(m, 2);
  cout << res << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<ll, ll> P;
const int MAXN = 1e5 + 7;
const int LOG = 20;
const int INF = 0x3f3f3f3f;

int jc(int n) {
  if (n <= 0)
    return 1;
  int ret = 1;
  for (int i = 1; i <= n; i++)
    ret *= i;
  return ret;
}

void solve() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  if (n >= 2) {
    ans = n * (n - 1) / 2;
  }
  if (m >= 2) {
    ans += m * (m - 1) / 2;
  }
  cout << ans << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int T;
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef pair<ll, ll> P;
const int MAXN = 1e5 + 7;
const int LOG = 20;
const int INF = 0x3f3f3f3f;

int jc(int n) {
  if (n <= 0)
    return 1;
  int ret = 1;
  for (int i = 1; i <= n; i++)
    ret *= i;
  return ret;
}

void solve() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  if (n >= 2) {
    ans = jc(n) / (jc(n - 2) * 2);
  }
  if (m >= 2) {
    ans += jc(m) / (jc(m - 2) * 2);
  }
  cout << ans << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int T;
  T = 1;
  while (T--) {
    solve();
  }
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#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;
}


Error: 0

Fixed submission:

#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;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define ss second
#define ff first
#define pb push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);

int main() {
  FIO;
  ll a, b;
  cin >> a >> b;
  ll s = 0;
  s = ((a * (a - 1)) / 2) + ((b * (b - 1)) / 2);
  cout << s << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define ss second
#define ff first
#define pb push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO                                                                    \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);

int main() {
  FIO;
  ll a, b;
  cin >> a >> b;
  ll s = 0;
  if (a > 1) {
    for (ll i = a - 1; i >= 1; i++) {
      s += i;
    }
  }
  if (b > 1) {
    for (ll i = b - 1; i >= 1; i++) {
      s += i;
    }
  }
  cout << s << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
int fact(int n) {
  if (n <= 1)
    return 1;
  else
    return n * fact(n - 1);
}
int result(int e, int o) {
  int odd = o * (o - 1) / 2;
  int even = e * (e - 1) / 2;

  return odd + even;
}

int main() {
  int even_no, odd_no;
  cin >> even_no >> odd_no;
  cout << result(even_no, odd_no);
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int fact(int n) {
  if (n <= 1)
    return 1;
  else
    return n * fact(n - 1);
}
int result(int e, int o) {
  int odd = fact(o) / (2 * fact(o - 2));
  int even = fact(e) / (2 * fact(e - 2));

  return odd + even;
}

int main() {
  int even_no, odd_no;
  cin >> even_no >> odd_no;
  cout << result(even_no, odd_no);
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#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;
}


Error: 0

Fixed submission:

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

int main() {
  int N, M;
  cin >> N >> M;
  int64_t x = 1;
  int64_t y = 1;

  for (int i = 1; i < N + 1; i++) {
    x *= i;
  }
  for (int i = 1; i < N - 1; i++) {
    y *= i;
  }
  int z = x / (2 * y);

  int64_t a = 1;
  int64_t b = 1;

  for (int i = 1; i < M + 1; i++) {
    a *= i;
  }
  for (int i = 1; i < M - 1; i++) {
    b *= i;
  }
  int c = a / (2 * b);

  cout << z + c << endl;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

using namespace std;

int combination(int n, int k) {
  int c[n + 1][n + 1];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      if (i == j || j == 0)
        c[i][j] = 1;
      else if (j > i) {
        c[i][j] = 0;
      } else
        c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
      // cout << c[i][j] << " "; //DEBUG
    }
    // cout << endl; //DEBUG
  }
  if (n >= k)
    return c[n][k];
  else
    return 0;
}

int main() {
  int N, M;
  cin >> N >> M;
  // cout << combination(N,M) << endl; //DEBUG
  cout << combination(N, 2) + combination(M, 2) << endl;
  return 0;
}


Error: WA

Fixed submission:

#include <iostream>

using namespace std;

int combination(int n, int k) {
  int c[n][n];
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      if (i == j || j == 0)
        c[i][j] = 1;
      else if (j > i) {
        c[i][j] = 0;
        break;
      } else
        c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
      // cout << c[i][j] << " "; //DEBUG
    }
    // cout << "\\n"; //DEBUG
  }

  if (n >= k)
    return c[n][k];
  else
    return 0;
}

int main() {
  int N, M;
  cin >> N >> M;
  // cout << combination(N,M) << endl; //DEBUG
  cout << combination(N, 2) + combination(M, 2) << endl;
  return 0;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

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

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


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int fact(int n);

int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); }

// Returns factorial of n
int fact(int n) {
  int res = 1;
  for (int i = 2; i <= n; i++)
    res = res * i;
  return res;
}

int main() {
  int n, m;
  cin >> n >> m;
  cout << nCr(n, 2) + nCr(m, 2);
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define INF 0x3f3f3f3f
#define SIS std::ios::sync_with_stdio(false)
using namespace std;
ll fast_pow(ll a, ll b, ll mod) {
  ll c = 1;
  while (b >= 2) {
    if (b % 2 == 0)
      a *= a, b /= 2;
    else
      c *= a, a *= a, b--, b /= 2;
    a %= mod, c %= mod;
  }
  return (a * c) % mod;
}
ll cal(ll n, ll m);
int main() {
  int n, m;
  while (cin >> n >> m) {
    ll ans = 0;
    if (n > 1)
      ans += cal(n, 2);
    if (m > 1)
      ans += cal(m, 2);
    cout << ans << endl;
  }
  return 0;
}

ll cal(ll n, ll m) { return n * (n - 1) / 2; }


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define INF 0x3f3f3f3f
#define SIS std::ios::sync_with_stdio(false)
using namespace std;
ll fast_pow(ll a, ll b, ll mod) {
  ll c = 1;
  while (b >= 2) {
    if (b % 2 == 0)
      a *= a, b /= 2;
    else
      c *= a, a *= a, b--, b /= 2;
    a %= mod, c %= mod;
  }
  return (a * c) % mod;
}
ll cal(ll n, ll m);
int main() {
  int n, m;
  while (cin >> n >> m) {
    ll ans = 0;
    if (n > 1)
      ans += cal(n, 2);
    if (m > 1)
      ans += cal(m, 2);
    cout << ans << endl;
  }
  return 0;
}

ll cal(ll n, ll m) {
  ll up = 1, a = 1, b = 1, c = n - m;
  for (ll i = 1; i <= n; i++)
    up *= i;
  for (ll i = 1; i <= m; i++)
    a *= i;
  for (ll i = 1; i <= c; i++)
    b *= i;
  return up / a / b;
}
Problem p02729 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>

int main() {
  using namespace std;
  long N, M;

  cin >> N >> M;

  int result = N * (N - 1) / 2 + M * (M - 1) / 2;

  cout << result << endl;
  return 0;
}


Error: 1

Fixed submission:

#include <iostream>

int main() {
  using namespace std;
  long N, M;

  cin >> N >> M;

  int result = N * (N - 1) / 2 + M * (M - 1) / 2;

  cout << result << endl;
  return 1;
}
Problem p02729 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int printNcR(int n, int r) {
  long long p = 1, k = 1;

  if (n - r < r)
    r = n - r;

  if (r != 0) {
    while (r) {
      p *= n;
      k *= r;
      long long m = __gcd(p, k);
      p /= m;
      k /= m;

      n--;
      r--;
    }
  }

  else
    p = 1;
  return p;
}

int main() {
  int a, b, aa = 0, bb = 0;
  cin >> a >> b;
  if (a > 1)
    aa = printNcR(a, 2);
  if (b > 1)
    bb = printNcR(b, 2);
  cout << aa + bb;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;

#define rep(i, b) for (i = 0; i < b; ++i)
#define repp(i, a, b) for (i = a; i < b; ++i)

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);
}
int main() {
  ll e, o;
  cin >> e >> o;
  ll on = binomialCoeff(o, 2);
  ll en = binomialCoeff(e, 2);
  cout << en + on;
  return 0;
}
/*
         ,--"""",--.__,---[],-------._
       ,"   __,'            \\         \\--""""""==;-
     ," _,-"  "/---.___     \\       ___\\   ,-'',"
    /,-'      / ;. ,.--'-.__\\  _,-"" ,| `,'   /
   /``""""-._/,-|:\\       []\\,' ```-/:;-. `. /
             `  ;:::      ||       /:,;  `-.\\
                =.,'__,---||-.____',.=
                =(:\\_     ||__    ):)=
               ,"::::`----||::`--':::"._
             ,':::::::::::||::::::::::::'.
    .__     ;:::.-.:::::__||___:::::.-.:::\\     __,
       """-;:::( O )::::>_|| _<::::( O )::::-"""
   =======;:::::`-`:::::::||':::::::`-`:::::\\=======
    ,--"";:::_____________||______________::::""----.          , ,
         ; ::`._(    |    |||     |   )_,'::::\\_,,,,,,,,,,____/,'_,
       ,;    :::`--._|____[]|_____|_.-'::::::::::::::::::::::::);_
      ;/ /      :::::::::,||,:::::::::::::::::::::::::::::::::::/
     /; ``''''----------/,'/,__,,,,,____:::::::::::::::::::::,"
     ;/                :);/|_;| ,--.. . ```-.:::::::::::::_,"
    /;                :::):__,'//""\\\\. ,--.. \\:::,:::::_,"
   ;/              :::::/ . . . . . . //""\\\\. \\::":__,"
   ;/          :::::::,' . . . . . . . . . . .:`::\\
   ';      :::::::__,'. ,--.. . .,--. . . . . .:`::`
   ';   __,..--'''-. . //""\\\\. .//""\\\\ . ,--.. :`:::`
   ;    /  \\\\ .//""\\\\ . . . . . . . . . //""\\\\. :`::`
   ;   /       . . . . . . . . . . . . . . . . .:`::`
   ;   (          . . . . . . . . . . . . . . . ;:::`
   ,:  ;,            . . . . . . . . . . . . . ;':::`
   ,:  ;,             . . . . . . . . . . . . .;`:::
   ,:   ;,             . . . . . . . . . . . . ;`::;`
    ,:  ;             . . . . . . . . . . . . ;':::;`
     :   ;             . . . . . . . . . . . ,':::;
      :   '.          . . . . . . . .. . . .,':::;`
       :    `.       . . . . . . . . . . . ;::::;`
        '.    `-.   . . . . . . . . . . ,-'::::;
          `:_    ``--..___________..--'':::::;'`
             `._::,.:,.:,:_ctr_:,:,.::,.:_;'`
________________`"\\/"\\/\\/'""""`\\/"\\/""\\/"____________________________

*/
Problem p02730 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
int main() {
  // your code goes here
  // ifstream cin("input.txt");
  // ofstream cout("output.txt");
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int n = s.length();
  bool ok = 1;
  int id1 = 0, id2 = n / 2 - 1;
  while (id1 < id2) {
    if (s[id1] != s[id2]) {
      ok = 0;
      break;
    }
    id1++;
    id2--;
  }
  if (!ok) {
    cout << "No";
    return 0;
  }
  id1 = n / 2 + 1, id2 = n - 1;
  while (id1 < id2) {
    if (s[id1] != s[id2]) {
      ok = 0;
      break;
    }
    id1++;
    id2--;
  }
  if (!ok) {
    cout << "No";
    return 0;
  }
  id1 = 0, id2 = n - 1;
  while (id1 < id2) {
    if (s[id1] != s[id2]) {
      ok = 0;
      break;
    }
    id1++;
    id2--;
  }
  if (!ok) {
    cout << "No";
    return 0;
  }

  cout << "Yes";

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
int main() {
  // your code goes here
  // ifstream cin("input.txt");
  // ofstream cout("output.txt");
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  int n = s.length();
  bool ok = 1;
  int id1 = 0, id2 = n / 2 - 1;
  while (id1 < id2) {
    if (s[id1] != s[id2]) {
      ok = 0;
      break;
    }
  }
  if (!ok) {
    cout << "No";
    return 0;
  }
  id1 = n / 2 + 1, id2 = n - 1;
  while (id1 < id2) {
    if (s[id1] != s[id2]) {
      ok = 0;
      break;
    }
  }
  if (!ok) {
    cout << "No";
    return 0;
  }
  cout << "Yes";

  return 0;
}