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

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

#define M 1046527
long long T[M];

class Hash {
  long long key;
  void getKey(char *p);
  int h1() { return key % M; }
  int h2() { return 1 + (key % (M - 1)); }
  int h(int i) { return (h1() + i * h2()) % M; }

public:
  void insert(char *str);
  bool find(char *str);
};

void Hash::getKey(char *p) {
  key = 0;
  for (int i = (strlen(p) - 1); i >= 0; i--) {
    int x = p[i] % 9;
    key += x * pow(10, i);
  }
}

void Hash::insert(char *str) {
  getKey(str);
  int i = 0;
  while (1) {
    int j = h(i);
    if (!T[j]) {
      T[j] = key;
      return;
    } else if (T[j] == key)
      return;
    else
      i++;
  }
}

bool Hash::find(char *str) {
  getKey(str);
  int i = 0;
  while (1) {
    int j = h(i);
    if (T[j] == key)
      return 1;
    else if (!T[j])
      return 0;
    else
      i++;
  }
}

int main() {
  Hash H;
  int n;
  char order[10], word[15];
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%s %s", order, word);
    switch (order[0]) {
    case 'i':
      H.insert(word);
      break;
    case 'f':
      if (H.find(word))
        printf("yes\\n");
      else
        printf("no\\n");
      break;
    default:
      break;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

#define M 1046527
long long T[M];

class Hash {
  long long key;
  void getKey(char *p);
  int h1() { return key % M; }
  int h2() { return 1 + (key % (M - 1)); }
  int h(int i) { return h1() + i * h2() % M; }

public:
  void insert(char *str);
  bool find(char *str);
};

void Hash::getKey(char *p) {
  key = 0;
  for (int i = (strlen(p) - 1); i >= 0; i--) {
    int x = p[i] % 9;
    key += x * pow(10, i);
  }
}

void Hash::insert(char *str) {
  getKey(str);
  int i = 0;
  while (1) {
    int j = h(i);
    if (!T[j]) {
      T[j] = key;
      return;
    } else if (T[j] == key)
      return;
    else
      i++;
  }
}

bool Hash::find(char *str) {
  getKey(str);
  int i = 0;
  while (1) {
    int j = h(i);
    if (T[j] == key)
      return 1;
    else if (!T[j])
      return 0;
    else
      i++;
  }
  return 0;
}

int main() {
  Hash H;
  int n;
  char order[10], word[15];
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%s %s", order, word);
    switch (order[0]) {
    case 'i':
      H.insert(word);
      break;
    case 'f':
      if (H.find(word))
        printf("yes\\n");
      else
        printf("no\\n");
      break;
    default:
      break;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var)                                                            \\
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

struct Dict {
  Dict() : buf_(initial_buf_size, list<string>()) {}

  void Insert(const string &s) {
    auto h = StrHash(s) % buf_.size();
    auto &slot = buf_[h];
    if (!FindInternal(slot, s)) {
      slot.push_front(s);
    }
  }

  bool Find(const string &s) const {
    auto h = StrHash(s) % buf_.size();
    auto &slot = buf_[h];
    return FindInternal(slot, s);
  }

private:
  constexpr static auto initial_buf_size = 1024 * 1024;

  bool FindInternal(const list<string> &slot, const string &s) const {
    return find_if(slot.begin(), slot.end(), [&](const string &s0) {
             return !s0.compare(s);
           }) != slot.end();
  }

  static size_t StrHash(const string &s) {
    size_t hash = 17;
    for (auto &&c : s) {
      hash += (hash * 23) + static_cast<size_t>(c) * 7;
    }
    return hash;
  }

  vector<list<string>> buf_;
};

int main() {
  int n;
  cin >> n;
  Dict dic;
  for (int i = 0; i < n; ++i) {
    string cmd;
    string str;
    cin >> cmd >> str;
    if (!cmd.compare("insert")) {
      dic.Insert(str);
    } else {
      cout << (dic.Find(str) ? "yes" : "no") << endl;
    }
  }
}

Error: TLE

Fixed submission:

#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var)                                                            \\
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

struct Dict {
  Dict() : buf_(initial_buf_size, list<string>()) {}

  void Insert(const string &s) {
    auto h = StrHash(s) % buf_.size();
    auto &slot = buf_[h];
    if (!FindInternal(slot, s)) {
      slot.push_front(s);
    }
  }

  bool Find(const string &s) const {
    auto h = StrHash(s) % buf_.size();
    auto &slot = buf_[h];
    return FindInternal(slot, s);
  }

private:
  constexpr static auto initial_buf_size = 1024;

  bool FindInternal(const list<string> &slot, const string &s) const {
    return find_if(slot.begin(), slot.end(), [&](const string &s0) {
             return !s0.compare(s);
           }) != slot.end();
  }

  static size_t StrHash(const string &s) {
    size_t hash = 17;
    for (auto &&c : s) {
      hash += (hash * 23) + static_cast<size_t>(c) * 7;
    }
    return hash;
  }

  vector<list<string>> buf_;
};

int main() {
  int n;
  cin >> n;
  Dict dic;
  for (int i = 0; i < n; ++i) {
    string cmd;
    string str;
    cin >> cmd >> str;
    if (!cmd.compare("insert")) {
      dic.Insert(str);
    } else {
      cout << (dic.Find(str) ? "yes" : "no") << endl;
    }
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  unordered_set<string> S;
  string word;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> word;
    if (word == "insert") {
      cin >> word;
      S.insert(word);
    } else if (word == "find") {
      cin >> word;
      cout << ((S.count(word) > 0) ? "yes" : "no") << endl;
    }
  }
}

Error: TLE

Fixed submission:

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

int main() {
  set<string> S;
  string word;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> word;
    if (word == "insert") {
      cin >> word;
      S.insert(word);
    } else if (word == "find") {
      cin >> word;
      cout << ((S.count(word) > 0) ? "yes" : "no") << endl;
    }
  }
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <queue>
#include <set>
#include <string>
using namespace std;
int main() {
  typedef set<string> set_t;
  int n;
  set_t Dic;
  string cmd, word;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> cmd;
    if (cmd == "insert") {
      cin >> word;
      Dic.insert(word);
    }
    if (cmd == "find") {
      cin >> word;
      if (Dic.count(word)) {
        cout << "yes" << endl;
      } else
        cout << "no" << endl;
    }
  }
  return 0;
}


Error: -6
free(): invalid pointer


Fixed submission:

#include <iostream>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
int main() {
  int n;
  cin >> n;
  typedef set<string> set_t;
  set_t A;
  string cmd;
  string ab;
  for (int i = 0; i < n; i++) {
    scanf("%s %s", &cmd, &ab);
    if (cmd == "insert") {
      A.insert(ab);
    } else if (cmd == "find") {
      if (A.count(ab) > 0) {
        printf("yes");
      } else {
        printf("no");
      }
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Memory Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

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

  int n;
  cin >> n;

  string query, str;
  set<string> str_set;

  for (int i = 0; i < n; i++) {
    cin >> query >> str;

    if (query == "insert") {
      str_set.insert(str);
    } else if (query == "find") {
      cout << (str_set.find(str) != str_set.end() ? "yes" : "no") << endl;
    }
  }

  return 0;
}


Error: MLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

class Dictionary {
private:
  const string MIN_WORD = "A";
  const string MAX_WORD = "TTTTTTTTTTT";
  vector<string> words;

public:
  Dictionary();
  int calc_key(string);
  void insert(string);
  bool find(string);
};

Dictionary::Dictionary() { words = vector<string>(calc_key(MAX_WORD), "X"); }

int Dictionary::calc_key(string word) {
  int key = 1;

  for (int i = 0; i < word.size(); i++) {
    switch (word[i]) {
    case 'A':
      key += 0;
      break;
    case 'C':
      key += 1;
      break;
    case 'G':
      key += 2;
      break;
    case 'T':
      key += 3;
      break;
    }

    key *= 4;
  }

  return key;
}

void Dictionary::insert(string word) { words[calc_key(word)] = word; }

bool Dictionary::find(string word) {
  if (words[calc_key(word)] == "X")
    return false;
  else
    return true;
}

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

  Dictionary *dict = new Dictionary();
  string query, word;

  for (int i = 0; i < n; i++) {
    cin >> query >> word;

    if (query == "insert") {
      dict->insert(word);
    } else if (query == "find") {
      cout << (dict->find(word) ? "yes" : "no") << endl;
    }
  }

  delete dict;

  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  set<string> dic;
  int n;
  cin >> n;
  string com, key;
  while (n--) {
    cin >> com >> key;
    if (com == "insert")
      dic.insert(key);
    else {
      if (dic.find(key) == dic.end())
        cout << "no" << endl;
      else
        cout << "yes" << endl;
    }
  }
  return 0;
}


Error: TLE

Fixed submission:

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

bool compare(string a, string b) {
  int length = min(a.size(), b.size());
  for (int i = 0; i < length; i++) {
    if (a[i] > b[i])
      return true;
    else if (a[i] < b[i])
      return false;
  }
  if (length == b.size())
    return true;
  else
    return false;
}

int main() {
  vector<string> dic;
  string com, str;
  int n;
  cin >> n;
  vector<string>::iterator it;
  rep(i, n) {
    cin >> com;
    cin >> str;
    if (com == "insert") {
      if (dic.empty())
        dic.push_back(str);
      else {
        it = dic.begin();
        for (; it != dic.end() && compare(str, *it); it++)
          ;
        dic.insert(it, str);
      }
    } else if (com == "find") {
      if (binary_search(dic.begin(), dic.end(), str))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

/*
 * ALDS1_4_C.cpp
 *
 *  Created on: Apr 26, 2018
 *      Author: 13743
 */

#include <cstdio>

using namespace std;

const int SIZE = 1045527;
int table[SIZE];

int getKey(char *s) {
  int key = 0;
  int exp = 1;
  for (int i = 0; s[i] != '\\0'; i++) {
    switch (s[i]) {
    case 'A':
      key += 4 * exp;
      break;
    case 'C':
      key += 3 * exp;
      break;
    case 'G':
      key += 2 * exp;
      break;
    default:
      key += 1 * exp;
      break;
    }
    exp *= 5;
  }
  return key;
}

void insert(char *s) {
  int key = getKey(s);
  int hash = key % SIZE;
  while (true) {
    if (table[hash] == 0 || table[hash] == key) {
      table[hash] = key;
      break;
    }
    hash = (hash + (1 + (key % (SIZE - 2)))) % SIZE;
  }
}

bool find(char *s) {
  int key = getKey(s);
  int hash = key % SIZE;
  int i = 0;
  while (i++ < SIZE) {
    if (table[hash] == key) {
      return true;
    } else if (table[hash] == 0) {
      return false;
    }
    hash = (hash + (1 + (key % (SIZE - 2)))) % SIZE;
  }
  return false;
}

int main() {
  int n;
  scanf("%d", &n);
  char d[10];
  char s[13];
  for (int i = 0; i < n; i++) {
    scanf("%s %s", d, s);
    ;
    if (d[0] == 'i') {
      insert(s);
    } else {
      if (find(s))
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }
}


Error: TLE

Fixed submission:

/*
 * ALDS1_4_C.cpp
 *
 *  Created on: Apr 26, 2018
 *      Author: 13743
 */

#include <cstdio>

using namespace std;

const int SIZE = 1045527;
int table[SIZE];

int getKey(char *s) {
  int key = 0;
  int exp = 1;
  for (int i = 0; s[i] != '\\0'; i++) {
    switch (s[i]) {
    case 'A':
      key += 4 * exp;
      break;
    case 'C':
      key += 3 * exp;
      break;
    case 'G':
      key += 2 * exp;
      break;
    default:
      key += 1 * exp;
      break;
    }
    exp *= 5;
  }
  return key;
}

void insert(char *s) {
  int key = getKey(s);
  int hash = key % SIZE;
  while (true) {
    if (table[hash] == 0 || table[hash] == key) {
      table[hash] = key;
      break;
    }
    hash = (hash + (1 + (key % (SIZE - 2)))) % SIZE;
  }
}

bool find(char *s) {
  int key = getKey(s);
  int hash = key % SIZE;
  int i = 0;
  while (i++ < SIZE) {
    if (table[hash] == key) {
      return true;
    }
    hash = (hash + (1 + (key % (SIZE - 2)))) % SIZE;
  }
  return false;
}

int main() {
  int n;
  scanf("%d", &n);
  char d[10];
  char s[13];
  for (int i = 0; i < n; i++) {
    scanf("%s %s", d, s);
    ;
    if (d[0] == 'i') {
      insert(s);
    } else {
      if (find(s))
        printf("yes\\n");
      else
        printf("no\\n");
    }
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
#include <string>
#define M 5070721
#define NIL (-1)
#define L 14
using namespace std;
typedef long long ll;
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;
}

ll getKey(char str[]) {
  ll sum = 0, p = 1, i;
  int len = strlen(str);
  for (i = 0; i < len; 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[]) {
  ll 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[]) {
  ll 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(void) {
  int n;
  char str[L], com[9];
  for (int 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);
    } else {
      if (find(str)) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <string>
#define M 5070721
#define NIL (-1)
#define L 14
using namespace std;
typedef long long ll;
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;
}

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

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

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

int find(char str[]) {
  ll 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[]) {
  ll 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(void) {
  int n;
  char str[L], com[9];
  for (int 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);
    } else {
      if (find(str)) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <string>

#define NMAX 1000000

using namespace std;

int main(void) {

  std::ios_base::sync_with_stdio(false);
  set<string> disc;
  string iof, str;
  int n;

  cin >> n;

  while (n--) {
    cin >> iof >> str;
    if (iof[0] == 'i')
      disc.insert(str);
    else {
      if (disc.find(str) != disc.end())
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

#define NMAX 100000

using namespace std;

int main(void) {

  std::ios_base::sync_with_stdio(false);
  vector<string> disc;
  string iof, str;
  int n;

  cin >> n;

  while (n--) {
    cin >> iof >> str;
    if (iof[0] == 'i')
      disc.push_back(str);
    else {
      if (find(disc.begin(), disc.end(), str) != disc.end())
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }

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

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

int main() {
  int n;
  cin >> n;
  string s, str;
  map<string, int> m;
  for (int i = 0; i < n; i++) {
    cin >> s >> str;
    if (s[0] == 'i') {
      m[str] = 1;
    } else {
      if (m[str])
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}

Error: 0

Fixed submission:

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

int numfunc(string s) {
  int r = 0;
  for (int i = 0; i < s.size(); i++)
    r += s[i] - '0';
  return r % 100;
}

int main() {
  int n;
  string func, str, lib[100][100];

  for (int i = 0; i < 100; i++)
    for (int j = 0; j < 100; j++)
      lib[i][j] = "0";

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> func >> str;
    // if(lib[0][0] == "0")cout << "123";

    int x = numfunc(str), flag = 0, r = 0;
    // cout << x;
    if (func == "insert") {
      for (int j = 0; lib[x][r] != "0"; j++)
        r++;
      lib[x][r] = str;
    }

    if (func == "find") {
      for (int j = 0; lib[x][j] != "0"; j++)
        if (lib[x][j] == str)
          flag = 1;
      if (flag)
        cout << "yes" << endl;
      else
        cout << "no" << endl;
      // cout << flag ? "yes" : "no" << endl;
      // cout << "OK";
    }
  }

  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int main() {
  set<string> st;
  int n;
  string op, str;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> op >> str;
    if (op == "insert") {
      //	  v.push_back(str);
      st.insert(str);
    } else { // find
      if (st.find(str) != st.end()) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  vector<string> v;
  v.reserve(1000000);
  int n;
  string op, str;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    cin >> op >> str;
    if (op == "insert") {
      v.push_back(str);
    } else { // find
      if (find(v.begin(), v.end(), str) != v.end()) {
        puts("yes");
      } else {
        puts("no");
      }
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

#define M 1046527

long long T[M];
//???????????\\??¢??°
long long h1(long long key) { return key % M; }

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

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

void insert(long long key) {
  long long i = 0;
  while (1) {
    int j = h(key, i);
    if (!T[j]) {
      T[j] = key;
      return;
    } else
      i++;
  }
  return;
}

bool find(long long key) {
  long long i = 0;
  while (1) {
    int j = h(key, i);
    if (T[j] == key)
      return 1;
    else if (!T[j])
      return 0;
    else
      i++;
  }
}

long long getKey(char *p) {
  long long key = 0;
  for (long long i = (strlen(p) - 1); i >= 0; i--) {
    long long x;
    switch (p[i]) {
    case 'A':
      x = 1;
      break;
    case 'C':
      x = 2;
      break;
    case 'G':
      x = 3;
      break;
    case 'T':
      x = 4;
      break;
    default:
      break;
    }
    key += x * pow(10, i);
  }
  return key;
}

int main() {
  int n;
  char order[10], word[15];
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%s %s", order, word);
    if (order[0] == 'i')
      insert(getKey(word));
    else if (find(getKey(word)))
      printf("yes\\n");
    else
      printf("no\\n");
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

#define M 1046527

long long T[M];
//???????????\\??¢??°
long long h1(long long key) { return key % M; }

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

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

void insert(long long key) {
  long long i = 0;
  while (1) {
    int j = h(key, i);
    if (!T[j]) {
      T[j] = key;
      return;
    } else
      i++;
  }
}

bool find(long long key) {
  long long i = 0;
  while (1) {
    int j = h(key, i);
    if (T[j] == key)
      return 1;
    else if (!T[j])
      return 0;
    else
      i++;
  }
}

int getKey(char *p) {
  long long key = 0;
  for (long long i = (strlen(p) - 1); i >= 0; i--) {
    long long x;
    switch (p[i]) {
    case 'A':
      x = 1;
      break;
    case 'C':
      x = 2;
      break;
    case 'G':
      x = 3;
      break;
    case 'T':
      x = 4;
      break;
    default:
      break;
    }
    key += x * pow(10, i);
  }
  return key;
}

int main() {
  int n;
  char order[10], word[15];
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%s %s", order, word);
    if (order[0] == 'i')
      insert(getKey(word));
    else if (find(getKey(word)))
      printf("yes\\n");
    else
      printf("no\\n");
  }
  return 0;
}