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())

S = list(str(input()) for i in range(n))
SortedS = sorted(S) 
s = [] 
S2 = [] 
count = 1
for i in range(n - 1):
    if i == n - 2 and SortedS[i] != SortedS[i + 1]:
        s.append(count)
        s.append(1)
        S2.append(SortedS[i])
        S2.append(SortedS[i + 1])
    
    else:
        if SortedS[i] == SortedS[i + 1]:
            count += 1
            if i == n - 2:
                s.append(count)
                S2.append(SortedS[i])
        else:
            s.append(count)
            S2.append(SortedS[i])
            count = 1
ans = []
M = max(s)
for i in range(len(s)):
    if s[i] == M:
        print(ans[i])

n = int(input())

S = list(str(input()) for i in range(n))
SortedS = sorted(S) 
s = [] 
S2 = [] 
count = 1
for i in range(n - 1):
    if i == n - 2:
        if SortedS[i] != SortedS[i + 1]:
            s.append(count)
            s.append(1)
            S2.append(SortedS[i])
            S2.append(SortedS[i + 1])
        else:
            s.append(count)
            S2.append(SortedS[i])
    
    else:
        if SortedS[i] == SortedS[i + 1]:
            count += 1
        else:
            s.append(count)
            S2.append(SortedS[i])
            count = 1

M = max(s)
for i in range(len(s)):
    if s[i] == M:
        print(S2[i])

n = int(input())

S = list(str(input()) for i in range(n))
SortedS = sorted(S) 
s = [] 
S2 = [] 
count = 1
for i in range(n - 1):
    if i == n - 2 and SortedS[i] != SortedS[i + 1]:
        s.append(count)
        s.append(1)
        S2.append(SortedS[i])
        S2.append(SortedS[i + 1])
    
    else:
        if SortedS[i] == SortedS[i + 1]:
            count += 1
            if i == n - 2:
                s.append(count)
                S2.append(SortedS[i])
        else:
            s.append(count)
            S2.append(SortedS[i])
            count = 1

M = max(s)
for i in range(len(s)):
    if s[i] == M:
        print(s[i])

n = int(input())

S = list(str(input()) for i in range(n))
SortedS = sorted(S) 
s = [] 
S2 = [] 
count = 1
for i in range(n - 1):
    if i == n - 2 and SortedS[i] != SortedS[i + 1]:
        s.append(count)
        s.append(1)
        S2.append(SortedS[i])
        S2.append(SortedS[i + 1])
    
    else:
        if SortedS[i] == SortedS[i + 1]:
            count += 1
            if i == n - 2:
                s.append(count)
                S2.append(SortedS[i])
        else:
            s.append(count)
            S2.append(SortedS[i])
            count = 1
ans = []
M = max(s)
for i in range(len(s)):
    if s[i] == M:
        ans.append(S2[i])
print(ans)

n = int(input())

S = list(str(input()) for i in range(n))
SortedS = sorted(S) 
s = [] 
S2 = [] 
count = 1
for i in range(n - 1):
    if i == n - 2 and SortedS[i] != SortedS[i + 1]:
        s.append(count)
        s.append(1)
        S2.append(SortedS[i])
        S2.append(SortedS[i + 1])
    
    else:
        if SortedS[i] == SortedS[i + 1]:
            count += 1
            if i == n - 2:
                s.append(count)
                S2.append(SortedS[i])
        else:
            s.append(count)
            S2.append(SortedS[i])
            count = 1

M = max(s)
for i in range(len(s)):
    if s[i] == M:
        print(S2[i])

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Accepted