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

Buggy submission (status: Memory Limit Exceeded):
#include <stdio.h>
#include <string.h>

#define M 20000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0)
      return 0;
  }
  return 0;
}

int insert(char str[]) {

  long long key, i, h;
  key = getKey(str);
  for (int i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main() {
  int i, n, h;
  char str[L], com[9];
  for (i = 0; i < M; i++)
    H[i][0] = '\0';

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%s %s", com, str);

    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }

  return 0;
}


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

#define M 2000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0)
      return 0;
  }
  return 0;
}

int insert(char str[]) {

  long long key, i, h;
  key = getKey(str);
  for (int i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main() {
  int i, n, h;
  char str[L], com[9];
  for (i = 0; i < M; i++)
    H[i][0] = '\0';

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%s %s", com, str);

    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }

  return 0;
}
Problem p02269 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define PUSH(n, v)                                                             \
  for (int i = 0; i < (n); i++) {                                              \
    int j;                                                                     \
    cin >> j;                                                                  \
    v.push_back(j);                                                            \
  }
#define ALL(v) v.begin(), v.end()

int getint(char c) {
  if (c == 'A')
    return 1;
  else if (c == 'C')
    return 2;
  else if (c == 'G')
    return 3;
  else
    return 4;
}

int getint(string s) {
  int j = 1;
  int a = 0;
  REP(i, s.size()) {
    a += j * getint(s[i]);
    j *= 5;
  }
  return a;
}

int main() {
  int n;
  cin >> n;
  set<int> st;
  REP(i, n) {
    string s, t;
    cin >> s >> t;
    int h = getint(t);
    if (s == "insert")
      st.insert(h);
    else {
      if (st.find(h) != st.end())
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <set>
#include <stack>
#include <vector>
using namespace std;

#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define PUSH(n, v)                                                             \
  for (int i = 0; i < (n); i++) {                                              \
    int j;                                                                     \
    cin >> j;                                                                  \
    v.push_back(j);                                                            \
  }
#define ALL(v) v.begin(), v.end()

int getint(char c) {
  if (c == 'A')
    return 1;
  else if (c == 'C')
    return 2;
  else if (c == 'G')
    return 3;
  else
    return 4;
}

int getint(string s) {
  int j = 1;
  int a = 0;
  REP(i, s.size()) {
    a += j * getint(s[i]);
    j *= 5;
  }
  return a;
}

int main() {
  int n;
  cin >> n;
  set<int> st;
  REP(i, n) {
    string s, t;
    cin >> s >> t;
    int h = getint(t);
    if (s[0] == 'i')
      st.insert(h);
    else {
      if (st.find(h) != st.end())
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}
Problem p02269 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define M 1046527
using namespace std;
long long h1(long long key) { return key % M; }
long long h2(long long key) { return 1 + (key % (M - 1)); }
long long getNum(char c) {
  if (c == 'A')
    return 1;
  if (c == 'C')
    return 2;
  if (c == 'G')
    return 3;
  if (c == 'T')
    return 4;
  return 0;
}
long long getValue(char *s) {
  long long i = 0, value = 0;
  while (s[i]) {
    value = value * 10 + getNum(s[i]);
    i++;
  }
  return value;
}
char s[1000006][13], word[13], order[10];
long long n, key, value;
int main() {
  cin >> n;
  for (long long i = 0; i < 1000006; i++)
    s[i][0] = 0;
  for (long long i = 0; i < n; i++) {
    scanf("%s %s", order, word);
    value = getValue(word);
    if (order[0] == 'i') {
      long long k = 0;
      while (true) {
        key = (h1(value) + k * h2(value)) % M;
        if (strcmp(s[key], word) == 0) {
          break;
        } else if (strlen(s[key]) == 0) {
          strcpy(s[key], word);
          break;
        }
        k++;
      }
    } else {
      long long k = 0;
      while (true) {
        key = (h1(value) + k * h2(value)) % M;
        if (strcmp(s[key], word) == 0) {
          cout << "yes\n";
          break;
        } else if (strlen(s[key]) == 0) {
          cout << "no\n";
          break;
        }
        k++;
      }
    }
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define M 1046527
using namespace std;
long long h1(long long key) { return key % M; }
long long h2(long long key) { return 1 + (key % (M - 1)); }
long long getNum(char c) {
  if (c == 'A')
    return 1;
  if (c == 'C')
    return 2;
  if (c == 'G')
    return 3;
  if (c == 'T')
    return 4;
  return 0;
}
long long getValue(char *s) {
  long long i = 0, value = 0;
  while (s[i]) {
    value = value * 10 + getNum(s[i]);
    i++;
  }
  return value;
}
char s[1046527][13], word[13], order[10];
long long n, key, value;
int main() {
  cin >> n;
  for (long long i = 0; i < 1000006; i++)
    s[i][0] = 0;
  for (long long i = 0; i < n; i++) {
    scanf("%s %s", order, word);
    value = getValue(word);
    if (order[0] == 'i') {
      long long k = 0;
      while (true) {
        key = (h1(value) + k * h2(value)) % M;
        if (strcmp(s[key], word) == 0) {
          break;
        } else if (strlen(s[key]) == 0) {
          strcpy(s[key], word);
          break;
        }
        k++;
      }
    } else {
      long long k = 0;
      while (true) {
        key = (h1(value) + k * h2(value)) % M;
        if (strcmp(s[key], word) == 0) {
          cout << "yes\n";
          break;
        } else if (strlen(s[key]) == 0) {
          cout << "no\n";
          break;
        }
        k++;
      }
    }
  }

  return 0;
}
Problem p02269 (C++)

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

using namespace std;

const unsigned long M = 1046527;
const int L = 14;

char H[M][L];

long long getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
  else
    return 0;
}

long long getKey(char str[]) {
  long long sum = 0, p = 1;
  for (int i = 0; i < strlen(str); ++i) {
    sum += p * getChar(str[i]);
    p *= 5;
  }
  return sum;
}

int h1(long long key) { return key % M; }
int h2(long long key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
  long long key, h;
  key = getKey(str);
  for (long long i = 0;; ++i) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0)
      return 0;
  }
}

int insert(char str[]) {
  long long key, h;
  key = getKey(str);
  for (long long i = 0;; ++i) {
    h = (h1(key) + i * h2(key));
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
}

int main() {
  for (int i = 0; i < M; ++i)
    H[i][0] = '\0';

  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    char cmd[L];
    char wrd[L];
    scanf("%s %s", cmd, wrd);

    if (cmd[0] == 'i') {
      insert(wrd);
    } else {
      cout << (find(wrd) ? "yes" : "no") << endl;
    }
  }

  return 0;
}

Fixed submission:
#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

const unsigned long M = 1046527;
const int L = 14;

char H[M][L];

long long getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
  else
    return 0;
}

long long getKey(char str[]) {
  long long sum = 0, p = 1;
  for (int i = 0; i < strlen(str); ++i) {
    sum += p * getChar(str[i]);
    p *= 5;
  }
  return sum;
}

int h1(long long key) { return key % M; }
int h2(long long key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
  long long key, h;
  key = getKey(str);
  for (long long i = 0;; ++i) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0)
      return 0;
  }
}

int insert(char str[]) {
  long long key, h;
  key = getKey(str);
  for (long long i = 0;; ++i) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
}

int main() {
  for (int i = 0; i < M; ++i)
    H[i][0] = '\0';

  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    char cmd[L];
    char wrd[L];
    scanf("%s %s", cmd, wrd);

    if (cmd[0] == 'i') {
      insert(wrd);
    } else {
      cout << (find(wrd) ? "yes" : "no") << endl;
    }
  }

  return 0;
}
Problem p02269 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  set<string> dict;

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

    cin >> command;
    cin >> val;

    if (command[0] == 'i') {
      // insert
      dict.insert(val);
    } else {
      // find
      if (dict.find(val) != dict.end()) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }

  return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  set<string> dict;

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

    cin >> command;
    cin >> val;

    if (command[0] == 'i') {
      // insert
      dict.insert(val);
    } else {
      // find
      if (dict.find(val) != dict.end()) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }

  return 0;
}
Problem p02269 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#define M 10465277
#define NIL (-1)
#define L 14

char H[M][L];
int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
  else
    return 0;
}
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0)
      return 0;
  }
  return 0;
}
int insert(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}
int main(int argc, char const *argv[]) {
  char str[L], com[9];
  int i, n, h;
  std::cin >> n;
  for (i = 0; i < M; i++)
    H[i][0] = '\0';
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s %s", com, str);
    if (com[0] == 'i') {
      insert(str);
      // printf("ins\n");
    } else {
      if (find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}

Fixed submission:
#include <cstring>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];
int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
  else
    return 0;
}
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}
int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }
int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0)
      return 0;
  }
  return 0;
}
int insert(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}
int main(int argc, char const *argv[]) {
  char str[L], com[9];
  int i, n, h;
  std::cin >> n;
  for (i = 0; i < M; i++)
    H[i][0] = '\0';
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s %s", com, str);
    if (com[0] == 'i') {
      insert(str);
      // printf("ins\n");
    } else {
      if (find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}
Problem p02269 (C++)

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

#define M 1000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return (key % M - 1) + 1; }
// Hash function
int hash(int key, int i) { return (h1(key) + i * h2(key)); }

int find(char str[]) {
  long long i = 0;
  long long key = getKey(str);
  while (true) {
    long long j = hash(key, i);
    if (strcmp(H[j], str) == 0)
      return 1;
    else if (strlen(H[j]) == 0)
      return 0;
    i++;
  }
}

int insert(char str[]) {
  long long i = 0;
  long long key = getKey(str);
  while (true) {
    long long j = hash(key, i);
    if (H[j][0] == '\0') {
      strcpy(H[j], str);
      return 1;
    } else {
      i++;
    }
  }
}

int main() {
  int i, n, h;
  char str[L], com[9];
  for (i = 0; i < M; i++)
    H[i][0] = '\0';

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%s %s", com, str);

    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }

  return 0;
}

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

#define M 1000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return (key % M - 1) + 1; }
// Hash function
int hash(int key, int i) { return (h1(key) + i * h2(key)) % M; }

int find(char str[]) {
  long long i = 0;
  long long key = getKey(str);
  while (true) {
    long long j = hash(key, i);
    if (strcmp(H[j], str) == 0)
      return 1;
    else if (strlen(H[j]) == 0)
      return 0;
    i++;
  }
}

int insert(char str[]) {
  long long i = 0;
  long long key = getKey(str);
  while (true) {
    long long j = hash(key, i);
    if (H[j][0] == '\0') {
      strcpy(H[j], str);
      return 1;
    } else {
      i++;
    }
  }
}

int main() {
  int i, n, h;
  char str[L], com[9];
  for (i = 0; i < M; i++)
    H[i][0] = '\0';

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%s %s", com, str);

    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }

  return 0;
}
Problem p02269 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <stdio.h>
#include <string.h>

#define M 10000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {

  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0)
      return 0;
  }

  return 0;
}

int insert(char str[]) {

  long long key, i, h;
  key = getKey(str);

  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main() {
  int i, n, h;
  char str[L], com[9];
  for (i = 0; i < M; i++)
    H[i][0] = '\0';

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%s %s", com, str);

    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }

  return 0;
}

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

#define M 1000000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {

  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0)
      return 0;
  }

  return 0;
}

int insert(char str[]) {

  long long key, i, h;
  key = getKey(str);

  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
  return 0;
}

int main() {
  int i, n, h;
  char str[L], com[9];
  for (i = 0; i < M; i++)
    H[i][0] = '\0';

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%s %s", com, str);

    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }

  return 0;
}
Problem p02269 (C++)

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
  else
    return 0;
}

long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 10;
  }
  return sum;
}

int h1(int key) { return key % M; }

int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0)
      return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
}
int main() {
  int i, n, h;
  char str[L], com[9];
  for (i = 0; i < M; i++)
    H[i][0] = '\0';
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s %s", com, str);
    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str))
        printf("yes\n");
      else
        printf("no\n");
    }
  }
  return 0;
}


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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
  else
    return 0;
}

long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 6;
  }
  return sum;
}

int h1(int key) { return key % M; }

int h2(int key) { return 1 + (key % (M - 1)); }

int find(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0)
      return 0;
  }
  return 0;
}

int insert(char str[]) {
  long long key, i, h;
  key = getKey(str);
  for (i = 0;; i++) {
    h = (h1(key) + i * h2(key)) % M;
    if (strcmp(H[h], str) == 0)
      return 1;
    else if (strlen(H[h]) == 0) {
      strcpy(H[h], str);
      return 0;
    }
  }
}
int main() {
  int i, n, h;
  char str[L], com[9];
  for (i = 0; i < M; i++)
    H[i][0] = '\0';
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%s %s", com, str);
    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str))
        printf("yes\n");
      else
        printf("no\n");
    }
  }
  return 0;
}
Problem p02269 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <list>
#include <stack>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;

#define N 1000000

class Hash {
private:
  list<string> *a;

  unsigned long long getChar(char ch) {
    switch (ch) {
    case 'A':
      return 1;
    case 'C':
      return 2;
    case 'G':
      return 3;
    case 'T':
      return 4;
    default:
      return 0;
    }
  }

  unsigned long long getKey(string str) {
    unsigned long long x = 0;
    for (unsigned int i = 0; i < str.length(); i++) {
      x += getChar(str[i]);
      x *= 10;
    }
    return x % N;
  }

public:
  Hash() { a = new list<string>[N]; }

  void insert(string str) { a[getKey(str)].push_back(str); }

  bool find(string str) {
    unsigned long long key = getKey(str);
    list<string>::iterator itr = a[key].begin();
    for (; itr != a[key].end(); itr++)
      if (str == *itr)
        return true;
    return false;
  }
};

int main() {
  Hash H;
  int n;
  cin >> n;
  string str;
  for (int i = 0; i < n; i++) {
    // cout << i << "\n";
    cin >> str;
    if (str[0] == 'i') {
      cin >> str;
      H.insert(str);
    } else if (str[0] == 'f') {
      cin >> str;
      if (H.find(str))
        cout << "yes\n";
      else
        cout << "no\n";
    }
  }
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <list>
#include <stack>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;

#define N 1000000

class Hash {
private:
  list<string> *a;

  unsigned long long getChar(char ch) {
    switch (ch) {
    case 'A':
      return 1;
    case 'C':
      return 2;
    case 'G':
      return 3;
    case 'T':
      return 4;
    default:
      return 0;
    }
  }

  unsigned long long getKey(string str) {
    unsigned long long x = 0;
    for (unsigned int i = 0; i < str.length(); i++) {
      x += getChar(str[i]);
      x *= 5;
    }
    return x % N;
  }

public:
  Hash() { a = new list<string>[N]; }

  void insert(string str) { a[getKey(str)].push_back(str); }

  bool find(string str) {
    unsigned long long key = getKey(str);
    list<string>::iterator itr = a[key].begin();
    for (; itr != a[key].end(); itr++)
      if (str == *itr)
        return true;
    return false;
  }
};

int main() {
  Hash H;
  int n;
  cin >> n;
  string str;
  for (int i = 0; i < n; i++) {
    // cout << i << "\n";
    cin >> str;
    if (str[0] == 'i') {
      cin >> str;
      H.insert(str);
    } else if (str[0] == 'f') {
      cin >> str;
      if (H.find(str))
        cout << "yes\n";
      else
        cout << "no\n";
    }
  }
}
Problem p02269 (C++)

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

int Hash[244140];
char s[13];

int getChar(char ch) {
  if (ch == 'A') {
    return 1;
  } else if (ch == 'C') {
    return 2;
  } else if (ch == 'G') {
    return 3;
  }
  return 4;
}

int getKey() {
  int sum = 0, p = 1;
  for (int i = 0; i < strlen(s); i++) {
    sum += p * (getChar(s[i]));
    p *= 5;
  }
  return sum;
}

int main() {
  int n;
  char com[7];
  scanf("%d", &n);
  while (n--) {
    scanf("%s %s", com, s);
    if (com[0] == 'i') {
      Hash[getKey()] = 1;
      // printf("%d\n",getKey());
    } else {
      if (Hash[getKey()]) {
        puts("yes");
      } else {
        puts("no");
      }
    }
  }
  return 0;
}

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

int Hash[244140625];
char s[13];

int getChar(char ch) {
  if (ch == 'A') {
    return 1;
  } else if (ch == 'C') {
    return 2;
  } else if (ch == 'G') {
    return 3;
  }
  return 4;
}

int getKey() {
  int sum = 0, p = 1;
  for (int i = 0; i < strlen(s); i++) {
    sum += p * (getChar(s[i]));
    p *= 5;
  }
  return sum;
}

int main() {
  int n;
  char com[7];
  scanf("%d", &n);
  while (n--) {
    scanf("%s %s", com, s);
    if (com[0] == 'i') {
      Hash[getKey()] = 1;
      // printf("%d\n",getKey());
    } else {
      if (Hash[getKey()]) {
        puts("yes");
      } else {
        puts("no");
      }
    }
  }
  return 0;
}
Problem p02269 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define M 10000019 /* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + key % (M - 1); }
int h(int key, int i) { return (h1(key) + i * h2(key)) % M; }

int find(char str[]) {
  long long key = getKey(str);
  for (int i = 0;; i++) {
    int idx = h(key, i);
    if (H[idx][0] == '\0')
      return false;
    if (strcmp(str, H[idx]) == 0)
      return true;
  }
}

int insert(char str[]) {
  long long key = getKey(str);
  int idx = 0;
  for (int i = 0;; i++) {
    idx = h(key, i);
    if (H[idx][0] == '\0')
      break;
  }
  strcpy(H[idx], str);
}

int main() {
  int i, n, h;
  char str[L], com[9];
  for (i = 0; i < M; i++)
    H[i][0] = '\0';

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%s %s", com, str);

    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define M 1000033 /* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch) {
  if (ch == 'A')
    return 1;
  else if (ch == 'C')
    return 2;
  else if (ch == 'G')
    return 3;
  else if (ch == 'T')
    return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]) {
  long long sum = 0, p = 1, i;
  for (i = 0; i < strlen(str); i++) {
    sum += p * (getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key) { return key % M; }
int h2(int key) { return 1 + key % (M - 1); }
int h(int key, int i) { return (h1(key) + i * h2(key)) % M; }

int find(char str[]) {
  long long key = getKey(str);
  for (int i = 0;; i++) {
    int idx = h(key, i);
    if (H[idx][0] == '\0')
      return false;
    if (strcmp(str, H[idx]) == 0)
      return true;
  }
}

int insert(char str[]) {
  long long key = getKey(str);
  int idx = 0;
  for (int i = 0;; i++) {
    idx = h(key, i);
    if (H[idx][0] == '\0')
      break;
  }
  strcpy(H[idx], str);
}

int main() {
  int i, n, h;
  char str[L], com[9];
  for (i = 0; i < M; i++)
    H[i][0] = '\0';

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%s %s", com, str);

    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }

  return 0;
}
Problem p02269 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
int main(void) {
  std::ios_base::sync_with_stdio(false);
  int n;
  std::cin >> n;
  std::set<std::string> DICTIONARY;
  std::string COMMAND;
  std::string WORD;
  for (int i = 0; i < n; ++i) {
    std::cin >> COMMAND >> WORD;
    if (COMMAND == "insert") {

      DICTIONARY.insert(WORD);
    } else if (COMMAND == "find") {

      if (std::find(DICTIONARY.begin(), DICTIONARY.end(), WORD) !=
          DICTIONARY.end()) {
        std::cout << "yes" << std::endl;
      } else {
        std::cout << "no" << std::endl;
      }
    }
  }
  //	system("pause");
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
int main(void) {
  std::ios_base::sync_with_stdio(false);
  int n;
  std::cin >> n;
  std::set<std::string> DICTIONARY;
  std::string COMMAND;
  std::string WORD;
  for (int i = 0; i < n; ++i) {
    std::cin >> COMMAND >> WORD;
    if (COMMAND == "insert") {

      DICTIONARY.insert(WORD);
    } else if (COMMAND == "find") {
      // if (std::find(DICTIONARY.begin(), DICTIONARY.end(), WORD) !=
      // DICTIONARY.end())
      if (DICTIONARY.find(WORD) != DICTIONARY.end()) {
        std::cout << "yes" << std::endl;
      } else {
        std::cout << "no" << std::endl;
      }
    }
  }
  //	system("pause");
  return 0;
}
Problem p02269 (C++)

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

typedef long long lli;

const int M = 5000001;
const int P = 32;

lli C[128];
lli X[M];

lli convert(const char s[]) {
  lli j = 0;
  for (lli i = 0; s[i] != '\0'; ++i) {
    j |= C[s[i]] << (i * 3LL);
  }
  return j;
}

void insert(const char s[]) {
  int x = convert(s);
  int p = x % M;
  while (X[p] != -1LL)
    p = (p + P) % M;
  X[p] = x;
}

bool find(const char s[]) {
  int x = convert(s);
  int p = x % M;
  while (X[p] != -1LL) {
    if (X[p] == x)
      return true;
    p = (p + P) % M;
  }
  return false;
}

int main() {
  int n;
  char s[100];
  C['A'] = 1LL;
  C['C'] = 2LL;
  C['G'] = 3LL;
  C['T'] = 4LL;
  fill(X, X + M, -1LL);
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s);
    if (s[0] == 'f') {
      scanf("%s", s);
      if (find(s))
        printf("yes\n");
      else
        printf("no\n");
    } else {
      scanf("%s", s);
      insert(s);
    }
  }
  return 0;
}

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

typedef long long lli;

const int M = 5000001;
const int P = M / 10;

lli C[128];
lli X[M];

lli convert(const char s[]) {
  lli j = 0;
  for (lli i = 0; s[i] != '\0'; ++i) {
    j |= C[s[i]] << (i * 3LL);
  }
  return j;
}

void insert(const char s[]) {
  int x = convert(s);
  int p = x % M;
  while (X[p] != -1LL)
    p = (p + P) % M;
  X[p] = x;
}

bool find(const char s[]) {
  int x = convert(s);
  int p = x % M;
  while (X[p] != -1LL) {
    if (X[p] == x)
      return true;
    p = (p + P) % M;
  }
  return false;
}

int main() {
  int n;
  char s[100];
  C['A'] = 1LL;
  C['C'] = 2LL;
  C['G'] = 3LL;
  C['T'] = 4LL;
  fill(X, X + M, -1LL);
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s);
    if (s[0] == 'f') {
      scanf("%s", s);
      if (find(s))
        printf("yes\n");
      else
        printf("no\n");
    } else {
      scanf("%s", s);
      insert(s);
    }
  }
  return 0;
}
Problem p02269 (C++)

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

typedef unsigned int uint;

const uint M = 6000011u;
const uint P = 2u;

uint Five[13];
uint C[128];
uint X[M];

uint convert(const char s[]) {
  uint j = 0;
  for (uint i = 0u; s[i] != '\0'; ++i) {
    j += C[s[i]] * Five[i];
  }
  return j;
}

void insert(const char s[]) {
  uint x = convert(s);
  uint p = x % M;
  while (X[p] != UINT_MAX)
    p = (p + P) % M;
  X[p] = x;
}

bool find(const char s[]) {
  uint x = convert(s);
  uint p = x % M;
  while (X[p] != UINT_MAX) {
    if (X[p] == x)
      return true;
    p = (p + P) % M;
  }
  return false;
}

int main() {
  int n;
  char s[100];

  C['A'] = 1u;
  C['C'] = 2u;
  C['G'] = 3u;
  C['T'] = 4u;
  Five[0] = 1u;
  for (int i = 1; i < 13; ++i)
    Five[i] = Five[i - 1] * 5u;

  fill(X, X + M, UINT_MAX);
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s);
    if (s[0] == 'f') {
      scanf("%s", s);
      if (find(s))
        printf("yes\n");
      else
        printf("no\n");
    } else {
      scanf("%s", s);
      insert(s);
    }
  }
  return 0;
}

Fixed submission:
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;

typedef unsigned int uint;

const uint M = 6000011u;
const uint P = M / 10u + 1u;

uint Five[13];
uint C[128];
uint X[M];

uint convert(const char s[]) {
  uint j = 0;
  for (uint i = 0u; s[i] != '\0'; ++i) {
    j += C[s[i]] * Five[i];
  }
  return j;
}

void insert(const char s[]) {
  uint x = convert(s);
  uint p = x % M;
  while (X[p] != UINT_MAX)
    p = (p + P) % M;
  X[p] = x;
}

bool find(const char s[]) {
  uint x = convert(s);
  uint p = x % M;
  while (X[p] != UINT_MAX) {
    if (X[p] == x)
      return true;
    p = (p + P) % M;
  }
  return false;
}

int main() {
  int n;
  char s[100];

  C['A'] = 1u;
  C['C'] = 2u;
  C['G'] = 3u;
  C['T'] = 4u;
  Five[0] = 1u;
  for (int i = 1; i < 13; ++i)
    Five[i] = Five[i - 1] * 5u;

  fill(X, X + M, UINT_MAX);
  scanf("%d", &n);
  while (n--) {
    scanf("%s", s);
    if (s[0] == 'f') {
      scanf("%s", s);
      if (find(s))
        printf("yes\n");
      else
        printf("no\n");
    } else {
      scanf("%s", s);
      insert(s);
    }
  }
  return 0;
}
Problem p02269 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <list>
#include <stdio.h>
#include <string>
using namespace std;
#define N 22369620
#define X 25
struct hush {
  list<int> a;
};
int main(void) {
  int n, sum = 0, x, f[1000000] = {0}, cou = 0;
  char str[7], acgt[13];
  hush H[N / X];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    sum = 0;
    scanf("%s", str);
    scanf("%s", acgt);
    for (int i = 0, k = 1; acgt[i] != '\0' && i < 12; i++, k *= 4) {
      switch (acgt[i]) {
      case 'A':
        x = 1;
        break;
      case 'C':
        x = 2;
        break;
      case 'G':
        x = 3;
        break;
      case 'T':
        x = 4;
        break;
      }
      sum += x * k;
    }
    if (str[0] == 'i') {
      H[sum / X].a.push_back(sum % X);
    } else {
      list<int>::iterator p = H[sum / X].a.begin();
      for (; p != H[sum / X].a.end(); ++p) {
        if ((sum % X) == *p) {
          f[cou] = 1;
        }
      }
      cou++;
    }
  }
  for (int i = 0; i < cou; i++) {
    if (f[i])
      printf("yes\n");
    else
      printf("no\n");
  }
}

Fixed submission:
#include <iostream>
#include <list>
#include <stdio.h>
#include <string>
using namespace std;
#define N 22369620
#define X 50
struct hush {
  list<int> a;
};
int main(void) {
  int n, sum = 0, x, f[1000000] = {0}, cou = 0;
  char str[7], acgt[13];
  hush H[N / X];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    sum = 0;
    scanf("%s", str);
    scanf("%s", acgt);
    for (int i = 0, k = 1; acgt[i] != '\0' && i < 12; i++, k *= 4) {
      switch (acgt[i]) {
      case 'A':
        x = 1;
        break;
      case 'C':
        x = 2;
        break;
      case 'G':
        x = 3;
        break;
      case 'T':
        x = 4;
        break;
      }
      sum += x * k;
    }
    if (str[0] == 'i') {
      H[sum / X].a.push_back(sum % X);
    } else {
      list<int>::iterator p = H[sum / X].a.begin();
      for (; p != H[sum / X].a.end(); ++p) {
        if ((sum % X) == *p) {
          f[cou] = 1;
        }
      }
      cou++;
    }
  }
  for (int i = 0; i < cou; i++) {
    if (f[i])
      printf("yes\n");
    else
      printf("no\n");
  }
}
Problem p02269 (C++)

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

int main() {
  // std::ios_base::sync_with_stdio(false);
  set<string> st;
  int n;
  cin >> n;
  while (n--) {
    string BUFF, c;
    cin >> BUFF >> c;
    if (BUFF == "insert")
      st.insert(c);
    else
      cout << (st.find(c) != st.end() ? "yes" : "no") << endl;
  }
}


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

int main() {
  std::ios_base::sync_with_stdio(false);
  set<string> st;
  int n;
  cin >> n;
  while (n--) {
    string BUFF, c;
    cin >> BUFF >> c;
    if (BUFF == "insert")
      st.insert(c);
    else
      cout << (st.find(c) != st.end() ? "yes" : "no") << endl;
  }
}
Problem p02269 (C++)

Buggy submission (status: Runtime Error):
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>

using namespace std;

const long N = 1046527;
char str[N][13];
long n;

int getInt(char ch) {
  switch (ch) {
  case 'A':
    return 1;
  case 'T':
    return 2;
  case 'G':
    return 3;
  case 'C':
    return 4;
  }
  return 0;
}
long long getKey(char *tmp) {
  long long sum = 0, p = 1;
  for (int i = 0; i < strlen(tmp); ++i) {
    sum += p * getInt(tmp[i]);
    p *= 5;
  }
  return sum;
}

int main() {
  scanf("%ld", &n);
  while (n--) {
    char ch[13];
    scanf("%s", ch);
    if (strcmp(ch, "insert") == 0) {
      scanf("%s", ch);
      long long tmp = getKey(ch);
      strcpy(str[tmp], ch);
    } else if (strcmp(ch, "find") == 0) {
      scanf("%s", ch);
      long long tmp = getKey(ch);
      if (strcmp(str[tmp], ch) == 0)
        cout << "yes\n";
      else
        cout << "no\n";
    }
  }
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>

using namespace std;

const long N = 16777216;
char str[N][13];
long n;

int getInt(char ch) {
  switch (ch) {
  case 'A':
    return 1;
  case 'T':
    return 2;
  case 'G':
    return 3;
  case 'C':
    return 4;
  }
  return 0;
}
long long getKey(char *tmp) {
  long long sum = 0, p = 1;
  for (int i = 0; i < strlen(tmp); ++i) {
    sum += p * getInt(tmp[i]);
    p *= 5;
  }
  return sum;
}

int main() {
  scanf("%ld", &n);
  while (n--) {
    char ch[13];
    scanf("%s", ch);
    if (strcmp(ch, "insert") == 0) {
      scanf("%s", ch);
      long long tmp = getKey(ch);
      strcpy(str[tmp], ch);
    } else if (strcmp(ch, "find") == 0) {
      scanf("%s", ch);
      long long tmp = getKey(ch);
      if (strcmp(str[tmp], ch) == 0)
        cout << "yes\n";
      else
        cout << "no\n";
    }
  }
}
Problem p02269 (C++)

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

int main() {
  int n, i;
  cin >> n;

  string command, str;
  set<string> S;
  for (i = 0; i < n; i++) {
    cin >> command >> str;
    if (command == "insert") {
      S.insert(str);
    } else {
      if (S.find(str) == S.end()) {
        cout << "no" << endl;
      } else {
        cout << "yes" << endl;
      }
    }
  }
  return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  int n, i;
  cin >> n;

  string command, str;
  set<string> S;
  for (i = 0; i < n; i++) {
    cin >> command >> str;
    if (command == "insert") {
      S.insert(str);
    } else {
      if (S.find(str) == S.end()) {
        cout << "no" << endl;
      } else {
        cout << "yes" << endl;
      }
    }
  }
  return 0;
}
Problem p02269 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define MOD1 1000000007;
#define MOD2 1000007
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/*  */

ull pow(ull x, ull n) {
  ull res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}
int dic_op(char str[14]) {
  int j;
  long long f = 1;
  long long g = 0;
  for (j = 0;; j++) {
    if (str[j] == 'A')
      g += f * 1;
    else if (str[j] == 'C')
      g += f * 2;
    else if (str[j] == 'G')
      g += f * 3;
    else if (str[j] == 'T')
      g += f * 4;
    else
      break;
    f *= 5;
  }
  return g;
}

int main() {
  int i, j, k, l;
  int n;
  long ans = 0;
  static char dic[7000000];
  char opstr[7];
  char str[13];
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%s %s", opstr, str);
    if (opstr[0] == 'i') {
      dic[dic_op(str)] = 1;
    } else if (opstr[0] == 'f') {
      if (dic[dic_op(str)] == 1)
        puts("yes");
      else
        puts("no");
      j++;
    }
  }
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#define REP(i, a, b) for (i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define MOD1 1000000007;
#define MOD2 1000007
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/*  */

ull pow(ull x, ull n) {
  ull res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * x;
    x = x * x;
    n >>= 1;
  }
  return res;
}
int dic_op(char str[14]) {
  int j;
  long long f = 1;
  long long g = 0;
  for (j = 0;; j++) {
    if (str[j] == 'A')
      g += f * 1;
    else if (str[j] == 'C')
      g += f * 2;
    else if (str[j] == 'G')
      g += f * 3;
    else if (str[j] == 'T')
      g += f * 4;
    else
      break;
    f *= 5;
  }
  return g;
}

int main() {
  int i, j, k, l;
  int n;
  long ans = 0;
  static char dic[10000000];
  char opstr[7];
  char str[13];
  cin >> n;
  for (i = 0; i < n; i++) {
    scanf("%s %s", opstr, str);
    if (opstr[0] == 'i') {
      dic[dic_op(str)] = 1;
    } else if (opstr[0] == 'f') {
      if (dic[dic_op(str)] == 1)
        puts("yes");
      else
        puts("no");
      j++;
    }
  }
  return 0;
}
Problem p02269 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  set<string> st;
  int n;
  cin >> n;
  while (n--) {
    string BUFF, c;
    cin >> BUFF >> c;
    if (BUFF == "insert")
      st.insert(c);
    else
      cout << (st.find(c) != st.end() ? "yes" : "no") << endl;
  }
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  set<string> st;
  int n;
  cin >> n;
  while (n--) {
    string BUFF, c;
    cin >> BUFF >> c;
    if (BUFF == "insert")
      st.insert(c);
    else
      cout << (st.find(c) != st.end() ? "yes" : "no") << endl;
  }
}
Problem p02269 (C++)

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

int dic[Lim];

int toint(string s) {
  int ret = 0;
  for (int i = 0; i < s.size(); ++i) {
    ret *= 5;
    switch (s[i]) {
    case 'A':
      ret += 1;
      break;
    case 'T':
      ret += 2;
      break;
    case 'G':
      ret += 3;
      break;
    case 'C':
      ret += 4;
      break;
    }
  }
  return ret;
}

void push(string s) {
  int a = toint(s);
  int i = a % Lim;
  while (true) {
    if (!dic[i]) {
      dic[i] = a;
      return;
    }
    i = (i + Jmp) % Lim;
  }
}

int find(string s) {
  int a = toint(s);
  int i = a % Lim;
  while (true) {
    if (!dic[i]) {
      return 0;
    }
    if (dic[i] == a) {
      return 1;
    }
    i = (i + Jmp) % Lim;
  }
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s, t;
    cin >> s >> t;
    if (s == "insert") {
      push(t);
    } else {
      if (find(t)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define Lim 9999991
#define Jmp 1000003

int dic[Lim];

int toint(string s) {
  int ret = 0;
  for (int i = 0; i < s.size(); ++i) {
    ret *= 5;
    switch (s[i]) {
    case 'A':
      ret += 1;
      break;
    case 'T':
      ret += 2;
      break;
    case 'G':
      ret += 3;
      break;
    case 'C':
      ret += 4;
      break;
    }
  }
  return ret;
}

void push(string s) {
  int a = toint(s);
  int i = a % Lim;
  while (true) {
    if (!dic[i]) {
      dic[i] = a;
      return;
    }
    i = (i + Jmp) % Lim;
  }
}

int find(string s) {
  int a = toint(s);
  int i = a % Lim;
  while (true) {
    if (!dic[i]) {
      return 0;
    }
    if (dic[i] == a) {
      return 1;
    }
    i = (i + Jmp) % Lim;
  }
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s, t;
    cin >> s >> t;
    if (s == "insert") {
      push(t);
    } else {
      if (find(t)) {
        printf("yes\n");
      } else {
        printf("no\n");
      }
    }
  }
  return 0;
}