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

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

long long pow(long long a, long long b, long long mod) {
  if (b == 0) {
    return 1;
  } else {
    if (b % 2 == 0) {
      return pow(a * a % mod, b / 2, mod);
    } else {
      return pow(a * a % mod, b / 2, mod) * a % mod;
    }
  }
}

long long gcd(long long a, long long b) {
  long long r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

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

  long long a, b, g;
  long long mod = 1000000007;
  map<pair<long long, long long>, pair<int, int>> m;
  int z = 0;

  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    if (a == 0 && b == 0) {
      z++;
    } else if (a > 0 && b > 0) {
      g = gcd(a, b);
      m[{a / g, b / g}].first++;
    } else if (a > 0) {
      g = gcd(a, -b);
      m[{-b / g, a / g}].second++;
    } else if (b > 0) {
      g = gcd(-a, b);
      m[{b / g, -a / g}].second++;
    } else {
      g = gcd(-a, -b);
      m[{-a / g, -b / g}].first++;
    }
  }

  long long ans = 1;
  long long tmp;
  for (auto p : m) {
    // cout<<p.second.first<<" "<<p.second.second<<endl;
    tmp = pow(2, p.second.first, mod);
    tmp += pow(2, p.second.second, mod);
    tmp--;
    tmp %= mod;
    ans *= tmp;
    ans %= mod;
  }
  ans--;
  ans += mod;
  ans %= mod;
  ans += z;
  ans %= mod;
  cout << ans << endl;

  return 0;
}

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

long long pow(long long a, long long b, long long mod) {
  if (b == 0) {
    return 1;
  } else {
    if (b % 2 == 0) {
      return pow(a * a % mod, b / 2, mod);
    } else {
      return pow(a * a % mod, b / 2, mod) * a % mod;
    }
  }
}

long long gcd(long long a, long long b) {
  long long r = a % b;
  while (r != 0) {
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

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

  long long a, b, g;
  long long mod = 1000000007;
  map<pair<long long, long long>, pair<int, int>> m;
  int z = 0;

  for (int i = 0; i < N; i++) {
    cin >> a >> b;
    if (a == 0 && b == 0) {
      z++;
    } else if (a == 0) {
      m[{0, 1}].first++;
    } else if (b == 0) {
      m[{0, 1}].second++;
    } else if (a > 0 && b > 0) {
      g = gcd(a, b);
      m[{a / g, b / g}].first++;
    } else if (a > 0) {
      g = gcd(a, -b);
      m[{-b / g, a / g}].second++;
    } else if (b > 0) {
      g = gcd(-a, b);
      m[{b / g, -a / g}].second++;
    } else {
      g = gcd(-a, -b);
      m[{-a / g, -b / g}].first++;
    }
  }

  long long ans = 1;
  long long tmp;
  for (auto p : m) {
    // cout<<p.second.first<<" "<<p.second.second<<endl;
    tmp = pow(2, p.second.first, mod);
    tmp += pow(2, p.second.second, mod);
    tmp--;
    tmp %= mod;
    ans *= tmp;
    ans %= mod;
  }
  ans--;
  ans += mod;
  ans %= mod;
  ans += z;
  ans %= mod;
  cout << ans << endl;

  return 0;
}
Problem p02679 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
using namespace std;
#define MAX 100005
#define MOD 1000000007
long long arr[MAX];
map<pair<long long, long long>, int> M;
set<pair<long long, long long>> S;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  pair<long long, long long> p, q;
  arr[0] = 1;
  int n, i, j;
  long long g;
  scanf("%d", &n);
  long long current = 0, ans = 1;
  for (i = 0; i < n; i++) {
    arr[i + 1] = (arr[i] * 2) % MOD;
    scanf("%lld %lld", &p.first, &p.second);
    g = gcd(abs(p.first), abs(p.second));
    if (g == 0) {
      current++;
      continue;
    }
    p.first = p.first / g;
    p.second = p.second / g;
    if (p.first < 0 || (p.first == 0 && p.second < 0)) {
      p.first = -p.first;
      p.second = -p.second;
    }
    j = S.size();
    S.insert(p);
    if (S.size() == j) {
      M[p]++;
    } else {
      M[p] = 1;
    }
  }
  long long zeros = current;
  while (S.size() > 0) {
    j = S.size();
    p = *(S.begin());
    current = arr[M[p]];
    q.first = p.second;
    q.second = -p.first;
    swap(p, q);
    if (p.first < 0 || (p.first == 0 && p.second < 0)) {
      p.first = -p.first;
      p.second = -p.second;
    }
    S.erase(p);
    if (S.size() < j) {
      current = (current + arr[M[p]] + MOD - 1) % MOD;
    }
    ans = (ans * current) % MOD;
    S.erase(q);
  }
  ans = (ans + zeros) % MOD;
  ans = (ans + MOD - 1) % MOD;
  printf("%lld", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
using namespace std;
#define MAX 200005
#define MOD 1000000007
long long arr[MAX];
map<pair<long long, long long>, int> M;
set<pair<long long, long long>> S;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  pair<long long, long long> p, q;
  arr[0] = 1;
  int n, i, j;
  long long g;
  scanf("%d", &n);
  long long current = 0, ans = 1;
  for (i = 0; i < n; i++) {
    arr[i + 1] = (arr[i] * 2) % MOD;
    scanf("%lld %lld", &p.first, &p.second);
    g = gcd(abs(p.first), abs(p.second));
    if (g == 0) {
      current++;
      continue;
    }
    p.first = p.first / g;
    p.second = p.second / g;
    if (p.first < 0 || (p.first == 0 && p.second < 0)) {
      p.first = -p.first;
      p.second = -p.second;
    }
    j = S.size();
    S.insert(p);
    if (S.size() == j) {
      M[p]++;
    } else {
      M[p] = 1;
    }
  }
  long long zeros = current;
  while (S.size() > 0) {
    j = S.size();
    p = *(S.begin());
    current = arr[M[p]];
    q.first = p.second;
    q.second = -p.first;
    swap(p, q);
    if (p.first < 0 || (p.first == 0 && p.second < 0)) {
      p.first = -p.first;
      p.second = -p.second;
    }
    S.erase(p);
    if (S.size() < j) {
      current = (current + arr[M[p]] + MOD - 1) % MOD;
    }
    ans = (ans * current) % MOD;
    S.erase(q);
  }
  ans = (ans + zeros) % MOD;
  ans = (ans + MOD - 1) % MOD;
  printf("%lld", ans);
  return 0;
}
Problem p02679 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

ll gcd(ll a, ll b) {
  while (b) {
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}

int main() {
  ios::sync_with_stdio(false);
  int n, y = 0;
  ll a[200005] = {}, b[200005] = {}, z = 1, p[200005] = {1};
  map<pair<ll, ll>, int> m;
  set<pair<ll, ll>> s;
  cin >> n;
  for (int i = 1; i <= n; i++)
    p[i] = p[i - 1] * 2 % mod;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    ll g = gcd(abs(a[i]), abs(b[i]));
    if (g == 0) {
      return 1;
      y = 1;
      continue;
    }
    a[i] /= g;
    b[i] /= g;
    m[{a[i], b[i]}]++;
  }
  for (auto i : m)
    if (s.find(i.first) == s.end()) {
      ll c, d, x = i.first.first, y = i.first.second;
      s.insert({x, y});
      s.insert({-y, x});
      s.insert({-x, -y});
      s.insert({y, -x});
      c = m[{x, y}] + m[{-x, -y}];
      d = m[{-y, x}] + m[{y, -x}];
      z = z * (p[c] + p[d] - 1) % mod;
    }
  cout << (z + mod - 1 + y) % mod;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

ll gcd(ll a, ll b) {
  while (b) {
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}

int main() {
  ios::sync_with_stdio(false);
  int n, y = 0;
  ll a[200005] = {}, b[200005] = {}, z = 1, p[200005] = {1};
  map<pair<ll, ll>, int> m;
  set<pair<ll, ll>> s;
  cin >> n;
  for (int i = 1; i <= n; i++)
    p[i] = p[i - 1] * 2 % mod;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    ll g = gcd(abs(a[i]), abs(b[i]));
    if (g == 0) {
      y++;
      continue;
    }
    a[i] /= g;
    b[i] /= g;
    m[{a[i], b[i]}]++;
  }
  for (auto i : m)
    if (s.find(i.first) == s.end()) {
      ll c, d, x = i.first.first, y = i.first.second;
      s.insert({x, y});
      s.insert({-y, x});
      s.insert({-x, -y});
      s.insert({y, -x});
      c = m[{x, y}] + m[{-x, -y}];
      d = m[{-y, x}] + m[{y, -x}];
      z = z * (p[c] + p[d] - 1) % mod;
    }
  cout << (z + mod - 1 + y) % mod;
}
Problem p02679 (C++)

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

long long gcd(long long x, long long y) { return (x % y) ? gcd(y, x % y) : y; }

const long long MOD = 1000000007;

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

  vector<long long> pw(200010);

  pw[0] = 1;
  for (int i = 1; i < 200010; ++i)
    pw[i] = (pw[i - 1] * 2) % MOD;

  map<pair<long long, long long>, pair<int, int>> x;

  long long zz = 0;
  for (int i = 0; i < N; ++i) {
    long long a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      zz++;
      continue;
    }
    if (make_pair(a, b) < make_pair(0LL, 0LL)) {
      a = -a;
      b = -b;
    }
    long long g = gcd(abs(a), abs(b));
    a /= g;
    b /= g;
    if (b > 0) {
      x[make_pair(a, b)].first++;
    } else {
      x[make_pair(-b, a)].second++;
    }
  }

  long long ans = 1;
  for (auto &p : x) {
    ans = ans * (pw[p.second.first] + pw[p.second.second] - 1) % MOD;
  }

  cout << (ans + zz + MOD - 1) % MOD << endl;

  return 0;
}


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

long long gcd(long long x, long long y) { return (y) ? gcd(y, x % y) : x; }

const long long MOD = 1000000007;

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

  vector<long long> pw(200010);

  pw[0] = 1;
  for (int i = 1; i < 200010; ++i)
    pw[i] = (pw[i - 1] * 2) % MOD;

  map<pair<long long, long long>, pair<int, int>> x;

  long long zz = 0;
  for (int i = 0; i < N; ++i) {
    long long a, b;
    cin >> a >> b;
    if (a == 0 && b == 0) {
      zz++;
      continue;
    }
    if (make_pair(a, b) < make_pair(0LL, 0LL)) {
      a = -a;
      b = -b;
    }
    long long g = gcd(abs(a), abs(b));
    a /= g;
    b /= g;
    if (b > 0) {
      x[make_pair(a, b)].first++;
    } else {
      x[make_pair(-b, a)].second++;
    }
  }

  long long ans = 1;
  for (auto &p : x) {
    ans = ans * (pw[p.second.first] + pw[p.second.second] - 1) % MOD;
  }

  cout << (ans + zz + MOD - 1) % MOD << endl;

  return 0;
}
Problem p02681 (C++)

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

int main(void) {
  char s[10], t[10];
  int len;
  scanf("%s %s", s, t);
  len = strlen(s);
  for (int i = 0; i < len; i++) {
    if (s[i] != t[i]) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}

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

int main(void) {
  char s[20], t[20];
  int len;
  scanf("%s %s", s, t);
  len = strlen(s);
  for (int i = 0; i < len; i++) {
    if (s[i] != t[i]) {
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}
Problem p02681 (C++)

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

using namespace std;

int main(void) {
  string S, T;
  cin >> S >> T;
  return S == T.substr(0, S.length());
}


Fixed submission:
#include <iostream>

using namespace std;

int main(void) {
  string S, T;
  cin >> S >> T;
  if (S == T.substr(0, S.length())) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}
Problem p02681 (C++)

Buggy submission (status: Runtime Error):
#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;
}


Fixed submission:
#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;
}
Problem p02681 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string x;
  string n;
  cin >> x >> n;
  n.pop_back();
  if (n == x) {
    cout << "Yes"
         << "\n";
    return true;
  } else {
    cout << "No"
         << "\n";
  }
}


Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string x;
  string n;
  cin >> x >> n;
  n.pop_back();
  if (n == x) {
    cout << "Yes"
         << "\n";
  } else {
    cout << "No"
         << "\n";
  }
}
Problem p02681 (C++)

Buggy submission (status: 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;
  }
}


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 (status: Runtime Error):
#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;
  }
}

Fixed submission:
#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;
  }
}
Problem p02681 (Python)

Buggy submission (status: Runtime Error):
s, t = input().split()
print("Yes" if s == t[:-1] else "No")


Fixed submission:
s = input()
t = input()
print("Yes" if s == t[:-1] else "No")
Problem p02681 (Python)

Buggy submission (status: Runtime Error):
# A - Registration
def main():
    S, T = map(int, open(0).read().split())
    print("Yes" if T[:-1] == S else "No")


if __name__ == "__main__":
    main()


Fixed submission:
# A - Registration
def main():
    S, T = open(0).read().split()
    print("Yes" if T[:-1] == S else "No")


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

Buggy submission (status: Runtime Error):
#!/usr/bin/env python3

S = list(input())
T = list(input())

if len(T) == len(S) + 1:
    flag = True
    for i in len(S):
        if S[i] != T[i]:
            flag = False
    if flag:
        print("Yes")
    else:
        print("No")
else:
    print("No")


Fixed submission:
#!/usr/bin/env python3

S = list(input())
T = list(input())

if len(T) == len(S) + 1:
    flag = True
    for i in range(len(S)):
        if S[i] != T[i]:
            flag = False
    if flag:
        print("Yes")
    else:
        print("No")
else:
    print("No")
Problem p02681 (Python)

Buggy submission (status: Runtime Error):
S = input()
T = input()

if T.startwith("S"):
    print("Yes")
else:
    print("No")


Fixed submission:
S = input()
T = input()

if T.startswith(S):
    print("Yes")
else:
    print("No")
Problem p02681 (Python)

Buggy submission (status: Runtime Error):
S, T = list(map(str, input().split()))

if (abs(len(T) - len(S)) == 1) and (T[:-1] == S):
    print("Yes")
else:
    print("No")


Fixed submission:
S = list(map(str, input().split()))[0]
T = list(map(str, input().split()))[0]

if (abs(len(T) - len(S)) == 1) and (T[:-1] == S):
    print("Yes")
else:
    print("No")
Problem p02681 (Python)

Buggy submission (status: Runtime Error):
s, t = map(str, input().split())

if s[: len(s)] == t[: len(s)]:
    print("Yes")
else:
    print("No")


Fixed submission:
s = input()
t = input()

if s[: len(s)] == t[: len(s)]:
    print("Yes")
else:
    print("No")
Problem p02681 (C++)

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

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

#define REP(i, n) for (int i = 0; i < n; i++) // 普通のループ
#define REPTO(i, n) for (int i = 0; i <= n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)  // 逆ループ
#define FOR(i, m, n) for (int i = m; i < n; i++) // 最初の数値を指定

int strlen(char *s) {
  int i = 0;
  while (s[i] != '\0') {
    i++;
  }
  return i;
}

int main() {
  char S[10];
  char T[10];
  cin >> S >> T;
  int ans = 0;
  for (int i = 0; i < strlen(S); i++) {
    if (S[i] == T[i]) {
    } else {
      ans = 1;
    }
  }
  if (ans == 0) {
    if (strlen(T) - strlen(S) == 1) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    cout << "No" << endl;
  }

  return 0;
}

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

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

#define REP(i, n) for (int i = 0; i < n; i++) // 普通のループ
#define REPTO(i, n) for (int i = 0; i <= n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)  // 逆ループ
#define FOR(i, m, n) for (int i = m; i < n; i++) // 最初の数値を指定

int strlen(char *s) {
  int i = 0;
  while (s[i] != '\0') {
    i++;
  }
  return i;
}

int main() {
  char S[20];
  char T[20];
  cin >> S >> T;
  int ans = 0;
  for (int i = 0; i < strlen(S); i++) {
    if (S[i] == T[i]) {
    } else {
      ans = 1;
    }
  }
  if (ans == 0) {
    if (strlen(T) - strlen(S) == 1) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    cout << "No" << endl;
  }

  return 0;
}
Problem p02681 (C++)

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

int main() {
  string S, T;
  cin >> S >> T;
  int a = S.size();
  char b = T.at(a + 1);
  if (T == S + b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

int main() {
  string S, T;
  cin >> S >> T;
  int a = S.size();
  char b = T.at(a);
  if (T == S + b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
Problem p02681 (C++)

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

int main() {
  string S, T;
  cin >> S >> T;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] != T[i]) {
      cout << "No";
      exit(1);
    }
  }
  cout << "Yes";
}


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

int main() {
  string S, T;
  cin >> S >> T;
  T.pop_back();
  if (S == T)
    cout << "Yes";
  else
    cout << "No";
}
Problem p02681 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <cstring>
using namespace std;
int main(void) {
  int i, flg, n;
  flg = 0;
  char s[10], t[10];
  scanf("%s", s);
  scanf("%s", t);
  n = strlen(s);
  for (i = 0; i < n; i++) {
    if (s[i] != t[i])
      flg = 1;
  }
  if (flg == 1)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}


Fixed submission:
#include <cstdio>
#include <cstring>
using namespace std;
int main(void) {
  int i, flg, n;
  flg = 0;
  char s[11], t[12];
  scanf("%s", s);
  scanf("%s", t);
  n = strlen(s);
  for (i = 0; i < n; i++) {
    if (s[i] != t[i])
      flg = 1;
  }
  if (flg == 1)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}
Problem p02681 (C++)

Buggy submission (status: Runtime Error):
#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";
  }
}

Fixed submission:
#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";
  }
}
Problem p02681 (C++)

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

  string s, t;
  cin >> s >> t;
  t = t.erase(t[t.size() - 1]);
  if (s == t) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {

  string s, t;
  cin >> s >> t;
  t = t.erase(t.size() - 1);
  if (s == t) {
    cout << "Yes";
  } else {
    cout << "No";
  }
  return 0;
}
Problem p02681 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;

  int len = t.length();
  if (len != s.length() + 1) {
    cout << "No" << endl;
    return -1;
  }

  string u = t.substr(0, len - 1);
  if (s != u) {
    cout << "No" << endl;
    return -1;
  }

  for (char c = 'a'; c <= 'z'; c++) {
    if (t[len - 1] == c) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


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

using namespace std;

int main() {
  string s, t;
  cin >> s >> t;

  int len = t.length();
  if (len != s.length() + 1) {
    cout << "No" << endl;
    return -1;
  }

  string u = t.substr(0, len - 1);
  if (s != u) {
    cout << "No" << endl;
    return 0;
  }

  for (char c = 'a'; c <= 'z'; c++) {
    if (t[len - 1] == c) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef long long LL;
typedef long double LD;

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

  LL a, b, c, k;
  cin >> a >> b >> c >> k;
  LL ans = 0;
  while (k != 0) {
    if (a != 0) {
      a--;
      ans++;
    } else if (b != 0) {
      b--;
    } else {
      ans--;
      c--;
    }
    k--;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef long long LL;
typedef long double LD;

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

  LL a, b, c, k;
  cin >> a >> b >> c >> k;
  LL ans = 0;
  if (a >= k) {
    ans = k;
  } else if (a + b >= k) {
    ans = a;
  } else {
    ans = a - (k - a - b);
  }
  cout << ans << endl;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long one, zero, minus_one;
  int k, amount = 0;
  cin >> one >> zero >> minus_one >> k;

  for (int i = 0; i < k; i++) {
    if (one > 0) {
      one -= 1;
      amount += 1;
    } else if (zero > 0) {
      zero -= 1;
    } else {
      minus_one -= 1;
      amount -= 1;
    }
  }
  cout << amount << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long one, zero, minus_one;
  int k, amount = 0;
  cin >> one >> zero >> minus_one >> k;
  if (one >= k) {
    amount = k;
  } else if (one + zero >= k) {
    amount = one;
  } else {
    amount = one - (k - (one + zero));
  }
  cout << amount << endl;
}
Problem p02682 (C++)

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

int main() {

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

  int A, B, C, K, ans = 0;
  cin >> A >> B >> C >> K;

  for (int i = 0; i < K; i++) {
    if (A > 0) {
      ans++;
      A--;
    } else if (B > 0) {
      B--;
    } else if (C > 0) {
      ans--;
      C--;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int main() {

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

  int A, B, C, K, ans = 0;
  cin >> A >> B >> C >> K;

  if (A > K)
    cout << K << endl;
  else if (A + B > K)
    cout << A << endl;
  else
    cout << A - (K - A - B) << endl;

  return 0;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int a, b, c, n, s;
int main() {
  cin >> a >> b >> c >> n;
  for (int i = 1; i <= n; i++) {
    if (a != 0)
      a--, s++;
    else if (b != 0)
      b--;
    else if (c != 0)
      c--, s--;
  }
  cout << s;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int a, b, c, n, s;
int main() {
  cin >> a >> b >> c >> n;
  if (n <= a)
    cout << n;
  else if (n <= a + b)
    cout << a;
  else
    cout << a - (n - a - b);
}
Problem p02682 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int64_t a, b, c, k;
  cin >> a >> b >> c >> k;

  if ((a + b) >= k) {
    cout << a << endl;
    return -1;
  }

  int64_t d = k - (a + b);
  if (c < d)
    cout << a - c << endl;
  else
    cout << a - d << endl;

  return 0;
}


Fixed submission:
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int64_t a, b, c, k;
  cin >> a >> b >> c >> k;

  if ((a + b) >= k) {
    if (a < k)
      cout << a << endl;
    else {
      cout << k << endl;
    }
    return 0;
  }

  int64_t d = k - (a + b);
  if (c < d)
    cout << a - c << endl;
  else
    cout << a - d << endl;

  return 0;
}
Problem p02682 (C++)

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

using namespace std;

int main() {
  int a, b, c, k, sum = 0;

  cin >> a >> b >> c >> k;

  while (k > 0) {
    if (k >= a && a > 0) {
      sum = sum + a;
      k = k - a;
      a = 0;
    } else if (k < a && a > 0) {
      sum = sum + k;
      k = 0;
      a = a - k;
    } else if (k < b && a == 0 && b > 0) {
      k = 0;
      b = b - k;
    } else if (k >= b && a == 0 && b > 0) {
      k = k - b;
      b = 0;
    } else if (k >= c && a == 0 && b == 0 && c > 0) {
      sum = sum - c;
      c = 0;
      k = k - c;
    } else if (k < c && a == 0 && b == 0 && c > 0) {
      sum = sum - k;
      c = c - k;
      k = 0;
    }
  }

  cout << sum;

  return 0;
}

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

using namespace std;

int main() {
  int a, b, c, k, sum = 0;

  cin >> a >> b >> c >> k;

  while (k > 0) {
    if (k >= a && a > 0) {
      sum = sum + a;
      k = k - a;
      a = 0;
    } else if (k < a && a > 0) {
      sum = sum + k;
      k = 0;
      a = a - k;
    } else if (k < b && a == 0 && b > 0) {
      k = 0;
      b = b - k;
    } else if (k >= b && a == 0 && b > 0) {
      k = k - b;
      b = 0;
    } else if (k >= c && a == 0 && b == 0 && c > 0) {
      sum = sum - c;
      c = 0;
      k = 0;
    } else if (k < c && a == 0 && b == 0 && c > 0) {
      sum = sum - k;
      c = c - k;
      k = 0;
    }
  }

  cout << sum;

  return 0;
}
Problem p02682 (C++)

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

int main() {
  int A, B, C, K;
  std::cin >> A >> B >> C >> K;

  int count = 0;
  for (int i = 0; i < K; i++) {
    if (A > 0) {
      ++count;
      --A;
    } else if (B > 0)
      --B;
    else
      --count;
  }
  std::cout << count << std::endl;
}

Fixed submission:
#include <iostream>

int main() {
  int A, B, C, K;
  std::cin >> A >> B >> C >> K;

  int count = 0;
  if (K > A) {
    count = A;
    for (int i = 0; i < K - A - B; i++)
      count--;
  } else
    count = K;

  std::cout << count << std::endl;
}
Problem p02682 (C++)

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

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = 0;
  for (int i = 0; i < d; i++) {
    if (a) {
      a--;
      ans++;
    } else if (b) {
      b--;
    } else {
      c--;
      ans--;
    }
  }
  cout << ans;
  return 0;
}


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

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

  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int ans = 0;
  int x = min(a, d);
  ans += x;
  a -= x;
  d -= x;
  if (d) {
    int y = min(b, d);
    b -= y;
    d -= y;
  }
  if (d) {
    ans -= d;
  }
  cout << ans;
  return 0;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
// @prefix atcoder
// @description atcoder template

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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'
#define INF (1ll << 60)

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
const int MOD = 1e9 + 7;

int a, b, c, k;

signed main() {
  cin >> a >> b >> c >> k;

  int res = 0;
  REP(i, k) {
    if (k <= a) {
      res = k;
    } else if (k <= a + b) {
      res = a;
    } else {
      res = a - (c - (a + b + c - k));
    }
  }

  cout << res << endl;
  return 0;
}


Fixed submission:
// @prefix atcoder
// @description atcoder template

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

// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// rep
//------------------------------------------
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGP(x) cerr << #x << ": " << x.first << " \t" << x.second << '\n'
#define INF (1ll << 60)

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
const int MOD = 1e9 + 7;

int a, b, c, k;

signed main() {
  cin >> a >> b >> c >> k;

  int res = 0;
  if (k <= a) {
    res = k;
  } else if (k <= a + b) {
    res = a;
  } else {
    res = a - (c - (a + b + c - k));
  }

  cout << res << endl;
  return 0;
}
Problem p02682 (C++)

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

int main() {
  int a, b, c, k;
  int ans = 0;
  cin >> a >> b >> c >> k;
  for (int i = 0; i < k; ++i) {
    if (a > 0) {
      ans += 1;
      --a;
    } else if (b > 0) {
      --b;
    } else {
      ans -= 1;
    }
  }
  cout << ans << endl;
}


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

int main() {
  int a, b, c, k;
  int ans = 0;
  cin >> a >> b >> c >> k;
  ans += min(a, k);
  k = k - (a + b);
  if (k > 0)
    ans -= k;
  cout << ans << endl;
}
Problem p02682 (C++)

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

int main() {
  int A, B, C, K;
  int sum = 0;
  cin >> A >> B >> C >> K;
  for (int i = K; i > 0; i--) {
    if (A > 0) {
      sum++;
      A--;
    } else if (A == 0 && B > 0)
      B--;
    else
      sum--;
  }
  cout << sum << endl;
}

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

int main() {
  int A, B, C, K;
  int sum = 0;
  cin >> A >> B >> C >> K;

  if (A > K)
    cout << K << endl;
  else if (A + B > K)
    cout << A << endl;
  else
    cout << 2 * A + B - K << endl;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans = 0;
  for (int i = 0; i < k; i++) {
    if (a > 0) {
      ans += 1;
      a--;
    } else if (b > 0) {
      b--;
    } else if (c > 0) {
      ans -= 1;
      c--;
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans = 0;
  if (k <= a) {
    ans = k;
  } else if (k <= a + b) {
    ans = a;
  } else {
    ans = a - (k - a - b);
  }
  cout << ans << endl;
  return 0;
}
Problem p02682 (C++)

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

int main() {
  int A, B, C, K, ans;
  cin >> A >> B >> C >> K;
  ans = 0;

  for (int i = 0; i < K; i++) {
    if (A > 0) {
      ans++;
      A--;
    } else if (B > 0) {
      B--;
    } else {
      ans--;
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  int A, B, C, K, ans;
  cin >> A >> B >> C >> K;
  ans = 0;

  if (A > K) {
    ans = K;
  } else if (A + B >= K) {
    ans = A;
  } else {
    ans = A - (K - A - B);
  }

  cout << ans << endl;

  return 0;
}
Problem p02682 (C++)

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

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

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

  lli a = 0, b = 0, c = 0, k = 0, count = 0;
  cin >> a >> b >> c >> k;

  while (k != 0) {
    if (a != 0) {
      count++;
      a--;
    } else if (b != 0) {
      b--;
    } else {
      count--;
      c--;
    }
    k--;
  }
  cout << count;
}

Fixed submission:
#include <bits/stdc++.h>
#define lli long long int

using namespace std;

int main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  freopen("error.txt", "w", stderr);
#endif

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

  lli a = 0, b = 0, c = 0, k = 0, count = 0;
  cin >> a >> b >> c >> k;

  while (k != 0) {
    if (a == k) {
      count = a;
      break;
    }
    if (a != 0) {
      count++;
      a--;
    } else if (b != 0) {
      b--;
    } else {
      count--;
      c--;
    }
    k--;
  }
  cout << count;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):

#include <iostream>
using namespace std;

int main() {
  int a, b, c, k, ans = 0;

  cin >> a >> b >> c >> k;

  while (1) {
    if (k == 0) {
      break;
    }

    if (a > 0) {
      ans++;
      a--;

      k--;
      continue;
    }
    if (b > 0) {
      b--;
      k--;
      continue;
    }
    if (c > 0) {
      ans--;
      c--;
      k--;
      continue;
    }
  }

  cout << ans << endl;
}

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int a, b, c, k, ans = 0;

  cin >> a >> b >> c >> k;

  if (a >= k && b == 0 && c == 0) {
    cout << k << endl;
    return 0;
  }

  while (1) {
    if (k == 0) {
      break;
    }

    if (a > 0) {
      ans++;
      a--;

      k--;
      continue;
    }
    if (b > 0) {
      b--;
      k--;
      continue;
    }
    if (c > 0) {
      ans--;
      c--;
      k--;
      continue;
    }
  }

  cout << ans << endl;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  ll sum = 0;
  ll card = 0;
  while (true) {
    if (card == K)
      break;
    if (A > 0) {
      sum += 1;
      card++;
      A--;
    } else if (A == 0 && B > 0) {
      card++;
      B--;
    } else if (A == 0 && B == 0 && C > 0) {
      sum--;
      card++;
      C--;
    }
  }
  cout << sum << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  ll sum = 0;
  if (K >= A) {
    sum += A;
    K = K - A;
  } else {
    sum += K;
    cout << sum << endl;
    return 0;
  }
  if (K >= B) {
    K = K - B;
  } else {
    cout << sum << endl;
    return 0;
  }

  if (K >= C) {
    sum -= C;
    K = K - C;
  } else {
    sum -= K;
    cout << sum << endl;
    return 0;
  }
  cout << sum << endl;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int d = 0;
  while (k) {
    if (a) {
      d++;
      k--;
      a--;
    } else if (b) {
      k--;
      b--;
    } else if (c) {
      d--;
      k--;
      c--;
    }
  }
  cout << d;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k <= a)
    cout << k << endl;
  else if (k <= a + b)
    cout << a << endl;
  else
    cout << a - (k - a - b) << endl;
  return 0;
}
Problem p02682 (C++)

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

int main(int argc, char const *argv[]) {
  ll a, b, c, k;
  scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
  vector<ll> v;
  while (a--)
    v.push_back(1);
  while (b--)
    v.push_back(0);
  while (c--)
    v.push_back(-1);
  ll ans = 0;
  for (int i = 0; i < k; ++i) {
    ans += v[i];
  }
  printf("%lld\n", ans);
  return 0;
}


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

int main(int argc, char const *argv[]) {
  int a, b, c, k;
  scanf("%d%d%d%d", &a, &b, &c, &k);
  printf("%d\n", min(a, k) - max(0, k - a - b));
  return 0;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
using namespace std;

int main() {
  int A, B, C, K, sum = 0;

  cin >> A >> B >> C >> K;
  while (1) {
    if (A == 0 || K == 0) {
      break;
    }
    sum++;
    A--;
    K--;
  }
  while (1) {
    if (B == 0 || K == 0) {
      break;
    }
    B--;
    K--;
  }
  while (1) {
    if (K == 0) {
      break;
    }
    sum--;
  }
  cout << sum << endl;
  return 0;
}

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

int main() {
  int A, B, C, K, sum = 0;

  cin >> A >> B >> C >> K;
  while (1) {
    if (A == 0 || K == 0) {
      break;
    }
    sum++;
    A--;
    K--;
  }
  while (1) {
    if (B == 0 || K == 0) {
      break;
    }
    B--;
    K--;
  }
  while (1) {
    if (K == 0) {
      break;
    }
    sum--;
    K--;
  }
  cout << sum << endl;
  return 0;
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void) {
  // Your code here!
  long long int a, b, c, k, point = 0;
  scanf("%lld %lld %lld %lld", &a, &b, &c, &k);
  for (int i = 0; i < k; i++) {
    if (a > 0) {
      point++;
      a--;
    } else if (b > 0) {
      b--;
    } else {
      point--;
      c--;
    }
  }
  printf("%lld", point);
}


Fixed submission:
#include <iostream>
#include <stdio.h>
using namespace std;
int main(void) {
  // Your code here!
  long long int a, b, c, k, point = 0;
  scanf("%lld %lld %lld %lld", &a, &b, &c, &k);
  for (int i = 0; i < k; i++) {
    if (a > 0) {
      point++;
      a--;
    } else if (b > 0) {
      b--;
    } else {
      point--;
    }
  }
  printf("%lld", point);
}
Problem p02682 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <string>
using namespace std;

int main() {
  int a, b, c, k;
  int sum = 0;
  cin >> a >> b >> c >> k;
  for (int i = 0; i < k; i++) {
    if (a != 0) {
      sum += 1;
      a -= 1;
    } else if (b != 0) {
      b -= 1;
    } else {
      sum -= 1;
    }
  }
  cout << sum << endl;
  return 0;
}

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

int main() {
  int a, b, c, k;
  int sum = 0;
  cin >> a >> b >> c >> k;
  if (k <= a)
    sum = k;
  else if (k <= b)
    sum = a;
  else
    sum = a - (k - a - b);
  cout << sum << endl;
  return 0;
}
Problem p02682 (C++)

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

int main() {
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  long long ans = 0;
  for (int i = 0; i < k; i++) {
    if (a > 0) {
      a--;
      ans++;
    } else if (b > 0) {
      b--;
    } else {
      c--;
      ans--;
    }
  }
  cout << ans << endl;
}

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

int main() {
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  long long ans = 0;
  if (k <= a)
    cout << k << endl;
  else if (k <= a + b)
    cout << a << endl;
  else
    cout << a - (k - a - b) << endl;
}
Problem p02682 (C++)

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

int main() {
  int A, B, C, K, sum = 0;
  cin >> A >> B >> C >> K;
  for (int i = 0; i < K; i++) {
    if (A > 0) {
      sum++;
      A--;
    } else if (B > 0) {
      B--;
    } else {
      sum--;
    }
  }
  cout << sum << endl;
  return 0;
}

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

int main() {
  int A, B, C, K, sum = 0;
  cin >> A >> B >> C >> K;
  if (A >= K) {
    sum = K;
  } else if (A + B >= K) {
    sum = A;
  } else {
    sum = A - (K - A - B);
  }
  cout << sum << endl;
  return 0;
}
Problem p02682 (C++)

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

using namespace std;

int main() {

  long a, b, c, k;

  cin >> a >> b >> c >> k;

  long sum = 0;

  while (k > 0) {
    if (a > 0) {
      a--;
      k--;
      sum++;
    } else if (b > 0) {
      b--;
      k--;
    } else {
      c--;
      k--;
      sum--;
    }
  }

  cout << sum << endl;

  return 0;
}


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

using namespace std;

int main() {

  long a, b, c, k;

  cin >> a >> b >> c >> k;

  long sum = 0;

  if (k > 0 && a > 0) {
    int x = min(a, k);
    sum += x;
    k -= x;
  }

  if (k > 0 && b > 0) {

    int x = min(b, k);
    k -= x;
  }

  if (k > 0 && c > 0) {

    int x = min(c, k);
    sum -= x;
    k -= x;
  }

  cout << sum << endl;

  return 0;
}
Problem p02682 (C++)

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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int r1 = k % a;
  int r2 = r1 % b;
  int r3 = r2 % b;
  cout << r1 - r3 << endl;
}


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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;

  if (a >= k) {
    cout << k << endl;
  } else {
    if (b >= k - a) {
      cout << a << endl;
    } else {
      cout << a - (k - a - b) << endl;
    }
  }
}
Problem p02682 (C++)

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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int d = 0;
  int ans = -2000000001;
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      int l = k - (i + j);
      d = 1 * i + -1 * l;
      if (ans < d) {
        ans = d;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  int ans = k < a ? k : a;
  int l = k - a - b;
  if (l > 0) {
    ans -= l;
  }
  cout << ans << endl;
}
Problem p02682 (C++)

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

int main() {
  int a, b, c, k;
  int sum = 0;
  cin >> a >> b >> c >> k;

  for (int i = 0; i < k; i++) {
    if (a != 0) {
      a--;
      sum++;
    } else if (b != 0) {
      b--;

    } else {
      sum--;
    }
  }

  cout << sum << endl;
}

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

int main() {
  int64_t a, b, c, k;
  int64_t sum = 0;
  cin >> a >> b >> c >> k;

  for (int i = 0; i < k; i++) {
    if (a != 0) {
      a--;
      sum++;
    } else if (b != 0) {
      b--;

    } else {
      sum--;
    }
  }

  cout << sum << endl;
}
Problem p02682 (C++)

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

using namespace std;
typedef long long ll;

int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  ll result = 0;

  for (ll i = 0; i < K; i++) {
    // cout << result << "\n";
    if (0 < A) {
      result++;
      A--;
      continue;
    }
    if (0 < B) {
      B--;
      continue;
    }
    if (0 < C) {
      result--;
      C--;
      continue;
    }
  }
  cout << result;

  return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
  ll A, B, C, K;
  cin >> A >> B >> C >> K;
  ll result = 0;

  if (K <= A) {
    result = K;
  } else if (K <= A + B) {
    result = A;
  } else {
    result = A - (K - A - B);
  }
  cout << result;

  return 0;
}
Problem p02682 (Python)

Buggy submission (status: Runtime Error):
A, B, C, K = map(int, input.split(" "))
if K <= A:
    print(K)
else:
    K = K - A
    if K <= B:
        print(A)
    else:
        K = K - B
        print(A - K)


Fixed submission:
A, B, C, K = map(int, input().split(" "))
if K <= A:
    print(K)
else:
    K = K - A
    if K <= B:
        print(A)
    else:
        K = K - B
        print(A - K)
Problem p02682 (Python)

Buggy submission (status: Time Limit Exceeded):
A, B, C, K = map(int, input().split())
a = []
b = []
c = []
for x in range(A):
    a.append(1)
for y in range(B):
    b.append(0)
for z in range(C):
    c.append(-1)
sum = 0
arr = a + b + c
for i in range(K):
    sum += arr[i]
print(sum)


Fixed submission:
A, B, C, K = map(int, input().split())
k = K
a = min(A, k)
k -= a
b = min(B, k)
k -= b
c = min(C, k)
print(a - c)
Problem p02682 (Python)

Buggy submission (status: Time Limit Exceeded):
a, b, c, k = map(int, input().split(" "))

cnt_a = 0
cnt_b = 0
cnt_c = 0

while k != 0:
    if a > 0:
        cnt_a += 1
        a -= 1
        k -= 1
    elif b > 0:
        cnt_b += 1
        b -= 1
        k -= 1
    else:
        cnt_c += 1
        c -= 1
        k -= 1

result = cnt_a * 1 + cnt_b * 0 + cnt_c * (-1)
print(result)


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

cnt_a = 0
cnt_b = 0
cnt_c = 0

if (a > 0) & (a > k):
    cnt_a = k
    k = 0
else:
    cnt_a = a
    k = k - cnt_a

if (b > 0) & (b > k):
    cnt_b = k
    k = 0
else:
    cnt_b = b
    k = k - cnt_b

if c > 0:
    cnt_c = k

result = cnt_a * 1 + cnt_b * 0 + cnt_c * (-1)
print(result)
Problem p02682 (Python)

Buggy submission (status: Time Limit Exceeded):
a, b, c, k = map(int, input().split())

ans = 0
for i in range(k):
    if a != 0:
        ans += 1
        a += -1
        continue
    if b != 0:
        ans += 0
        b += -1
        continue
    if c != 0:
        ans += -1
        c += -1
        continue
print(ans)


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

ans = 0

if a > k:
    ans += 1 * k
    k = 0
else:
    ans += 1 * a
    k -= a

if b > k:
    ans += 0 * k
    k = 0
else:
    ans += 0 * b
    k -= b

if c > k:
    ans += -1 * k
    k = 0
else:
    ans += -1 * c
    k -= c


print(ans)
Problem p02682 (Python)

Buggy submission (status: Time Limit Exceeded):
a, b, c, k = map(int, input().split())

ans = 0

while True:
    flg = True

    for i in range(a):
        ans += 1
        k -= 1
        if k == 0:
            flg = False
            break

    if not flg:
        break

    for i in range(b):
        k -= 1
        if k == 0:
            flg = False
            break

    if not flg:
        break

    for i in range(c):
        ans += -1
        k -= 1
        if k == 0:
            flg = False
            break

    if not flg:
        break

print(ans)


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

if k <= a:
    print(k)
elif k <= a + b:
    print(a)
else:
    print(a - (k - a - b))