USACO 2019 December Contest, Bronze Problem 1.Cow Gymnastics

Problem: https://usaco.org/index.php?page=viewproblem2&cpid=963

I need help debugging this code:
inn=open(“gymnastics.in”,“r”)

k,n=list(map(int,inn.readline().split()))
exercise_sets=[]
for x in range(k):
exercise_sets.append(inn.readline().replace(" “,”").strip())
ahead=""
ans=0
for i in sorted(exercise_sets[0]):

for j in exercise_sets:
ahead+=j.split(i)[1]

nodupe=set(ahead)

for g in nodupe:
if ahead.count(g)==k:
ans+=1

ahead=""

out=open(“gymnastics.out”,“w”)

out.write(str(ans))

^