Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03247 (python)

Fixed submission:
import sys
N=int(input())
table=[]
for i in range(N):
    x,y=map(int,input().split())
    table.append((x,y))
L=[0,0]
for x,y in table:
    L[(x+y)%2]=1
if sum(L)==2:
    print(-1)
    sys.exit()
def f(a,b):
    pas=''
    s=a[::-1]
    t=b[::-1]
    A=[0]*31
    B=[0]*31
    for i in range(len(s)):
        if s[i]=='1':
            A[i]=1
    for i in range(len(t)):
        if t[i]=='1':
            B[i]=1
    n=31
    for i in range(n):
        if A[i]==0 and B[i]==0:
            pas+='L'
        if A[i]==0 and B[i]==1:
            pas+='D'
        if A[i]==1 and B[i]==0:
            pas+='U'
        if A[i]==1 and B[i]==1:
            pas+='R'
        
    return pas
if L[0]==1:
    m=32
    d=[1]+[pow(2,i) for i in range(31)]
    ans=[]
    S=[]
    for x,y in table:
        S.append((x-1,y))
    for x,y in S:
        a='R'
        u=(x+y+(pow(2,31)-1))//2
        v=(x-y+(pow(2,31)-1))//2
        u=bin(u)[2:]
        v=bin(v)[2:]
        a+=f(u,v)
        ans.append(a)       
else:
    m=31
    d=[pow(2,i) for i in range(31)]
    ans=[]
    S=table
    for x,y in S:
        a=''
        u=(x+y+(pow(2,31)-1))//2
        v=(x-y+(pow(2,31)-1))//2
        u=bin(u)[2:]
        v=bin(v)[2:]
        a+=f(u,v)
        ans.append(a)      

print(m)
print(' '.join(map(str,d)))
for s in ans:
    print(s)

Buggy submission (verdict: Runtime Error):
import sys
N=int(input())
table=[]
for i in range(N):
    x,y=map(int,input().split())
    table.append((x,y))
L=[0,0]
for x,y in table:
    L[(x+y)%2]=1
if sum(L)==2:
    print(-1)
    sys.exit()
def f(x,y,m):
    s=m
    a=''
    if x>=0:
        a+='R'*x
        s-=x
    else:
        a+='L'*abs(x)
        s-=abs(x)
    if y>=0:
        a+='U'*y
        s-=y
    else:
        a+='D'*abs(y)
        s-=abs(y)
    s=s//2
    a+='LR'*s
    return a
if L[0]==1:
    m=40
    d=[1]*40
    ans=[]
    for x,y in table:
        ans.append(f(x,y,m))
else:
    m=39
    d=[1]*39
    ans=[]
    for x,y in table:
        ans.append(f(x,y,m))

print(m)
print(' '.join(map(str,d)))
for s in ans:
    print(s)

Buggy submission (verdict: Runtime Error):
import sys
N=int(input())
table=[]
for i in range(N):
    x,y=map(int,input().split())
    table.append((x,y))
L=[0,0]
for x,y in table:
    L[(x+y)%2]=1
if sum(L)==2:
    print(-1)
    sys.exit()
def f(x,y,m):
    s=m
    a=''
    if x>=0:
        a+='R'*x
        s-=x
    else:
        a+='L'*abs(x)
        s-=abs(x)
    if y>=0:
        a+='U'*y
        s-=y
    else:
        a+='D'*abs(y)
        s-=abs(y)
    a+='LR'*s
    return a
if L[0]==1:
    m=40
    d=[1]*40
    ans=[]
    for x,y in table:
        ans.append(f(x,y,m))
else:
    m=39
    d=[1]*39
    ans=[]
    ans=[]
    for x,y in table:
        ans.append(f(x,y,m))

print(m)
print(' '.join(map(str,d)))
for s in ans:
    print(s)
Problem p03270 (python)

Fixed submission:
K,N=map(int,input().split())
mod=998244353
L=max(K,N)
table=[1]*(3*L+5)
t=1
for i in range(1,3*L+5):
    t*=i
    t%=mod
    table[i]=t
rtable=[1]*(3*L+5)
t=1
for i in range(1,3*L+5):
    t*=pow(i,mod-2,mod)
    t%=mod
    rtable[i]=t
ans=[]
for k in range(2,K+2):
    num=0
    if k%2==1:
        l=k//2
        p=l
        r=K-2*l
        for q in range(l+1):
            if N-q>=0 and r+q-1>=0:
                s=(table[l]*rtable[q]*rtable[l-q])%mod
                s=(s*pow(2,q,mod))%mod
                t=(table[N+r-1]*rtable[N-q]*rtable[r+q-1])%mod
                s=(s*t)%mod
                num+=s
                num=num%mod
                #print(10,q,k,l,p,num,s)
        ans.append(num)
    else:
        l=k//2
        p=l-1
        r=K-k+1
        for q in range(p+1):
            if N-q-1>=0 and r+q-1>=0:
                s=(table[p]*rtable[q]*rtable[p-q])%mod
                s=(s*pow(2,q,mod))%mod
                t=(table[N+r-2]*rtable[N-q-1]*rtable[r+q-1])%mod
                s=(s*t)%mod
                num+=s
                num%=mod
                #print(9,q,k,l,p,num,s)
            if N-q>=0 and r+q-1>=0:
                s=(table[p]*rtable[q]*rtable[p-q])%mod
                s=(s*pow(2,q,mod))%mod
                t=(table[N+r-1]*rtable[N-q]*rtable[r+q-1])%mod
                s=(s*t)%mod
                num+=s
                num%=mod 
                #print(10,q,k,l,p,num,s)
        ans.append(num)
print('\n'.join(map(str,ans)))
ans=ans[::-1]
print('\n'.join(map(str,ans[1:])))

Buggy submission (verdict: Runtime Error):
K,N=map(int,input().split())
mod=998244353
table=[1]*(2*N+5)
t=1
for i in range(1,2*N+5):
    t*=i
    t%=mod
    table[i]=t
rtable=[1]*(2*N+5)
t=1
for i in range(1,2*N+5):
    t*=pow(i,mod-2,mod)
    t%=mod
    rtable[i]=t
ans=[]
for k in range(2,K+2):
    num=0
    if k%2==1:
        l=k//2
        p=l
        r=K-2*l
        for q in range(l+1):
            if N-q>=0 and r+q-1>=0:
                s=(table[l]*rtable[q]*rtable[l-q])%mod
                s=(s*pow(2,q,mod))%mod
                t=(table[N+r-1]*rtable[N-q]*rtable[r+q-1])%mod
                s=(s*t)%mod
                num+=s
                num=num%mod
                #print(10,q,k,l,p,num,s)
        ans.append(num)
    else:
        l=k//2
        p=l-1
        r=K-k+1
        for q in range(p+1):
            if N-q-1>=0 and r+q-1>=0:
                s=(table[p]*rtable[q]*rtable[p-q])%mod
                s=(s*pow(2,q,mod))%mod
                t=(table[N+r-2]*rtable[N-q-1]*rtable[r+q-1])%mod
                s=(s*t)%mod
                num+=s
                num%=mod
                #print(9,q,k,l,p,num,s)
            if N-q>=0 and r+q-1>=0:
                s=(table[p]*rtable[q]*rtable[p-q])%mod
                s=(s*pow(2,q,mod))%mod
                t=(table[N+r-1]*rtable[N-q]*rtable[r+q-1])%mod
                s=(s*t)%mod
                num+=s
                num%=mod 
                #print(10,q,k,l,p,num,s)
        ans.append(num)
print('\n'.join(map(str,ans)))
ans=ans[::-1]
print('\n'.join(map(str,ans[1:])))
Problem p03287 (python)

Fixed submission:
from collections import defaultdict
N,M=map(int,input().split())
A=[int(i) for i in input().split()]
P=[0]*(N+1)
for i in range(N):
    P[i+1]=P[i]+A[i]
dd=defaultdict(int)
for p in P:
    dd[p%M]+=1
ans=0
def dou(x):
    return (x*(x-1))//2
for s in dd.values():
    ans+=dou(s)
print(ans)

Buggy submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
P=map(int, input().split()):
Acnt = [0 for i in range(M)]
sym = 0

for A in P:
    sym = (sym + A) % M
    Acnt[sym] += 1

print(int(Acnt[0] + sum([cnt * (cnt - 1) for cnt in Acnt]) / 2))
Problem p03362 (python)

Fixed submission:
L=[2,11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,
  401,421,431,461,491,521,541,571,601,631,641,661,701,751,761,811,821,
  881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,
  1201,1231,1291, 1301,1321,1361,1381,1451,1471]
N = int(input())
A = []
for i in range(N):
    A.append(L[i])
print(' '.join(map(str, A)))

Buggy submission (verdict: Runtime Error):
L=[	7151,8111,8741,8431,9241,11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291]
print(L.join(map(str,[3,4,5][:int(input())])))
Problem p03380 (python)

Fixed submission:
import sys
N = int(input())
A =[int(i) for i in input().split()]
a = max(A)
if a%2==0:
    seco=0
    s =a//2
    for i in A:
        if i <=s:
            seco=max(seco,i)
        else:
            seco=max(seco,a-i)
else:
    seco=0
    s = a//2 +1
    for i in A:
        if i <=s:
            seco=max(seco,i)
        else:
            seco=max(seco,a-i)

for i in A:
    if i==seco:
        print(a,seco)
        sys.exit()
print(a,a-seco)

Buggy submission (verdict: Runtime Error):
import sys
N = int(input())
A =[int(i) for i in input().split()]
a = max(A)
if a%2==0:
    s =a//2
    for i in A:
        if i <=s:
            seco=max(seco,i)
        else:
            seco=max(seco,a-i)
else:
    seco=0
    s = a//2 +1
    for i in A:
        if i <=s:
            seco=max(seco,i)
        else:
            seco=max(seco,a-i)

for i in A:
    if i==seco:
        print(a,seco)
        sys.exit()
print(a,a-seco)
Problem p03389 (python)

Fixed submission:
A,B,C=map(int,input().split())
L=[A,B,C]
L.sort()
ans=0
s=(L[-1]-L[0])//2
L[0]=L[0]+2*s
t=(L[-1]-L[1])//2
L[1]=L[1]+2*t
L.sort()
a=0
if L[0]!=L[1]:
    a=2
elif L[1]!=L[2]:
    a=1
print(s+t+a)

Buggy submission (verdict: Runtime Error):
from math import sqrt 
Q = int(input())
table=[]
for i in range(Q):
    A,B=map(int,input().split())
    if A>B:
        table.append([B,A])
    else:
        table.append([A,B])
def f(a,b):
    if a==b:
        return 2*a-2
    if a+1==b:
        return 2*a-2
    m = int(sqrt(a*b))
    if m**2 ==a*b:
        return 2*m-3
    if m*(m+1) >= a*b:
        return 2*m -2
    return 2*m-1

ans = []
for a,b in table:
    ans.append(f(a,b))
print('\n'.join(map(str,ans)))
Problem p03450 (python)

Fixed submission:
class WeightUnionfindtree:
    def __init__(self,number):
        self.par = [i for i in range(number)]
        self.rank = [0]*(number)
        self.weight=[0]*(number)

    def find(self,x):#親を探す xの親を示す
        if self.par[x] ==x:
            return x
        else:
            r = self.find(self.par[x])
            self.weight[x]+=self.weight[self.par[x]]
            self.par[x]=r
            return self.par[x]
        
    def weighted(self,x):
        self.find(x)
        return self.weight[x]
    
    def union(self,x,y,w):#weight(y) = weight(x) + w となるように x と y をマージする
        w += self.weighted(x)
        w -= self.weighted(y)
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return 
        if self.rank[px]<self.rank[py]:
            self.par[px]=py
            self.weight[px]=-w
        else:
            self.par[py]=px
            self.weight[py] = w
        if self.rank[px]==self.rank[py]:
            self.rank[px] +=1
    
    def connect(self,x,y):#親が同じかみる
        return self.find(x)==self.find(y)
    
    def diff(self,x,y):
        return self.weighted(y)-self.weighted(x)
    
N,M = map(int,input().split())
Tree = WeightUnionfindtree(N)
ans = 'Yes'
for i in range(M):
    L,R,D = map(int,input().split())
    if Tree.connect(L-1,R-1):
        if Tree.diff(L-1,R-1)!=D:
            ans = 'No'
    else:
        Tree.union(L-1,R-1,D)
print(ans)

Buggy submission (verdict: Runtime Error):
class WeightUnionfindtree:
    def __init__(self,number):
        self.par = [i for i in range(number)]
        self.rank = [0]*(number)
        self.weight=[0]*(number)

    def find(self,x):#親を探す xの親を示す
        if self.par[x] ==x:
            return x
        else:
            r = self.find(self.par[x])
            self.weight[x]+=self.weight[self.par[x]]
            self.par[x]=r
            return self.par[x]
        
    def weighted(self,x):
        self.find(x)
        return self.weight[x]
    
    def union(self,x,y,w):#weight(y) = weight(x) + w となるように x と y をマージする
        w += self.weighted(x)
        w -= self.weighted(y)
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return 
        if self.rank[px]<self.rank[py]:
            self.par[px]=py
            self.weight[px]=-w
        else:
            self.par[py]=px
            self.weight[py] = w
        if self.rank[px]==self.rank[py]:
            self.rank[px] +=1
    
    def connect(self,x,y):#親が同じかみる
        return self.find(x)==self.find(y)
    
    def diff(self,x,y):
        return self.weighted(y-self.weighted(x)
    
N,M = map(int,input().split())
Tree = WeightUnionfindtree(N)
ans = 'Yes'
for i in range(M):
    L,R,D = map(int,input().split())
    if Tree.connect(L-1,R-1):
        if Tree.diff(L-1,R-1)!=D:
            ans = 'No'
    else:
        Tree.union(L-1,R-1,D)
print(ans)
Problem p03472 (python)

Fixed submission:
from bisect import bisect_right,bisect_left
import sys
N,H = map(int,input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
B.sort()
ama=max(A)
x = bisect_right(B,ama)
ans = 0
if x ==N:
    if H%ama ==0:
        ans += H//ama 
    else:
        ans += H//ama +1
    print(ans)
    sys.exit()
for i in range(N-1,x-1,-1):
    if H<=0:
        print(ans)
        sys.exit()
    else:
        H-=B[i]
        ans +=1
if H>0:
    if H%ama ==0:
        ans += H//ama 
    else:
        ans += H//ama +1
print(ans)

Buggy submission (verdict: Runtime Error):
from bisect import bisect_right,bisect_left
import sys
N,H = map(int,input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
B.sort()
ama=max(A)
x = bisect_right(B,ama)
ans = 0
if x ==N:
    if H%ama ==0:
        ans += H//ama 
    else:
        ans += H//ama +1
    print(ans)
    sys.exit()
for i in range(N-1,x-1,-1):
    if H<=0:
        print(ans)
        sys.exit()
    else H>0:
        H-=B[i]
        ans +=1
if H>0:
    if H%ama ==0:
        ans += H//ama 
    else:
        ans += H//ama +1
print(ans)
Problem p03504 (python)

Fixed submission:
N,C =map(int,input().split())
chan=[[] for i in range(C)]
for i in range(N):
    a,b,c=map(int,input().split())
    chan[c-1].append([a,b])
for i in range(C):
    chan[i].sort()
imos=[0]*(10**5+2)
for i in range(C):
    if len(chan[i])==0:
        continue
    imos[chan[i][0][0]]+=1
    imos[chan[i][0][1]+1]-=1
    for k in range(1,len(chan[i])):
        if chan[i][k][0]==chan[i][k-1][1]:
            imos[chan[i][k][0]+1]+=1
            imos[chan[i][k][1]+1]-=1
        else:
            imos[chan[i][k][0]]+=1
            imos[chan[i][k][1]+1]-=1

for i in range(1,10**5+2):
     imos[i] +=imos[i-1]  
print(max(imos))

Buggy submission (verdict: Runtime Error):
N,C =map(int,input().split())
chan=[[] for i in range(C)]
for i in range(N):
    a,b,c=map(int,input().split())
    chan[c-1].append([a,b])
for i in range(C):
    chan[i].sort()
imos=[0]*(10**5+1)
for i in range(C):
    if len(chan[i])==0:
        continue
    imos[chan[i][0][0]]+=1
    imos[chan[i][0][1]+1]-=1
    for k in range(1,len(chan[i])):
        if chan[i][k][0]==chan[i][k-1][1]:
            imos[chan[i][k][0]+1]+=1
            imos[chan[i][k][1]+1]-=1
        else:
            imos[chan[i][k][0]]+=1
            imos[chan[i][k][1]+1]-=1

for i in range(1,10**5+1):
     imos[i] +=imos[i-1]  
print(max(imos))
Problem p03565 (python)

Fixed submission:
S = input()
T = input()
if len(S) < len(T):
    print('UNRESTORABLE')
    exit()

candidates = []
for i in range(len(S) - len(T) + 1):
    for c1,c2 in zip(S[i:i+len(T)], T):
        if c1 != '?' and c1 != c2:
            break
    else:
        cand = S[:i] + T + S[i+len(T):]
        candidates.append(cand.replace('?','a'))

if candidates:
    print(min(candidates))
else:
    print('UNRESTORABLE')

Buggy submission (verdict: Runtime Error):

S = str(input())
T = str(input())
a = len(S)
b = len(T)
if (a < b):
    print("UNRESTORABLE")
    exit()
m = a-b
B = "UNRESTORABLE"
for i in range(m+1):
    for j in range(b):
        if S[i+j] == T[j]:
            S =S.replace(S[i:i+b+1], T)
            S = S.replace('?', 'a')
            B = S
            break
            
            
print(B)
Problem p03601 (python)

Fixed submission:
a,b,c,d,e,f=map(int,input().split())
ans=0
s=0
t=0
for i in range(f//100+1):
    w=(f-100*a*i)//100
    for j in range(w+1):
        if i==0 and j==0:
            continue
        x=a*i+b*j
        for k in range(x*e//c+1):
            v=(x*e-c*k)//d
            for l in range(v+1):
                y=c*k+d*l
                if 100*x+y <=f:
                    p=100*y/(100*x+y)
                    if ans<=p:
                        s=100*x+y
                        t=y
                        ans=p
print(s,t)

Buggy submission (verdict: Runtime Error):
import sys
a,b,c,d,e,f=map(int,input().split())
ans=0
s=0
t=0
for i in range(f//100+1):
    if i==0 and j==0:
        continue
    w=(f-100*a*i)//100
    for j in range(w+1):
        x=a*i+b*j
        for k in range(x*e//c+1):
            if k==0 and l==0:
                continue
            v=(x*e-c*k)//d
            for l in range(v+1):
                y=c*k+d*l
                if 100*x+y <=f:
                    p=100*y/(100*x+y)
                    if ans<p:
                        s=100*x+y
                        t=y
print(s,t)

Buggy submission (verdict: Runtime Error):
import sys
a,b,c,d,e,f=map(int,input().split())
ans=0
s=0
t=0
for i in range(f//100+1):
    if i==0 and j==0:
        continue
    w=(f-100*a*i)//100
    for j in range(w+1):
        x=a*i+b*j
        for k in range(x*e//c+1):
            v=(x*e-c*k)//d
            for l in range(v+1):
                y=c*k+d*l
                if 100*x+y <=f:
                    p=100*y/(100*x+y)
                    if ans<p:
                        s=100*x+y
                        t=y
print(s,t)
Problem p03602 (python)

Fixed submission:
import sys
import copy

N = int(input())
table = []
for i in range(N):
    A = [int(j) for j in input().split()]
    table.append(A)
tas = copy.deepcopy(table)
for k in range(N):
    for i in range(N):
        for j in range(N):
            tas[j][i] = min(tas[j][i], tas[j][k] + tas[k][i])

for y in range(N):
    for x in range(y+1, N):
        if table[y][x] != tas[y][x]:
            print(-1)
            sys.exit()
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        flag = True
        for k in range(N):
            if i == k or j == k:
                continue
            if table[j][i] >= table[j][k] + table[k][i]:
                flag = False
        if flag:
            ans += table[j][i]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import copy

N = int(input())
table = []
for i in range(N):
    A = [int(j) for j in input().split()]
    table.append(A)
tas = copy.deepcopy(table)
for k in range(N):
    for i in range(N):
        for j in range(N):
            tas[j][i] = min(tas[j][i], tas[j][k] + tas[k][i])

for y in range(N):
    for x in range(y+1, N):
        if A[y][x] != tas[y][x]:
            print(-1)
            sys.exit()
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        flag = True
        for k in range(N):
            if i == k or j == k:
                continue
            if table[j][i] >= table[j][k] + table[k][i]:
                flag = False
        if flag:
            ans += table[j][i]
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import copy
N=int(input())
table=[]
for i in range(N):
    A=[int(j) for j in input().split() ]
    table.append(A)
tas=copy.deepcopy(table)
for k in range(N):
    for i in range(N):
        for j in range(N):
            tas[j][i]=min(tas[j][i],tas[j][k]+tas[k][i])
            
for y in range(N):
    for x in range(N):
        if A[y][x]!=tas[y][x]:
            print(-1)
            sys.exit()
ans=0
for i in range(N):
    for j in range(i+1,N):
        flag =True
        for k in range(N):
            if i==k or j==k:
                continue
            if table[j][i]==table[j][k] +table[k][i]:
                flag = False
        if flag:        
            ans+=table[j][i]
print(ans)
Problem p03660 (python)

Fixed submission:
from collections import deque
N = int(input())
table=[[] for i in range(N)]
for i in range(N-1):
    a,b = map(int,input().split())
    table[a-1].append(b-1)
    table[b-1].append(a-1)
adis=[0]*N
avis=[False]*N
avis[0]=True
bdis=[0]*N
bvis=[False]*N
bvis[N-1]=True
akei=deque()
akei.append(0)
bkei=deque()
bkei.append(N-1)
while akei:
    x = akei.popleft()
    for s in table[x]:
        if not avis[s]:
            adis[s]=adis[x]+1
            avis[s]=True
            akei.append(s)
while bkei:
    x = bkei.popleft()
    for s in table[x]:
        if not bvis[s]:
            bdis[s]=bdis[x]+1
            bvis[s]=True
            bkei.append(s)
white=0
brack=0
for i in range(N):
    if adis[i]<=bdis[i]:
        brack+=1
    else:
        white+=1
if white<brack:
    print('Fennec')
else:
    print('Snuke')

Buggy submission (verdict: Runtime Error):
class Unionfindtree:
    def __init__(self,number):
        self.par = [i for i in range(number)]
        self.rank = [0]*(number)

    def find(self,x):#親を探す
        if self.par[x] ==x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self,x,y):#x,yを繋げる
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return 
        if self.rank[px]<self.rank[py]:
            self.par[px]=py
        else:
            self.par[py]=px
        if self.rank[px]==self.rank[py]:
            self.rank[px] +=1
    
    def connect(self,x,y):#親が同じかみる
        return self.find(x)==self.find(y)
    
btree = Unionfindtree(N)
wtree = Unionfindtree(N)
N = int(input())
table=[]
for i in range(N-1):
    a,b=map(int,input().split())
    table.append([a-1,b-1])
for x,y in table:
    if x==N-1 or y==N-1:
        continue
    btree.union(x,y)
brack=0
for i in range(N):
    if btree.connect(0,i):
        brack+=1
for x,y in table:
    if x==0 or y==0:
        continue
    wtree.union(x,y)
white=0
for i in range(N):
    if btree.connect(N-1,i):
        white+=1

mid = (brack+white)-N
brack-= mid
white-=mid
if mid %2==0:
    brack+= mid//2
    white+=mid//2
else:
    brack+= (mid//2)+1
    white+=mid//2    
    
if brack>white:
    print('Fennec')
else:
    print('Snuke')
Problem p03676 (python)

Fixed submission:
N=int(input())
A=[int(i) for i in input().split()]
mod=10**9+7
deni=[1]*(N+1)#(k)!を格納
quot=[1]*(N+1)#(k)!の逆数を格納
for i in range(1,N+1):
    deni[i]=(deni[i-1]*(i+1))%mod
for i in range(1,N+1):
    t=pow(i+1,mod-2,mod)
    quot[i]=(quot[i-1]*t)%mod
deni=[1]+deni
quot=[1]+quot
box=[[0,0]]*(N+1)
for i in range(N+1):
    if box[A[i]-1][0]==1:
        k_1=box[A[i]-1][1]
        k_2=N-i
        break
    box[A[i]-1]=[1,i]
K=k_1+k_2
ans =[]
for k in range(1,N+2):
    if k==1:
        ans.append(N)
    elif K>=k-1:
        s=deni[N+1]
        s=(s*quot[k])%mod
        s=(s*quot[N+1-k])%mod
        t=deni[K]
        t=(t*quot[k-1])%mod
        t=(t*quot[K-k+1])%mod
        #print(s,t)
        ans.append((s-t)%mod)
    else:
        s=deni[N+1]
        s=(s*quot[k])%mod
        s=(s*quot[N-k+1])%mod
        #print(s)
        ans.append(s)
#print(ans)
print('\n'.join(map(str,ans)))

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(i) for i in input().split()]
mod=10**9+7
deni=[1]*(N+1)#(k)!を格納
quot=[1]*(N+1)#(k)!の逆数を格納
for i in range(1,N+1):
    deni[i]=(deni[i-1]*(i+1))%mod
for i in range(1,N+1):
    t=pow(i+1,mod-2,mod)
    quot[i]=(quot[i-1]*t)%mod
deni=[1]+deni
quot=[1]+quot
box=[[0,0]]*(N+1)
for i in range(N):
    if box[A[i]-1][0]==1:
        k_1=box[A[i]-1][1]
        k_2=N-i
        break
    box[A[i]-1]=[1,i]
K=k_1+k_2
ans =[]
for k in range(1,N+2):
    if k==1:
        ans.append(N)
    elif K>=k-1:
        s=deni[N+1]
        s=(s*quot[k])%mod
        s=(s*quot[N+1-k])%mod
        t=deni[K]
        t=(t*quot[k-1])%mod
        t=(t*quot[K-k+1])%mod
        #print(s,t)
        ans.append((s-t)%mod)
    else:
        s=deni[N+1]
        s=(s*quot[k])%mod
        s=(s*quot[N-k+1])%mod
        #print(s)
        ans.append(s)
#print(ans)
print('\n'.join(map(str,ans)))