alexjercan/bugnet huggingface dataset:
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  vector<string> st(n);
  int ans = 1;

  for (int i = 0; i < n; i++) {
    cin >> st.at(i);
  }
  sort(st.begin(), st.end());
  for (int i = 1; i < n; i++) {
    if (st.at(i) != st.at(i - 1)) {
      ans++;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  vector<string> st(n);
  int ans = 1;

  for (int i = 0; i < n; i++) {
    cin >> st.at(i);
  }

  for (int i = 1; i < n; i++) {
    int c = 0;
    for (int m = 0; m < i; m++) {
      if (st.at(i) != st.at(m)) {
        c++;
      }
    }
    if (c == i)
      ans++;
  }
  cout << ans << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  vector<string> S(200010);

  int counter = 0;

  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  reverse(S.begin(), S.end());
  for (int i = 0; i < N - 1; i++) {
    if (S.at(i) != S.at(i + 1)) {
      counter++;
    }
  }

  cout << counter + 1 << endl;
}


Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 0) >= this->size() (which is 0)


Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<string> S;

  int counter = 0;

  for (int i = 0; i < N; i++) {
    cin >> S.at(i);
  }
  sort(S.begin(), S.end());
  for (int i = 0; i < N - 1; i++) {
    if (S.at(i) != S.at(i + 1)) {
      counter++;
    }
  }

  cout << counter << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <vector>
#define mod 1000000007
#define ll long long
#define pi acos(-1)
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s[200005];
  for (int i = 0; i < n; i++)
    cin >> s[i];
  sort(s, s + n);
  ll sum = 0;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1])
      sum++;
  }
  cout << sum + 1;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <vector>
#define mod 1000000007
#define ll long long
#define pi acos(-1)
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s[200005];
  int k = 0;
  ll sum = 0;
  while (n--) {
    cin >> s[k];
    if (k == 0) {
      sum++;
      k++;
      continue;
    }
    int flag = 0;
    for (int i = 0; i < k; i++) {
      if (s[i] == s[k]) {
        flag = 1;
        break;
      }
    }
    if (!flag) {
      sum++;
      k++;
    }
  }
  cout << sum;

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

#include <algorithm>
#include <iostream>
#include <string>
#define rep(a, i, n) for (int i = (a); i < (n); i++)

using namespace std;

int main() {
  int n, tmp = 0;
  cin >> n;
  string s[n];
  rep(0, i, n) { cin >> s[i]; }
  sort(s, s + n);
  rep(0, i, n - 1) {
    if (s[i] == s[i + 1])
      tmp++;
  }
  cout << n - tmp << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
#define rep(a, i, n) for (int i = (a); i < (n); i++)

using namespace std;

int main() {
  int n, count, tmp = 0;
  cin >> n;
  string s[n];
  rep(0, i, n) {
    cin >> s[i];
    rep(0, j, i) {
      if (s[i] == s[j]) {
        tmp++;
        break;
      }
    }
  }
  count = n - tmp;
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {

  int n;
  cin >> n;

  vector<string> data(n);

  for (int i = 0; i < n; i++) {
    cin >> data.at(i);
  }

  sort(data.begin(), data.end());

  int count = 1;

  for (int i = 1; i < n; i++) {

    int check = 1;

    if (data.at(i) == data.at(i - 1)) {
      check = 0;
    }

    count += check;
  }

  cout << count << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {

  int n;
  cin >> n;

  vector<string> data(n);

  for (int i = 0; i < n; i++) {
    cin >> data.at(i);
  }

  int count = 1;

  for (int i = 1; i < n; i++) {

    int check = 1;
    for (int j = 0; j <= i - 1; j++) {

      if (data.at(i) == data.at(j)) {
        check = 0;
        break;
      }
    }
    count += check;
  }

  cout << count << endl;

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

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

  ll N;
  cin >> N;
  string Si;

  set<string> st;
  rep(i, N) {
    cin >> Si;
    st.insert(Si);
  }
  cout << st.size();
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

  ll N;
  cin >> N;

  vector<pair<string, ll>> S;
  string target;
  bool flag;
  rep(i, N) {
    flag = false;
    cin >> target;
    rep(i, S.size()) {
      if (S[i].first == target) {
        S[i].second++;
        flag = true;
      }
    }
    if (!flag) {
      pair<string, ll> new_pair;
      new_pair.first = target;
      new_pair.second = 1;
      S.push_back(new_pair);
    }
  }
  cout << S.size();
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define MAX 200000

int main() {
  int N;
  string str;
  vector<string> S;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> str;
    S.push_back(str);
  }
  sort(S.begin(), S.end());

  int count = 1;

  str = S[0];
  for (int i = 0; i < S.size(); i++) {
    if (str != S[i]) {
      count++;
      str = S[i];
    }
  }
  cout << count;
  return 0;
}


Error: TLE

Fixed submission:

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

#define MAX 200000

int main() {
  int N;
  string str;
  vector<string> S;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> str;
    if (count(S.begin(), S.end(), str) == 0) {
      S.push_back(str);
    }
  }
  cout << S.size();
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  cin >> n;
  vector<string> s(n);
  int ans = n;
  for (i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  sort(s.begin(), s.end());
  for (i = 1; i < n; i++) {
    if (s.at(i - 1) == s.at(i)) {
      ans--;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j;
  cin >> n;
  vector<string> s(n + 1);
  int ans = n;
  for (i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (s.at(i) == s.at(j)) {
        ans--;
        break;
      }
    }
  }
  cout << ans << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\\n", a)
#define printll(a) printf("%lld\\n", a)
#define printYes() printf("Yes\\n")
#define printNo() printf("No\\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;

int main() {
  int n;
  scanInt(n);
  string s;
  vector<string> a;
  rep(i, n) {
    cin >> s;
    a.push_back(s);
  }
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  printInt((int)a.size());
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\\n", a)
#define printll(a) printf("%lld\\n", a)
#define printYes() printf("Yes\\n")
#define printNo() printf("No\\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;

int main() {
  int n;
  scanInt(n);
  string s;
  vector<string> a;
  rep(i, n) {
    cin >> s;
    if (find(a.begin(), a.end(), s) == a.end())
      a.push_back(s);
  }
  printInt((int)a.size());
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  long long int N, i, j;
  cin >> N;
  string S[N];
  for (i = 0; i < N; i++) {
    cin >> S[i];
  }

  vector<string> A;
  for (i = 0; i < N; i++) {
    A.push_back(S[i]);
  }

  sort(A.begin(), A.end());

  int ans = 1;
  for (i = 0; i < N - 1; i++) {
    if (A[i] != A[i + 1])
      ans++;
  }
  cout << ans << endl;

  return 0;
}


Error: TLE

Fixed submission:

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

int main() {
  long long int N, i, j;
  cin >> N;
  string S[N];
  for (i = 0; i < N; i++) {
    cin >> S[i];
  }

  int count, ans = 1;
  string T[N];
  T[0] = S[0];
  for (i = 1; i < N; i++) {
    count = 0;
    j = -1;
    do {
      j++;
    } while (S[i] != T[j] && j + 1 < ans);

    if (j + 1 == ans && S[i] != T[j]) {
      T[ans] = S[i];
      ans++;
    }
  }

  cout << ans << endl;

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

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

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

  set<string> st;
  for (int i = 0; i < N; i++) {
    string str;
    cin >> str;
    st.insert(str);
  }

  cout << st.size() << endl;
}

Error: TLE

Fixed submission:

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

int new_check(int N, string str, vector<string> memo) {

  for (int j = 0; j < N; j++) {
    if (str == memo.at(j)) {
      return 0;
    }
  }
  return 1;
}

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

  vector<string> str(N);

  vector<string> memo(N);

  int ans = 0;

  for (int i = 0; i < N; i++) {
    cin >> str.at(i);
  }

  for (int l = 0; l < N; l++) {
    ans += new_check(l, str.at(l), memo);
    memo.at(l) = str.at(l);
  }

  cout << ans << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  cin >> N;
  vector<string> k(N);
  for (int i = 0; i < N; i++) {
    cin >> k.at(i);
  }
  sort(k.begin(), k.end());
  k.erase(unique(k.begin(), k.end()), k.end());
  cout << k.size() << endl;
}

Error: WA

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<string> k(N);
  for (int i = 0; i < N; i++) {
    cin >> k.at(i);
  }
  sort(k.begin(), k.end());
  cout << k.at(1) << endl;
  k.erase(unique(k.begin(), k.end()));
  cout << k.at(1) << endl;
  cout << k.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <functional>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  set<string> s;

  while (n--) {
    string l;
    cin >> l;
    s.insert(l);
  }

  cout << s.size() << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> g;
  string s;
  cin >> s;
  g.push_back(s);

  for (int i = 0; i < n - 1; i++) {
    int cnt = 0;
    cin >> s;

    for (int j = 0; j < g.size(); j++) {
      if (g.at(j) == s) {
        cnt++;
        break;
      }
    }

    if (cnt == 0) {
      g.push_back(s);
      continue;
    }
  }
  cout << g.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  list<string> list1;
  for (int i = 0; i < n; i++) {
    string name;
    cin >> name;
    list1.push_front(name);
  }
  list1.sort();
  list1.unique();

  // string *various = new string[n];
  // int count = 0;
  // for(int i=0;i<n;i++){
  //     string name;
  //     int flag = 0;
  //     cin >> name;
  //     for(int j=0;j<i;j++){
  //         if(various[j] == name){
  //             flag = 1;
  //             break;
  //         }
  //     }
  //     if(flag == 0){
  //         various[i] = name;
  //         count++;
  //     }
  // }
  cout << list1.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  string *various = new string[n];
  int count = 0;
  for (int i = 0; i < n; i++) {
    string name;
    int flag = 0;
    cin >> name;
    for (int j = 0; j < i; j++) {
      if (various[j] == name) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      various[i] = name;
      count++;
    }
  }
  cout << count << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<string> S(N);
  // string S[N];
  for (int i = 0; i < N; i++)
    cin >> S[i];
  sort(S.begin(), S.end());
  // sort(S,S+N);
  S.erase(unique(S.begin(), S.end()), S.end());
  cout << S.size() << endl;
}


Error: TLE

Fixed submission:

#include "bits/stdc++.h"
using namespace std;

int main() {
  int N;
  cin >> N;
  string S[N];
  for (int i = 0; i < N; i++)
    cin >> S[i];
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] != "0") {
      for (int j = i + 1; j < N; j++) {
        if (S[j] != "0") {
          if (S[i] == S[j])
            S[j] = "0";
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (S[i] != "0")
      count++;
  }
  cout << count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  set<string> s;
  while (n--) {
    string t;
    cin >> t;
    s.insert(t);
  }
  cout << s.size() << '\\n';
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <string.h>
using namespace std;
char a[10][10];
int main() {
  ios::sync_with_stdio(false);
  int n, num;
  scanf("%d", &n);
  num = n;
  for (int i = 0; i < n; i++)
    scanf("%s", a[i]);
  for (int i = 0; i < n; i++)
    for (int j = i; j >= 0; j--)
      if (!strcmp(a[j], a[i])) {
        num--;
        break;
      }
  printf("%d\\n", num);
  getchar();
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define INF 1000000000
#define loop(i, a, b) for (int i = a; i < b; i++)
int main() {
  // freopen("contest.txt","r",stdin);
  // freopen("contest.txt","w",stdout);
  IOS int n;
  cin >> n;
  map<string, string> m;
  string a, b;
  loop(i, 0, n) {
    cin >> a;
    m.insert(pair<string, string>(a, a));
  }
  cout << m.size() << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define IOS                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define INF 1000000000
#define loop(i, a, b) for (int i = a; i < b; i++)
int main() {
  // freopen("contest.txt","r",stdin);
  // freopen("contest.txt","w",stdout);
  IOS int a, b, c, d;
  int count_ = 0;
  int n;
  cin >> n;
  string s[n];
  vector<string> s1;
  loop(i, 0, n) {
    cin >> s[i];
    if (i == 0)
      s1.push_back(s[i]);
    else {
      int flag = 0;
      for (int j = s1.size() - 1; j >= 0; j--) {
        if (s1[j] == s[i]) {
          flag = 1;
          break;
        }
      }
      if (flag == 0)
        s1.push_back(s[i]);
    }
  }

  cout << s1.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  string a[200000];
  for (int i = 0; i < N; i++)
    cin >> a[i];
  set<string> b;
  for (int i = 0; i < N; i++)
    b.insert(a[i]);
  cout << b.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<string> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  sort(a.begin(), a.end());

  long ans = 0;

  while (N > 0) {
    int s = count(a.begin(), a.end(), a[N - 1]);
    for (int f = 0; f < s; f++) {
      a.pop_back();
    }
    ans++;
    N -= s;
  }

  cout << ans << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

// #define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main() {
  set<string> ss;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    ss.insert(s);
  }
  cout << ss.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

// #define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  vector<string> ss(200000);
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> ss[i];
    int flag = 1;
    for (int j = i - 1; j >= 0; j--) {
      if (ss[i] == ss[j]) {
        flag = 0;
        break;
      }
    }
    if (flag)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#include <string>
#include <vector>
#define ll long long
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;

int main() {
  fast;
  int n;
  cin >> n;
  map<string, int> p;

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

    p[s]++;
  }

  cout << p.size() << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <string>
#include <vector>
#define ll long long
#define fast                                                                   \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
using namespace std;

int main() {
  fast;
  int n, counter, count = 0;
  cin >> n;
  vector<string> s;
  string temp;

  for (int i = 0; i < n; i++) {
    cin >> temp;
    s.push_back(temp);
    temp.clear();
  }

  if (n > 0) {
    counter = 1;
  }

  for (int i = 1; i < n; i++) {
    count = 0;
    for (int j = 0; j < i; j++) {
      if (s[i] != s[j]) {
        count++;
      }
    }
    if (count == i) {
      counter++;
    }
  }

  cout << counter;

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

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

int main() {
  int N;
  cin >> N;
  map<string, int> S;
  string tmp;

  cin >> tmp;
  S[tmp] = 0;
  int n = 1;
  for (int i = 1; i < N; i++) {
    cin >> tmp;
    if (!S.count(tmp)) {
      S[tmp] = i;
      n++;
    }
  }
  cout << n << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<string> S(N);

  int K = 1;
  string tmp;
  bool flag;

  cin >> S[0];
  for (int i = 1; i < N; i++) {
    cin >> tmp;
    flag = false;

    for (int j = 0; j < K; j++) {
      if (tmp == S[j]) {
        flag = true;
        break;
      }
    }

    if (flag == true) {
      continue;
    }
    S[K] = tmp;
    K++;
  }
  cout << K << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

// GCD, LCM
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  string S[200010] = {}, B[200010] = {};
  map<string, int> mp;
  int N, ans = 0;
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> S[i];

    mp[S[i]]++;
  }

  ans = mp.size();

  cout << ans << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

// GCD, LCM
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
  string S[200010] = {}, B[200010] = {};
  int N, ans = 0;
  cin >> N;

  for (int i = 0; i < N; i++) {
    cin >> S[i];

    int f = 0;
    for (int j = 1; j <= ans; j++) {
      if (B[j] == S[i]) {
        f = 1;
        break;
      }
    }
    if (f == 0) {
      ans++;
      B[ans] = S[i];
    }
  }

  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  // Your code here!
  int n;
  cin >> n;

  vector<string> s(n);
  for (int i = 0; i < n; i++)
    cin >> s[i];

  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());

  cout << s.size() << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main(void) {
  // Your code here!
  int n;
  cin >> n;

  vector<string> s(n);
  for (int i = 0; i < n; i++)
    cin >> s[i];

  int ct = 0;
  for (int i = 0; i < n; i++) {
    ct++;
    for (int j = i + 1; j < n; j++) {
      if (s[i] == s[j]) {
        ct--;
        break;
      }
    }
  }
  cout << ct << endl;
}