Buggy python submission (verdict: Runtime Error):


def get_group(str):
    return str.split(':')[0];

def get_member(str):
    return str.split(':')[1].split('.')[0].split(',');

def get_num(group, map, ans):
    for person in map[group]:
        if person in map:
            get_num(person, map, ans);
        else:
            ans[person] = True;

def main():
    while True:
        str = input();
        if len(str) == 0:
            continue;

        n = int(str);
        if n == 0:
            break;

        group = {};
        group.clear();
        name = {};
        name.clear();

        for i in range(0, n):
            str = input();
            name[i] = get_group(str);
            group[name[i]] = get_member(str);

        ans = {};
        ans.clear();
        get_num(name[0], group, ans);
        print(len(ans));

main();

Fixed submission:
def get_num(u, map, vis):
    if u in vis:
        return 0;
    else:
        vis[u] = True;
    ans = 0;
    if u in map:
        for v in map[u]:
            ans += get_num(v, map, vis);
    else:
            ans += 1;
    return ans;
def main():
    while True:
        n = int(input());
        if n == 0:
            break;
        edge = {}; name = {}; vis = {};
        for i in range(0, n):
            str = input();
            u = name[i] = str.split(':')[0];
            group = str.split(':')[1].split('.')[0].split(',');
            for v in group:
                if u in edge:
                    edge[u][v] = True;
                else:
                    edge[u] = {v:True};
        print(get_num(name[0], edge, vis));
main();

Buggy python submission (verdict: Runtime Error):
def get_group(str):
    return str.split(':')[0];
def get_member(str):
    return str.split(':')[1].split('.')[0].split(',');
def get_num(group, map, ans):
    for person in map[group]:
        if person in map:
            get_num(person, map, ans);
        else:
            ans[person] = True;
def main():
    while True:
        str = input();
        if len(str) == 0:
            continue;
        n = int(str);
        if not str.isdigit():
            continue;
        if n == 0:
            break;
        group = {};
        group.clear();
        name = {};
        name.clear();
        for i in range(0, n):
            str = input();
            name[i] = get_group(str);
            group[name[i]] = get_member(str);
        ans = {};
        ans.clear();
        get_num(name[0], group, ans);
        print(len(ans));
main();

Fixed submission:
def get_num(u, map, vis):
    if u in vis:
        return 0;
    else:
        vis[u] = True;
    ans = 0;
    if u in map:
        for v in map[u]:
            ans += get_num(v, map, vis);
    else:
            ans += 1;
    return ans;
def main():
    while True:
        n = int(input());
        if n == 0:
            break;
        edge = {}; name = {}; vis = {};
        for i in range(0, n):
            str = input();
            u = name[i] = str.split(':')[0];
            group = str.split(':')[1].split('.')[0].split(',');
            for v in group:
                if u in edge:
                    edge[u][v] = True;
                else:
                    edge[u] = {v:True};
        print(get_num(name[0], edge, vis));
main();