Buggy python submission (verdict: Time Limit Exceeded):


N=int(input())

S_list = []
S_count = []
max = 1
temp_list = []
#for i in range(N):
#    s = input()
#    temp_list.append(s)

for i in range(N):
    s = input()
    #temp_list = []
    #temp_list.append(s)
    try:
        index = S_list.index(s)
        S_count[index] += 1
        if max < S_count[index]:
            max = S_count[index]
    except ValueError:
        S_list.append(s)
        S_count.append(1)
    
     
#print(S_list)
#print(S_count)
#print(max)
S_max = []
for j in range(len(S_list)):
    if S_count[j] == max:
        S_max.append(S_list[j])

S_max.sort()
for k in range(len(S_max)):
    print(S_max[k])

Fixed submission:


N=int(input())

S_list = []
S_count = []
max = 1
temp_list = []
#for i in range(N):
#    s = input()
#    temp_list.append(s)
S_dict = {}
for i in range(N):
    s = input()
    if s in S_dict.keys():
        S_dict[s] += 1
        if max < S_dict[s]:
            max = S_dict[s]
    else:
        S_dict[s] = 1
    
     
#print(S_list)
#print(S_count)
#print(max)
S_max = []
for j in S_dict:
    if S_dict[j] == max:
        S_max.append(j)

S_max.sort()
for k in range(len(S_max)):
    print(S_max[k])

Buggy python submission (verdict: Time Limit Exceeded):


N=int(input())

S_list = []
S_count = []
max = 1
for i in range(N):
    s = input()
    temp_list = []
    temp_list.append(s)
    #if s in S_list:
    if not set(S_list).isdisjoint(set(temp_list)):   
        index = S_list.index(s)
        #S_count.append(S_count[index]+1)
        S_count[index] += 1
        if max < S_count[index]:
            max = S_count[index]
    else:
        S_list.append(s)
        S_count.append(1)
        #if max < S_count[i]:
        #    max = S_count[i]
     
#print(S_list)
#print(S_count)
#print(max)
S_max = []
for j in range(len(S_list)):
    if S_count[j] == max:
        S_max.append(S_list[j])

S_max.sort()
for k in range(len(S_max)):
    print(S_max[k])

Fixed submission:


N=int(input())

S_list = []
S_count = []
max = 1
temp_list = []
#for i in range(N):
#    s = input()
#    temp_list.append(s)
S_dict = {}
for i in range(N):
    s = input()
    if s in S_dict.keys():
        S_dict[s] += 1
        if max < S_dict[s]:
            max = S_dict[s]
    else:
        S_dict[s] = 1
    
     
#print(S_list)
#print(S_count)
#print(max)
S_max = []
for j in S_dict:
    if S_dict[j] == max:
        S_max.append(j)

S_max.sort()
for k in range(len(S_max)):
    print(S_max[k])

Buggy python submission (verdict: Time Limit Exceeded):


N=int(input())

S_list = []
S_count = []
max = 1
for i in range(N):
    s = input()
    if s in S_list:
        index = S_list.index(s)
        #S_count.append(S_count[index]+1)
        S_count[index] += 1
        if max < S_count[index]:
            max = S_count[index]
    else:
        S_list.append(s)
        S_count.append(1)
        #if max < S_count[i]:
        #    max = S_count[i]
     
#print(S_list)
#print(S_count)
#print(max)
S_max = []
for j in range(len(S_list)):
    if S_count[j] == max:
        S_max.append(S_list[j])

S_max.sort()
for k in range(len(S_max)):
    print(S_max[k])

Fixed submission:


N=int(input())

S_list = []
S_count = []
max = 1
temp_list = []
#for i in range(N):
#    s = input()
#    temp_list.append(s)
S_dict = {}
for i in range(N):
    s = input()
    if s in S_dict.keys():
        S_dict[s] += 1
        if max < S_dict[s]:
            max = S_dict[s]
    else:
        S_dict[s] = 1
    
     
#print(S_list)
#print(S_count)
#print(max)
S_max = []
for j in S_dict:
    if S_dict[j] == max:
        S_max.append(j)

S_max.sort()
for k in range(len(S_max)):
    print(S_max[k])