qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import collections
import itertools

a = int(input())

s = [input() for i in range(a)]

counter = collections.Counter(s)

mode_v = counter.most_common()[0][-1]
it = itertools.takewhile(
    lambda kv: kv[-1] == mode_v, counter.most_common()
)

l = []

for k, v in it:
  l.append(k)

print(sorted(l))  
  

Fixed code:
import collections
import itertools

a = int(input())

s = [input() for i in range(a)]

counter = collections.Counter(s)

mode_v = counter.most_common()[0][-1]
it = itertools.takewhile(
    lambda kv: kv[-1] == mode_v, counter.most_common()
)

l = []

for k, v in it:
  l.append(k)

l = sorted(l)
  
for i in l:
  print(i)
Buggy code:
n = int(input())
s = [0 for i in range(n)]
dics = {}
for i in range(n):
    try:
        s = input()
        a = dics[s]
        dics[s] += 1
    except KeyError:
        dics[s] = 1
max_v = max(dics.values())
max_k_list = [kv[0] for kv in dics.items() if kv[1] == max(dics.values())]
for i in max_k_list:
    print(i)

Fixed code:
n = int(input())
dics = {}
for i in range(n):
    try:
        s = input()
        dics[s] += 1
    except KeyError:
        dics[s] = 1
max_v = max(dics.values())

max_k_list = [kv[0] for kv in dics.items() if kv[1] == max_v]
max_k_list.sort()
for i in max_k_list:
    print(i)
Buggy code:
N = int(input())
S = [0]*N
for i in range(N):
    S[i] = input()
A = {}
for s in S:
    if s not in A:
        A[s] = 1
    else:
        A[s] += 1

B = [(a, A[a]) for a in A]
# print(B)
B.sort(reverse=True, key=lambda x: x[1])
# print(B)
count = B[0][1]
for b in B:
    if b[1] == count:
        print(b[0])


Fixed code:
N = int(input())
S = [0]*N
for i in range(N):
    S[i] = input()
A = {}
for s in S:
    if s not in A:
        A[s] = 1
    else:
        A[s] += 1

B = [(a, A[a]) for a in A]
# print(B)
B.sort(reverse=True, key=lambda x: x[1])
# print(B)
count = B[0][1]
ans = []
for b in B:
    if b[1] == count:
        ans.append(b[0])

ans.sort()
for a in ans:
    print(a)
Buggy code:
n = int(input()
s = dict()
for i in range(n):
    si = input()
    if si in s:
        s[si] +=1
    else:
        s[si] = 0
l = max(s.values())
ans = []
for i in s:
    if s[i] == 1:
        ans.append(i)
ans.sort()
for i in ans:
    print(i)

Fixed code:
n = int(input())
s = dict()
for i in range(n):
    si = input()
    if si in s:
        s[si] +=1
    else:
        s[si] = 0
l = max(s.values())
ans = []
for i in s:
    if s[i] ==l:
        ans.append(i)
ans.sort()
for i in ans:
    print(i)
Buggy code:
import collections
N = int(input())
S = {}
for i in range(N):
    value = input()
    if value not in S:
        S[value] = 1
    else:
        S[value] += 1
S_largest = max(S.values())
S_sorted = sorted(S.items(),reverse=True)
print(S_sorted)
ans = []
for i in range(len(S_sorted)):
    if S_sorted[i][1] == S_largest:
        ans.append(S_sorted[i][0])
    else:
        break
ans_sorted = sorted(ans)
for a in ans_sorted:
    print(a)


Fixed code:
import collections
N = int(input())
S = {}
for i in range(N):
    value = input()
    if value not in S:
        S[value] = 1
    else:
        S[value] += 1
S_largest = max(S.values())
S_sorted = sorted(S.items(), key=lambda x:x[1], reverse=True)
ans = []
for i in range(len(S_sorted)):
    if S_sorted[i][1] == S_largest:
        ans.append(S_sorted[i][0])
    else:
        break
ans_sorted = sorted(ans)
for a in ans_sorted:
    print(a)
Buggy code:
n = int(input())
s = [input() for _ in range(n)]
dic = {}
for i in range(n):
  if s[i] not in dic:
    dic[s[i]] = 1
    else:
      dic[s[i]] += 1
max_dic_val = max(dic.values()) 
ans = []
for keys in dic.keys():
  if dic[keys] == max_dic_val: 
    ans.append(keys)
ans = sorted(ans)
for words in ans:
  print(words)

Fixed code:
n=int(input())
s=[input() for _ in range(n)]
dic={}
for i in range(n):
  if s[i] not in dic:
    dic[s[i]]=1
  else:
    dic[s[i]]+=1
largest=max(dic.values())
ans=[]
for keys in dic.keys():
  if dic[keys]==largest:
    ans.append(keys)
ans=sorted(ans)
for words in ans:
  print(words)
Buggy code:
import collections

def main():
    n = int(input())

    s_list = []

    for i in range(n):
        s = str(input())
        s_list.append(s)

    c = collections.Counter(s_list)
    c_list = c.most_common()

    print_count = len(c_list)
    for j in range(len(c_list)-1):
        if c_list[j+1][1] < c_list[j][1]:
            print_count = j+1
            break
    
    for k in range(print_count):
        print(c_list[k][0])
    

if __name__ == '__main__':
    main()



Fixed code:
import collections

def main():
    n = int(input())

    s_list = []

    for i in range(n):
        s = str(input())
        s_list.append(s)

    c = collections.Counter(s_list)
    c_list = c.most_common()

    print_count = len(c_list)
    new_list = []

    for j in range(len(c_list)):
        new_list.append(c_list[j][0])
        if j != len(c_list)-1:
            if c_list[j+1][1] < c_list[j][1]:
                print_count = j+1
                break
    
    sorted_list = sorted(new_list)
    for k in sorted_list:
        print(k)
    

if __name__ == '__main__':
    main()
Buggy code:
import collections
N = int(input())
List=[input() for i in range(N)]

c = collections.Counter(List)
c_sorted = sorted(c.items(), key=lambda x:x[1],reverse=True)

maxCount = c_sorted[0][1]
keys = [k for k, v in c.items() if v ==maxCount]
for s in keys:
    print(s)

Fixed code:
import collections
N = int(input())
List=[input() for i in range(N)]
 
c = collections.Counter(List)
c_sorted = sorted(c.items(), key=lambda x:x[1],reverse=True)
 
maxCount = c_sorted[0][1]
keys = [k for k, v in c.items() if v ==maxCount]
keys.sort()
for s in keys:
    print(s)
Buggy code:
from collections import defaultdict

N = int(input())
S_dic = defaultdict(int)

for i in range(N):
  S = input()
  S_dic[S] += 1

m = max(S_dic.values())
max_S = [i[0] for i in S_dic.items() if i[1] == m ]
print("\n".join(max_S))

Fixed code:
from collections import defaultdict

N = int(input())
S_dic = defaultdict(int)

for i in range(N):
  S = input()
  S_dic[S] += 1

m = max(S_dic.values())
max_S = [i[0] for i in S_dic.items() if i[1] == m ]
max_S.sort()
print("\n".join(max_S))
Buggy code:
from collections import Counter
N = int(input())
data = [0] * N


for i in range(0, N):
    data[i] = input()

count = Counter(data)
#count = sorted(count, key=lambda x: x[0])
#count = sorted(count)
most = count.most_common()
mostNum = most[0][1]
print(count)    # counter_object
print(most)     # list;[(val,num),(val,num),/////]
print(mostNum)  # number of most

most.sort()

for i in most:
    if (i[1] == mostNum):
        print(i[0])


Fixed code:
from collections import Counter
N = int(input())
data = [0] * N


for i in range(0, N):
    data[i] = input()

count = Counter(data)
#count = sorted(count, key=lambda x: x[0])
#count = sorted(count)
most = count.most_common()
mostNum = most[0][1]
'''
print(count)    # counter_object
print(most)     # list;[(val,num),(val,num),/////]
print(mostNum)  # number of most
'''
most.sort()

for i in most:
    if (i[1] == mostNum):
        print(i[0])
Buggy code:
def main():
    from collections import Counter
    import sys
    input = sys.stdin.readline
    n=int(input())
    s=[]
    for _ in []*n:
        s.append(input().rstrip())
    c = Counter(s)
    ans=[]
    max_vote = max(c.values())
    for i,j in c.items():
        if j == max_vote:
            ans.append(i)
    print("\n".join(sorted(ans)))
main()

Fixed code:
from collections import Counter
import sys
input = sys.stdin.readline
n=int(input())
s=[]
for _ in range(n):
    s.append(input().rstrip())
c = Counter(s)
ans=[]
max_vote = max(c.values())
for i,j in c.items():
    if j == max_vote:
        ans.append(i)
print("\n".join(sorted(ans)))
Buggy code:
from collections import defaultdict
n = int(input())

d = defaultdict(int)
for _ in range(n):
    key = input()
    d[key] += 1

dict = sorted(d.items(), key=lambda x:x[1], reverse=True)
max_v = max(d.values())

dict_li = []
for a in dict:
    if a[1]==max_v:
        dict_li.append(a[0])
    else:
        exit()

dict_li.sort()
for s in dict_li:
    print(s)


Fixed code:
from collections import defaultdict
n = int(input())

d = defaultdict(int)
for _ in range(n):
    key = input()
    d[key] += 1

dict = sorted(d.items(), key=lambda x:x[1], reverse=True)
max_v = max(d.values())

dict_li = []
for a in dict:
    if a[1]==max_v:
        dict_li.append(a[0])

dict_li.sort()
for s in dict_li:
    print(s)
Buggy code:
import collections
a = int(input())
line = [input() for k in range(a)]

c = collections.Counter(line)

max_number = max(c.values())
common = c.most_common()

max_common = []
for k in range(a):
  if common[k][1] == max_number:
    max_common.append(common[k][0])
  else:
    break
for k in sorted(max_common):
  print(k)

Fixed code:
import collections
a = int(input())
line = [input() for k in range(a)]
c = collections.Counter(line)
common = c.most_common()
max_number = common[0][1]
a = len(common)
max_common = []
for k in range(a):
  if common[k][1] == max_number:
    max_common.append(common[k][0])
  else:
    break
for k in sorted(max_common):
  print(k)
Buggy code:
from collections import Counter

n = int(input())

s = [input() for _ in range(n)]

c = Counter(s)

csort = sorted(c.items(), key=lambda x:x[1],reverse=True)

maxc = csort[0][1]

for s,v in csort:
    if v == maxc:
        print(s)

Fixed code:
from collections import Counter

n = int(input())

s = [input() for _ in range(n)]

c = Counter(s)

csort = sorted(c.items(), key=lambda x:x[1],reverse=True)

maxc = csort[0][1]
ans = []
for s,v in csort:
    if v == maxc:
        ans.append(s)
        
anssort = sorted(ans)

for s in anssort:
    print(s)
Buggy code:
def main():
	# n,m = map(int,input().split())
	n = int(input())
	l = [str(input()) for i in range(n)]
	
	import collections

	c = collections.Counter(l)
	lc = sorted(list(c.items()), key = lambda x:x[1] , reverse = True)
	# print(lc)
	ans = []
	checker = 0
	i = 0
	while checker == 0:
		if lc[i][1] == lc[0][1]:
			ans.append(lc[i][0])
		else:
			checker += 1
		i += 1

	# keys = [k for k, v in c.items() if v == max(c.values())]
	# print(list(c.items())[0][0])
	# checker = 0
	# while checker == 0:
	# 	if c.items() == max(c.values()):
	ans.sort()
	print('\n'.join(map(str, ans)))

	
	
 
if __name__ == '__main__':
	main()

Fixed code:
def main():
	# n,m = map(int,input().split())
	n = int(input())
	l = [str(input()) for i in range(n)]
	
	import collections

	c = collections.Counter(l)
	lc = sorted(list(c.items()), key = lambda x:x[1] , reverse = True)
	# print(lc[0][0])
	ans = []
	checker = 0
	i = 0
	while checker == 0 and i < len(lc):
		if lc[i][1] == lc[0][1]:
			ans.append(lc[i][0])
		else:
			checker += 1
		i += 1

	# keys = [k for k, v in c.items() if v == max(c.values())]
	# print(list(c.items())[0][0])
	# checker = 0
	# while checker == 0:
	# 	if c.items() == max(c.values()):
	ans.sort()
	print('\n'.join(map(str, ans)))

	
	
 
if __name__ == '__main__':
	main()
Buggy code:
i = int(input())

dic = {}
for j in range(i):
    word = input()
    if word in dic:
        dic[word] += 1
    else:
        dic[word] = 1


dic2 = sorted(dic.items(), key=lambda x:x[1])
print(dic2)
k = len(dic2)-1
s = 0
ans = []
for p in range(len(dic2)):
    t = dic2[k][1]
    ans.append(dic2[k][0])
    k -= 1
    if t == dic2[k][1]:
        s = 1
    else:
        break
ans.sort()
for ak in ans:
    print(ak)

Fixed code:
i = int(input())

dic = {}
for j in range(i):
    word = input()
    if word in dic:
        dic[word] += 1
    else:
        dic[word] = 1


dic2 = sorted(dic.items(), key=lambda x:x[1])
k = len(dic2)-1
s = 0
ans = []
for p in range(len(dic2)):
    t = dic2[k][1]
    ans.append(dic2[k][0])
    k -= 1
    if t == dic2[k][1]:
        s = 1
    else:
        break
ans.sort()
for ak in ans:
    print(ak)
Buggy code:
from collections import Counter
S = []
N = int(input())
for i in range(N):
    s = input()
    S.append(s)

c = collections.Counter(S)
max_num = max(c.values())
max_list = [i for i,j in c.items() if j==max_num]
max_list.sort()
print('\n'.join(max_list))

Fixed code:
from collections import Counter
S = []
N = int(input())
for i in range(N):
    s = input()
    S.append(s)

c = Counter(S)
max_num = max(c.values())
max_list = [i for i,j in c.items() if j==max_num]
max_list.sort()
print('\n'.join(max_list))
Buggy code:
#from math import sqrt
#from heapq import heappush, heappop
#from collections import deque

n = int(input())

l = []
for _ in range(n):
    s = input()
    l.append(s)

l.sort()

max_count = 0
count = 0
results = []
ps = None
for s in l:
    if s == ps or ps is None:
        count += 1
    else:
        if max_count < count:
            max_count = count
            results = [ps]
        elif count == max_count:
            results.append(ps)
        count = 1
    ps = s

if max_count < count:
    max_count = count
    results = [ps]
elif count == max_count:
    results.append(ps)

results.sort()
print("--")
for str in results:
    print(str)


Fixed code:
#from math import sqrt
#from heapq import heappush, heappop
#from collections import deque

n = int(input())

l = []
for _ in range(n):
    s = input()
    l.append(s)

l.sort()

max_count = 0
count = 0
results = []
ps = None
for s in l:
    if s == ps or ps is None:
        count += 1
    else:
        if max_count < count:
            max_count = count
            results = [ps]
        elif count == max_count:
            results.append(ps)
        count = 1
    ps = s

if max_count < count:
    max_count = count
    results = [ps]
elif count == max_count:
    results.append(ps)

results.sort()
for str in results:
    print(str)
Buggy code:
N = int(input())
S = []
for _ in range(N):
    S.append(input())
    
import collections
c = collections.Counter(S)
most = c.most_common()
answerlist = [most[0][0]]
i = 0
while most[i][1] == most[i+1][1]:
    answerlist.append(most[i+1][0])
    i += 1
    if i == len(most)-1:
        break
sortanswer = sorted(answerlist)
for i in range(len(sortanswer)):
    print(sortanswer[i])

Fixed code:
N = int(input())
S = []
for _ in range(N):
    S.append(input())
    
import collections
c = collections.Counter(S)
most = c.most_common()
answerlist = [most[0][0]]
i = 0
if len(most) > 1:
    while most[i][1] == most[i+1][1]:
        answerlist.append(most[i+1][0])
        i += 1
        if i == len(most)-1:
            break
sortanswer = sorted(answerlist)
for i in range(len(sortanswer)):
    print(sortanswer[i])
Buggy code:
def main():
    N = int(input())
    S = [input() for _ in range(N)]
    dict = {}
    for i in range(N):
        if S[i] not in dict:
            dict[S[i]] = 1
        else:
            dict[S[i]] += 1
    ans = {}
    p = 0
    for i ,j in dict.items():
        if p < j : p = j

        if j not in ans:
            ans[j] = [i]
        else:
            ans[j].append(i)
    for i in range(len(ans[p])):
        print(ans[p][i])
if __name__ == '__main__':
    main()


Fixed code:
def main():
    N = int(input())
    S = [input() for _ in range(N)]
    dict = {}
    for i in range(N):
        if S[i] not in dict:
            dict[S[i]] = 1
        else:
            dict[S[i]] += 1
    ans = {}
    p = 0
    for i ,j in dict.items():
        if p < j : p = j

        if j not in ans:
            ans[j] = [i]
        else:
            ans[j].append(i)
    ans[p].sort()
    for i in range(len(ans[p])):
        print(ans[p][i])
if __name__ == '__main__':
    main()
Buggy code:
n = int(input())
s = [input() for i in range(n)]
import collections

counted = collections.Counter(s)

m = max(counted.values())

chars = []
for key, value in counted.items():
    if value == m:
        chars.append(key)

print(sorted(chars))


Fixed code:
n = int(input())
s = [input() for i in range(n)]
import collections

counted = collections.Counter(s)

m = max(counted.values())

chars = []
for key, value in counted.items():
    if value == m:
        chars.append(key)
chars=sorted(chars)

for i in range(len(chars)):
    print(chars[i])
Buggy code:
from collections import defaultdict
dic=defaultdict(int)
n=int(input())
for _ in range(n): dic[input()]+=1
lis=sorted(dic.items(),key=lambda x:x[1],reverse=True)
M=lis[0][1]
ans=[]
for i in range(n):
    if lis[i][1]==M: ans.append(lis[i][0])
    else: break
ans.sort()
for i in ans: print(i)

Fixed code:
from collections import defaultdict
dic=defaultdict(int)
n=int(input())
for _ in range(n): dic[input()]+=1
lis=sorted(dic.items(),key=lambda x:x[1],reverse=True)
M=lis[0][1]
ans=[]
for i in range(len(lis)):
    if lis[i][1]==M: ans.append(lis[i][0])
    else: break
ans.sort()
for i in ans: print(i)
Buggy code:
from sys import stdin
import sys
import math
from functools import reduce
import itertools

n = int(stdin.readline().rstrip())

d = {}

for i in range(n):
    s = stdin.readline().rstrip()

    if s in d:
        d[s] += 1
    else:
        d[s] = 1

d = sorted(d.items(), key=lambda x:x[1], reverse=True)

m = d[0][1]
a = []
for i in range(n):
    if d[i][1] == m:
        a.append(d[i][0])
    else:
        break

a.sort()

for aa in a:
    print(aa)

Fixed code:
from sys import stdin
import sys
import math
from functools import reduce
import itertools

n = int(stdin.readline().rstrip())

d = {}
for i in range(n):
    s = stdin.readline().rstrip()

    if s in d:
        d[s] += 1
    else:
        d[s] = 1

d = sorted(d.items(), key=lambda x:x[1], reverse=True)

m = d[0][1]
a = []
i = 0
for i in range(len(d)):
    if d[i][1] == m:
        a.append(d[i][0])
    else:
        break

a.sort()

for aa in a:
    print(aa)
Buggy code:
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]
Clist = Counter(S).most_common()
num = Clist[0][1]
anses = [Clist[0][0]]
for X in Clist[1:]:
    if X[1] == num:
        anses.append(X[0])

for ans in anses:
    print(ans)

Fixed code:
from collections import Counter

N = int(input())
S = [input() for _ in range(N)]
Clist = Counter(S).most_common()
num = Clist[0][1]
anses = [Clist[0][0]]
for X in Clist[1:]:
    if X[1] == num:
        anses.append(X[0])
anses.sort()
for ans in anses:
    print(ans)
Buggy code:

import collections

rl = sys.stdin.readline

n = int(rl())

li = []
for _ in range(n):
    li.append(rl().rstrip())
c = collections.Counter(li)
max_cnt = 0
li = []
for k, v in c.items():
    if v < max_cnt:
        continue
    elif v == max_cnt:
        li.append(k)
    else:
        max_cnt = v
        li = [k]
li.sort()
print('\n'.join(li))





Fixed code:
import sys
import math
import itertools
import numpy
import collections

rl = sys.stdin.readline

n = int(rl())

li = []
for _ in range(n):
    li.append(rl().rstrip())
c = collections.Counter(li)
max_cnt = 0
li = []
for k, v in c.items():
    if v < max_cnt:
        continue
    elif v == max_cnt:
        li.append(k)
    else:
        max_cnt = v
        li = [k]
li.sort()
print('\n'.join(li))
Buggy code:
n = int(input())
s = [input() for _ in range(n)]

d = {}
m = 0
for x in s:
    if x in d:
        d[x] += 1
        m = max(m, d[x])
    else:
        d[x] = 0

print(sorted({k:v for k, v in d.items() if v == m}.keys()))

Fixed code:
n = int(input())
s = [input() for _ in range(n)]

d = {}
m = 0
for x in s:
    if x in d:
        d[x] += 1
        m = max(m, d[x])
    else:
        d[x] = 0

for x in sorted({k:v for k, v in d.items() if v == m}.keys()):
    print(x)
Buggy code:
import collections

n = int(input())
s = [input() for i in range(n)]

c_sort = collections.Counter(s).most_common()
list_most = [c_sort[i][0] for i in range(len(c_sort)) if c_sort[i][1] == c_sort[0][1]]
for i in list_most:
    print(i)

Fixed code:
import collections

n = int(input())
s = [input() for _ in range(n)]
c_sort = collections.Counter(s).most_common()
list_most = [c_sort[i][0] for i in range(len(c_sort)) if c_sort[i][1] == c_sort[0][1]]
for i in sorted(list_most):
    print(i)
Buggy code:
from operator import itemgetter
import datetime

n = int(input())
sn = dict()

for i in range(n):
    s = input()
    if(s in sn):
        sn[s] += 1
    else:
        sn[s] = 1

sn = sorted(sn.items(), key=lambda x:x[1], reverse=True)
#print(sn)

max_val = max(dict(sn).values())

for si in sn:
    if(int(si[1]) == max_val):
        print(si[0])
    else:
        break

Fixed code:
from operator import itemgetter
import datetime

n = int(input())
sn = dict()

for i in range(n):
    s = input()
    if(s in sn):
        sn[s] += 1
    else:
        sn[s] = 1

sn = sorted(sn.items(), key=lambda x:(-x[1],x[0]))
#print(sn)

max_val = max(dict(sn).values())

for si in sn:
    if(int(si[1]) == max_val):
        print(si[0])
    else:
        break
Buggy code:
import sys
from collections import Counter

read = sys.stdin.read

N, *S = map(str, read().split())
s = Counter(S)
n = max(s.values())
answer = [i for i, j in s if j == n]
answer.sort()
print('\n'.join(answer))


Fixed code:
import sys
from collections import Counter

read = sys.stdin.read

N, *S = map(str, read().split())
s = Counter(S)
n = max(s.values())
answer = [i for i, j in s.items() if j == n]
answer.sort()
print('\n'.join(answer))
Buggy code:
from sys import stdin
def read():
    return stdin.readline().strip()

dict={}
output=[]

iteration=int(read())

max_val=-1

for _ in range(iteration):
    item=read()
    
    if dict.get(item) is None:
        dict[item]=0 
    dict[item]+=1 
    max_val = max(dict[item],max_val)
#max_val=max(dict.values())
for k,v in dict:
    
    if(max_val==v):
        output.append(k)
    
    
output.sort()
print('\n'.join(output))


Fixed code:

from sys import stdin
def read():
    return stdin.readline().strip()

dict={}
output=[]

iteration=int(read())

max_val=-1

for _ in range(iteration):
    item=read()
    
    if dict.get(item) is None:
        dict[item]=0 
    dict[item]+=1 
    max_val = max(dict[item],max_val)
#max_val=max(dict.values())
for k,v in dict.items():
    
    if(max_val==v):
        output.append(k)
    
    
output.sort()
print('\n'.join(output))
Buggy code:
from collections import Counter

n=int(split())
l=[input() for i in range(n)]
c=Counter(l)
d=max(c.values())
max_list=[k for k,v in c.items() if v==d]
max_list.sort()
for j in max_list:
  print(j)

Fixed code:
from collections import Counter

n=int(input())
l=[input() for i in range(n)]
c=Counter(l)
d=max(c.values())
max_list=[k for k,v in c.items() if v==d]
max_list.sort()
for j in max_list:
  print(j)
Buggy code:

n = int(input())
dic = {}
b = []
for i in range(n):
    a = input()
    b.append(a)
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1
M = max(dic.values())
for j,k in sorted(dic.items()):
    if k == M:
        print(j)


Fixed code:

n = int(input())
dic = {}
b = []
for i in range(n):
    a = input()
    b.append(a)
for o in b:
    if o in dic:
        dic[o] += 1
    else:
        dic[o] = 1
M = max(dic.values())
for j,k in sorted(dic.items()):
    if k == M:
        print(j)
Buggy code:
N = int(input())
from collections import Counter
Sc = Counter([input() for _ in range(N)])
max_count = max(Sc.values())
ans = sorted([k for k, v in Sc.items() if v == max_count)])
print(*ans, sep="\n")

Fixed code:
N = int(input())
from collections import Counter
Sc = Counter([input() for _ in range(N)])
max_count = max(Sc.values())
ans = sorted([k for k, v in Sc.items() if v == max_count])
print(*ans, sep="\n")
Buggy code:
from collections import Counter
N = int(input())
Sc = Counter([input() for _ in range(N)]).most_common()
print(Sc)
max_num = Sc[0][1]
ans = []
for key, val in Sc:
    if val == max_num:
        ans.append(key)
ans.sort()
for t in ans:
    print(t)

Fixed code:
from collections import Counter
N = int(input())
Sc = Counter([input() for _ in range(N)]).most_common()
# print(Sc)
max_num = Sc[0][1]
ans = []
for key, val in Sc:
    if val == max_num:
        ans.append(key)
ans.sort()
for t in ans:
    print(t)