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

#include <stdio.h>
#include <string.h>
using namespace std;

#define LIM 48828125
#define LEN 13

char H[LIM][LEN];

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

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

int h1(long long key) { return key % LIM; }
int h2(long long key) { return 1 + (key % (LIM - 1)); }
long long hashValue(long long key, int i) { return h1(key) + i * h2(key); }

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

int main() {
  int n;
  char com[6], str[12];
  scanf("%d", &n);

  while (scanf("%s %s", com, str) != EOF) {
    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str)) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <stdio.h>
#include <string.h>
using namespace std;

#define LIM 1430400
#define LEN 13

char H[LIM][LEN];

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

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

int h1(long long key) { return key % LIM; }
int h2(long long key) { return 1 + (key % (LIM - 1)); }
long long hashValue(long long key, int i) { return h1(key) + i * h2(key); }

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

int main() {
  int n;
  char com[6], str[12];
  scanf("%d", &n);

  while (scanf("%s %s", com, str) != EOF) {
    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 <iostream>
#include <list>
#include <stack>
#include <stdio.h>
#include <utility>
#include <vector>
using namespace std;

#define N 100000
unsigned int table(string str) {
  unsigned int x = 0;
  for (unsigned int i = 0; i < str.length(); i++) {
    x += (str[i] - 'A');
    x *= 100;
  }
  return x % N;
}
class Hash {
private:
  list<string> a[N];

public:
  Hash() {}

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

  bool find(string str) {
    unsigned int key = table(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";
    }
  }
}


Error: TLE

Fixed submission:

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

#define N 1000000
unsigned int table(string str) {
  unsigned int x = 0;
  for (unsigned int i = 0; i < str.length(); i++) {
    x += str[i];
  }
  return x % N;
}
class Hash {
private:
  list<string> a[N];

public:
  Hash() {}

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

  bool find(string str) {
    unsigned int key = table(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, verdict: 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 *= 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";
    }
  }
}


Error: TLE

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 *= 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";
    }
  }
}
Problem p02269 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#include <string.h>

#define LEN 14
#define LIM 2000000

char H[LIM][LEN];

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

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

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

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

int find(char str[]) {
  int key = getKey(str);
  for (int i = 0; i < LIM; i++) {
    int h = hashValue(key, i);
    if (strcmp(H[h], str) == 0) {
      return 1;
    } else if (strlen(H[h]) == 0) {
      return 0;
    }
  }
  return 0;
}

int main() {
  int n;
  char com[7], str[LEN];
  scanf("%d", &n);

  while (scanf("%s %s", com, str) != EOF) {
    if (com[0] == 'i') {
      insert(str);
    } else if (com[0] == 'f') {
      if (find(str)) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }

  return 0;
}


Error: 0

Fixed submission:

#include <stdio.h>
#include <string.h>

#define LEN 14
#define LIM 2000000

char H[LIM][LEN];

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

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

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

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

int find(char str[]) {
  int key = getKey(str);
  for (int i = 0; i < LIM; i++) {
    int h = hashValue(key, i);
    if (strcmp(H[h], str) == 0) {
      return 1;
    } else if (strlen(H[h]) == 0) {
      return 0;
    }
  }
  return 0;
}

int main() {
  int n;
  char com[7], str[LEN];
  scanf("%d", &n);

  while (scanf("%s %s", com, str) != EOF) {
    if (com[0] == 'i') {
      insert(str);
    } else if (com[0] == 'f') {
      if (find(str)) {
        printf("yes\\n");
      } else {
        printf("no\\n");
      }
    }
  }

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

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

int main() {
  string cmd, str;
  unordered_set<string> s;
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> cmd;
    cin >> str;
    if (cmd == "insert") {
      s.insert(str);
    } else if (cmd == "find") {
      if (s.count(str) != 0) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
}

Error: TLE

Fixed submission:

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

#define C 79528
#define S 100000

string table[S];

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

int encode(string str) {
  int num = 0;
  while (str.size() != 0) {
    char c = str[str.size() - 1];
    str.pop_back();
    int i = ctoi(c);
    num = num * 5 + i;
  }
  return num;
}

long long my_hash(int key) { return (C - (key % C)) % S; }

void insert(string str) {
  long long key = encode(str);
  int i = 0;
  while (1) {
    long long h = (my_hash(key) + i) % S;
    if (table[h].size() == 0) {
      table[h] = str;
      break;
    }
    i++;
    key = h;
  }
}

bool find(string str) {
  long long key = encode(str);
  int i = 0;
  while (1) {
    long long h = (my_hash(key) + i) % S;
    if (table[h] == str) {
      return true;
    } else if (table[h].size() == 0) {
      return false;
    }
    key = h;
    i++;
  }
}

int main() {
  string cmd, str;
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> cmd;
    cin >> str;
    if (cmd == "insert") {
      insert(str);
    } else if (cmd == "find") {
      if (find(str)) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;
static const int M = 1046527;

vector<string> H(M);

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

long long int getKey(string s) {
  long long int sum = 0;
  long long int p = 1;
  for (int i = 0; i < s.size(); ++i) {
    sum += p * convertChartoNum(s[i]);
    p *= 5;
  }
  return (sum);
}

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

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

int find(string s) {
  long long int key = 0;
  int h = 0;
  key = getKey(s);
  for (long long int i = 0;; ++i) {
    h = (h1(key) + i * h2(key)) % M;
    if (H[h] == s) {
      return (1);
    } else if (H[h].size() == 0) {
      return (0);
    }
  }
  return (0);
}

void insert(string s) {
  long long key = getKey(s);
  long long h = 0;
  for (long long int i = 0;; ++i) {
    h = (h1(key) + i * h2(key)) % M;
    if (H[h] == s) {
      return;
    }
    if (H[h].size() == 0) {
      H[h] = s;
      return;
    }
  }
}

void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string command, str;
    cin >> command >> str;
    if (command[0] == 'i') {
      insert(str);
    } else {
      if (find(str) == 1) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
}

int main() {
  solve();
  return (0);
}

Error: TLE

Fixed submission:

#include <iostream>
#include <set>
#include <string>

using namespace std;

void solve() {
  set<string> S;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string command, str;
    cin >> command >> str;
    if (command == "insert") {
      S.insert(str);
    } else if (command == "find") {
      set<string>::iterator it = S.find(str);
      if (it != S.end()) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    }
  }
}

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

#include <iostream>
#include <unordered_set>

using namespace std;

int main() {
  unordered_set<string> dict;

  int n;
  cin >> n;

  while (n--) {
    string op, str;
    cin >> op >> str;
    if (op.at(0) == 'i') {
      dict.insert(str);
    } else {
      cout << (dict.find(str) != dict.end() ? "yes" : "no") << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <set>

using namespace std;

int main() {
  set<string> dict;

  int n;
  cin >> n;
  while (n--) {
    string op, str;
    cin >> op >> str;
    if (op.at(0) == 'i') {
      dict.insert(str);
    } else {
      cout << (dict.find(str) != dict.end() ? "yes" : "no") << endl;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  int n;
  string query, word;
  set<string> dict;
  cin >> n;
  for (; n--;) {
    cin >> query >> word;
    if (query == "insert")
      dict.insert(word);
    else {
      if (dict.find(word) == dict.end())
        puts("no");
      else
        puts("yes");
    }
  }
}

Error: TLE

Fixed submission:

#include <iostream>
#include <set>
#include <string>
using namespace std;
int main() {
  int n;
  string query, word;
  set<string> dict;
  cin >> n;
  for (; n--;) {
    cin >> query >> word;
    if (query == "insert")
      dict.insert(word);
    else {
      if (dict.find(word) == dict.end())
        cout << "no";
      else
        cout << "yes";
      cout << endl;
    }
  }
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define N 1000002
#define L 13
#define M 1000003

char T[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;
}

int getkey(char str[]) {
  int key, s, sum = 0, p = 1;

  s = strlen(str);

  for (int i = 0; i < s; i++) {
    key = getchar(str[i]);
    sum += p * key;
    p *= 5;
  }
  return sum;
}

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

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

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

int insert(char str[]) {
  int key, h;

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

int main() {
  int n, h;
  char str[L], com[9];

  for (int i = 0; i < M; i++)
    T[i][0] = '\\0';
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> com >> str;

    if (com[0] == 'i') {
      insert(str);
    } else {
      if (find(str))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

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

char stock[1000000][13];

int find(char ch[], int t) {
  for (int i = 0; i < t; i++) {
    if (strcmp(ch, stock[i]) == 0)
      return 1;
  }
  return 0;
}

int main() {
  int n, t = 0;
  char com[7], ch[4];

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> com >> ch;

    if (com[0] == 'i') {
      strcpy(stock[t], ch);
      t++;
    } else if (com[0] == 'f') {
      if (find(ch, t))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }

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

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

typedef struct trie Trie;

struct trie {
  bool flag;
  Trie *next[4];

  trie() {
    flag = false;
    fill(next, next + 4, (trie *)0);
  }
};

int judge(const char c) {
  int ret;
  switch (c) {
  case 'A':
    ret = 0;
    break;
  case 'C':
    ret = 1;
    break;
  case 'G':
    ret = 2;
    break;
  case 'T':
    ret = 3;
    break;
  }
  return ret;
}

bool str_find(string str, Trie *tmp) {
  bool flag = true;
  int ind;

  for (int i = 0; i < (int)str.length(); i++) {
    ind = judge(str[i]);

    if (!tmp->next[ind]) {
      flag = false;
      break;
    }
    tmp = tmp->next[ind];
  }
  if (!tmp->flag)
    flag = false;

  return flag;
}

void str_insert(string str, Trie *tmp) {
  int ind;

  for (int i = 0; i < (int)str.length(); i++) {
    ind = judge(str[i]);

    if (!tmp->next[ind])
      tmp->next[ind] = new Trie;
    tmp = tmp->next[ind];
  }
  tmp->flag = true;
}

int main(int argc, char *argv[]) {
  std::ios_base::sync_with_stdio(false);

  int n;
  string str;
  Trie root;

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

    if (str[0] == 'i') {
      cin >> str;
      str_insert(str, &root);
    } else {
      cin >> str;
      if (str_find(str, &root))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}

Error: MLE

Fixed submission:

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

typedef struct trie Trie;

struct trie {
  bool flag;
  Trie *next[26];

  trie() {
    flag = false;
    fill(next, next + 26, (trie *)0);
  }
};

bool str_find(string str, Trie *tmp) {
  bool flag = true;
  int c;

  for (int i = 0; i < (int)str.length(); i++) {
    c = str[i] - 'A';

    if (!tmp->next[c]) {
      flag = false;
      break;
    }
    tmp = tmp->next[c];
  }
  if (!tmp->flag)
    flag = false;

  return flag;
}

void str_insert(string str, Trie *tmp) {
  int c;

  for (int i = 0; i < (int)str.length(); i++) {
    c = str[i] - 'A';

    if (!tmp->next[c])
      tmp->next[c] = new Trie;
    tmp = tmp->next[c];
  }
  tmp->flag = true;
}

int main(int argc, char *argv[]) {
  std::ios_base::sync_with_stdio(false);

  int n;
  string str;
  Trie root;

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

    if (str[0] == 'i') {
      cin >> str;
      str_insert(str, &root);
    } else {
      cin >> str;
      if (str_find(str, &root))
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}
Problem p02269 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <vector>
// #include <conio.h>
using namespace std;

int main() {
  std::ios_base::sync_with_stdio(false);
  int n;
  set<string> list;
  string key;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> key;
    if (key == "insert") {
      cin >> key;
      list.insert(key);
    } else if (key == "find") {
      cin >> key;
      if (list.find(key) != list.end())
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <set>
#include <string>
#include <vector>
// #include <conio.h>
using namespace std;

int main() {
  int n;
  set<string> list;
  string key;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> key;
    if (key == "insert") {
      cin >> key;
      list.insert(key);
    } else if (key == "find") {
      cin >> key;
      if (list.find(key) != list.end())
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
  return 0;
}