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

#include <iostream>
#include <map>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
constexpr ll mod = 1000000007;
map<pll, ll> mp;
ll pw(ll a, ll x) {
  ll ret = 1;
  while (x) {
    if (x & 1)
      (ret *= a) %= mod;
    (a *= a) %= mod;
    x /= 2;
  }
  return ret;
}

ll gcd(ll a, ll b) {
  if (a < 0)
    a *= -1;
  if (b < 0)
    b *= -1;
  if (a < b)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(a % b, b);
}

int main() {
  int i, n, cnt = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      cnt++;
    } else {
      ll x = gcd(a, b);
      a /= x;
      b /= x;
      if (a < 0) {
        a *= -1;
        b *= -1;
      }
      if (a == 0)
        b = 1;
      mp[{a, b}]++;
    }
  }
  ll ans = 1;
  for (auto p : mp) {
    auto pp = p.first;
    ll a = pp.first, b = pp.second;
    ll aa = -b, bb = a;
    if (aa < 0) {
      aa *= -1;
      bb *= -1;
    }
    if (aa == 0)
      bb = 1;
    if (mp.find({aa, bb}) != mp.end()) {
      ll s = mp[{aa, bb}], t = p.second;
      (ans *= ((pw(2, s) + pw(2, t) - 1) % mod)) %= mod;
      mp.erase({aa, bb});
    } else {
      (ans *= pw(2, p.second)) %= mod;
    }
  }
  ans += cnt;
  cout << (ans + mod - 1) % mod << endl;
}

Error: 0

Fixed submission:

#include <iostream>
#include <map>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
constexpr ll mod = 1000000007;
map<pll, ll> mp;
ll pw(ll a, ll x) {
  ll ret = 1;
  while (x) {
    if (x & 1)
      (ret *= a) %= mod;
    (a *= a) %= mod;
    x /= 2;
  }
  return ret;
}

ll gcd(ll a, ll b) {
  if (a < 0)
    a *= -1;
  if (b < 0)
    b *= -1;
  if (a < b)
    swap(a, b);
  if (b == 0)
    return a;
  return gcd(a % b, b);
}

int main() {
  int i, n, cnt = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    ll a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      cnt++;
    } else {
      ll x = gcd(a, b);
      a /= x;
      b /= x;
      if (a == 0 || b == 0)
        exit(1);
      if (a < 0) {
        a *= -1;
        b *= -1;
      }
      if (a == 0)
        b = 1;
      if (gcd(a, b) != 1)
        exit(1);
      mp[{a, b}]++;
    }
  }
  ll ans = 1;
  for (auto p : mp) {
    auto pp = p.first;
    ll a = pp.first, b = pp.second;
    ll aa = -b, bb = a;
    if (aa < 0) {
      aa *= -1;
      bb *= -1;
    }
    if (aa == 0)
      bb = 1;
    if (mp.find({aa, bb}) != mp.end()) {
      ll s = mp[{aa, bb}], t = p.second;
      (ans *= ((pw(2, s) + pw(2, t) - 1) % mod)) %= mod;
      mp.erase({aa, bb});
    } else {
      (ans *= pw(2, p.second)) %= mod;
    }
  }
  (ans += cnt) %= mod;
  cout << ans - 1 << endl;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

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

using ll = long long;
constexpr ll mod = 1000000007;

ll myPow(ll b, ll e) {
  ll res = 1;
  while (e) {
    if (e & 1)
      res = res * b % mod;
    b = b * b % mod;
    e >>= 1;
  }
  return res;
}

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

  ll n;
  cin >> n;
  ll a[n], b[n];
  for (ll i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  map<pair<ll, ll>, ll> cnt;
  for (ll i = 0; i < n; ++i) {
    if (a[i] == b[i] && b[i] == 0) {
      cnt[make_pair(0LL, 0LL)] += 1;
    } else if (b[i] == 0) {
      cnt[make_pair(1LL, 0LL)] += 1;
    } else if (a[i] == 0) {
      cnt[make_pair(0LL, 1LL)] += 1;
    } else {
      ll gcd = __gcd(abs(a[i]), abs(b[i]));
      pair<ll, ll> p;
      p.first = a[i] / gcd;
      p.second = b[i] / gcd;
      if (p.second < 0) {
        p.first *= -1;
        p.second *= -1;
      }
      cnt[p] += 1;
    }
  }
  ll ans = 1;
  for (auto it = cnt.begin(); it != cnt.end(); ++it) {
    pair<ll, ll> p = it->first;
    if (p.first == 0 && p.second == 0)
      continue;
    pair<ll, ll> q;
    if (p.first <= 0) {
      q.first = p.second;
      q.second = -p.first;
    } else {
      q.first = -p.second;
      q.second = p.first;
    }
    auto itr = cnt.find(q);
    if (p.first <= 0 && itr != cnt.end())
      continue;
    ll a = it->second, b = (itr == cnt.end() ? 0 : itr->second);
    ans = ans * (myPow(2, a) + myPow(2, b) + mod - 1) % mod;
  }
  ans = (ans + cnt[make_pair(0LL, 0LL)] + mod - 1) % mod;
  cout << ans << endl;

  return 0;
}

Error: -6
c6b77c91-dd2c-4007-8206-21906f9637a3.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02679/C++/s700505535.cpp:59: int main(): Assertion `ans < 0' failed.


Fixed submission:

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

using ll = long long;
constexpr ll mod = 1000000007;

ll myPow(ll b, ll e) {
  ll res = 1;
  while (e) {
    if (e & 1)
      res = res * b % mod;
    b = b * b % mod;
    e >>= 1;
  }
  return res;
}

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

  ll n;
  cin >> n;
  ll a[n], b[n];
  for (ll i = 0; i < n; ++i) {
    cin >> a[i] >> b[i];
  }
  map<pair<ll, ll>, ll> cnt;
  for (ll i = 0; i < n; ++i) {
    ll gcd = __gcd(a[i], b[i]);
    pair<ll, ll> p;
    if (gcd == 0) {
      p.first = p.second = 0;
    } else {
      p.first = a[i] / gcd;
      p.second = b[i] / gcd;
    }
    cnt[p] += 1;
  }
  ll ans = 1;
  for (auto it = cnt.begin(); it != cnt.end(); ++it) {
    pair<ll, ll> p = it->first;
    if (p.first == 0 && p.second == 0)
      continue;
    pair<ll, ll> q;
    if (p.first <= 0) {
      q.first = p.second;
      q.second = -p.first;
    } else {
      q.first = -p.second;
      q.second = p.first;
    }
    auto itr = cnt.find(q);
    if (p.first <= 0 && itr != cnt.end())
      continue;
    ll a = it->second, b = (itr == cnt.end() ? 0 : itr->second);
    ans = ans * (myPow(2, a) + myPow(2, b) + mod - 1) % mod;
  }
  ans = (ans + cnt[make_pair(0LL, 0LL)]) % mod;
  ans += mod - 1;
  ans %= mod;
  assert(ans < 0);
  cout << ans << endl;

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

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

const int MOD = 1e9 + 7;

long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }

long long pow_mod(long long x, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1)
      res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  int N;
  cin >> N;
  using P = pair<long long, long long>;
  map<P, long long> mp;
  vector<long long> a(N), b(N);
  int cnt_zero = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a[i] >> b[i];
    long long g = gcd(a[i], b[i]);
    if (a[i] == 0 && b[i] == 0) {
      ++cnt_zero;
      continue;
    }
    a[i] /= g;
    b[i] /= g;
    ++mp[P(a[i], b[i])];
  }
  // DUMP(mp);

  long long ans = 1;
  for (auto e : mp) {
    // DUMP(e);
    if (mp[P(e.first.first, e.first.second)] == 0)
      continue;
    if (mp[P(-e.first.second, e.first.first)] != 0) {
      ans = ans *
            ((pow_mod(2, mp[P(e.first.first, e.first.second)]) +
              pow_mod(2, mp[P(-e.first.second, e.first.first)]) - 1) %
             MOD) %
            MOD;
      mp[P(-e.first.second, e.first.first)] = 0;
    } else if (mp[P(e.first.second, -e.first.first)] != 0) {
      ans = ans *
            ((pow_mod(2, mp[P(e.first.first, e.first.second)]) +
              pow_mod(2, mp[P(e.first.second, -e.first.first)]) - 1) %
             MOD) %
            MOD;
      mp[P(e.first.second, -e.first.first)] = 0;
    } else {
      ans = ans * pow_mod(2, mp[P(e.first.first, e.first.second)]) % MOD;
    }
  }

  ans -= 1;
  if (cnt_zero)
    ans += cnt_zero;
  while (ans < 0)
    ans += MOD;
  cout << ans << endl;
}


Error: 0

Fixed submission:

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

const int MOD = 1e9 + 7;

long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }

long long pow_mod(long long x, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1)
      res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}

int main() {
  int N;
  cin >> N;
  using P = pair<long long, long long>;
  map<P, int> mp;
  for (int i = 0; i < N; ++i) {
    long long a, b;
    cin >> a >> b;
    long long g = gcd(a, b);
    if (a / g < 0) {
      a *= -1;
      b *= -1;
    }
    ++mp[P(a / g, b / g)];
  }

  // DUMP(mp);

  long long ans = 1;
  int cnt = 0;
  for (auto e : mp) {
    long long a = e.first.first, b = e.first.second;
    if (b < 0)
      continue;
    if (a == 0 && b == 0) {
      cnt += mp[P(0, 0)];
    } else if (mp[P(a, b)] != 0 && mp[P(b, -a)] != 0) {
      ans = ans *
            ((pow_mod(2, mp[P(a, b)]) - 1) % MOD +
             (pow_mod(2, mp[P(b, -1)]) - 1) % MOD + 1) %
            MOD;
      cnt += mp[P(a, b)] + mp[P(b, -a)];
    }
  }

  ans = ans * pow_mod(2, N - cnt) % MOD - 1;
  while (ans < 0)
    ans += MOD;
  cout << ans % MOD << endl;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define REP(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\\n"
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T> auto compare = [](T x, T y) -> bool { return (x < y); };
const int MOD = 1000000007;

// aとbの最大公約数を返す
long long gcd(long long a, long long b) {
  while (a != 0 && b != 0) {
    if (a >= b)
      a %= b;
    else
      b %= a;
  }
  return a + b;
}

int N;
ll A[200010], B[200010];
ll P[200010];

signed main() {
  cin >> N;
  REP(i, N) { cin >> A[i] >> B[i]; }
  P[0] = 1;
  REP(i, N) P[i + 1] = 2 * P[i] % MOD;
  map<pll, pll> mp;
  ll z = MOD - 1;
  REP(i, N) {
    if (A[i] == 0 && B[i] == 0) {
      z++;
      continue;
    }
    if (pll(A[i], B[i]) < pll(0LL, 0LL)) {
      A[i] *= -1;
      B[i] *= -1;
    }
    ll g = gcd(abs(A[i]), abs(B[i]));
    if (g != 0)
      A[i] /= g;
    B[i] /= g;
    if (B[i] > 0)
      mp[pll(A[i], B[i])].first++;
    else
      mp[pll(-B[i], A[i])].second++;
  }
  ll ans = 1;
  for (auto p : mp) {
    int a = p.second.first, b = p.second.second;
    ans = ans * (P[a] + P[b] - 1) % MOD;
  }
  PRINT((z + ans) % MOD);
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define REP(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\\n"
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T> auto compare = [](T x, T y) -> bool { return (x < y); };
const int MOD = 1000000007;

// aとbの最大公約数を返す
long long gcd(long long a, long long b) {
  while (a != 0 && b != 0) {
    if (a >= b)
      a %= b;
    else
      b %= a;
  }
  return a + b;
}

int N;
ll A[200010], B[200010];
ll P[200010];

signed main() {
  cin >> N;
  REP(i, N) {
    cin >> A[i] >> B[i];
    if (A[i] < 0) {
      A[i] *= -1;
      B[i] *= -1;
    }
    ll g = gcd(abs(A[i]), abs(B[i]));
    if (g != 0)
      A[i] /= g;
    B[i] /= g;
  }
  P[0] = 1;
  REP(i, N) P[i + 1] = 2 * P[i] % MOD;
  map<pll, pll> mp;
  ll z = MOD - 1;
  REP(i, N) {
    if (A[i] == 0 && B[i] == 0) {
      z++;
      continue;
    }
    if (B[i] > 0)
      mp[pll(A[i], B[i])].first++;
    else
      mp[pll(-B[i], A[i])].second++;
  }
  ll ans = 1;
  for (auto p : mp) {
    int a = p.second.first, b = p.second.second;
    ans = ans * (P[a] + P[b] - 1) % MOD;
  }
  PRINT((z + ans) % MOD);
  return 0;
}
Problem p02679 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <map>
#define mod 1000000007
#define LL long long
using namespace std;
map<pair<LL, LL>, pair<int, int>> mp;
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL quick_pow(LL a, LL b) {
  LL ret = 1;
  while (b) {
    if (b & 1)
      ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret % mod;
}
int main() {
  int n, i;
  LL a, b, d, zero = 0, sum = 1;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%lld%lld", &a, &b);
    if (!a && !b) {
      zero++;
      continue;
    }
    d = gcd(a, b);
    a /= d, b /= d;
    if (b < 0)
      a = -a, b = -b;
    if (a <= 0)
      mp[make_pair(b, -a)].second++;
    else
      mp[make_pair(a, b)].first++;
  }
  for (map<pair<LL, LL>, pair<int, int>>::iterator it = mp.begin();
       it != mp.end(); it++)
    sum = (quick_pow((LL)2, (LL)it->second.first) - 1 +
           quick_pow((LL)2, (LL)it->second.second) - 1 + 1) %
          mod * sum % mod;
  sum = (sum + zero - 1) % mod;
  sum = (sum % mod + mod) % mod;
  printf("%lld\\n", sum);
  return 0;
}

Error: 0

Fixed submission:

#include <cstdio>
#include <map>
#define mod 1000000007
#define LL long long
using namespace std;
map<pair<LL, LL>, pair<int, int>> mp;
LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
LL quick_pow(LL a, LL b) {
  LL ret = 1;
  while (b) {
    if (b & 1)
      ret = ret * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return ret % mod;
}
int main() {
  int n, i;
  LL a, b, d, zero = 0, sum = 1;
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%lld%lld", &a, &b);
    if (!a && !b)
      zero++;
    d = gcd(a, b);
    a /= d, b /= d;
    if (b < 0)
      a = -a, b = -b;
    if (a < 0)
      mp[make_pair(b, -a)].second++;
    else
      mp[make_pair(a, b)].first++;
  }
  for (map<pair<LL, LL>, pair<int, int>>::iterator it = mp.begin();
       it != mp.end(); it++)
    sum = (quick_pow((LL)2, (LL)it->second.first) - 1 +
           quick_pow((LL)2, (LL)it->second.second) - 1 + 1) %
          mod * sum % mod;
  sum = (sum + zero - 1) % mod;
  sum = (sum % mod + mod) % mod;
  printf("%lld\\n", sum);
  return 0;
}
Problem p02681 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string S, T;
  cin >> S >> T;
  unsigned int i = 0;
  while (S.at(i) == T.at(i)) {
    i = i + 1;
    if (i == S.size()) {
      break;
    }
  }
  if (i == S.size()) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Error: 0

Fixed submission:

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

int main() {
  string S, T;
  cin >> S >> T;
  unsigned int i = 1;
  while (S.at(i) == T.at(i)) {
    i = i + 1;
    if (i == S.size()) {
      break;
    }
  }
  if (i == S.size()) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02681 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string n;
  cin >> n;
  string t;
  cin >> t;
  int cnt = 0;
  int N = n.length();
  for (int i = 0; i < N; i++) {
    if (n.at(i) == t.at(i)) {
      cnt++;

    } else {
    }
  }

  if (cnt == N) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 8) >= this->size() (which is 8)


Fixed submission:

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

int main() {
  string n;
  cin >> n;
  string t;
  cin >> t;
  int cnt = 0;
  int N = n.length();
  for (int i = 0; i <= N; i++) {
    if (n.at(i) == t.at(i)) {
      cnt++;

    } else {
    }
  }

  if (cnt == N) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02681 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string b = "", m, n;
  cin >> m >> n;
  int f = n.size() - 1;
  for (int i = 0; i < f; i++) {
    b += n[i];
  }

  if (b == m)
    cout << "Yes";
  else
    cout << "No";

  return 0;
}


Error: WA

Fixed submission:

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

int main() {
  string b = "", m, n;
  cin >> m >> n;
  for (int i = 0; i <= m.size() - 2; i++) {
    b += m[i];
  }

  if (b == n)
    cout << "Yes";
  else
    cout << "No";

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

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

int main() {
  string s1, s2;
  cin >> s1 >> s2;
  s2.pop_back();
  if (s1 == s2) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}

Error: -11

Fixed submission:

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

int main() {
  string s1, s2;
  cin >> s1 >> s2;
  s2.erase(s2.end());
  if (s1 == s2) {
    cout << "Yes";
  } else {
    cout << "No";
  }
}
Problem p02681 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>
using namespace std;

int main(void) {
  string s, t;
  cin >> s >> t;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) != t.at(i)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main(void) {
  int a, b, c, k, ans = 0;
  cin >> a >> b >> c >> k;
  while (k) {
    if (a) {
      ans += 1;
      a--;
      k--;
    } else if (b) {
      ans += 0;
      b--;
      k--;
    } else if (c) {
      ans += -1;
      c--;
      k--;
    }
  }
  cout << ans << endl;
}
Problem p02681 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  string t;
  cin >> s >> t;
  int flag = 0;
  int i = 0;
  while (i < s.size()) {
    if (s[i] != t[i]) {
      cout << "No" << endl;
      flag = 1;
      break;
    } else {
      i++;
    }
  }
  if (!flag) {
    cout << "Yes" << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  string t;
  cin >> s >> t;
  int flag = 0;
  if (t.size() != s.size() + 1) {
    cout << "No" << endl;

  } else {
    int i = 0;
    while (i < s.size()) {
      if (s[i] != t[i]) {
        cout << "No" << endl;
        flag = 1;
        break;
      }
      if (!flag) {
        cout << "Yes" << endl;
      }
    }
  }
  return 0;
}
Problem p02681 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  string a, b;
  cin >> a;
  cin >> b;
  int i = 0;
  bool flag = false;
  while (a[i] != '\\0') {
    if (a[i] != b[i]) {
      flag = true;
      break;
    }
    i++;
  }
  if (flag)
    cout << "No"
         << "\\n";
  else
    cout << "Yes"
         << "\\n";
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  string a, b;
  cin >> a;
  cin >> b;
  int i = 0;
  bool flag = false;
  while (a[i] != '\\0') {
    if (a[i] != b[i]) {
      flag = true;
      break;
    }
  }
  if (flag)
    cout << "No" << endl;
  else {
    if (b[i + 1] == '\\0')
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}
Problem p02681 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
  string s, t;
  const string YES = "Yes";
  const string NO = "No";
  cin >> s >> t;

  // cout << "[" << s << "]" << endl;
  // cout << "[" << t << "]" << endl;

  if (s.empty() || t.empty()) {
    cout << NO;
    return 0;
  }
  if (s.length() == 0 || s.length() > 10) {
    cout << NO;
    return 0;
  }
  if (s.length() + 1 != t.length()) {
    cout << NO;
    return 0;
  }
  // cout << "here" << endl;
  // cout << s.length() << endl;
  // cout << s.compare(0, s.length(), t) << endl;
  if (0 != t.compare(0, s.length(), s)) {
    cout << NO;
    return 0;
  }

  cout << YES;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
  // 整数の入力
  // int n, k;
  // cin >> n >> k;
  // cout << n << " " << k << endl;
  string s, t;
  const string YES = "Yes";
  const string NO = "No";
  cin >> s >> t;

  // cout << "[" << s << "]" << endl;
  // cout << "[" << t << "]" << endl;

  if (s.empty() || t.empty()) {
    cout << NO;
    return 1;
  }
  if (s.length() == 0 || s.length() > 10) {
    cout << NO;
    return 1;
  }
  if (s.length() + 1 != t.length()) {
    cout << NO;
    return 1;
  }
  // cout << "here" << endl;
  // cout << s.length() << endl;
  // cout << s.compare(0, s.length(), t) << endl;
  if (0 != t.compare(0, s.length(), s)) {
    cout << NO;
    return 1;
  }

  cout << YES;
  return 0;
}
Problem p02681 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  string s, s2;
  int cnt = 0;

  cin >> s;
  cin >> s2;

  for (unsigned int i = 0; i < s.size(); i++) {
    cnt++;
    if (s.at(i) != s2.at(i)) {
      cout << "No" << endl;
      return 0;
    }
  }

  if (s2.size() != s.size() + 1) {
    cout << "No" << endl;
    return 0;
  }

  if (s2.at(s.size()) < 'a' || s2.at(s.size()) > 'z') {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  string s, s2;

  cin >> s;
  cin >> s2;

  for (unsigned int i = 0; i < s.size(); i++) {
    if (s.at(i) != s2.at(i)) {
      cout << "No" << endl;
      return -1;
    }
  }

  if (s2.size() != s.size() + 1) {
    cout << "No" << endl;
    return -1;
  }

  if (s2.at(s.size()) < 'a' || s2.at(s.size()) > 'z') {
    cout << "No" << endl;
    return -1;
  }

  cout << "Yes" << endl;
  return 0;
}
Problem p02681 (C++) — buggy submission, verdict: Runtime Error

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

int main(void) {
  char s[11], t[11];

  scanf("%s%s", s, t);
  if (strlen(s) + 1 == strlen(t)) {
    for (int i = 0; i < strlen(s); i++) {
      if (s[i] == t[i]) {
        if (i == (strlen(s) - 1)) {
          printf("Yes\\n");
        }
      } else {
        printf("No\\n");
        return 0;
      }
    }
  } else {
    printf("No\\n");
  }

  return 0;
}


Error: 0

Fixed submission:

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

int main(void) {
  char s[10], t[10];

  scanf("%s%s", s, t);
  if (strlen(s) + 1 == strlen(t)) {
    for (int i = 0; i < strlen(s); i++) {
      if (s[i] == t[i]) {
        if (i == (strlen(s) - 1)) {
          printf("Yes\\n");
        }
      } else {
        printf("No\\n");
        return 0;
      }
    }
  } else {
    printf("No\\n");
  }

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

#include <iostream>

using namespace std;
string ss, st;

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

  cin >> ss >> st;
  for (int k = 0; k < ss.size(); ++k) {
    if (ss[k] != st[k]) {
      cout << "No"
           << "\\n";
      return 0;
    }
  }

  cout << "Yes"
       << "\\n";

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
string s, t;
int pre() {

  for (int i = 0; i < s.size(); ++i) {
    if (s[i] != t[i]) {
      cout << "No"
           << "\\n";
      return 0;
    }
  }
  cout << "Yes"
       << "\\n";
}

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

  cin >> s >> t;
  { pre(); }
  return 0;
}
Problem p02681 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  string S, T;
  cin >> S >> T;

  int N = S.size();

  for (int i = 0; i < N; i++) {

    if (S.at(i) != T.at(i)) {

      cout << "No" << endl;
      break;
    }

    else if ((i == N - 1) && (S.at(N - 1) == T.at(N - 1))) {

      cout << "Yes" << endl;
    }
  }
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::at: __n (which is 8) >= this->size() (which is 8)


Fixed submission:

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

int main() {
  string S, T;
  cin >> S >> T;

  int N = S.size();

  for (int i = 0; i < N + 1; i++) {
    if (i == N) {
      cout << "YES" << endl;
    }

    if (S.at(i) != T.at(i)) {

      cout << "NO" << endl;
    }
  }
}