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

#include <cstdio>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
  int n, r, i;
  char s[256], t[256], c;
  string p;
  while (scanf("%d", &n), n) {
    map<string, vector<string>> m;
    queue<string> q;
    while (n--) {
      scanf(" %[a-z]:", s);
      if (q.empty())
        q.push(s);
      for (;;) {
        scanf(" %[a-z]%c", t, &c);
        m[s].push_back(t);
        if (c == '.')
          break;
      }
    }
    r = 0;
    map<string, bool> c;
    while (q.size()) {
      p = q.front();
      q.pop();
      if (c[p])
        continue;
      c[p] = 1;
      if (m.find(p) != m.end())
        for (i = 0; i < m[p].size(); ++i)
          q.push(m[p][i]);
      else
        ++r;
    }
    printf("%d\\n", r);
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef set<string> S;
int main() {
  int n, f;
  char s[256], t[256], c;
  while (scanf("%d", &n), n) {
    map<string, vector<string>> m;
    S r;
    while (n--) {
      scanf(" %[a-z]:", s);
      if (r.empty())
        r.insert(s);
      for (;;) {
        scanf(" %[a-z]%c", t, &c);
        m[s].push_back(t);
        if (c == '.')
          break;
      }
    }
    do {
      f = 0;
      for (S::iterator i = r.begin(); i != r.end(); ++i) {
        if (m.find(*i) != m.end()) {
          f = 1;
          r.insert(m[*i].begin(), m[*i].end());
          r.erase(i);
          break;
        }
      }
    } while (f);
    printf("%u\\n", r.size());
  }
  return 0;
}
Problem p00884 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int main(void) {
  int n;
  while (cin >> n, n) {
    map<string, set<string>> teams;
    bool f = false;
    string fteamname;
    for (int i = 0; i < n; ++i) {
      string s;
      cin >> s;
      int b = s.find(":");
      string teamname = s.substr(0, b);
      if (f == false)
        fteamname = teamname;
      f = true;
      vector<string> splitted;
      int cur = b + 1, nxt;
      while ((nxt = s.find(',', cur)) != string::npos ||
             (nxt = s.find('.', cur)) != string::npos) {
        splitted.push_back(s.substr(cur, nxt - cur));
        cur = nxt + 1;
      }
      for (int i = 0; i < splitted.size(); ++i)
        teams[teamname].insert(splitted[i]);
    }

    set<string> firstteam;
    set<string> done;
    priority_queue<string> Q;
    Q.push(fteamname);
    while (!Q.empty()) {
      string teamname = Q.top();
      Q.pop();
      set<string>::iterator it = teams[teamname].begin();
      for (; it != teams[teamname].end(); ++it) {
        if (teams.find(*it) != teams.end()) {
          if (done.find(*it) == done.end()) {
            Q.push(*it);
            done.insert(*it);
          }
        } else
          firstteam.insert(*it);
      }
    }
    cout << firstteam.size() << endl;
  }
  return 0;
}

Error: MLE

Fixed submission:

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

int main(void) {
  int n;
  while (cin >> n, n) {
    map<string, set<string>> teams;
    bool f = false;
    string fteamname;
    for (int i = 0; i < n; ++i) {
      string s;
      cin >> s;
      int b = s.find(":");
      string teamname = s.substr(0, b);
      if (f == false)
        fteamname = teamname;
      f = true;
      vector<string> splitted;
      int cur = b + 1, nxt;
      while ((nxt = s.find(',', cur)) != string::npos ||
             (nxt = s.find('.', cur)) != string::npos) {
        splitted.push_back(s.substr(cur, nxt - cur));
        cur = nxt + 1;
      }
      for (int i = 0; i < splitted.size(); ++i)
        teams[teamname].insert(splitted[i]);
    }

    set<string> firstteam;
    priority_queue<string> Q;
    Q.push(fteamname);
    while (!Q.empty()) {
      string teamname = Q.top();
      Q.pop();
      set<string>::iterator it = teams[teamname].begin();
      for (; it != teams[teamname].end(); ++it) {
        if (teams.find(*it) != teams.end())
          Q.push(*it);
        else
          firstteam.insert(*it);
      }
    }
    cout << firstteam.size() << endl;
  }
  return 0;
}
Problem p00884 (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;

int main() {
  int n;
  while (scanf("%d", &n), n) {
    map<string, set<string>> mp, memo;
    string f;
    rep(i, n) {
      string s, t, p;
      cin >> s;
      for (auto &c : s) {
        if (c == ':') {
          p = t;
          t = "";
          if (!i)
            f = p;
        } else if (c == ',' || c == '.') {
          mp[p].insert(t);
          t = "";
        } else
          t += c;
      }
    }
    function<set<string>(string)> dfs = [&](string s) {
      if (memo.find(s) != memo.end())
        return memo[s];
      set<string> res;
      for (auto &t : mp[s]) {
        if (mp.find(t) == mp.end())
          res.insert(t);
        else {
          set<string> k = dfs(t);
          for (auto &p : k)
            res.insert(p);
        }
      }
      return memo[s] = res;
    };
    set<string> r = dfs(f);
    printf("%d\\n", dfs(f).size());
  }
}

Error: TLE

Fixed submission:

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

int main() {
  int n;
  while (scanf("%d", &n), n) {
    map<string, set<string>> mp;
    string f;
    rep(i, n) {
      string s, t, p;
      cin >> s;
      for (auto &c : s) {
        if (c == ':') {
          p = t;
          t = "";
          if (!i)
            f = p;
        } else if (c == ',' || c == '.') {
          mp[p].insert(t);
          t = "";
        } else
          t += c;
      }
    }
    function<set<string>(string)> dfs = [&](string s) {
      set<string> res;
      for (auto &t : mp[s]) {
        if (mp.find(t) == mp.end())
          res.insert(t);
        else {
          set<string> k = dfs(t);
          for (auto &p : k)
            res.insert(p);
        }
      }
      return res;
    };
    set<string> r = dfs(f);
    printf("%d\\n", dfs(f).size());
  }
}
Problem p00884 (C++) — buggy submission, verdict: Memory Limit Exceeded

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

int N;

string Input(map<string, set<string>> &m) {
  string str;
  int count = 0;
  stringstream ss;
  cin >> str;
  for (int i = 0; i < (int)str.size(); i++) {
    if (str[i] == ':' || str[i] == ',' || str[i] == '.') {
      count++;
      str[i] = ' ';
    }
  }

  ss << str;
  string top;
  ss >> top;
  for (int i = 0; i < count - 1; i++) {
    string s;
    ss >> s;
    m[top].insert(s);
  }

  return top;
}

void solve() {
  map<string, set<string>> m;
  vector<string> sSet(N);
  for (int i = 0; i < N; i++)
    sSet[i] = Input(m);

  set<string> ans;
  queue<string> que;
  for (auto i : m[sSet[0]])
    que.push(i);
  map<string, bool> used;
  while (que.size()) {
    string str = que.front();
    que.pop();
    used[str] = true;
    if (m.find(str) == m.end())
      ans.insert(str);
    else {
      for (auto i : m[str])
        if (used.find(i) == used.end())
          que.push(i);
    }
  }

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

int main() {
  while (cin >> N, N)
    solve();

  return 0;
}

Error: MLE

Fixed submission:

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

int N;

string Input(map<string, set<string>> &m) {
  string str;
  int count = 0;
  stringstream ss;
  cin >> str;
  for (int i = 0; i < (int)str.size(); i++) {
    if (str[i] == ':' || str[i] == ',' || str[i] == '.') {
      count++;
      str[i] = ' ';
    }
  }

  ss << str;
  string top;
  ss >> top;
  for (int i = 0; i < count - 1; i++) {
    string s;
    ss >> s;
    m[top].insert(s);
  }

  return top;
}

void solve() {
  map<string, set<string>> m;
  vector<string> sSet(N);
  for (int i = 0; i < N; i++)
    sSet[i] = Input(m);

  set<string> ans;
  queue<string> que;
  for (auto i : m[sSet[0]])
    que.push(i);
  while (que.size()) {
    string str = que.front();
    que.pop();
    if (m.find(str) == m.end())
      ans.insert(str);
    else {
      for (auto i : m[str])
        que.push(i);
    }
  }

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

int main() {
  while (cin >> N, N)
    solve();

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

set<string> st;

void dfs(string s, map<string, vector<string>> mp, vector<string> group,
         map<string, bool> &used) {
  if (used[s])
    return;
  REP(j, mp[s].size()) {
    string mem = mp[s][j];
    if (mp[mem].size() == 0)
      st.insert(mem);
    else
      dfs(mem, mp, group, used);
  }
  used[s] = 1;
}

int main() {
  int n;
  while (cin >> n && n) {
    map<string, vector<string>> mp;
    vector<string> group;
    REP(i, n) {
      string s, t, u;
      cin >> s;
      int x = 0;
      while (s[x] != ':') {
        t += s[x];
        x++;
      }
      group.push_back(t);
      x++;
      while (x < s.length()) {
        if (s[x] == ',' || s[x] == '.') {
          mp[t].push_back(u);
          u.clear();
        } else {
          u += s[x];
        }
        x++;
      }
    }
    st.clear();
    map<string, bool> used;
    dfs(group[0], mp, group, used);
    cout << st.size() << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;

set<string> st;

void dfs(string s, map<string, vector<string>> mp, vector<string> group) {
  REP(j, mp[s].size()) {
    string mem = mp[s][j];
    if (mp[mem].size() == 0)
      st.insert(mem);
    else
      dfs(mem, mp, group);
  }
}

int main() {
  int n;
  while (cin >> n && n) {
    map<string, vector<string>> mp;
    vector<string> group;
    REP(i, n) {
      string s, t, u;
      cin >> s;
      int x = 0;
      while (s[x] != ':') {
        t += s[x];
        x++;
      }
      group.push_back(t);
      x++;
      while (x < s.length()) {
        if (s[x] == ',' || s[x] == '.') {
          mp[t].push_back(u);
          u.clear();
        } else {
          u += s[x];
        }
        x++;
      }
    }
    st.clear();
    dfs(group[0], mp, group);
    cout << st.size() << endl;
  }

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

#include <cstdio>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

int n;
set<string> st;
vector<vector<string>> group;
map<string, int> gindex;
vector<bool> flag;

void func(int index) {
  flag[index] = true;
  map<string, int>::iterator it;

  for (int i = 0; i < group[index].size(); ++i) {
    it = gindex.find(group[index][i]);

    if (it == gindex.end()) {
      st.insert(group[index][i]);
    } else if (!flag[it->second]) {
      func(it->second);
    }
  }
}

int main() {
  char str[30];
  int n;

  while (scanf("%d", &n), n != 0) {
    group.assign(n, vector<string>());
    flag.assign(n, false);
    st.clear();
    gindex.clear();

    for (int i = 0; i < n; ++i) {
      scanf(" %[^:]:", str);
      gindex[str] = i;
      char ch = ',';
      while (ch != '.') {
        scanf("%[^,.]%c", str, &ch);
        group[i].push_back(str);
      }
    }

    func(0);
    printf("%d\\n", st.size());
  }
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

int n;
set<string> st;
vector<vector<string>> group;
map<string, int> gindex;

void func(int index) {
  map<string, int>::iterator it;
  for (int i = 0; i < group[index].size(); ++i) {
    it = gindex.find(group[index][i]);

    if (it == gindex.end()) {
      st.insert(group[index][i]);
    } else {
      func(it->second);
    }
  }
}

int main() {
  char str[30];
  int n;

  while (scanf("%d", &n), n != 0) {
    group.assign(n, vector<string>());
    st.clear();
    gindex.clear();

    for (int i = 0; i < n; ++i) {
      scanf(" %[^:]:", str);
      gindex[str] = i;
      char ch = ',';
      while (ch != '.') {
        scanf("%[^,.]%c", str, &ch);
        group[i].push_back(str);
      }
    }

    func(0);
    printf("%d\\n", st.size());
  }
}
Problem p00884 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

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

map<string, vector<string>> data;
string startkey;

bool input() {

  data.clear();
  int n;
  cin >> n;
  if (n == 0)
    return false;

  rep(i, n) {
    string str;
    cin >> str;

    string key;
    vector<string> val;
    int keypos = 0;
    rep(j, str.size()) {
      if (str[j] == ':') {
        key = str.substr(0, j);
        keypos = j + 1;
      }
      if (str[j] == ',' || str[j] == '.') {
        val.push_back(str.substr(keypos, j - keypos));
        keypos = j + 1;
      }
    }
    if (i == 0)
      startkey = key;
    data[key] = val;
  }
  return true;
}

map<string, set<string>> memo;

set<string> rec(string key) {

  if (memo.find(key) != memo.end())
    return memo[key];

  set<string> ret;

  if (data[key].size() == 0) {
    ret.insert(key);
  } else {
    for (auto i : data[key]) {
      set<string> result = rec(i);
      for (auto j : result) {
        ret.insert(j);
      }
    }
  }
  return memo[key] = ret;
}

int solve() {
  memo.clear();
  // for(auto i: data){
  //   cout<<"||"<<i.first<<endl;
  //   for(auto j: i.second){
  //     cout<<j<<endl;
  //   }
  // }

  set<string> res = rec(startkey);

  // for(auto i: res){
  //   cout<<"res | "<<i<<endl;
  // }
  return res.size();
}

int main() {
  while (input())
    cout << solve() << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

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

map<string, vector<string>> data;
string startkey;

bool input() {

  data.clear();
  int n;
  cin >> n;
  if (n == 0)
    return false;

  rep(i, n) {
    string str;
    cin >> str;

    string key;
    vector<string> val;
    int keypos = 0;
    rep(j, str.size()) {
      if (str[j] == ':') {
        key = str.substr(0, j);
        keypos = j + 1;
      }
      if (str[j] == ',' || str[j] == '.') {
        val.push_back(str.substr(keypos, j - keypos));
        keypos = j + 1;
      }
    }
    if (i == 0)
      startkey = key;
    data[key] = val;
  }
  return true;
}

set<string> rec(string key) {
  set<string> ret;

  if (data[key].size() == 0) {
    ret.insert(key);
  } else {
    for (auto i : data[key]) {
      set<string> result = rec(i);
      for (auto j : result) {
        ret.insert(j);
      }
    }
  }
  return ret;
}

int solve() {

  // for(auto i: data){
  //   cout<<"||"<<i.first<<endl;
  //   for(auto j: i.second){
  //     cout<<j<<endl;
  //   }
  // }

  set<string> res = rec(startkey);

  // for(auto i: res){
  //   cout<<"res | "<<i<<endl;
  // }
  return res.size();
}

int main() {
  while (input())
    cout << solve() << endl;
}
Problem p00884 (C++) — buggy submission, verdict: Time Limit Exceeded

// 54
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>

using namespace std;

map<string, string> m;
set<string> ms;
set<string> ch;

void dfs(string g) {
  if (ch.count(g))
    return;
  ch.insert(g);
  string mg = m[g];
  for (int i = 0; i < mg.size(); i++) {
    if (mg[i] == '.' || mg[i] == ',') {
      mg[i] = ' ';
    }
  }
  stringstream ss(mg);
  for (string mg; ss >> mg;) {
    if (m.count(mg)) {
      dfs(mg);
    } else {
      ms.insert(mg);
    }
  }
}

int main() {
  for (int n; cin >> n, n;) {
    string g1;
    cin.ignore();
    m.clear();
    ms.clear();
    ch.clear();
    for (int i = 0; i < n; i++) {
      string s;
      getline(cin, s);
      string g = s.substr(0, s.find(':'));
      if (i == 0) {
        g1 = g;
      }
      m[g] = s.substr(s.find(':') + 1);
    }
    dfs(g1);
    cout << ms.size() << endl;
  }
  return 0;
}


Error: TLE

Fixed submission:

// 54
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>

using namespace std;

map<string, string> m;
set<string> ms;

void dfs(string g) {
  string mg = m[g];
  for (int i = 0; i < mg.size(); i++) {
    if (mg[i] == '.' || mg[i] == ',') {
      mg[i] = ' ';
    }
  }
  stringstream ss(mg);
  for (string mg; ss >> mg;) {
    if (m.count(mg)) {
      dfs(mg);
    } else {
      ms.insert(mg);
    }
  }
}

int main() {
  for (int n; cin >> n, n;) {
    string g1;
    cin.ignore();
    m.clear();
    ms.clear();
    for (int i = 0; i < n; i++) {
      string s;
      getline(cin, s);
      string g = s.substr(0, s.find(':'));
      if (i == 0) {
        g1 = g;
      }
      m[g] = s.substr(s.find(':') + 1);
    }
    dfs(g1);
    cout << ms.size() << endl;
  }
  return 0;
}
Problem p00884 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

map<string, bool> visited;
void merge(const string &grp, map<string, vector<string>> &m,
           set<string> &members) {
  if (visited[grp])
    return;

  const vector<string> &v = m[grp];
  for (int i = 0; i < v.size(); ++i) {
    string name = v[i];
    if (m.count(name) > 0) {
      merge(name, m, members);
    } else {
      members.insert(name);
    }
  }
  visited[grp] = true;
}

int main() {
  ios::sync_with_stdio(0);
  while (true) {
    int N;
    cin >> N;
    if (!N)
      break;

    map<string, vector<string>> m;
    string first;
    for (int i = 0; i < N; ++i) {
      string s;
      cin >> s;
      int colon = s.find(":");
      string group = s.substr(0, colon);
      string members = s.substr(colon + 1);
      members.erase(members.size() - 1);
      for (int j = 0; j < members.size(); ++j) {
        if (members[j] == ',')
          members[j] = ' ';
      }

      istringstream is(members);
      string name;
      vector<string> &v = m[group];
      while (is >> name) {
        v.push_back(name);
      }
      if (i == 0)
        first = group;
    }

    visited.clear();
    set<string> members;
    merge(first, m, members);
    cout << members.size() << endl;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

void merge(const string &grp, map<string, vector<string>> &m,
           set<string> &members) {
  const vector<string> &v = m[grp];
  for (int i = 0; i < v.size(); ++i) {
    string name = v[i];
    if (m.count(name) > 0) {
      merge(name, m, members);
    } else {
      members.insert(name);
    }
  }
}

int main() {
  ios::sync_with_stdio(0);
  while (true) {
    int N;
    cin >> N;
    if (!N)
      break;

    map<string, vector<string>> m;
    string first;
    for (int i = 0; i < N; ++i) {
      string s;
      cin >> s;
      int colon = s.find(":");
      string group = s.substr(0, colon);
      string members = s.substr(colon + 1);
      members.erase(members.size() - 1);
      for (int j = 0; j < members.size(); ++j) {
        if (members[j] == ',')
          members[j] = ' ';
      }

      istringstream is(members);
      string name;
      vector<string> &v = m[group];
      while (is >> name) {
        v.push_back(name);
      }
      if (i == 0)
        first = group;
    }

    set<string> members;
    merge(first, m, members);
    cout << members.size() << endl;
  }

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

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

using namespace std;

int n;
vector<vector<string>> s;
vector<string> m;
set<string> se;

int main(void) {
  while (cin >> n && n) {
    ;
    m.clear();
    s.clear();
    se.clear();
    for (int i = 0; i < n; i++) {
      string t;
      vector<string> u;
      cin >> t;
      int l = 0, r = 0;
      while (t[r] != ':')
        r++;
      u.push_back(t.substr(l, r - l));
      m.push_back(t.substr(l, r - l));

      r++;
      while (1) {
        l = r;
        while (t[r] != '.' && t[r] != ',')
          r++;
        u.push_back(t.substr(l, r - l));
        m.push_back(t.substr(l, r - l));
        if (t[r] == '.')
          break;
        r++;
      }
      s.push_back(u);
    }
    sort(m.begin(), m.end());
    m.erase(unique(m.begin(), m.end()), m.end());

    for (int i = 0; i < s[0].size(); i++)
      se.insert(s[0][i]);
    s.erase(s.begin());
    bool f = true;
    int cnt = 1;
    while (f) {
      f = false;
      for (int i = 0; i < s.size(); i++) {
        set<string>::iterator it = se.find(s[i][0]);
        if (it != se.end()) {
          for (int j = 1; j < s[i].size(); j++)
            se.insert(s[i][j]);
          s.erase(s.begin() + i);
          cnt++;
          f = true;
        }
      }
    }
    cout << se.size() - cnt << endl;
  }
}

Error: MLE

Fixed submission:

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

using namespace std;

vector<string> member;

int rec(int n, vector<vector<string>> s, vector<string> t) {
  int ret = 0;
  for (int i = 1; i < t.size(); i++) {
    int f = 0;
    for (int j = 0; j < s.size(); j++) {
      if (s[j][0] == t[i])
        f = j;
    }
    if (f == 0) {
      member.push_back(t[i]);
    } else
      rec(n, s, s[f]);
  }
  return ret;
}

int main(void) {
  int n;
  while (cin >> n && n) {
    vector<vector<string>> s(n);
    member.clear();
    for (int i = 0; i < n; i++) {
      string t;
      cin >> t;
      int l = 0, r = 0;
      while (t[r] != ':')
        r++;
      s[i].push_back(t.substr(l, r - l));
      r++;
      while (1) {
        l = r;
        while (t[r] != '.' && t[r] != ',')
          r++;
        s[i].push_back(t.substr(l, r - l));
        if (t[r] == '.')
          break;
        r++;
      }
    }
    /*
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < s[i].size(); j++) {
            cout << s[i][j] << " ";
        }
        cout << endl;
    }
    */
    rec(n, s, s[0]);
    sort(member.begin(), member.end());
    member.erase(unique(member.begin(), member.end()), member.end());
    cout << member.size() << endl;
  }
}