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

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

int main() {
  int N;
  int i, num;
  N >= 1;
  N <= 200000;
  string S[200000];
  cin >> N;
  set<string> gift;

  for (i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (i = 0; i < N; i++) {
    gift.insert(S[i]);
  }
  num = gift.size();
  cout << num << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int N;
  int i, num;
  string S[1000];
  cin >> N;
  set<string> gift;

  for (i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (i = 0; i < N; i++) {
    gift.insert(S[i]);
  }
  num = gift.size();
  cout << num << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N;
  int i, num;
  N >= 1;
  N <= 200000;
  string S[200000];
  cin >> N;
  set<string> gift;

  for (i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (i = 0; i < N; i++) {
    gift.insert(S[i]);
  }
  num = gift.size();
  cout << num << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int N;
  int i, num;
  N >= 1;
  N <= 20000;
  string S[20000];
  cin >> N;
  set<string> gift;

  for (i = 0; i < N; i++) {
    cin >> S[i];
  }
  for (i = 0; i < N; i++) {
    gift.insert(S[i]);
  }
  num = gift.size();
  cout << num << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using ll = long long int;

int main(int argc, char *argv[]) {
  ll n;
  std::cin >> n;

  std::vector<std::string> s;
  for (ll i = 0; i < n; ++i) {
    std::string str;
    std::cin >> str;
    s.emplace_back(str);
  }

  std::sort(s.begin(), s.end());

  ll ans = 1;
  ll idx = 0;
  for (ll i = 1; i < n; i++) {
    if (s[idx] != s[i]) {
      idx = i;
      ++ans;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using ll = long long int;

int main(int argc, char *argv[]) {
  ll n;
  std::cin >> n;

  std::vector<std::string> s;
  for (ll i = 0; i < n; ++i) {
    std::string str;
    std::cin >> str;

    auto result = std::find(s.begin(), s.end(), str);
    if (result == s.end()) {
      s.emplace_back(str);
    }
  }

  std::cout << s.size() << std::endl;

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

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

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

  string s[N], check[N], word;

  vector<string> vector;
  cin >> word;

  for (int i = 1; i < N; ++i) {
    vector.push_back(word);
    cin >> word;
  }
  vector.push_back(word);

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

  int count = 0, j = 0;

  check[0] = vector.at(0);
  count++;

  for (int i = 1; i < N; ++i) {
    if (vector.at(i) != check[count - 1]) {
      check[count] = vector.at(i);
      count++;
    }
  }
  std::cout << count << std::endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

int main(void) {
  int N;
  std::cin >> N;

  std::string s[N], check[N];

  for (int i = 0; i < N; ++i) {
    std::cin >> s[i];
  }

  int count = 0, j = 0;

  check[0] = s[0];
  count++;

  for (int i = 0; i < N; ++i) {
    j = 0;
    while (j < count) {
      if (s[i] != check[j]) {
        j++;
        if (j == count) {
          check[count] = s[i];
          count++;
          break;
        }
      } else {
        break; // same
      }
    }
  }

  std::cout << count << std::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;
  string a[N];
  set<string> b;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    b.insert(a[i]);
  }
  cout << b.size() << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  string a[N];
  set<string> b;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (find(b.begin(), b.end(), a[i]) == b.end())
      b.insert(a[i]);
  }
  cout << b.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <stdlib.h>
#include <time.h>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

class Node {
public:
  string name;
  Node *child[2];

  Node(void) {
    child[0] = nullptr;
    child[1] = nullptr;
  }
  Node(string str) {
    child[0] = nullptr;
    child[1] = nullptr;
    name = str;
  }

  int count(void) {
    int temp = 1;
    temp += child[0] != nullptr ? child[0]->count() : 0;
    temp += child[1] != nullptr ? child[1]->count() : 0;
    return temp;
  }

  int insert(string str) {
    if (name == str)
      return 0;
    if (name > str) {
      if (child[0] == nullptr)
        child[0] = new Node(str);
      else
        child[0]->insert(str);
    } else {
      if (child[1] == nullptr)
        child[1] = new Node(str);
      else
        child[1]->insert(str);
    }
    return 0;
  }
};

int main(void) {
  int N;
  string str;
  cin >> N;

  cin >> str;
  Node root(str);

  for (int i = 1; i < N; i++) {
    cin >> str;
    root.insert(str);
  }

  cout << root.count() << endl;

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <stdlib.h>
#include <time.h>

#define rep(i, n) for (int i = 0; i < n; i++)

using namespace std;

class Node {
public:
  string name;
  int n;
  Node *child[2];

  Node(void) {
    n = 0;
    child[0] = nullptr;
    child[1] = nullptr;
  }
  Node(string str) {
    n = 0;
    child[0] = nullptr;
    child[1] = nullptr;
    name = str;
  }

  int count(void) {
    int temp = n;
    temp += child[0] != nullptr ? child[0]->count() : 0;
    temp += child[1] != nullptr ? child[1]->count() : 0;
    return temp;
  }

  int insert(string str) {
    if (name == str) {
      n++;
      return 0;
    }
    if (name > str) {
      if (child[0] == nullptr)
        child[0] = new Node(str);
      else
        child[0]->insert(str);
    } else {
      if (child[1] == nullptr)
        child[1] = new Node(str);
      else
        child[1]->insert(str);
    }
  }
};

int main(void) {
  int N;
  string str;
  cin >> N;

  cin >> str;
  Node root(str);

  for (int i = 1; i < N; i++) {
    cin >> str;
    root.insert(str);
  }

  cout << root.count() << endl;

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

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

int main() {
  int num;
  std::cin >> num;
  int count = 0;
  map<string, int> keihinn;

  for (int i = 0; i < num; i++) {
    string tmp;
    std::cin >> tmp;
    if (keihinn.find(tmp) != keihinn.end())
      keihinn[tmp] = 1;
    else
      keihinn[tmp]++;
  }
  cout << keihinn.size() << endl;

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int num;
  std::cin >> num;
  int count = 0;
  string *keihinn;
  keihinn = new string[num];

  for (int i = 0; i < num; i++) {
    int flag = 0;
    string tmp;
    std::cin >> tmp;
    for (int j = 0; j < count; j++) {
      if (tmp.compare(keihinn[j]) == 0) {
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      keihinn[count] = tmp;
      count++;
    }
  }
  cout << count << endl;

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

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

int main() {
  int N;
  int result = 0;
  cin >> N;

  string data[200010];
  for (int i = 0; i < N; i++)
    cin >> data[i];
  sort(data, data + 200010);
  reverse(data, data + 200010);

  for (int i = 0; i < N; i++) {
    if (data[i] != data[i + 1]) {
      result++;
    }
  }

  cout << result << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int vector_finder(std::vector<string> vec, string number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance(vec.begin(), itr);
  if (index != vec.size()) { // 発見できたとき
    return 1;
  } else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int N;
  int result = 0;
  cin >> N;
  string present;
  vector<string> vec;

  for (int i = 0; i < N; i++) {
    cin >> present;
    if (vector_finder(vec, present) == 0) {
      vec.push_back(present);
      result++;
    }
  }
  cout << result << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  ll N;
  cin >> N;
  set<string> X;
  rep(i, N) {
    string A;
    cin >> A;
    X.insert(A);
  }
  cout << X.size() << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  ll N;
  cin >> N;
  vector<string> X(0);
  rep(i, N) {
    string A;
    cin >> A;
    int counter = 0;
    rep(j, X.size()) {
      if (A != X.at(j))
        counter++;
    }
    if (counter == X.size())
      X.push_back(A);
  }
  cout << X.size() << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <set>
#include <vector>
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {

  int n;
  cin >> n;
  set<string> st;

  rep(i, n) {
    string s;
    cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <vector>
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

int main() {

  int n;
  string s[100000];

  cin >> n;

  rep(i, n) cin >> s[i];

  int cnt = 0;
  rep(i, n) {
    rep(j, n) {
      if (s[i] == s[j])
        cnt++;
    }
  }

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

#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
// using ll = long long;
using namespace std;
const int mod = 1000000007;

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, ans = 0;
  cin >> n;
  string s[n];

  REP(i, n) { cin >> s[i]; }

  sort(s, s + n);

  REP(i, n - 1) {
    if (s[i] != s[i + 1]) {
      ans += 1;
    }
  }

  cout << ans + 1 << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
// using ll = long long;
using namespace std;
const int mod = 1000000007;

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, ans = 0, flag = 0;
  cin >> n;
  string s[n];

  REP(i, n) {
    flag = 0;
    cin >> s[i];
    REP(j, i) {
      if (s[i] == s[j]) {
        flag = 1;
      }
    }
    if (flag == 0) {
      ans += 1;
    }
  }

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

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

using namespace std;

int N;
string s;
set<string> set_;

int main() {
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> s;
    set_.insert(s);
  }
  cout << set_.size();
  return 0;
}

Error: TLE

Fixed submission:

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

string S[200010];

int main() {
  int N;
  cin >> N;
  int sum = 0;
  for (int i = 0; i < N; ++i) {
    cin >> S[i];
  }
  for (int i = 0; i < N; ++i) {
    sum++;
    for (int j = 0; j < i; ++j) {
      if (S[i] == S[j]) {
        sum--;
        break;
      }
    }
  }
  cout << sum;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  cin >> n;
  set<string> st;
  rep(i, n) {
    string s;
    cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  cin >> n;
  int cou = 1;
  vector<string> a;
  string s;
  cin >> s;
  a.push_back(s);
  rep(i, n - 1) {
    cin >> s;
    int j;
    for (j = 0; j < a.size(); j++) {
      if (s == a[j]) {
        break;
      }
    }
    if (j == a.size()) {
      cou++;
      a.push_back(s);
    }
  }
  cout << cou << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < a; i++)
using namespace std;
using ll = long long;
int main(void) {
  int n, ans = 1;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  sort(s.begin(), s.end());
  for (int i = 0; i < n - 1; i++) {
    if (s[i] != s[i + 1])
      ans++;
  }
  // if(s[n-2]!=s[n-1])ans+=2;
  cout << ans << endl;
  // int n,size=0;
  // cin>>n;
  // string s,t[n];
  // rep(i,n){
  //     cin>>s;
  //     for(int j=0;j<=size;j++){
  //         if(j==size)t[size++]=s;
  //         if(s==t[j])break;
  //     }
  // }
  // cout<<size<<endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < a; i++)
using namespace std;
using ll = long long;
int main(void) {
  int n, size = 0;
  cin >> n;
  string s, t[n];
  rep(i, n) {
    cin >> s;
    for (int j = 0; j <= size; j++) {
      if (j == size)
        t[size++] = s;
      if (s == t[j])
        break;
    }
  }
  cout << size << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

#define roop(i, n) for (int i = 0; i < n; i++)
#define DIV 1000000007

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
  float x = 1;
  while (n > 0) { // 全てのbitが捨てられるまで
    if (n & 1) {  // 一番右のbitが１のとき
      x *= a;
    }
    a *= a;
    n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
  }
  return x;
}

ll combination(ll n, ll r) {
  if (n < 0 || r < 0 || r > n)
    return -1;

  if (n - r < r)
    r = n - r;
  if (r == 0)
    return 1;
  if (r == 1)
    return n;

  vector<ll> num(r);
  vector<ll> den(r);

  for (ll i = 0; i < r; i++) {
    num[i] = n - r + i + 1;
    den[i] = i + 1;
  }

  for (ll p = 2; p <= r; p++) {
    ll pivot = den[p - 1];
    if (pivot > 1) {
      ll offset = (n - r) % p;
      for (ll k = p - 1; k < r; k += p) {
        num[k - offset] /= pivot;
        den[k] /= pivot;
      }
    }
  }
  ll result = 1;
  for (ll k = 0; k < r; k++) {
    if (num[k] > 1)
      result *= num[k];
  }
  return result;
}

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  for (ll i = 0; i < n; i++) {
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  ll count = 1;
  for (ll i = 0; i < n - 1; i++) {
    if (s[i] != s[i + 1]) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

#define roop(i, n) for (int i = 0; i < n; i++)
#define DIV 1000000007

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
  float x = 1;
  while (n > 0) { // 全てのbitが捨てられるまで
    if (n & 1) {  // 一番右のbitが１のとき
      x *= a;
    }
    a *= a;
    n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
  }
  return x;
}

ll combination(ll n, ll r) {
  if (n < 0 || r < 0 || r > n)
    return -1;

  if (n - r < r)
    r = n - r;
  if (r == 0)
    return 1;
  if (r == 1)
    return n;

  vector<ll> num(r);
  vector<ll> den(r);

  for (ll i = 0; i < r; i++) {
    num[i] = n - r + i + 1;
    den[i] = i + 1;
  }

  for (ll p = 2; p <= r; p++) {
    ll pivot = den[p - 1];
    if (pivot > 1) {
      ll offset = (n - r) % p;
      for (ll k = p - 1; k < r; k += p) {
        num[k - offset] /= pivot;
        den[k] /= pivot;
      }
    }
  }
  ll result = 1;
  for (ll k = 0; k < r; k++) {
    if (num[k] > 1)
      result *= num[k];
  }
  return result;
}

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  vector<string> t;
  ll count = 0;
  ll beforeCount = 0;
  for (ll i = 0; i < n; i++) {
    cin >> s[i];
    if (i == 0) {
      t.push_back(s[0]);
    }
    beforeCount = count;
    for (ll j = 0; t[j] != "\\0"; j++) {
      if (s[i] == t[j]) {
        count++;
        break;
      }
    }
    if (i != 0 && beforeCount == count) {
      t.push_back(s[i]);
    }
  }
  cout << n - (count - 1) << endl;
  return 0;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int main() {
  int n;
  string lottery[200000];

  cin >> n;
  for (int a = 0; a < n; a++) {
    cin >> lottery[a];
  }

  sort(lottery, lottery + n);

  int counter = 0;
  for (int i = 0; i < n; i++) {
    if (lottery[i] != lottery[i - 1]) {
      counter++;
    }
  }

  cout << counter << endl;
}

// tle:
/*#include <iostream>
#include <vector>
using namespace std;

int main()
{
        int n;
        vector<string> lottery;

        cin >> n;
        for (int a = 0; a < n; a++)
        {
                string s;
                cin >> s;
                lottery.push_back(s);
        }

        vector<string> used;
        int counter = 0;
        int j = 0;
        for (int i = 0; i < n; i++) //check every draw
        {
                int flag = 1;
                for (int k = 0; k < j; k++)
                {
                        if (lottery[i] == used[k])
                        {
                                flag = 0;
                        }
                }

                if (flag)
                {
                        used.push_back(lottery[i]);
                        counter++;
                        j++;
                }
        }

        cout << counter << endl;
}*/

Error: TLE

Fixed submission:

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

int main() {
  int n;
  vector<string> lottery;

  cin >> n;
  for (int a = 0; a < n; a++) {
    string s;
    cin >> s;
    lottery.push_back(s);
  }

  vector<string> used;
  int counter = 0;
  int j = 0;
  for (int i = 0; i < n; i++) // check every draw
  {
    int flag = 1;
    for (int k = 0; k < j; k++) {
      if (lottery[i] == used[k]) {
        flag = 0;
      }
    }

    if (flag) {
      used.push_back(lottery[i]);
      counter++;
      j++;
    }
  }

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

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

int main() {
  int N;
  cin >> N;
  vector<string> A(N);
  map<string, int> B;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (!(B.count(A.at(i)))) {
      B[A.at(i)] = i;
    }
  }
  cout << B.size() << endl;
}


Error: 0

Fixed submission:

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

int main() {
  int N;
  vector<string> A(N);
  cin >> N;
  map<string, int> B;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    if (!(B.count(A.at(i)))) {
      B[A.at(i)] = i;
    }
  }
  cout << B.size() << 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> V(N);
  for (int i = 0; i < N; i++) {
    cin >> V[i];
  }

  set<string> S;
  for (int i = 0; i < N; i++) {
    S.insert(V[i]);
  }
  cout << S.size() << endl;
}


Error: TLE

Fixed submission:

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  for (int i = 0; i < N; i++) {
    cin >> s[i];
  }
  bool x;
  int count = 0;
  for (int i = 0; i < N; i++) {
    x = true;
    for (int j = 0; j <= i; j++) {
      if (s[i] == s[j] && i != j) {
        x = false;
        break;
      }
    }
    if (x) {
      for (int j = i + 1; j < N; j++) {
        if (s[j] == s[i]) {
          count++;
        }
      }
    }
  }
  cout << N - count << endl;
}
Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const ll INF = 1LL << 60;
const ll M = 1000000007;
ll mpow(ll a, ll b) {
  ll res = 1;
  while (b != 0) {
    if (b & 1)
      res = res * a % M;
    a = a * a % M;
    b = b >> 1;
  }
  return res;
}
ll mcomb(ll n, ll k) {
  if (k > n / 2)
    return mcomb(n, n - k);
  ll res = 1;
  for (ll i = 0; i < k; i++) {
    res = res * (n - i) % M;
    res = res * mpow(k - i, M - 2) % M;
  }
  return res;
}
/*template*/

int main() {
  ll n;
  cin >> n;
  string s[n];
  for (ll i = 0; i < n; i++)
    cin >> s[i];
  sort(s, s + n);
  ll ans = 1;
  for (ll i = 1; i < n; i++) {
    if (s[i] != s[i - 1])
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
const ll INF = 1LL << 60;
const ll M = 1000000007;
ll mpow(ll a, ll b) {
  ll res = 1;
  while (b != 0) {
    if (b & 1)
      res = res * a % M;
    a = a * a % M;
    b = b >> 1;
  }
  return res;
}
ll mcomb(ll n, ll k) {
  if (k > n / 2)
    return mcomb(n, n - k);
  ll res = 1;
  for (ll i = 0; i < k; i++) {
    res = res * (n - i) % M;
    res = res * mpow(k - i, M - 2) % M;
  }
  return res;
}
/*template*/

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  string s[n];
  for (ll i = 0; i < n; i++) {
    cin >> s[i];
    bool flag = true;
    for (ll j = 0; j < i; j++) {
      if (s[i] == s[j]) {
        flag = false;
        break;
      }
    }
    if (flag)
      ans++;
  }
  cout << ans << 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);

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

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

  decltype(S)::iterator result = unique(S.begin(), S.end());
  S.erase(result, S.end());
  cout << S.size() << endl;
}

Error: TLE

Fixed submission:

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

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

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

  int typeNum = 0;

  sort(S.begin(), S.end());
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      if (S.at(i) == S.at(j)) {
        typeNum++;
        break;
      }
    }
  }
  cout << N - typeNum << endl;
}