Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
#!/mnt/c/Users/moiki/bash/env/bin/python
D,G = map(int, input().split())
points = [ [int(j) for j in input().split()] for _ in range(D)]
points = [ [x[0], x[1], 100*e*x[0]] for e,x in enumerate(points, 1)]

ans = float("inf")
for i in range(1<<D): # for complete bonus bit set 
    lg = G
    cnt = 0
    for d in range(D):
        if i & (1<<d) != 0:
            lg -= points[d][1] # complete bonus
            # lg -= (100*(d+1))*points[d][0] # normal points
            lg -= points[d][2] # normal points
            cnt += points[d][0]
            if lg <= 0:
                break
    if lg <= 0:
        ans = min(ans, cnt)
        continue
    
    # other points
    for d in range(D-1, -1, -1):
        if i & (1<<d) != 0: continue

        if lg <= points[d][2]:
            quot = (lg+(100*(d+1)-1)) // (100*(d+1)) # carryUp
            lg -= 100*(d+1)*quot
            cnt += quot;  break
        else:
            cnt += points[d][0]
            lg -= points[d][2]
    if lg <= 0:
        ans = min(ans, cnt)
        continue
print(ans)


Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
N = int(input())
if N == 0:
    print(0)
    exit(0)

if N >= 0:
    b = bin(N)[2:]

    lst = [0 for _ in range(len(b)+10)]

    for e,s in enumerate(reversed(b)):
        if e % 2 == 0:
            lst[e] += int(s)
        elif e % 2 == 1:
            lst[e] += int(s)
            lst[e+1] += int(s)

    for e,s in enumerate(lst):
        if s >= 2:
            # if e % 2 == 0:
            while lst[e] > 1:
                lst[e] -= 2
                if lst[e+1] > 0:
                    lst[e+1] -= 1
                else:
                    lst[e+1] += 1
                    lst[e+2] += 1
            # else:
            #     while lst[e] > 1:
            #         lst[e] -= 2
            #         if lst[e+1] > 0:
            #             lst[e+1] -= 1
            #         else:
            #             lst[e+1] += 1
            #             lst[e+2] += 1

    flag = False
    for s in "".join(map(str, reversed(lst))):
        if not flag and s=="0":
            continue
        else:
            flag = True
            print(s, end="")
    print()
else:
    b = bin(N)[3:]
    lst = [0 for _ in range(100)]
    for e,s in enumerate(reversed(b)):
        if e % 2 == 0:
            lst[e] += int(s)
            lst[e+1] += int(s)
        else:
            lst[e] += int(s)


    for e,s in enumerate(lst):
        if s >= 2:
            while lst[e] > 1:
                lst[e] -= 2
                if lst[e+1] > 0:
                    lst[e+1] -= 1
                else:
                    lst[e+1] += 1
                    lst[e+2] += 1

    flag = False


    for s in "".join(map(str, reversed(lst))):
        if not flag and s == "0":
            continue
        else:
            flag = True
            print(s, end="")
    print()

# print("".join(map(str, reversed(lst))))
Buggy python submission (verdict: Time Limit Exceeded):
#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
A = list(map(int, input().split()))

from collections import defaultdict
d = defaultdict(int)

ans = 0
for i in range(N-1, -1, -1):
    b = defaultdict(int)

    b[ A[i] % M ]  += 1
    for dkey in d.keys():
        b[ (A[i] + dkey)%M ] +=   d[dkey] # b[A[i]] + d[dkey] 
    ans += b[0]

    d = b

#print("ans: ", ans)
# print(d)
print(ans)
    
    


Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
A = list(map(int, input().split()))

from collections import defaultdict
# d = defaultdict(int)
d = defaultdict(list)
# d = defaultdict(set)
# d = {}


B = [0] * (N+1)
B[0] = 0 
# B[1] = A[0]
for i in range(0,N):
    B[i+1] = A[i]
    B[i+1] += B[i]

# print(B)


for i in range(0,N+1):
    d[ B[i] % M] += [i]
    # d[ B[i] % M] |= set([i])
# print(d)
# exit(0)

from bisect import bisect_left

ans = 0
for i in range(0,N+1):
    m = B[i] % M 
    # print(d[m])
    ans += bisect_left( d[m], i)
    # print("{i:3d}: d[{m}]: {d}  bisect({i}): {bi}".format(m=m, d=d[m], i=i, bi=bisect_left(d[m], i)))

    
    
# for i in range(N-1, -1, -1):

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))


ans = 0
for i in range(N):
    tmp_sum = 0
    tmp_xor = 0
    for j in range(i, N):
        tmp_sum += A[j]
        tmp_xor ^= A[j]
        if tmp_sum != tmp_xor :
            break
        else:
            ans += 1
print(ans)

Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
N = int(input())
A = list(map(int, input().split()))


tmpxor = 0
tmpadd = 0
ans = 0
minindex = 0
maxindex = 0
for e,i in enumerate(A):
    tmpadd += i
    tmpxor ^= i
    maxindex = e
    if tmpxor != tmpadd:
        while tmpxor != tmpadd and minindex < e:
            tmpxor ^= A[minindex]
            tmpadd -= A[minindex]
            minindex += 1
            # ans += 1
    ans += maxindex - minindex + 1


        # if tmpxor != tmpadd:
        #     maxindex -= 1
    # ans += maxindex - minindex + 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
p = list(map(int, input().split()))
swappair= [list(map(int, input().split())) for _ in range(M)]

union_list = [-1 for _ in range(N+1)]

def find(a): # get root
    while not union_list[a] == -1:
        a = union_list[a]
    return a

def merge(a,b): 
    ia = find(a)
    ib = find(b)
    if ia < ib:
        union_list[ib] = ia
    elif ia > ib:
        union_list[ia] = ib
    elif ia==ib:
        union_list[ia] -= 1
        union_list[ib] = ia
    


def is_same_grp(a,b):
    ia = find(a)
    ib = find(b)
    return ia == ib

for i in range(M):
    merge(*swappair[i])

ans = 0
for i in range(1,N+1):
    ans += int( is_same_grp(i, p[i-1]))

print(ans)




Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
p = list(map(int, input().split()))
swappair= [list(map(int, input().split())) for _ in range(M)]

union_list = [-1 for _ in range(N+1)]

def find(a): # get root
    while not union_list[a] == -1:
        a = union_list[a]
    return a

def merge(a,b): 
    ia = find(a)
    ib = find(b)
    if ia == ib:
        return 
        
    if ia < ib:
        union_list[ib] = ia
    elif ia > ib:
        union_list[ia] = ib
    


def is_same_grp(a,b):
    ia = find(a)
    ib = find(b)
    return ia == ib

for i in range(M):
    merge(*swappair[i])

ans = 0
for i in range(1,N+1):
    ans += int( is_same_grp(i, p[i-1]))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
p = list(map(int, input().split()))
swappair= [list(map(int, input().split())) for _ in range(M)]

union_list = [-1 for _ in range(N+1)]

def find(a): # get root
    while not union_list[a] == -1:
        a = union_list[a]
    return a

def merge(a,b): 
    ia = find(a)
    ib = find(b)
    union_list[ib] = ia

def is_same_grp(a,b):
    ia = find(a)
    ib = find(b)
    return ia == ib

for i in range(M):
    merge(*swappair[i])

ans = 0
for i in range(1,N+1):
    ans += int( is_same_grp(i, p[i-1]))

print(ans)




Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
p = list(map(int, input().split()))
swappair= [list(map(int, input().split())) for _ in range(M)]

union_list = [-1 for _ in range(N+1)]

def find(a): # get root
    while not union_list[a] == -1:
        a = union_list[a]
    return a

def merge(a,b): 
    ia = find(a)
    ib = find(b)
    if ia == ib:
        return 
        
    if ia < ib:
        union_list[ib] = ia
    elif ia > ib:
        union_list[ia] = ib
    


def is_same_grp(a,b):
    ia = find(a)
    ib = find(b)
    return ia == ib

for i in range(M):
    merge(*swappair[i])

ans = 0
for i in range(1,N+1):
    ans += int( is_same_grp(i, p[i-1]))

print(ans)
Buggy python submission (verdict: Runtime Error):
s=input()
from collections import defaultdict 
if len(s)<26:
  d=defaultdict(int)
  for c in s:
    d[c]+=1
  for bb in b:
    if d[bb]==0:
      print(s+bb)
      exit() 
N=len(s)
for first in range(N-1,0,-1):
  mn=s[first]
  for i in range(first-1,-1, -1):
    if s[i]<mn:
      print(s[:i]+mn)
      exit()
print(-1)
    


Fixed submission:
s=input()
b="abcdefghijklmnopqrstuvwxyz"
from collections import defaultdict 
if len(s)<26:
  d=defaultdict(int)
  for c in s:
    d[c]+=1
  for bb in b:
    if d[bb]==0:
      print(s+bb)
      exit() 
N=len(s)
lst=[]
for first in range(N-1,0,-1):
  mn=s[first]
  for i in range(first-1,-1, -1):
    if s[i]<mn:
      lst.append(s[:i]+mn)
      #print(s[:i]+mn)
      #exit()
if lst:
  print(sorted(lst)[0])
  exit()
print(-1)

Buggy python submission (verdict: Runtime Error):
s=input() 
b="".join(list(reversed("zyxwvutsrqponmlkjihgfedcba")))
if s=="zyxwvutsrqponmlkjihgfedcba":
  print(-1)
  exit()
from collections import defaultdict 
if len(s)<26:
  d=defaultdict(int)
  for c in s:
    d[c]+=1
  for bb in b:
    if d[bb]==0:
      print(s+bb)
      exit() 
N=len(s)
for first in range(N-1,0,-1):
  mn=s[first]
  for i in range(first-1,-1, -1):
    if s[i]<mn:
      print(s[:i]+mn+s[i:first]+s[first+1])
      exit()
    


Fixed submission:
s=input()
b="abcdefghijklmnopqrstuvwxyz"
from collections import defaultdict 
if len(s)<26:
  d=defaultdict(int)
  for c in s:
    d[c]+=1
  for bb in b:
    if d[bb]==0:
      print(s+bb)
      exit() 
N=len(s)
lst=[]
for first in range(N-1,0,-1):
  mn=s[first]
  for i in range(first-1,-1, -1):
    if s[i]<mn:
      lst.append(s[:i]+mn)
      #print(s[:i]+mn)
      #exit()
if lst:
  print(sorted(lst)[0])
  exit()
print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
#!/mnt/c/Users/moiki/bash/env/bin/python
H,W,D = map(int, input().split())
m = [ list(map(int, input().split())) for _ in range(H)]
Q = int(input())
pos = {}

for h in range(H):
    for w in range(W):
        pos[m[h][w]] = (h,w)
        



d = {}


for i in range(1, 1+D):
    bhop = i
    hop = i + D
    while hop <= H*W:
        d[hop] = abs( pos[hop][0] - pos[bhop][0]) + abs( pos[hop][1] - pos[bhop][1]) 
        bhop = hop
        hop  = hop+D


for i in range(Q):
    L,R = map(int, input().split())
    ans = 0
    hop = L+D
    bhop = L
    while hop <= R:
        ans += d[hop]
        bhop = hop
        hop  = hop+D

    print(ans)
    


Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
H,W,D = map(int, input().split())
M = [ list(map(int, input().split())) for _ in range(H)]
Q = int(input())
pos = {}
from itertools import accumulate

for h in range(H):
    for w in range(W):
        pos[M[h][w]] = (h,w)
        

accd = [ [0] for _ in range(D)]

distance = lambda p,np: abs(p[0]-np[0])+abs(p[1]-np[1])

for i in range(1,D+1):
    p = pos[i]
    amari = i % D

    tmp = i + D

    while tmp <= H*W:
        nextp = pos[tmp]
        accd[amari].append( accd[amari][-1] + distance(p,nextp) )

        tmp += D
        p = nextp

# print(accd)
# exit(0)

for i in range(Q):
    L,R = map(int, input().split())
    ans = 0

    if not L == R:
        if R%D == 0:
            ans = accd[L%D][(R-R%D)//D-1] - accd[L%D][(L-L%D)//D-1]
        else:
            ans = accd[L%D][(R-R%D)//D] - accd[L%D][(L-L%D)//D]


    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

def primes(n):
    """ Returns  a list of primes < n """
    sieve = [True] * n
    for i in range(3,int(n**0.5)+1,2):
        if sieve[i]:
            sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,n,2) if sieve[i]]

BIT = Bit(10**5+1)

plist = primes(10**5+1)
# print(plist)
pp = []
for p in plist[1:]:
    if (p+1) //2 in plist:
        pp.append( p )
        BIT.add(p,1)
# print(pp)

Q = int(input())
for i in range(Q):
    l,r = map(int,input().split())
    if l in pp:
        l-=1
    if r in pp:
        r+=1
    print( BIT.sum(r) - BIT.sum(l) )


Fixed submission:
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

def primes(n):
    """ Returns  a list of primes < n """
    sieve = [True] * n
    for i in range(3,int(n**0.5)+1,2):
        if sieve[i]:
            sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,n,2) if sieve[i]]

BIT = Bit(10**5+1)

plist = primes(10**5+1)
# print(plist)
pp = []
for p in plist[1:]:
    if (p+1) //2 in plist:
        pp.append( p )
        BIT.add(p,1)
# print(pp)

Q = int(input())
for i in range(Q):
    l,r = map(int,input().split())
    if l in pp:
        l-=1
    if r in pp:
        r+=1
    print( BIT.sum(r) - BIT.sum(l) )
Buggy python submission (verdict: Runtime Error):
s=input()
baks=s[:]
s="".join(list(filter(lambda x:x!="x",s)))
revs="".join(list(reversed(s)))
i=0 
j=len(s-1)
ans=0
while i<=j:
  if s[i]==s[j]:
    i+=1
    j-=1
  elif s[i]=="x":
    ans+=1
    i+=1
  elif s[j]=="x":
    ans+=1
    j-=1
  else:  break
if i <=j :
  print(-1)
  exit(0) 
else: print(ans)
  

  

Fixed submission:
s=input()

i=0 
j=len(s)-1
ans=0
while i<=j:
  if s[i]==s[j]:
    i+=1
    j-=1
  elif s[i]=="x":
    ans+=1
    i+=1
  elif s[j]=="x":
    ans+=1
    j-=1
  else:  break
if i <=j :
  print(-1)
  exit(0) 
else: print(ans)
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
A=[[int(j) for j in input().split()] for _ in range(H)]
from collections import defaultdict
d=defaultdict(int)
for a in A:
  for j in a:
    d[j]+=1

four=0
two=0
one=0

for i in  range(26):
  c=chr(ord("a")+i)
  if d[c]>=4:
    four+=d[c]//4 
    d[c]%=4
  if d[c]>=2:
    two+=d[c]//2
    d[c]%=2
  if d[c]>=1:
    one+=d[c]
    d[c]-=1
    
if four<=(H//2)*(W//2):    
  print("No")
  exit(0)
four-=(H//2)*(W//2)
two+=four*2

if H%2==1:
  if two < W//2:
    print("No")
    exit()
  two-=W//2
if W%2==1:
  if two <H//2:
    print("No")
    exit()
  two-=H//2

print("Yes")
  

Fixed submission:
H,W=map(int,input().split())
A=[input() for _ in range(H)]
from collections import defaultdict
d=defaultdict(int)
for a in A:
  for j in a:
    #print("j: ",j)
    d[j]+=1

four=0
two=0
one=0

for i in  range(26):
  c=chr(ord("a")+i)
  if d[c]>=4:
    four+=d[c]//4 
    d[c]%=4
  if d[c]>=2:
    two+=d[c]//2
    d[c]%=2
  if d[c]>=1:
    one+=d[c]
    d[c]-=1

if four<(H//2)*(W//2):    
  print("No")
  exit(0)
four-=(H//2)*(W//2)
two+=four*2

if H%2==1:
  if two < W//2:
    print("No")
    exit()
  two-=W//2
if W%2==1:
  if two <H//2:
    print("No")
    exit()
  two-=H//2

print("Yes")
Buggy python submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))

lst = []
ans = 0
skip = False
for e,p in enumerate(P,1):
    if skip:
        skip = False
        continue
    if e == p:
        ans += 1
        if e-1 < N and P[e] == e+1:
            skip = True
        # lst.append(e)
print(ans)
exit(0)

st = False
ans = 0
for a,b,c in zip(lst[::2], lst[1::2] + [-1], lst[2::2] + [-1, -1]):
    print(a,b,c)
    if b == -1:
        if st:
            break
        ans += 1
        break

    if c == -1:
        if not st and a +1 == b:
            ans += 1
        elif st :
            ans += 1
        else:
            ans += 2
        break

    if not st and a+1 == b:
        ans += 1
        continue
    if not st and b+1 == c:
        st = True
        ans += 1
    if st and b+1 == c:
        ans += 1

    st = False
    ans += 2
print(ans)




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

lst = []
ans = 0
for e,p in enumerate(P,1):
    if e == p:
        ans += 1

        if e < N:
            P[e] = 0
print(ans)
exit(0)

st = False
ans = 0
for a,b,c in zip(lst[::2], lst[1::2] + [-1], lst[2::2] + [-1, -1]):
    print(a,b,c)
    if b == -1:
        if st:
            break
        ans += 1
        break

    if c == -1:
        if not st and a +1 == b:
            ans += 1
        elif st :
            ans += 1
        else:
            ans += 2
        break

    if not st and a+1 == b:
        ans += 1
        continue
    if not st and b+1 == c:
        st = True
        ans += 1
    if st and b+1 == c:
        ans += 1

    st = False
    ans += 2
print(ans)
Buggy python submission (verdict: Runtime Error):
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))

nc=1
nct=A[0]
ans=[]
for y in range(H):
  if y%2==0:
    st=""
    for x in range(W):
      nct-=1
      st+=str(nc)
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
  else:
    st=""
    for x in range(W-1,-1,-1):
      nc-=1
      st+=str(nc)
      if nct==0 and nc!=N:
        nct=A[nc]
        nc+=1
    st="".join(list(reversed(st)))
  ans.append(st)
        
      
for y in range(H):
  print(ans[y])

Fixed submission:
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))
ANS = [ [0]*W for _ in range(H)]
nc=1
nct=A[0]
ans=[]
for y in range(H):
  if y%2==0:
    for x in range(W):
      nct-=1
      ANS[y][x] = str(nc)
      if nct==0 and nc<N:
        nct=A[nc]
        nc+=1
  else:
    for x in range(W-1,-1,-1):
      nct-=1
      ANS[y][x] = str(nc) 
      if nct==0 and nc<N:
        nct=A[nc]
        nc+=1
        
      
for y in range(H):
    print(" ".join(ANS[y]) )
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
import sys
ab=[list(map(int, input().split())) for _ in range (N-1)]
con=[[] for _ in range(N+1)]

#print(ab)
for a,b in ab :
  con[a].append(b)
  con[b].append(a)

#black Fennec
pc=[0]*(N+1)
q=[(1,0)]
vis=[False]*(N+1)
vis[1]=True
Fcnt=N
while q:
  n,c=q.pop()
  pc[n]=c
  for ch in con[n]:
    if vis[ch]==True:
      continue
    q.append((ch,c+1))
    
q=[(N,0)]
vis=[False]*(N+1)
vis[1]=True
while q:
  n,c=q.pop()
  if pc[n]>c:
    Fcnt-=1
  for ch in con[n]:
    if vis[ch]==True:
      continue
    q.append((ch,c+1))
    
if Fcnt>N-Fcnt:
  print("Fennec")
else:
  print("Snuke")


Fixed submission:
N=int(input())

import sys
sys.setrecursionlimit(10**5)
ab=[list(map(int, input().split())) for _ in range (N-1)]
con=[[] for _ in range(N+1)]

#print(ab)
for a,b in ab :
  con[a].append(b)
  con[b].append(a)

#black Fennec
pc=[0]*(N+1)
q=[(1,0)]
vis=[False]*(N+1)
vis[1]=True
Fcnt=N
while q:
  n,c=q.pop()
  pc[n]=c
  for ch in con[n]:
    if vis[ch]==True:
      continue
    vis[ch]=True
    q.append((ch,c+1))
    
q=[(N,0)]
vis=[False]*(N+1)
vis[N]=True
while q:
  n,c=q.pop()
  if pc[n]>c:
    Fcnt-=1
  for ch in con[n]:
    if vis[ch]==True:
      continue
    vis[ch]=True
    q.append((ch,c+1))
    
if Fcnt>N-Fcnt:
  print("Fennec")
else:
  print("Snuke")

Buggy python submission (verdict: Runtime Error):
N=int(input())
import sys
ab=[[int(j) for j in sys.stdin.readline()] for _ in range (N-1)]
con=[[] for _ in range(N+1)]

for a,b in ab :
  con[a].append(b)
  con[b].append(a)

#black Fennec
pc=[0]*(N+1)
q=[(1,0)]
vis=[False]*(N+1)
vis[1]=True
Fcnt=N
while q:
  n,c=q.pop()
  pc[n]=c
  for ch in con[n]:
    if vis[ch]==True:
      continue
    q.append((ch,c+1))
    
q=[(N,0)]
vis=[False]*(N+1)
vis[1]=True
while q:
  n,c=q.pop()
  if pc[n]>c:
    Fcnt-=1
  for ch in con[n]:
    if vis[ch]==True:
      continue
    q.append((ch,c+1))
    
if Fcnt>N-Fcnt:
  print("Fennec")
else:
  print("Snuke")

Fixed submission:
N=int(input())

import sys
sys.setrecursionlimit(10**5)
ab=[list(map(int, input().split())) for _ in range (N-1)]
con=[[] for _ in range(N+1)]

#print(ab)
for a,b in ab :
  con[a].append(b)
  con[b].append(a)

#black Fennec
pc=[0]*(N+1)
q=[(1,0)]
vis=[False]*(N+1)
vis[1]=True
Fcnt=N
while q:
  n,c=q.pop()
  pc[n]=c
  for ch in con[n]:
    if vis[ch]==True:
      continue
    vis[ch]=True
    q.append((ch,c+1))
    
q=[(N,0)]
vis=[False]*(N+1)
vis[N]=True
while q:
  n,c=q.pop()
  if pc[n]>c:
    Fcnt-=1
  for ch in con[n]:
    if vis[ch]==True:
      continue
    vis[ch]=True
    q.append((ch,c+1))
    
if Fcnt>N-Fcnt:
  print("Fennec")
else:
  print("Snuke")
Buggy python submission (verdict: Runtime Error):
N,A,B,C,D=map(int,input().split())


#print("target:", abs(A-B))
#print("range: ", D-C)
#print("target is larger than D: " ,
#     abs(A-B)>D)
#target=abs(A-B)
#print("next target is: ", target-D)
#print("how many? : ", (target-D)//(D-C))

ans=False
def g(a,b,c,d,n):
  if (n-1)%2==0:
    target=abs(a-b) #スタートは0
    gain=d-c
    if ((n-1)//2)*gain>=target:
      return True
    else:
      return False
  else:
    target=abs(a-b)
    gain=d-c
    if target>d:
      if (n-2)//2 * gain >=target-d:
        return True
      else:
        return False
    elif target<c:
      if (n-2)//2 *gain >= c- target:
        return True
      else:
        return False
    elif c<=target<=d:
      return True
      
A,B=min(A,B),max(A,B)
target=B-A
pos=0
for i in range(N+1):
  target=abs(target)
  if  g(pos, target, C,D, N-i):
      print("YES")
      exit(0)
 　target-=D
    
print("NO")
exit(0)      
  
if g(A,B,C,D,N):
  print("YES")
else:
  print("NO")
    

Fixed submission:
N,A,B,C,D = map(int, input().split())

n = N-1

found = False

B = abs(A-B)
for i in range(0, n+1):
    if C*(n-i)-D*(i) <= B <= D*(n-i)-C*(i):
        found = True
        break

if found:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
N,A,B=map(int,input().split())
H=[inp(input()) for _ in range(N)]
H=sorted(H,reverse=True)

ok=max(H)//B+1
ng=0
mid=(ok+ng)//2
while ok-ng>1:
  cntlive=0
  for h in H:
    h-=B*mid
    if h>0:
      cntlive+=1
  if cntlive<=mid:
    ok=mid
  else:
    ng=mid
  mid=(ok+ng)//2
print(ok)

Fixed submission:
N,A,B=map(int,input().split())
H=[int(input()) for _ in range(N)]
H=sorted(H,reverse=True)

ok=max(H)//B+1
ng=0
mid=(ok+ng)//2
while ok-ng>1:
  cntlive=0
  for h in H:
    h-=B*mid
    if h>0:
      cntlive+=(h+A-B-1)//(A-B)
  if cntlive<=mid:
    ok=mid
  else:
    ng=mid
  mid=(ok+ng)//2
print(ok)
Buggy python submission (verdict: Runtime Error):
n,a,b = map(int, input().split())

if n == 1 and a == b:
  print(1)
elif n == 1:
  print(0)
elif a > b:
  print(0)
elif n == 2:
  print(1)	
elif n > 2:
  print( (B-A+1) * (n-2) )
else:
  print(0)

Fixed submission:
n,a,b = map(int, input().split())

if n == 1 and a == b:
  print(1)
elif n == 1:
  print(0)
elif a > b:
  print(0)
elif n == 2:
  print(1)	
elif n > 2:
  print( b * (n-2) - a * (n-2) + 1) 
else:
  print(0)

Buggy python submission (verdict: Runtime Error):
n,a,b = map(int, input().split())

if n == 1 and a == b:
  print(1)
elif n == 1:
  print(0)
elif a > b:
  print(0)
elif n == 2:
  print(1)
elif n > 2:
  print( (B-A+1) * (n-2) )

Fixed submission:
n,a,b = map(int, input().split())

if n == 1 and a == b:
  print(1)
elif n == 1:
  print(0)
elif a > b:
  print(0)
elif n == 2:
  print(1)	
elif n > 2:
  print( b * (n-2) - a * (n-2) + 1) 
else:
  print(0)