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

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define rrep(i, n) RFOR(i, n, 0)
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;

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

  ll N, K;
  cin >> N >> K;

  ll t[N], d[N];
  map<ll, ll> mp1;
  rep(i, N) { cin >> t[i] >> d[i]; }

  vector<pll> v;

  rep(i, N) { v.push_back((pll){d[i], t[i]}); };

  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  map<ll, ll> mp;
  ll ans = 0;
  ll typ = 0;
  vector<ll> w;
  for (ll i = 0; i < K; i++) {
    pll p = v[i];
    auto it = mp.find(p.se);
    if (it == mp.end()) {
      mp[p.se] = 0;
      typ++;
    }

    mp[p.se]++;
    if (mp[p.se] >= 2)
      w.push_back(p.fi);

    ans += p.fi;
  }

  ans += typ * typ;
  // cout << "first:" << ans << endl;
  ll ans2 = ans;
  ll anst = ans;

  for (int i = K; i < N; i++) {
    pll p = v[i];
    // cout << i << " " << p.se << endl;
    auto it = mp.find(p.se);
    if (it != mp.end())
      continue;

    mp[p.se] = 1;

    ans2 -= w[w.size() - 1];
    ans2 += p.fi;
    ans2 -= typ * typ;
    ans2 += (typ + 1) * (typ + 1);

    w.pop_back();
    typ++;

    anst = max(anst, ans2);
    // cout << i << ":" << ans << " " << typ << endl;
  }

  cout << max(ans, anst) << endl;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define rrep(i, n) RFOR(i, n, 0)
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;

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

  ll N, K;
  cin >> N >> K;

  ll t[N], d[N];
  map<ll, ll> mp1;
  rep(i, N) { cin >> t[i] >> d[i]; }

  vector<pll> v;

  rep(i, N) { v.push_back((pll){d[i], t[i]}); };

  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  map<ll, ll> mp;
  ll ans = 0;
  ll typ = 0;
  vector<ll> w;
  for (ll i = 0; i < K; i++) {
    pll p = v[i];
    auto it = mp.find(p.se);
    if (it == mp.end()) {
      mp[p.se] = 0;
      typ++;
    }

    mp[p.se]++;
    if (mp[p.se] >= 2)
      w.push_back(p.fi);

    ans += p.fi;
  }

  ans += typ * typ;
  // cout << "first:" << ans << endl;
  ll ans2 = ans;
  ll anst = ans;

  for (int i = K; i < N; i++) {
    pll p = v[i];
    // cout << i << " " << p.se << endl;
    auto it = mp.find(p.se);
    if (it != mp.end())
      continue;

    mp[p.se] = 1;

    if (w.size() == 0)
      continue;
    ans2 -= w[w.size() - 1];
    ans2 += p.fi;
    ans2 -= typ * typ;
    ans2 += (typ + 1) * (typ + 1);

    w.pop_back();
    typ++;

    anst = max(anst, ans2);
    // cout << i << ":" << ans << " " << typ << endl;
  }

  cout << max(ans, anst) << endl;
}
Problem p03148 (C++)

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

int n, k;
map<int, vector<int>> m;
vector<vector<int> *> v;
priority_queue<int> p;

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    int t, d;
    scanf("%d %d", &t, &d);
    m[t].push_back(d);
  }
  for (map<int, vector<int>>::iterator i = m.begin(), e = m.end(); i != e;
       i++) {
    sort(i->second.begin(), i->second.end());
    v.push_back(&i->second);
  }
  sort(v.begin(), v.end(),
       [](const vector<int> *v1, const vector<int> *v2) -> bool {
         return v1->back() > v2->back();
       });
  int vs = (k <= v.size()) ? k : v.size();
  int ans[k];
  for (int i = 0; i < vs; i++) {
    ans[i] = v[i]->back();
    v[i]->pop_back();
  }
  for (int i = 0; i < vs; i++) {
    for (vector<int>::iterator j = v[i]->begin(), e = v[i]->end(); j != e;
         j++) {
      p.emplace(*j);
    }
  }
  for (int i = vs; i < k; i++) {
    ans[i] = p.top();
    p.pop();
  }
  int x = vs;
  while (true) {
    if (ans[x - 1] + 2 * x - 1 >= p.top())
      break;
    ans[--x] = p.top();
    p.pop();
  }
  long sum = 0;
  for (int i = 0; i < k; i++)
    sum += ans[i];
  sum += static_cast<long>(x) * x;
  printf("%ld\n", sum);
  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <map>
#include <queue>
#include <vector>
using namespace std;

int n, k;
map<int, vector<int>> m;
vector<vector<int> *> v;
priority_queue<int> p;

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++) {
    int t, d;
    scanf("%d %d", &t, &d);
    m[t].push_back(d);
  }
  for (map<int, vector<int>>::iterator i = m.begin(), e = m.end(); i != e;
       i++) {
    sort(i->second.begin(), i->second.end());
    v.push_back(&i->second);
  }
  sort(v.begin(), v.end(),
       [](const vector<int> *v1, const vector<int> *v2) -> bool {
         return v1->back() > v2->back();
       });
  int vs = (k <= v.size()) ? k : v.size();
  int ans[k];
  for (int i = 0; i < vs; i++) {
    ans[i] = v[i]->back();
    v[i]->pop_back();
  }
  for (int i = 0; i < vs; i++) {
    for (vector<int>::iterator j = v[i]->begin(), e = v[i]->end(); j != e;
         j++) {
      p.emplace(*j);
    }
  }
  for (int i = vs; i < k; i++) {
    ans[i] = p.top();
    p.pop();
  }
  int x = vs;
  while (true) {
    if (p.empty() || ans[x - 1] + 2 * x - 1 >= p.top())
      break;
    ans[--x] = p.top();
    p.pop();
  }
  long sum = 0;
  for (int i = 0; i < k; i++)
    sum += ans[i];
  sum += static_cast<long>(x) * x;
  printf("%ld\n", sum);
  return 0;
}
Problem p03149 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define f(p, n) for (ll i = p; i < n; i++)
ll exp(ll a, ll b, ll m);

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

#ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
#endif
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll a1[10] = {0};
  a1[a] = 1, a1[b] = 1;
  a1[c] = 1, a1[d] = 1;

  if (a1[1] == 1 && a1[9] == 1 && a1[7] == 1 && a1[4] == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}

ll exp(ll a, ll b, ll m) {
  if (b == 0) {
    return 1;
  }
  ll temp = exp(a, b / 2, m);
  temp = (temp * temp) % m;
  if (b & 1) {
    return (temp * (a % m)) % m;
  }
  return temp;
}


Fixed submission:
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define f(p, n) for (ll i = p; i < n; i++)
ll exp(ll a, ll b, ll m);

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

  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll a1[10] = {0};
  a1[a] = 1, a1[b] = 1;
  a1[c] = 1, a1[d] = 1;

  if (a1[1] == 1 && a1[9] == 1 && a1[7] == 1 && a1[4] == 1)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}

ll exp(ll a, ll b, ll m) {
  if (b == 0) {
    return 1;
  }
  ll temp = exp(a, b / 2, m);
  temp = (temp * temp) % m;
  if (b & 1) {
    return (temp * (a % m)) % m;
  }
  return temp;
}
Problem p03149 (C++)

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

int main() {
  string s;
  for (int i = 0; i < 4; i++) {
    cin >> s.at(i);
  }
  sort(s.begin(), s.end());
  string k = "NO";
  if (s == "1479") {
    k = "YES";
  }
  cout << k << endl;
  return 0;
}


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

int main() {
  string s = "    ";
  for (int i = 0; i < 4; i++) {
    cin >> s.at(i);
  }
  sort(s.begin(), s.end());
  string k = "NO";
  if (s == "1479") {
    k = "YES";
  }
  cout << k << endl;
  return 0;
}
Problem p03149 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int a;
  string s = "";
  for (int i = 0; i < 4; i++) {
    cin >> a;
    s.at(i) = '0' + a;
  }
  sort(s.begin(), s.end());
  if (s == "1479") {
    cout << "YES";
  } else {
    cout << "NO";
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int a;
  string s = "9999";
  for (int i = 0; i < 4; i++) {
    cin >> a;
    s.at(i) = '0' + a;
  }
  sort(s.begin(), s.end());
  if (s == "1479") {
    cout << "YES";
  } else {
    cout << "NO";
  }
}
Problem p03149 (C++)

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

int main() {
  string s;
  cin >> s.at(0) >> s.at(1) >> s.at(2) >> s.at(3);
  sort(s.begin(), s.end());
  if (s == "1479")
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

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

int main() {
  string s = "0000";
  cin >> s.at(0) >> s.at(1) >> s.at(2) >> s.at(3);
  sort(s.begin(), s.end());
  if (s == "1479")
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
Problem p03149 (C++)

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

int main() {
  vector<int> N(4);
  vector<int> hash_table(4, -1);
  hash_table[1] = 1;
  hash_table[9] = 1;
  hash_table[7] = 1;
  hash_table[4] = 1;
  int cnt = 4;
  for (int i = 0; i < 4; i++) {
    cin >> N[i];
    if (hash_table[N[i]] > 0) {
      hash_table[N[i]]--;
      cnt--;
    }
  }
  if (cnt == 0)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}

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

int main() {
  vector<int> N(4);
  vector<int> hash_table(10, -1);
  hash_table[1] = 1;
  hash_table[9] = 1;
  hash_table[7] = 1;
  hash_table[4] = 1;
  int cnt = 4;
  for (int i = 0; i < 4; i++) {
    cin >> N[i];
    if (hash_table[N[i]] > 0) {
      hash_table[N[i]]--;
      cnt--;
    }
  }
  if (cnt == 0)
    cout << "YES";
  else
    cout << "NO";
  return 0;
}
Problem p03149 (C++)

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

int main() {
  vector<int> cnt(10);
  for (int i = 0; 4; i++) {
    int n;
    cin >> n;
    cnt.at(n)++;
  }
  if (cnt.at(1) == 1 && cnt.at(9) == 1 && cnt.at(7) == 1 && cnt.at(4))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


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

int main() {
  vector<int> cnt(10);
  for (int i = 0; i < 4; i++) {
    int n;
    cin >> n;
    cnt.at(n)++;
  }
  if (cnt.at(1) == 1 && cnt.at(9) == 1 && cnt.at(7) == 1 && cnt.at(4))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
Problem p03149 (C++)

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

int main() {
  std::vector<int> v;
  std::vector<int> ans{1, 4, 7, 9};
  for (int i = 0; i < 3; i++)
    std::cin >> v[i];
  std::sort(v.begin(), v.end());
  if (v == ans) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }
  return 0;
}


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

int main() {
  std::vector<int> v(4, 0);
  int org[] = {1, 4, 7, 9};
  std::vector<int> ans(org, org + 4);
  for (int i = 0; i < 4; i++)
    std::cin >> v[i];
  std::sort(v.begin(), v.end());
  if (v == ans) {
    std::cout << "YES" << std::endl;
  } else {
    std::cout << "NO" << std::endl;
  }
  return 0;
}
Problem p03149 (Python)

Buggy submission (status: Runtime Error):
print("YES" if set(map(int, input().split())) == set(1, 9, 7, 4) else "NO")


Fixed submission:
print("YES" if set(list(map(int, input().split()))) == set([1, 9, 7, 4]) else "NO")
Problem p03149 (C++)

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

int main() {
  cin.tie(0)->sync_with_stdio(false);

  vector<int> n(4);
  REP(i, 4) cin >> n[i];
  sort(n.begin(), n.end());

  string s;
  REP(i, 4) s.push_back(n[i]);

  if (stoi(s) == 1479)
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';
  return 0;
}

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

int main() {
  cin.tie(0)->sync_with_stdio(false);

  vector<char> n(4);
  REP(i, 4) cin >> n[i];
  sort(n.begin(), n.end());

  string s;
  REP(i, 4) s.push_back(n[i]);

  if (stoi(s) == 1479)
    cout << "YES" << '\n';
  else
    cout << "NO" << '\n';
  return 0;
}
Problem p03149 (Python)

Buggy submission (status: Runtime Error):
import sys

input = sys.stdin.readline

N = list(map(int, input().split())).sorted()
if N[0] == 1 and N[1] == 4 and N[2] == 7 and N[3] == 9:
    print("YES")
else:
    print("NO")


Fixed submission:
import sys

input = sys.stdin.readline

N = sorted(list(map(int, input().split())))
if N[0] == 1 and N[1] == 4 and N[2] == 7 and N[3] == 9:
    print("YES")
else:
    print("NO")
Problem p03149 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int n, a[N], b[N];
int main() {
  for (int i = 0; i < 4; ++i)
    cin >> a[i];
  for (int i = 0; i < 4; ++i)
    b[i] = i;
  do {
    if (a[b[0]] == 1 && a[b[1]] == 9 && a[b[2]] == 7 && a[b[3]] == 4)
      return puts("YES");
  } while (next_permutation(b, b + 4));
  puts("NO");
}

Fixed submission:
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int n, a[N], b[N];
int main() {
  for (int i = 0; i < 4; ++i)
    cin >> a[i];
  for (int i = 0; i < 4; ++i)
    b[i] = i;
  do {
    if (a[b[0]] == 1 && a[b[1]] == 9 && a[b[2]] == 7 && a[b[3]] == 4) {
      puts("YES");
      return 0;
    }
  } while (next_permutation(b, b + 4));
  puts("NO");
}
Problem p03150 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

  string s;
  cin >> s;
  string answer = "keyence";

  int size, i;
  size = s.size();
  if (s == answer) {
    cout << "YES" << endl;
    return 0;
  }
  if (size < 8) {
    cout << "NO" << endl;
    return 0;
  }

  for (i = 0; i < size; i++) {
    string tmp;
    tmp = s;
    tmp.erase(tmp.begin() + i, tmp.begin() + i + size - 7);
    // cout <<tmp <<endl;
    if (tmp == answer) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

  string s;
  cin >> s;
  string answer = "keyence";

  int size, i;
  size = s.size();
  if (s == answer) {
    cout << "YES" << endl;
    return 0;
  }
  if (size < 8) {
    cout << "NO" << endl;
    return 0;
  }

  for (i = 0; i < 8; i++) {
    string tmp;
    tmp = s;
    tmp.erase(tmp.begin() + i, tmp.begin() + i + size - 7);
    // cout <<tmp <<endl;
    if (tmp == answer) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
Problem p03150 (C++)

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

int main() {
  regex re[8];
  re[0] = "keyence.*";
  re[1] = "keyenc.*e";
  re[2] = "keyen.*ce";
  re[3] = "keye.*nce";
  re[4] = "key.*ence";
  re[5] = "ke.*yence";
  re[6] = "k.*eyence";
  re[7] = ".*keyence";
  string s;
  cin >> s;
  bool ret = false;
  for (int i = 0; i < s.size(); i++) {
    ret = ret || regex_match(s, re[i]);
  }
  cout << (ret ? "YES" : "NO") << endl;

  return 0;
}

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

int main() {
  regex re[8];
  re[0] = "keyence.*";
  re[1] = "keyenc.*e";
  re[2] = "keyen.*ce";
  re[3] = "keye.*nce";
  re[4] = "key.*ence";
  re[5] = "ke.*yence";
  re[6] = "k.*eyence";
  re[7] = ".*keyence";
  string s;
  cin >> s;
  bool ret = false;
  for (int i = 0; i < 8; i++) {
    ret = ret || regex_match(s, re[i]);
  }
  cout << (ret ? "YES" : "NO") << endl;

  return 0;
}
Problem p03150 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

char s[110];
int szS;

string target;

int main() {
  scanf("%s", s);
  szS = strlen(s);
  string ss = s;

  int delDepth = szS - 7;
  if (delDepth == 0) {
    if (ss == "keyence")
      printf("YES\n");
    else
      printf("NO\n");
    return 0;
  }

  for (int i = 0; i < szS - 7; i++) {
    target = ss.substr(0, i) + ss.substr(i + delDepth);
    if (target == "keyence") {
      printf("YES\n");
      return 0;
    }
  }

  printf("NO\n");

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

char s[110];
int szS;

string target;

int main() {
  scanf("%s", s);
  szS = strlen(s);
  string ss = s;

  int delDepth = szS - 7;
  if (delDepth == 0) {
    if (ss == "keyence")
      printf("YES\n");
    else
      printf("NO\n");
    return 0;
  }

  for (int i = 0; i < szS - delDepth; i++) {
    target = ss.substr(0, i) + ss.substr(i + delDepth);
    if (target == "keyence") {
      printf("YES\n");
      return 0;
    }
  }

  printf("NO\n");

  return 0;
}
Problem p03150 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size(), a = 0;
  if (n == 7)
    cout << "YES" << endl;
  else {
    for (int i = 0; i < n - 7 + 1; i++) {
      string t = s.substr(0, i) + s.substr(n + i - 7, 7 - i);
      if (t == "keyence") {
        a++;
        cout << "YES" << endl;
        break;
      }
    }
    if (a == 0)
      cout << "NO" << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n = s.size(), a = 0;
  if (n == 7)
    cout << "YES" << endl;
  else {
    for (int i = 0; i < 7; i++) {
      string t = s.substr(0, i) + s.substr(n + i - 7, 7 - i);
      if (t == "keyence") {
        a++;
        cout << "YES" << endl;
        break;
      }
    }
    if (a == 0)
      cout << "NO" << endl;
  }
}
Problem p03150 (C++)

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

int main() {
  const string keyword = "keyence";
  string S;
  cin >> S;

  bool is_satisfied = false;
  for (size_t len_head = 0; len_head <= keyword.size(); len_head++) {
    size_t len_tail = keyword.size() - len_head;
    if (S.substr(0, len_head) == keyword.substr(0, len_head) &&
        S.substr(S.size() - len_tail) == keyword.substr(S.size() - len_tail)) {
      is_satisfied = true;
      break;
    }
  }
  string ans = is_satisfied ? "YES" : "NO";
  cout << ans << endl;
}

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

int main() {
  const string keyword = "keyence";
  string S;
  cin >> S;

  bool is_satisfied = false;
  for (size_t len_head = 0; len_head <= keyword.size(); len_head++) {
    size_t len_tail = keyword.size() - len_head;
    if (S.substr(0, len_head) == keyword.substr(0, len_head) &&
        S.substr(S.size() - len_tail) ==
            keyword.substr(keyword.size() - len_tail)) {
      is_satisfied = true;
      break;
    }
  }
  string ans = is_satisfied ? "YES" : "NO";
  cout << ans << endl;
}
Problem p03150 (C++)

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

using namespace std;

int main(void) {
  string s;
  cin >> s;
  int n = s.length();
  bool flag = false;
  for (int i = 0; i <= n; ++i) {
    if (s.substr(0, i) + s.substr(n - (7 - i)) == string("keyence"))
      flag = true;
  }
  cout << (flag ? "YES" : "NO") << endl;
  return 0;
}

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

using namespace std;

int main(void) {
  string s;
  cin >> s;
  int n = s.length();
  bool flag = false;
  for (int i = 0; i <= 7; ++i) {
    if (s.substr(0, i) + s.substr(n - (7 - i)) == string("keyence"))
      flag = true;
  }
  cout << (flag ? "YES" : "NO") << endl;
  return 0;
}
Problem p03150 (C++)

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

int main() {
  string s, f, b, x;
  cin >> s;
  for (int i = 0; i < s.size() - 6; i++) {
    f = s.substr(0, i - 0);
    b = s.substr(f.size() + (s.size() - 7),
                 s.size() - (s.size() - 7 + f.size()));
    x = f + b;
    // cout<<f<<" "<<b<<endl;
    if (x == "keyence") {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}

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

int main() {
  string s, f, b, x;
  cin >> s;
  for (int i = 0; i < 8; i++) {
    f = s.substr(0, i - 0);
    b = s.substr(f.size() + (s.size() - 7),
                 s.size() - (s.size() - 7 + f.size()));
    x = f + b;
    // cout<<f<<" "<<b<<endl;
    if (x == "keyence") {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}
Problem p03150 (C++)

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

bool f() {
  string s;
  cin >> s;
  string a = "keyence";
  int l = s.size();
  if (l < 7)
    return false;
  for (int i = 0; i < 8; i++) {
    if (s.substr(0, i) != a.substr(0, i))
      continue;
    int j = 7 - i;
    if (s.substr(l - 1 - j, j) == a.substr(6 - j, j))
      return true;
  }
  return false;
}

int main() {
  if (f())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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

bool f() {
  string s;
  cin >> s;
  string a = "keyence";
  int l = s.size();
  if (l < 7)
    return false;
  for (int i = 0; i < 8; i++) {
    if (s.substr(0, i) != a.substr(0, i))
      continue;
    int j = 7 - i;
    if (s.substr(l - j, j) == a.substr(7 - j, j))
      return true;
  }
  return false;
}

int main() {
  if (f())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
Problem p03150 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef long long Int;
Int mod = 1e9 + 7;
Int MOD = 998244353;

int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  Int n = (Int)s.size();
  bool res;
  for (Int i = 0; i < (Int)s.size() - 7; i++) {
    string t = s.substr(0, i);
    t = t + s.substr(n - (7 - i));
    // dump(t);
    if (t == "keyence") {
      res = true;
    }
  }
  if (s == "keyence")
    res = true;
  dump(res ? "YES" : "NO");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <ctype.h>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define dump(a) cout << (a) << '\n';
typedef long long Int;
Int mod = 1e9 + 7;
Int MOD = 998244353;

int main() {
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  Int n = (Int)s.size();
  bool res = false;
  for (Int i = 0; i <= 7; i++) {
    string t = s.substr(0, i);
    t = t + s.substr(n - (7 - i));
    // dump(t);
    if (t == "keyence") {
      res = true;
    }
  }
  if (s == "keyence")
    res = true;
  dump(res ? "YES" : "NO");
  return 0;
}
Problem p03150 (C++)

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(), s.end())
#define reverse(s) reverse(s.begin(), s.end())
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)

const ll mod = 1e9 + 7;

// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

// 素数判定
bool isPrime(ll x) {
  ll i;
  if (x < 2)
    return 0;
  else if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (i = 3; i * i <= x; i += 2)
    if (x % i == 0)
      return 0;
  return 1;
}

// 桁和
int digsum(ll n) {
  int res = 0;
  while (n > 0) {
    res += n % 10;
    n /= 10;
  }
  return res;
}

// 桁数
int dignum(ll n) {
  int res = 0;
  while (n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

// 文字列中の特定の文字カウント
ll stringcount(string s, char c) { return count(s.cbegin(), s.cend(), c); }

// 階乗
ll ka(ll i) {
  ll res = 1;
  while (i > 0) {
    res = res * i;
    i--;
  }
  return res;
}

// ncr
ll ncr(ll x, ll y) {
  ll a = x;
  ll b = 1;
  if (y > (x / 2)) {
    y = x - y;
  }
  for (ll i = 1; i < y; i++) {
    a *= x - i;
    b *= i + 1;
  }
  return a / b;
}

int main() {
  string s;
  cin >> s;
  string key = "keyence";
  bool ok = false;

  if (key == s)
    ok = true;

  int x = s.size() - key.size();

  for (int i = 0; i < x - 1; i++) {
    string t = s;
    t.erase(t.begin() + i, t.begin() + i + x);
    if (t == key)
      ok = true;
  }
  if (ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(), s.end())
#define reverse(s) reverse(s.begin(), s.end())
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)

const ll mod = 1e9 + 7;

// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

// 素数判定
bool isPrime(ll x) {
  ll i;
  if (x < 2)
    return 0;
  else if (x == 2)
    return 1;
  if (x % 2 == 0)
    return 0;
  for (i = 3; i * i <= x; i += 2)
    if (x % i == 0)
      return 0;
  return 1;
}

// 桁和
int digsum(ll n) {
  int res = 0;
  while (n > 0) {
    res += n % 10;
    n /= 10;
  }
  return res;
}

// 桁数
int dignum(ll n) {
  int res = 0;
  while (n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

// 文字列中の特定の文字カウント
ll stringcount(string s, char c) { return count(s.cbegin(), s.cend(), c); }

// 階乗
ll ka(ll i) {
  ll res = 1;
  while (i > 0) {
    res = res * i;
    i--;
  }
  return res;
}

// ncr
ll ncr(ll x, ll y) {
  ll a = x;
  ll b = 1;
  if (y > (x / 2)) {
    y = x - y;
  }
  for (ll i = 1; i < y; i++) {
    a *= x - i;
    b *= i + 1;
  }
  return a / b;
}

int main() {
  string s;
  cin >> s;
  string key = "keyence";
  bool ok = false;

  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < s.size() - i; j++) {
      string t = s;
      t.erase(i, j);
      if (t == key)
        ok = true;
    }
  }
  if (ok)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
Problem p03150 (C++)

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

int main() {
  string s;
  bool f = 0;

  cin >> s;

  if (s == "keyence")
    f = 1;
  else if (s.size() > 7) {
    for (int i = 0; i < s.size() - 7; i++) {
      string t = s.substr(0, i) + s.substr(i + s.size() - 7, s.size());
      if (t == "keyence") {
        f = 1;
        break;
      }
    }
  }

  if (f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}


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

int main() {
  string s;
  bool f = 0;

  cin >> s;

  if (s == "keyence")
    f = 1;
  else if (s.size() > 7) {
    for (int i = 0; i < 7; i++) {
      string t = s.substr(0, i) + s.substr(i + s.size() - 7, s.size());
      if (t == "keyence") {
        f = 1;
        break;
      }
    }
  }

  if (f)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}
Problem p03150 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define FOR(x, xs) for (auto &x : xs)

using namespace std;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT *delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  string target = "keyence";
  string s;
  cin >> s;
  int n = s.size();
  REP(i, 0, n - 7) {
    if (s.substr(0, i) + s.substr(n - 7 + i) == target) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

#define REP(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define FOR(x, xs) for (auto &x : xs)

using namespace std;
typedef long long ll;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT *delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  string target = "keyence";
  string s;
  cin >> s;
  int n = s.size();
  REP(i, 0, 8) {
    if (s.substr(0, i) + s.substr(n - 7 + i) == target) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;

  return 0;
}
Problem p03150 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl /*, greater<ll>*/> pql; // 降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for (ll i = 1; i <= ll(n); ++i)
// #define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
// #define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
bool chmax(ll &a, ll b) {
  if (b > a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  string S;
  cin >> S;
  if (S.size() >= 7) {
    rep(i, 8) {
      if (S.substr(0, i) + S.substr(S.size() - 8 + i) == "keyence")
        goto ABLE;
    }
  }
  cout << "NO" << newl;
  return 0;

ABLE:
  cout << "YES" << newl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl /*, greater<ll>*/> pql; // 降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for (ll i = 1; i <= ll(n); ++i)
// #define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
// #define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
bool chmax(ll &a, ll b) {
  if (b > a) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  string S;
  cin >> S;
  rep(i, 8) {
    if (S.substr(0, i) + S.substr(S.size() - 7 + i) == "keyence")
      goto ABLE;
  }
  cout << "NO" << newl;
  return 0;

ABLE:
  cout << "YES" << newl;
  return 0;
}
Problem p03150 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pa = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const long double EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//

int main() {
  init();
  string s, k = "keyence";
  cin >> s;
  int N = s.size();
  bool isok = false;
  rep(i, N - 7) {
    string t = s.substr(0, i) + s.substr(N - 7 + i, 7 - i);
    // cout << s.substr(0, i) << " " << s.substr(N - 7 + i, 7 - i) << endl;
    if (t == k) {
      isok = true;
      break;
    }
  }
  cout << (isok ? "YES" : "NO") << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pa = pair<ll, ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const long double EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//

int main() {
  init();
  string s, k = "keyence";
  cin >> s;
  int N = s.size();
  bool isok = false;
  rep(i, 8) {
    string t = s.substr(0, i) + s.substr(N - 7 + i, 7 - i);
    // cout << s.substr(0, i) << " " << s.substr(N - 7 + i, 7 - i) << endl;
    if (t == k) {
      isok = true;
      break;
    }
  }
  cout << (isok ? "YES" : "NO") << endl;
  return 0;
}
Problem p03150 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  int subN = N - 7;
  if (subN < 0) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    string first = S.substr(0, i);
    string middle = S.substr(i, subN);
    string last = S.substr(i + subN);
    string ans = first + last;
    // cout << ans << endl;
    if (ans == "keyence") {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string S;
  cin >> S;
  int N = S.size();
  int subN = N - 7;
  if (subN < 0) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 0; i < N - subN + 1; i++) {
    string first = S.substr(0, i);
    string middle = S.substr(i, subN);
    string last = S.substr(i + subN);
    string ans = first + last;
    // cout << ans << endl;
    if (ans == "keyence") {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
Problem p03150 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main() {
  string s;
  cin >> s;
  // string key = "keyence";
  int slen = s.size();
  bool ans = false;
  if (s == "keyence") {
    cout << "YES" << endl;
    return 0;
  }
  for (int i = 1; i <= slen; i++) {
    for (int j = 0; j <= slen - i; j++) {
      if (s.erase(j, i) == "keyence")
        ans = true;
    }
  }
  if (ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main() {
  string s;
  cin >> s;
  // string key = "keyence";
  int slen = s.size();
  bool ans = false;
  if (s == "keyence") {
    cout << "YES" << endl;
    return 0;
  }
  for (int i = 1; i <= slen; i++) {
    for (int j = 0; j <= slen - i; j++) {
      string t = s;
      if (t.erase(j, i) == "keyence")
        ans = true;
    }
  }
  if (ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}
Problem p03150 (C++)

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i <= n - 7; i++) {
    string t = s.substr(0, i) + s.substr(n - 7 + i, n);
    if (t == "keyence") {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}


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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i <= 7; i++) {
    string t = s.substr(0, i) + s.substr(n - 7 + i);
    if (t == "keyence") {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
Problem p03150 (C++)

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

int main() {
  string k = "keyence";
  string t;
  cin >> t;
  if (t.size() < k.size())
    return 0 * printf("NO\n");
  for (int i = 0; i < t.size() - k.size() + 1; i++) {
    string s = t.substr(0, i) + t.substr(t.size() - k.size() + i, k.size() - i);
    if (s == k)
      return 0 * printf("YES\n");
  }
  printf("NO\n");
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair

int main() {
  string k = "keyence";
  string t;
  cin >> t;
  if (t.size() < k.size())
    return 0 * printf("NO\n");
  for (int i = 0; i < k.size() + 1; i++) {
    string s = t.substr(0, i) + t.substr(t.size() - k.size() + i, k.size() - i);
    if (s == k)
      return 0 * printf("YES\n");
  }
  printf("NO\n");
  return 0;
}
Problem p03150 (Python)

Buggy submission (status: Runtime Error):
from re import fullmatch

S = input()
_s = "keyence"
flag = False
for i in range(len(_s)):
    if fullmatch(f".*{_s[:i]}.*{_s[i:]}.*", S):
        flag = True
print("YES") if flag else print("NO")


Fixed submission:
from re import fullmatch

S = input()
_s = "keyence"
flag = False
for i in range(len(_s)):
    tmp = fullmatch("(.*)" + _s[:i] + "(.*)" + _s[i:] + "(.*)", S)
    if tmp and sum([1 for j in range(1, 4) if tmp.group(j)]) <= 1:
        flag = True
print("YES") if flag else print("NO")
Problem p03150 (Python)

Buggy submission (status: Runtime Error):
S = str(input())
s = input()
for i in range(len(s)):
    for j in range(i, len(s)):
        a = s[:i] + s[j:]
        if a == "keyence":
            print("YES")
            exit()
print("NO")


Fixed submission:
s = str(input())
for i in range(len(s)):
    for j in range(i, len(s)):
        a = s[:i] + s[j:]
        if a == "keyence":
            print("YES")
            exit()
print("NO")
Problem p03150 (Python)

Buggy submission (status: Runtime Error):
N = input()

S = "keyence"
index = 0
for item in N:
    if S[index] == item:
        index += 1

print("YES" if index == len(S) else "NO")


Fixed submission:
N = input()

S = "keyence"
if S == N[: len(S)]:
    print("YES")
elif S == N[-len(S) :]:
    print("YES")
else:
    for index in range(len(S)):
        if S[:index] == N[:index] and S[-(len(S) - index) :] == N[-(len(S) - index) :]:
            print("YES")
            break
    else:
        print("NO")
Problem p03150 (C++)

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

int main() {
  string S;
  cin >> S;
  int len = (int)(S.size());
  bool ans = false;

  if (S.substr(0, 7) == "keyence" || S.substr(len - 7) == "keyence")
    ans = true;
  for (int i = 1; i < len - 1; i++) {
    string a = S.substr(0, i);
    string b = S.substr(len - 7 + i);
    if (a + b == "keyence")
      ans = true;
  }
  if (ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


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

int main() {
  string S;
  cin >> S;
  int len = (int)(S.size());
  bool ans = false;

  if (S.substr(0, 7) == "keyence" || S.substr(len - 7) == "keyence")
    ans = true;
  for (int i = 1; i < 7; i++) {
    string a = S.substr(0, i);
    string b = S.substr(len - 7 + i);
    if (a + b == "keyence")
      ans = true;
  }
  if (ans)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
Problem p03150 (C++)

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

typedef long long ll;
typedef pair<int, int> p_int;
typedef pair<ll, ll> p_ll;
typedef tuple<ll, ll, ll> t3_ll;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int prime[] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37, 41,
               43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
const ll inf = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  bool ok = false;
  for (int i = 0; i < 9; i++) {
    string x = s;
    x.erase(i, s.size() - 7);
    if (x == "keyence") {
      ok = true;
    }
  }
  if (ok)
    cout << "YES";
  else
    cout << "NO";
  cout << endl;
}

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

typedef long long ll;
typedef pair<int, int> p_int;
typedef pair<ll, ll> p_ll;
typedef tuple<ll, ll, ll> t3_ll;
int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
int prime[] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37, 41,
               43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97};
const ll inf = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  bool ok = false;
  for (int i = 0; i < 7; i++) {
    string x = s;
    x.erase(i, s.size() - 7);
    if (x == "keyence") {
      ok = true;
    }
  }
  if (ok)
    cout << "YES";
  else
    cout << "NO";
  cout << endl;
}
Problem p03150 (C++)

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

const char *key = "keyence";
const int keylen = 7;

int main() {
  string str;
  cin >> str;
  int f, b;
  for (f = 0; key[f] == str.at(f); f++)
    ;
  for (b = 0; key[keylen - b - 1] == str.at(str.length() - b - 1); b++)
    ;
  cout << ((f + b) >= keylen ? "YES" : "NO") << endl;
}

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

const char *key = "keyence";
const int keylen = 7;

int main() {
  string str;
  cin >> str;
  int f, b;
  for (f = 0; f < keylen; f++) {
    if (key[f] != str.at(f))
      break;
  }
  for (b = 0; b < keylen; b++) {
    if (key[keylen - b - 1] != str.at(str.length() - b - 1))
      break;
  }
  cout << ((f + b) >= keylen ? "YES" : "NO") << endl;
}
Problem p03151 (C++)

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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < (n); i++)
#define CLR(mat, f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a <= x && x < b)
#define out(ans) cout << ans << endl
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const int INF = 1000000;
const double PI = 3.14159265359;

int main() {

  ifstream in("12.txt");
  cin.rdbuf(in.rdbuf());

  ll n;
  cin >> n;
  ll a[n], b[n];
  ll asum = 0, bsum = 0;

  rep(i, 0, n) {
    cin >> a[i];
    asum += a[i];
  }
  rep(i, 0, n) {
    cin >> b[i];
    bsum += b[i];
  }

  if (asum < bsum) {
    out(-1);
    return 0;
  }

  ll sum = 0;
  multiset<ll, greater<ll>> se;
  ll ans = 0;
  rep(i, 0, n) {
    if (a[i] < b[i]) {
      sum += b[i] - a[i];
      ans++;
    } else if (a[i] > b[i]) {
      se.insert(a[i] - b[i]);
    }
  }
  if (sum == 0) {
    out(0);
    return 0;
  }
  // out(sum);
  for (multiset<ll, greater<ll>>::iterator itr = se.begin(); itr != se.end();
       itr++) {
    sum -= *itr;
    ans++;
    if (sum <= 0) {
      out(ans);
      return 0;
    }
  }

  return 0;
}


Fixed submission:
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < (n); i++)
#define CLR(mat, f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a <= x && x < b)
#define out(ans) cout << ans << endl
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
const int INF = 1000000;
const double PI = 3.14159265359;

int main() {

  // ifstream in("12.txt");
  // cin.rdbuf(in.rdbuf());

  ll n;
  cin >> n;
  ll a[n], b[n];
  ll asum = 0, bsum = 0;

  rep(i, 0, n) {
    cin >> a[i];
    asum += a[i];
  }
  rep(i, 0, n) {
    cin >> b[i];
    bsum += b[i];
  }

  if (asum < bsum) {
    out(-1);
    return 0;
  }

  ll sum = 0;
  multiset<ll, greater<ll>> se;
  ll ans = 0;
  rep(i, 0, n) {
    if (a[i] < b[i]) {
      sum += b[i] - a[i];
      ans++;
    } else if (a[i] > b[i]) {
      se.insert(a[i] - b[i]);
    }
  }
  if (sum == 0) {
    out(0);
    return 0;
  }
  // out(sum);
  for (multiset<ll, greater<ll>>::iterator itr = se.begin(); itr != se.end();
       itr++) {
    sum -= *itr;
    ans++;
    if (sum <= 0) {
      out(ans);
      return 0;
    }
  }

  return 0;
}