Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):

def myAnswer(N:int,dic:dict) -> None:
   MAX = max(dic.values())
   dic2 = sorted(dic.items())
   for key,value in dic2:
      if(MAX == value):
         print(key)

def main():
   N = int(input())
   dic = {}
   for _ in range(N):
      s = input()
      if(s in dic.keys()):
         dic[s]+=1
      else:
         dic[s]=1
   myAnswer(N,dic)
if __name__ == '__main__':
   main()

Fixed submission:

N = int(input())
C = dict()


for i in range(N):
    a = input()
    if(a not in C.keys()):
        C[a] = 1
    else:
        val = C[a]
        C[a] = val + 1

m=0
for i in C.values():
    if(i > m):
        m=i

ans = sorted(C.items())
for i  in ans:
    if(m==i[1]):
        print(i[0])

Buggy python submission (verdict: Runtime Error):

N = int(input())
S = [input() for i in range(N)]
C = dict()


for i in range(N):
    a = input()
    if(a not in C.keys()):
        C[a] = 1
    else:
        val = C[a]
        C[a] = val + 1

maxv=0
for i in C.values():
    if(i > maxv):
        maxv=i

ans = sorted(C.items())
for i  in ans:
    if(maxv==i[1]):
        print(i[0])

Fixed submission:

N = int(input())
C = dict()


for i in range(N):
    a = input()
    if(a not in C.keys()):
        C[a] = 1
    else:
        val = C[a]
        C[a] = val + 1

m=0
for i in C.values():
    if(i > m):
        m=i

ans = sorted(C.items())
for i  in ans:
    if(m==i[1]):
        print(i[0])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
H,N=map(int,input().split())
A = list(map(int,input().split()))

for i in range(N):
    m=max(A)
    H-=m
    if(H <= 0):
        print('Yes')
        sys.exit()
    A.remove(m)
print('No')


Fixed submission:
import sys
H,N=map(int,input().split())
A = list(map(int,input().split()))

sortA=sorted(A)

for i in range(N):
    H-=sortA.pop()
    if(H <= 0):
        print('Yes')
        sys.exit()
print('No')
Buggy python submission (verdict: Time Limit Exceeded):
def myAnswer(N:int,P:list) -> int:
   total = 0
   for i in range(N):
      if(min(P[:i+1])>= P[i]):
         total+=1
   return total

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   P = list(map(int,input().split()))
   print(myAnswer(N,P[:]))

if __name__ == '__main__':
   main()

Fixed submission:
import sys
input = sys.stdin.readline

N=int(input())
P = list(map(int,input().split()))


cnt=1
M=P[0]#現在の最小値
for i in range(1,N):
    if(M > P[i]):#Pの値が現在の最小値より小さかったら最小値を更新しcnt++する
        M=P[i]
        cnt+=1



print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
def myAnswer(N:int,P:list) -> int:
   total = 0
   for i in range(N):
      for j in range(0,i):
         if(P[j]< P[i]):
            break
      else:
         total += 1
   return total

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   P = list(map(int,input().split()))
   print(myAnswer(N,P[:]))

if __name__ == '__main__':
   main()

Fixed submission:
import sys
input = sys.stdin.readline

N=int(input())
P = list(map(int,input().split()))


cnt=1
M=P[0]#現在の最小値
for i in range(1,N):
    if(M > P[i]):#Pの値が現在の最小値より小さかったら最小値を更新しcnt++する
        M=P[i]
        cnt+=1



print(cnt)
Buggy python submission (verdict: Runtime Error):
import math
A,B=map(int,input().split())

def lcm(x,y):
    return (x*y)//math.gcd(x,y)

print(lcm(A,B))



Fixed submission:
import fractions
A,B=map(int,input().split())

def lcm(x,y):
    return (x*y)//fractions.gcd(x,y)

print(lcm(A,B))
Buggy python submission (verdict: Time Limit Exceeded):
def myAnswer(N:int,A:list) -> int:
   for bit in range(2**N - 1):
      i = 1
      counter = 0
      for n in range(N): 
         if(bit & (1<<n)):
            counter += 1
            continue
         else:
            if( A[n] != i):
               break
            i+=1

      else:
         return counter
   return -1


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))

if __name__ == '__main__':
   main()

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
counter=0
n=1
for a in A:
    if(a == n):
        n+=1
    else:
        counter+=1

print(counter) if(n != 1) else print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N=int(input())
a = list(map(int,input().split()))
cnt=0
j=0
if((1 in a)==False):
    print(-1)
    sys.exit()
i=1
while(a):
    if(a[0]!=i):
        cnt+=1
        a.pop(0)
    elif(a[0]==i):
        i+=1
        a.pop(0)


print(cnt)




Fixed submission:
N = int(input())
A = list(map(int,input().split()))
counter=0
n=1
for a in A:
    if(a == n):
        n+=1
    else:
        counter+=1

print(counter) if(n != 1) else print(-1)
Buggy python submission (verdict: Runtime Error):
rom itertools import accumulate
def myAnswer(N:int,A:list) -> int:
   accum = list(accumulate(A))
   ans = 10**10
   now = accum.pop()
   for a in accum:
      if(abs(now - a - a) < ans):
         ans = abs(now - 2*a)
   return ans

   

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

Fixed submission:
from itertools import accumulate
def myAnswer(N:int,A:list) -> int:
   accum = list(accumulate(A))
   ans = 10**10
   now = accum.pop()
   for a in accum:
      if(abs(now - a - a) < ans):
         ans = abs(now - 2*a)
   return ans

   

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()
Buggy python submission (verdict: Runtime Error):
N=int(input())
ans=0
ans=N//2 if(N%2==0) else ans=N//2 + 1

print(ans/N)

Fixed submission:
N=int(input())
ans=0
if(N%2==0):
  ans=N//2
else:
  ans=N//2 + 1

print(ans/N)
Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = 0
for a in A:
  if(a >= K):ans+=1
print(ans)

Fixed submission:

def myAnswer(N:int,A:list) -> int:
   dic ={}
   for i in range(1,N+1):
      dic[i]=A[i - 1]
   ans = sorted(dic.items(), key=lambda x:x[1])
   for a in ans:
      print(a[0],end=" ")
   print()
def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A = list(map(int,input().split()))

   myAnswer(N,A[:])

if __name__ == '__main__':
   main()
Buggy python submission (verdict: Runtime Error):
S=input()

weather={"Sunny":"Cloudy","Rainy":"Sunny","Cloudy":"Rainy"}

print(wather[S])

Fixed submission:
S=input()

weather={"Sunny":"Cloudy","Rainy":"Sunny","Cloudy":"Rainy"}

print(weather[S])
Buggy python submission (verdict: Time Limit Exceeded):
def myAnswer(N:int,S:list) -> int:
   counter = 0
   dic = {}
   for s in S:
      if(s in dic.keys()):
         dic[s]+=1
      else:
         dic[s] = 0
   for value in dic.values():
      counter += (value * (value + 1)) // 2
   return counter

def modelAnswer():
   return
def main():
   N = int(input())
   S = ["".join(sorted(list(input()))) for _ in range(N)]
   print(myAnswer(N,S))
if __name__ == '__main__':
   main()

Fixed submission:
N=int(input())
s=[]
cnt=dict()


for _ in range(N):
    tmp=list(input())
    sotmp=sorted(tmp)
    stmp=''.join(sotmp)
    s.append(stmp)

ss=sorted(s)

for word in ss:
    if((word in cnt.keys())==False):
        cnt[word]=0
    else:
        cnt[word]+=1


total=0
for value in cnt.values():
    total+=(1+value)*value//2

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s=[]
cnt=dict()


for _ in range(N):
    tmp=list(input())
    stmp=str(sorted(tmp))
    if((stmp in s)==True):
        n=s.index(stmp)
        if((n in cnt.keys())==False):
            cnt[n]=1
        else:
            cnt[n]+=1
    else:
        s.append(stmp)

total=0
for value in cnt.values():
    total+=(1+value)*value//2

print(total)


Fixed submission:
N=int(input())
s=[]
cnt=dict()


for _ in range(N):
    tmp=list(input())
    sotmp=sorted(tmp)
    stmp=''.join(sotmp)
    s.append(stmp)

ss=sorted(s)

for word in ss:
    if((word in cnt.keys())==False):
        cnt[word]=0
    else:
        cnt[word]+=1


total=0
for value in cnt.values():
    total+=(1+value)*value//2

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
s=[]
cnt=dict()
for _ in range(N):
    tmp=list(input())
    stmp=sorted(tmp)
    if(( stmp in s)==True):
        n=s.index(stmp)
        if((n in cnt.keys())==False):
            cnt[n]=1
        else:
            cnt[n]+=1
    else:
        s.append(stmp)


total=0
for value in cnt.values():
    total+=(1+value)*value//2

print(total)

Fixed submission:
N=int(input())
s=[]
cnt=dict()


for _ in range(N):
    tmp=list(input())
    sotmp=sorted(tmp)
    stmp=''.join(sotmp)
    s.append(stmp)

ss=sorted(s)

for word in ss:
    if((word in cnt.keys())==False):
        cnt[word]=0
    else:
        cnt[word]+=1


total=0
for value in cnt.values():
    total+=(1+value)*value//2

print(total)
Buggy python submission (verdict: Time Limit Exceeded):
def myAnswer(N:int,A:list) -> None:
   MAX = max(A)
   tmp = A[:]
   for i in range(N):
      if(A[i] == MAX):
         tmp.remove(A[i])
         print(max(tmp))
         tmp = A[:]
      else:
         print(MAX)

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A =[]
   for _ in range(N):
      A.append(int(input()))
   myAnswer(N,A)

if __name__ == '__main__':
   main()

Fixed submission:
def myAnswer(N:int,A:list) -> None:
   MAX1 = max(A)
   tmp = A[:]
   tmp.remove(MAX1)
   MAX2 = max(tmp)
   for i in range(N):
      if(A[i] == MAX1):
         print(MAX2)
      else:
         print(MAX1)

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A =[]
   for _ in range(N):
      A.append(int(input()))
   myAnswer(N,A)

if __name__ == '__main__':
   main()
Buggy python submission (verdict: Runtime Error):
'''
Accepted    　:No
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :分
WAの回数　     :回
合計時間　　  　:分
'''
from math import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)

def myAnswer(A:int,B:int,C:int,D:int) -> int:
   divC = B//C - (A - 1)//C 
   divD = B//D - (A - 1)//D
   divCD = B//lcm(C,D) - (A - 1)//lcm(C,D) 
   # print(divC,divD,divCD)
   return (B - A + 1) - (divC + divD - divCD)

def modelAnswer():
   return
def main():
   A,B,C,D = map(int,input().split())
   print(myAnswer(A,B,C,D))

if __name__ == '__main__':
   main()

Fixed submission:
'''
Accepted    　:No
difficult   　: 
ペナルティ　  　:5分
実際の回答時間  :分
WAの回数　     :回
合計時間　　  　:分
'''
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

def myAnswer(A:int,B:int,C:int,D:int) -> int:
   divC = B//C - (A - 1)//C 
   divD = B//D - (A - 1)//D
   divCD = B//lcm(C,D) - (A - 1)//lcm(C,D) 
   # print(divC,divD,divCD)
   return (B - A + 1) - (divC + divD - divCD)

def modelAnswer():
   return
def main():
   A,B,C,D = map(int,input().split())
   print(myAnswer(A,B,C,D))

if __name__ == '__main__':
   main()
Buggy python submission (verdict: Time Limit Exceeded):

def myAnswer(N:int,A:list,B:list) -> str:
   dic = {}
   for a,b in  zip(A,B):
      if(b in dic.keys()):
         dic[b].append(a)
      else:
         dic[b] = [a]
   now = 0
   dic = sorted(dic.items())
   for deadline,time in dic:
      time.sort()
      # print(deadline,time)
      for t in time:
         if(deadline < now + t):
            return "No"
         now += t
   return "Yes"

def modelAnswer():
   return
def main():
   N = int(input())
   A = []
   B = []
   for _ in range(N):
      a,b = map(int,input().split())
      A.append(a)
      B.append(b)
   print(myAnswer(N,A,B))
if __name__ == '__main__':
   main()

Fixed submission:

def myAnswer(N:int,A:list,B:list) -> str:
   dic = {}
   for a,b in  zip(A,B):
      if(b in dic.keys()):
         dic[b].append(a)
      else:
         dic[b] = [a]
   now = 0
   dic = sorted(dic.items())
   for deadline,time in dic:
      time.sort()
      # print(deadline,time)
      for t in time:
         if(deadline < now + t):
            return "No"
         now += t
   return "Yes"

def modelAnswer():
   return
def main():
   N = int(input())
   A = []
   B = []
   for _ in range(N):
      a,b = map(int,input().split())
      A.append(a)
      B.append(b)
   print(myAnswer(N,A,B))
if __name__ == '__main__':
   main()
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
def myAnswer(N:int,S:str) -> int:
   counter = 0
   for i in range(1,N+1):
      for p in itertools.combinations(S,i):
         if (len(set(p)) == i):
            counter += 1

   return counter

def modelAnswer():
   return
def main():
   N = int(input())
   S = input()
   print(myAnswer(N,S))
if __name__ == '__main__':
   main()

Fixed submission:
from collections import Counter
def myAnswer(N:int,S:list) -> int:
   counter = Counter(S)
   ans = 1
   for s in list(set(S)):
      ans *= counter[s] + 1

   return (ans - 1) % (10 ** 9 + 7)
def modelAnswer():
   return
def main():
   N = int(input())
   S = list(input())
   print(myAnswer(N,S))
if __name__ == '__main__':
   main()
Buggy python submission (verdict: Time Limit Exceeded):
def myAnswer(S:list) -> int:
   counter = 0
   while True:
      for i in range(len(S)-1):
         if(S[i]!=S[i+1]):
            S.pop(i)
            S.pop(i)
            counter += 2
            break
      else:
         break
   return counter

def modelAnswer():
   tmp=1
def main():
   S = list(input())
   print(myAnswer(S[:]))
if __name__ == '__main__':
   main()

Fixed submission:
def myAnswer(S:list) -> int:
   C0 = 0
   C1 = 0
   for s in S:
      if(s =="0"):
         C0+=1
      else:
         C1 += 1
   return 2*min(C0,C1)

def modelAnswer():
   tmp=1
def main():
   S = list(input())
   print(myAnswer(S[:]))
if __name__ == '__main__':
   main()
Buggy python submission (verdict: Runtime Error):
import fractions
def myAnswer(N:int,A:list) -> int:
   A.sort()
   target = A.pop(0)
   for a in A:
      if(fractions.gcd(A[0],A[1])==1):
         return 1
   return target

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

Fixed submission:
import fractions
def myAnswer(N:int,A:list) -> int:
   A.sort()
   pre = A.pop(0)
   ans = 10**10
   for a in A:
      ans = min(fractions.gcd(pre,a),ans)
      pre = a
   return ans

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

Buggy python submission (verdict: Runtime Error):
import math
def myAnswer(N:int,A:list) -> int:
   A.sort()
   return math.gcd(A[0],A[1])

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

Fixed submission:
import fractions
def myAnswer(N:int,A:list) -> int:
   A.sort()
   pre = A.pop(0)
   ans = 10**10
   for a in A:
      ans = min(fractions.gcd(pre,a),ans)
      pre = a
   return ans

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()
Buggy python submission (verdict: Runtime Error):
import sys
S=(input())

key=['k','e','y','e','n','c','e']
ans=''
i=0
number=[]

if(S=="keyence"):
    print("YES")
    sys.exit()

for n,s in enumerate(S):
    if(s==key[i]):
        ans+=s
        i+=1
    else:
        number.append(n)

pre=number.pop(0)
a=pre
for n in number:
    if(pre!=(n-1)):
        print("NO")
        sys.exit()
    pre=n
if(ans!="keyence"):
    print('NO')
else:
    print('YES')

Fixed submission:
def myAnswer(S:str) -> str:
   if(S == "keyence"):return "YES"
   for i in range(len(S)-1):
      for j in range(i+1,len(S)):
         if(S[:i]+S[j:] == "keyence"):
            return "YES"
   return "NO"

def modelAnswer():
   return
def main():
   S = (input())
   print(myAnswer(S))
if __name__ == '__main__':
   main()
Buggy python submission (verdict: Time Limit Exceeded):
def myAnswer(S:list) -> int:
   N = len(S)
   counter = 0
   for i in range(N):
      for j in range(N-1,i,-1):
         if(S[j]> S[j-1]):
            S[j],S[j-1] = S[j -1],S[j]
            counter += 1
   return counter

def modelAnswer():
   tmp=1
def main():
   S = list(input())
   print(myAnswer(S[:]))
if __name__ == '__main__':
   main()

Fixed submission:
def myAnswer(S:list) -> int:
   N = 0
   counter = 0
   for n,s in enumerate(S):
      if(s == "W"):
         counter += n - N
         N += 1
         

   return counter

def modelAnswer():
   tmp=1
def main():
   S = list(input())
   print(myAnswer(S[:]))
if __name__ == '__main__':
   main()
Buggy python submission (verdict: Runtime Error):
def myAnswer(D:int, N:int) -> int:
   return 100**D * (N - (N - 1)//99)


def modelAnswer():
   tmp=1
def main():
   D,N =map(int,input().split())
   print(myAnswer(D,N))
if __name__ == '__main__':
   main()

   return ans 


Fixed submission:
def myAnswer(D:int, N:int) -> int:
   if(N == 100):
      return 100**D * (N + 1 )
   else:
      return 100**D * N


def modelAnswer():
   tmp=1
def main():
   D,N =map(int,input().split())
   print(myAnswer(D,N))
if __name__ == '__main__':
   main()
Buggy python submission (verdict: Time Limit Exceeded):

N=int(input())
S=list(input())


def csum(lis):
      counter=[]

      for i,l in enumerate(lis):
          counter.append(lis[i+1:].count('E') + lis[:i].count('W'))

      return min(counter)

print(csum(S))


Fixed submission:
def myAnswer(N:int,S:list) -> int:
   rightW = S.count("W")
   rightE = N - rightW
   leftW = 0
   leftE = 0
   ans = 10**10
   for s in S:
      if(s == "W"):
         rightW -= 1
         ans = min(ans,rightE + leftW)
         leftW += 1
      else:
         rightE -= 1
         ans = min(ans,rightE + leftW)
         leftE += 1
   return ans

def modelAnswer():
   return
def main():
   N = int(input())
   S = list(input())
   print(myAnswer(N,S))
if __name__ == '__main__':
   main()
Buggy python submission (verdict: Runtime Error):
def myAnswer(N:int)->int:
   K = len(str(N)) #桁数
   c = N // 10**(K-1) #最上位の桁の数
   if((c*10**(K-1) + int("9"*(K-1)))<= N):
      return c + 9 *(K - 1)
   else:
      return c + 9 *(K - 1) -1 


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   print(myAnswer(N))

if __name__ == '__main__':
   main()

Fixed submission:

def myAnswer(N:int)->int:
   K = len(str(N)) #桁数
   if(K == 1):return N
   c = N // 10**(K-1) #最上位の桁の数
   if((c*10**(K-1) + int("9"*(K-1)))<= N):
      return c + 9 *(K - 1)
   else:
      return c + 9 *(K - 1) -1 


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   print(myAnswer(N))

if __name__ == '__main__':
   main()
Buggy python submission (verdict: Time Limit Exceeded):
def myAnswer(N:int,A:list) -> int:
   dic = {}
   counter = 0
   for a in A:
      if(a in dic.keys()):
         if(dic[a]==a):
            counter += 1
         else:
            dic[a]+= 1
      else:
         dic[a] = 1
   for key,value in dic.items():
      if(value < key):
         counter += value
   return counter

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A))
if __name__ == '__main__':
   main()

Fixed submission:
def myAnswer(N:int,A:list) -> int:
   dic = {}
   counter = 0
   for a in A:
      if(a in dic.keys()):
         if(dic[a]==a):
            counter += 1
         else:
            dic[a]+= 1
      else:
         dic[a] = 1
   for key,value in dic.items():
      if(value < key):
         counter += value
   return counter

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A))
if __name__ == '__main__':
   main()
Buggy python submission (verdict: Runtime Error):
def myAnswer(N:int,A:list) -> int:
   if(N == 1): return 1
   dic ={}
   for a in A:
      if(a == 0):
         for i in range(2):
            if(i in dic.keys()):
               dic[i]+=1
            else:
               dic[i]=1
      else:
         for i in range(a-1,a+2):
            if(i in dic.keys()):
               dic[i]+=1
            else:
               dic[i] = 1
   return max(list(dic.values()))

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ =

Fixed submission:
def myAnswer(N:int,A:list) -> int:
   if(N == 1): return 1
   dic ={}
   for a in A:
      if(a == 0):
         for i in range(2):
            if(i in dic.keys()):
               dic[i]+=1
            else:
               dic[i]=1
      else:
         for i in range(a-1,a+2):
            if(i in dic.keys()):
               dic[i]+=1
            else:
               dic[i] = 1
   return max(list(dic.values()))

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()
Buggy python submission (verdict: Runtime Error):
def myAnswer(N:int,P:list) -> int:
   ans = 0
   counter = 0
   for i in range(1,N+1):
      if(i == P[i - 1]):
         counter += 1
      elif(counter != 0):
         ans += sum(divmod(counter,2))
         counter = 0
   if(counter != 0):
      ans += sum(divmod(counter,2))
   return ans

def modelAnswer(N:int,P:list) -> int:
   ans = 0
   for i in range(1,N+1):
      if(i == P[i - 1]):
         ans += 1
         P[i - 1],P[i] = P[i],P[i - 1]
   return ans

def main():
   N = int(input())
   P = list(map(int,input().split()))
   print(modelAnswer(N,P[:]))
if __name__ == '__main__':
   main()

Fixed submission:

def myAnswer(N:int,P:list) -> int:
   ans = 0
   counter = 0
   for i in range(1,N+1):
      if(i == P[i - 1]):
         counter += 1
      elif(counter != 0):
         ans += counter//2 + counter % 2 if(counter > 1) else 1
         counter = 0
   if(counter != 0):
      ans += counter//2 + counter % 2 if(counter > 1) else 1
   return ans

def modelAnswer():
   return
def main():
   N = int(input())
   P = list(map(int,input().split()))
   print(myAnswer(N,P[:]))
if __name__ == '__main__':
   main()
Buggy python submission (verdict: Time Limit Exceeded):
def myAnswer(N:int,A:list) ->int:
   if((2 in A) == False):return -1
   botton = A[0]
   keiro = [1]
   counter = 0
   while botton != 2:
      botton = A[botton - 1]
      if(botton in keiro):
         return -1
      keiro.append(botton)
      counter += 1
   return counter+1


def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A = [int(input()) for _ in range(N)]
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

Fixed submission:
def myAnswer(N:int,A:list) ->int:
   if((2 in A) == False):return -1
   graph = {}
   for n,a in enumerate(A):
      graph[n] = a - 1
   i = 0
   counter = 0
   while True:
      if(graph[i] == "-"):
         return -1
      if(graph[i] == 1):
         counter += 1
         break
      tmp = graph[i]
      graph[i] = "-"
      i = tmp
      counter += 1
   return counter




def modelAnswer():
   tmp=1
def main():
   N = int(input())
   A = [int(input()) for _ in range(N)]
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()
Buggy python submission (verdict: Time Limit Exceeded):
def myAnswer(N:int) ->int:
   ans = 1
   for i in range(1,N+1):
      ans *=i
   return ans % (10**9 + 7)

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   print(myAnswer(N))


if __name__ == '__main__':
   main()


Fixed submission:
from math import factorial
def myAnswer(N:int) ->int:
   ans =factorial(N)
   return ans % (10**9 + 7)

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   print(myAnswer(N))


if __name__ == '__main__':
   main()