Problem: We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it.  Print all strings that are written on the most number of votes, in lexicographical order.

Submission attempts (in order):
N = int(input())
list_S = [input() for i in range(N) ]
list_S.sort()
list_a = []
a = 0
while a < N :
    list_a.append(list_S.count(list_S[a]))
    a += list_S.count(list_S[a])
newlist_a = sorted(list_a,reverse=True)
n = newlist_a.count(newlist_a[0])
ans = ""
if n == 1:
    t = 0
    for i in range(list_a.index(newlist_a[0])):
        t += list_a[i]
    ans = list_S[t+1]
else:
    if newlist_a[0]==1:
        for i in range(len(list_S)):
            ans += list_S[i]
            ans += "\n"
    else:            
        list_t = []
        for i,x in enumerate(list_a):
            if x == newlist_a[0]:
                list_t.append(sum(list_a[0:i]))
                ans += list_S[list_t[i-1]]
                ans += "\n"
print(ans)


N = int(input())
list_S = [input() for i in range(N)]
list_S.sort()
list_a = []
a = 0
for i in range(N-1):
    if list_S[i] == list_S[i+1]:
        a += 1
    else:
        list_a.append(a+1)
        a = 0
list_a.append(a+1)
newlist_a = sorted(list_a,reverse=True)
n = newlist_a.count(newlist_a[0])
ans = ""
if n == 1:
    t = 0
    for i in range(list_a.index(newlist_a[0])):
        t += list_a[i]
    if N == 1:
        ans = list_S[t]
    else:
        ans = list_S[t+1]
else:
    if newlist_a[0]==1:
        for i in range(len(list_S)):
            ans += list_S[i]
            ans += "\n"
    else:            
        list_t = []
        b = 0
        for i,x in enumerate(list_a):
            if x == newlist_a[0]:
                list_t.append(sum(list_a[0:i]))
                ans += list_S[list_t[b]]
                ans += "\n"
                b += 1
print(ans)

N = int(input())
list_S = [input() for i in range(N) ]
list_S.sort()

list_a = []
a = 0
for i in range(N-1):
    if list_S[i] == list_S[i+1]:
        a += 1
    else:
        list_a.append(a)
        a = 0
list_a.append(a)

newlist_a = sorted(list_a,reverse=True)

n = newlist_a.count(newlist_a[0])
list_ans = []
if n == 1:
    t = list_a.index(newlist_a[0])
    m = 0
    for i in range(t):
        m += list_a[i]
    list_ans.append(list_S[m+t])
else:
    list_t = []
    list_t.append(list_a.index(newlist_a[0]))
    for i in range(newlist_a.count(newlist_a[0])-1):
        list_a.remove(newlist_a[i])
        list_t.append(list_a.index(newlist_a[i])+1)

    for i in range(len(list_t)):
        m = 0
        for j in range(list_t[i]):
            m += list_a[j]
        list_ans.append(list_S[m+list_t[i]])
list_ans.sort()
print(list_ans)

N = int(input())
list_S = [input() for i in range(N) ]
list_S.sort()
list_a = []
a = 0
for i in range(N-1):
    if list_S[i] == list_S[i+1]:
        a += 1
    else:
        list_a.append(a+1)
        a = 0
list_a.append(a+1)
newlist_a = sorted(list_a,reverse=True)
n = newlist_a.count(newlist_a[0])
ans = ""
if n == 1:
    t = 0
    for i in range(list_a.index(newlist_a[0])):
        t += list_a[i]
    if N == 1:
        ans = list_S[t]
    else:
        ans = list_S[t+1]
else:
    if newlist_a[0]==1:
        for i in range(len(list_S)):
            ans += list_S[i]
            ans += "\n"
    else:            
        list_t = []
        for i,x in enumerate(list_a):
            if x == newlist_a[0]:
                list_t.append(sum(list_a[0:i]))
                ans += list_S[list_t[i-1]]
                ans += "\n"
print(ans)

N = int(input())
list_S = [input() for i in range(N)]
list_S.sort()
list_a = []
a = 0
for i in range(N-1):
    if list_S[i] == list_S[i+1]:
        a += 1
    else:
        list_a.append(a+1)
        a = 0
list_a.append(a+1)
newlist_a = sorted(list_a,reverse=True)
A = newlist_a[0]
n = newlist_a.count(A)
ans = ""
if n == 1:
    t = 0
    for i in range(list_a.index(A)):
        t += list_a[i]
    if N == 1:
        ans = list_S[t]
    else:
        ans = list_S[t+1]
else:
    if A==1:
        for i in range(len(list_S)):
            ans += list_S[i]
            ans += "\n"
    else:            
        list_t = []
        b = 0
        for i,x in enumerate(list_a):
            if x == A:
                list_t.append(sum(list_a[0:i]))
                ans += list_S[list_t[b]]
                ans += "\n"
                b += 1
print(ans)

N = int(input())
list_S = [input() for i in range(N) ]
list_S.sort()
list_a = []
a = 0
for i in range(N-1):
    if list_S[i] == list_S[i+1]:
        a += 1
    else:
        list_a.append(a+1)
        a = 0
list_a.append(a+1)
newlist_a = sorted(list_a,reverse=True)
n = newlist_a.count(newlist_a[0])

list_ans = []
if n == 1:
    t = list_a.index(newlist_a[0])
    m = 0
    for i in range(t):
        m += list_a[i]
    list_ans.append(list_S[m+t])
else:
    list_A = []
    for i in range(len(list_a)):
        list_A.append(list_a[i])
    list_t = []
    list_t.append(list_A.index(newlist_a[0]))
    for i in range(newlist_a.count(newlist_a[0])-1):
        list_A.remove(newlist_a[i])
        list_t.append(list_A.index(newlist_a[i])+i+1)
        
    for i in range(len(list_t)):
        m = 0
        for j in range(list_t[i]):
            m += list_a[j]
        if newlist_a[0]==1:
            list_ans.append(list_S[m])
        else:
            list_ans.append(list_S[m+list_t[i]])
list_ans.sort()
ans = ""
for i in range(len(list_ans)):
    ans += list_ans[i]
    ans += "\n"
print(ans)


N = int(input())
list_S = [input() for i in range(N) ]
list_S.sort()
list_a = []
a = 0
while a < N :
    list_a.append(list_S.count(list_S[a]))
    a += list_S.count(list_S[a])
newlist_a = sorted(list_a,reverse=True)
n = newlist_a.count(newlist_a[0])
ans = ""
if n == 1:
    t = 0
    for i in range(list_a.index(newlist_a[0])):
        t += list_a[i]
    ans = list_S[t+1]
else:
    if newlist_a[0]==1:
        for i in range(len(list_S)):
            ans += list_S[i]
            ans += "\n"
    else:            
        list_t = []
        for i,x in enumerate(list_a):
            if x == newlist_a[0]:
                list_t.append(sum(list_a[0:i]))
        for i in range(len(list_t)):
            ans += list_S[list_t[i]]
            ans += "\n"
print(ans)

N = int(input())
list_S = [input() for i in range(N) ]
list_S.sort()
list_a = []
a = 0
for i in range(N-1):
    if list_S[i] == list_S[i+1]:
        a += 1
    else:
        list_a.append(a)
        a = 0
list_a.append(a)
newlist_a = sorted(list_a,reverse=True)
n = newlist_a.count(newlist_a[0])
list_ans = []
if n == 1:
    t = list_a.index(newlist_a[0])
    m = 0
    for i in range(t):
        m += list_a[i]
    list_ans.append(list_S[m+t])
else:
    list_A = []
    for i in range(len(list_a)):
        list_A.append(list_a[i])
    list_t = []
    list_t.append(list_A.index(newlist_a[0]))
    for i in range(newlist_a.count(newlist_a[0])-1):
        list_A.remove(newlist_a[i])
        list_t.append(list_A.index(newlist_a[i])+i+1)
        
    for i in range(len(list_t)):
        m = 0
        for j in range(list_t[i]):
            m += list_a[j]
        if newlist_a[0]==1:
            list_ans.append(list_S[m])
        else:
            list_ans.append(list_S[m+list_t[i]])
list_ans.sort()
print(list_ans)


import copy

N = int(input())
list_S = [input() for i in range(N) ]
list_S.sort()
list_a = []
a = 0
for i in range(N-1):
    if list_S[i] == list_S[i+1]:
        a += 1
    else:
        list_a.append(a+1)
        a = 0
list_a.append(a+1)
newlist_a = sorted(list_a,reverse=True)
n = newlist_a.count(newlist_a[0])
ans = ""
if n == 1:
    t = list_a.index(newlist_a[0])
    m = 0
    for i in range(t):
        m += list_a[i]
    ans +=list_S[m+t]
else:
    if newlist_a[0]==1:
        for i in range(len(list_S)):
            ans += list_S[i]
            ans += "\n"
    else:            
        list_A = copy.copy(list_a)
        list_t = []
        list_t.append(list_A.index(newlist_a[0]))
        for i in range(n-1):
            list_A.remove(newlist_a[i])
            m = 0
            for j in range(list_A.index(newlist_a[i])+i+1):
                m += list_a[j]
            list_t.append(m)
        for i in range(len(list_t)):
            ans += list_S[list_t[i]]
            ans += "\n"
print(ans)


N = int(input())
list_S = [input() for i in range(N) ]
list_S.sort()

list_a = []
a = 1
for i in range(N-1):
    if list_S[i] == list_S[i+1]:
        a += 1
    else:
        list_a.append(a)
        a = 1
list_a.append(a)


newlist_a = sorted(list_a,reverse=True)


n = newlist_a.count(newlist_a[0])

list_ans = []
if n == 1:

    t = list_a.index(newlist_a[0])

    m = 0
    for i in range(t):
        m += list_a[i]
    list_ans.append(list_S[m+t])
else:

    list_A = []
    for i in range(len(list_a)):
        list_A.append(list_a[i])
    list_t = []
    list_t.append(list_A.index(newlist_a[0]))
    for i in range(newlist_a.count(newlist_a[0])-1):
        list_A.remove(newlist_a[i])
        list_t.append(list_A.index(newlist_a[i])+i+1)
        
    for i in range(len(list_t)):
        m = 0
        for j in range(list_t[i]):
            m += list_a[j]
        if newlist_a[0]==1:
            list_ans.append(list_S[m])
        else:
            list_ans.append(list_S[m+list_t[i]])
list_ans.sort()
print(list_ans)


N = int(input())
list_S = [input() for i in range(N) ]
list_S.sort()
print(list_S)


list_a = []
a = 0
for i in range(N-1):
    if list_S[i] == list_S[i+1]:
        a += 1
    else:
        list_a.append(a)
        a = 0
list_a.append(a)



newlist_a = sorted(list_a,reverse=True)

n = newlist_a.count(newlist_a[0])
list_ans = []
if n == 1:

    t = list_a.index(newlist_a[0])

    m = 0
    for i in range(t):
        m += list_a[i]
    list_ans.append(list_S[m+t])
else:

    list_t = []
    list_t.append(list_a.index(newlist_a[0]))
    for i in range(newlist_a.count(newlist_a[0])-1):
        list_a.remove(newlist_a[i])
        list_t.append(list_a.index(newlist_a[i])+1)

    for i in range(len(list_t)):
        m = 0
        for j in range(list_t[i]):
            m += list_a[j]
        list_ans.append(list_S[m+list_t[i]])
list_ans.sort()
print(list_ans)

N = int(input())
list_S = [input() for i in range(N) ]
list_S.sort()
list_a = []
a = 0
for i in range(N-1):
    if list_S[i] == list_S[i+1]:
        a += 1
    else:
        list_a.append(a)
        a = 0
list_a.append(a)
newlist_a = sorted(list_a,reverse=True)
n = newlist_a.count(newlist_a[0])
list_ans = []
if n == 1:
    t = list_a.index(newlist_a[0])
    m = 0
    for i in range(t):
        m += list_a[i]
    list_ans.append(list_S[m+t])
else:
    list_A = []
    for i in range(len(list_a)):
        list_A.append(list_a[i])
    list_t = []
    list_t.append(list_A.index(newlist_a[0]))
    for i in range(newlist_a.count(newlist_a[0])-1):
        list_A.remove(newlist_a[i])
        list_t.append(list_A.index(newlist_a[i])+i+1)
    for i in range(len(list_t)):
        m = 0
        for j in range(list_t[i]):
            m += list_a[j]
        if newlist_a[0]==0:
            list_ans.append(list_S[m])
        else:
            list_ans.append(list_S[m+list_t[i]])
list_ans.sort()
print(list_ans)

S = [input() for i in range(N) ]
list_S.sort()
list_a = []
a = 0
for i in range(N-1):
    if list_S[i] == list_S[i+1]:
        a += 1
    else:
        list_a.append(a+1)
        a = 0
list_a.append(a+1)
newlist_a = sorted(list_a,reverse=True)
n = newlist_a.count(newlist_a[0])
ans = ""
if n == 1:
    t = 0
    for i in range(list_a.index(newlist_a[0])):
        t += list_a[i]
    if N == 1:
        ans = list_S[t]
    else:
        ans = list_S[t+1]
else:
    if newlist_a[0]==1:
        for i in range(len(list_S)):
            ans += list_S[i]
            ans += "\n"
    else:            
        list_t = []
        a = 0
        for i,x in enumerate(list_a):
            if x == newlist_a[0]:
                list_t.append(sum(list_a[0:i]))
                ans += list_S[list_t[a]]
                ans += "\n"
                a += 1
print(ans)


N = int(input())
list_S = [input() for i in range(N) ]
list_S.sort()
list_a = []
a = 0
for i in range(N-1):
    if list_S[i] == list_S[i+1]:
        a += 1
    else:
        list_a.append(a+1)
        a = 0
list_a.append(a+1)
newlist_a = sorted(list_a,reverse=True)
n = newlist_a.count(newlist_a[0])
ans = ""
if n == 1:
    t = 0
    for i in range(list_a.index(newlist_a[0])):
        t += list_a[i]
    if N == 1:
        ans = list_S[t]
    else:
        ans = list_S[t+1]
else:
    if newlist_a[0]==1:
        for i in range(len(list_S)):
            ans += list_S[i]
            ans += "\n"
    else:            
        list_t = []
        for i,x in enumerate(list_a):
            if x == newlist_a[0]:
                list_t.append(sum(list_a[0:i]))
                ans += list_S[list_t[i]]
                ans += "\n"
print(ans)

N = int(input())
list_S = [input() for i in range(N) ]
list_S.sort()
list_a = []
a = 0
while a < N :
    list_a.append(list_S.count(list_S[a]))
    a += list_S.count(list_S[a])
newlist_a = sorted(list_a,reverse=True)
n = newlist_a.count(newlist_a[0])
ans = ""
if n == 1:
    t = 0
    for i in range(list_a.index(newlist_a[0])):
        t += list_a[i]
    ans = list_S[t+1]
else:
    if newlist_a[0]==1:
        for i in range(len(list_S)):
            ans += list_S[i]
            ans += "\n"
    else:            
        list_t = []
        for i in range(n):
            b = list_a.index(newlist_a[0],i)
            m = 0
            for j in range(b):
                m += list_a[j]
            list_t.append(m)
        for i in range(len(list_t)):
            ans += list_S[list_t[i]]
            ans += "\n"
print(ans)


N = int(input())
list_S = [input() for i in range(N) ]
list_S.sort()
list_a = []
a = 0
while a < N :
    list_a.append(list_S.count(list_S[a]))
    a += list_S.count(list_S[a])
newlist_a = sorted(list_a,reverse=True)
n = newlist_a.count(newlist_a[0])

ans = ""
if n == 1:
    t = list_a.index(newlist_a[0])
    m = 0
    for i in range(t):
        m += list_a[i]
    ans +=list_S[m+t]
else:
    if newlist_a[0]==1:
        for i in range(len(list_S)):
            ans += list_S[i]
            ans += "\n"
    else:            
        list_A = []
        for i in range(len(list_a)):
            list_A.append(list_a[i])
        list_t = []
        list_t.append(list_A.index(newlist_a[0]))
        for i in range(n-1):
            list_A.remove(newlist_a[i])
            m = 0
            for j in range(list_A.index(newlist_a[i])+i+1):
                m += list_a[j]
            list_t.append(m)
        for i in range(len(list_t)):
            ans += list_S[list_t[i]]
            ans += "\n"
print(ans)


N = int(input())
list_S = [input() for i in range(N) ]

list_S.sort()

list_a = []
a = 0
while a < N :
    list_a.append(list_S.count(list_S[a]))
    a += list_S.count(list_S[a])

newlist_a = sorted(list_a,reverse=True)

n = newlist_a.count(newlist_a[0])
ans = ""

if n == 1:
    t = 0
    for i in range(list_a.index(newlist_a[0])):
        t += list_a[i]
    ans = list_S[t+1]
else:

    if newlist_a[0]==1:
        for i in range(len(list_S)):
            ans += list_S[i]+"\n"
    else:            

        list_t = []
        for i in range(n):
            m = 0
            for j in range(list_a.index(newlist_a[0],i+1)):       
                m += list_a[j]
            list_t.append(m)
        for i in range(len(list_t)):
            ans += list_S[list_t[i]]+"\n"
print(ans)


N = int(input())
list_S = [input() for i in range(N) ]
list_S.sort()
print(list_S)
list_a = []
a = 0
for i in range(N-1):
    if list_S[i] == list_S[i+1]:
        a += 1
    else:
        list_a.append(a)
        a = 0
list_a.append(a)
newlist_a = sorted(list_a,reverse=True)
n = newlist_a.count(newlist_a[0])
list_ans = []
if n == 1:
    t = list_a.index(newlist_a[0])
    m = 0
    for i in range(t):
        m += list_a[i]
    list_ans.append(list_S[m+t])
else:
    list_A = []
    for i in range(len(list_a)):
        list_A.append(list_a[i])
    list_t = []
    list_t.append(list_A.index(newlist_a[0]))
    for i in range(newlist_a.count(newlist_a[0])-1):
        list_A.remove(newlist_a[i])
        list_t.append(list_A.index(newlist_a[i])+i+1)      
    for i in range(len(list_t)):
        m = 0
        for j in range(list_t[i]):
            m += list_a[j]
        if newlist_a[0]==0:
            list_ans.append(list_S[m])
        else:
            list_ans.append(list_S[m+list_t[i]])
list_ans.sort()
print(list_ans)


N = int(input())
list_S = [input() for i in range(N) ]
list_S.sort()
list_a = []
a = 0
for i in range(N-1):
    if list_S[i] == list_S[i+1]:
        a += 1
    else:
        list_a.append(a+1)
        a = 0
list_a.append(a+1)
newlist_a = sorted(list_a,reverse=True)
n = newlist_a.count(newlist_a[0])

ans = ""
if n == 1:
    t = list_a.index(newlist_a[0])
    m = 0
    for i in range(t):
        m += list_a[i]
    ans +=list_S[m+t]
else:
    if newlist_a[0]==1:
        for i in range(len(list_S)):
            ans += list_S[i]
            ans += "\n"
    else:            
        list_A = []
        for i in range(len(list_a)):
            list_A.append(list_a[i])
        list_t = []
        list_t.append(list_A.index(newlist_a[0]))
        for i in range(n-1):
            list_A.remove(newlist_a[i])
            m = 0
            for j in range(list_A.index(newlist_a[i])+i+1):
                m += list_a[j]
            list_t.append(m)
        for i in range(len(list_t)):
            ans += list_S[list_t[i]]
            ans += "\n"
print(ans)


import collections

N = int(input())
S = [input() for i in range(N)]
c =collections.Counter(S)
C = c.most_common()
list_C = []
for i in range(len(c)):
    list_C.append(C[i][1])
m = 1
for i in range(len(list_C)-1):
    if list_C[i]==list_C[i+1]:
        m += 1
    else:
        break
ans= []
for i in range(m):
    ans.append(C[i][0])
ans = sorted(ans)
for i in range(len(ans)):
    print(ans[i])

Verdicts: Runtime Error

Time Limit Exceeded

Wrong Answer

Runtime Error

Time Limit Exceeded

Runtime Error

Time Limit Exceeded

Wrong Answer

Time Limit Exceeded

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Time Limit Exceeded

Wrong Answer

Wrong Answer

Time Limit Exceeded

Accepted