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

Fixed submission:
n = int(input())

points = [list(map(int, input().split(" "))) for _ in range(n)]
X = 0
Y = 1
ans = 10 ** 14
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        x1, y1 = points[i]
        x2, y2 = points[j]
        p = x1 - x2
        q = y1 - y2
        cost = n
        for point1 in points:  # そのpointからcost0で遷移できる先があるかどうか
            fromx, fromy = point1
            for point2 in points:
                tox, toy = point2
                if fromx - tox == p and fromy - toy == q:
                    cost -= 1
                    break
        if ans > cost:
            ans = cost
if n == 1:
    print(1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())

points = [list( map(int,input().split(" "))) for _ in range(n)]
X = 0
Y = 1
ans = 10 ** 14
for i  in range(n):
  for j in range(n):
    if i == j:
      continue
    x1,y1 = points[i]
    x2,y2 = points[j]
    p = x1 - x2
    q = y1 - y2
    cost = n
    for point1 in points: #そのpointからcost0で遷移できる先があるかどうか
      fromx,fromy = point1
      for point2 in points:
        tox,toy = point2
        if fromx - tox == p and fromy - toy == q:
          cost -= 1
          break
    if ans < cost:
      ans = cost
print(cost)

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
N = int(input())
Xs = []
Ys = []
za = []

for i in range(N):
    x,y = list(map(int, input().split(" ")))
    Xs.append(x)
    Ys.append(y)
    za.append((x,y))

za.sort(key=lambda x:x[0])
dix = defaultdict(lambda :0)
diy = defaultdict(lambda :0)
for i,z in enumerate(za[1:]):
    x = z[0]
    before = za[i][0]
    tempx = x -before
    y = z[1]
    before = za[i][1]
    tempy =  y -before
    diy[(tempx,tempy)] += 1

ymax = max(diy.values())
cand = [N - ymax]


za.sort(key=lambda x:x[1])
dix = defaultdict(lambda :0)
diy = defaultdict(lambda :0)
for i,z in enumerate(za[1:]):
    x = z[0]
    before = za[i][0]
    tempx = x -before
    y = z[1]
    before = za[i][1]
    tempy =  y -before
    diy[(tempx,tempy)] += 1

ymax = max(diy.values())
cand.append(N - ymax)


print(min(cand))
Problem p03007 (python)

Fixed submission:
import heapq
from collections import defaultdict
N = int(input())
nums  = list(map(int, input().split(" ")))
# 正の数、負の数の個数で操作をコントロール？
p_count = 0
m_count = 0
pos = []
minus = []
for num in nums:
    if num < 0:
        m_count += 1
        minus.append(num)
    else:
        p_count += 1
        pos.append(num)
pos.sort()
minus.sort() #小さい順番
途中式 = []
if N == 2:
    x = max(nums) 
    y = min(nums)
    print(max(nums) - min(nums))
    print(x, y)
else:
    #正の数を一つにして、そこから引きまくる
    if m_count == 0: #マイナスが無かったら作る
        x = min(pos)
        y = max(pos)
        途中式.append((x, y))
        minus.append(x - y)
        pos.remove(x)
        pos.remove(y)
        p_count -=2
        m_count += 1

    if p_count > 1: # 正が複数あったら、マイナスから引くことで減らしていく
        for i in range(p_count - 1):
            #マイナスから正が1個になるまで引いていく
            x = minus.pop()
            y = pos.pop()
            途中式.append((x,y))
            minus.append(x- y)
    elif p_count == 0 : #正が一つも無かったら、作る
        x = minus.pop()
        y = minus.pop()
        途中式.append((x, y))
        pos.append(x - y)

    x = pos.pop()
    for i in minus:
        y = i
        途中式.append((x, y))
        x -=y
    print(x)
    for temp in 途中式:
        x,y = temp
        print(x,y)

Buggy submission (verdict: Runtime Error):
import heapq
from collections import defaultdict
N = int(input())
nums  = list(map(int, input().split(" ")))
# 正の数、負の数の個数で操作をコントロール？
p_count = 0
m_count = 0
pos = []
minus = []
for num in nums:
    if num < 0:
        m_count += 1
        minus.append(num)
    else:
        p_count += 1
        pos.append(num)
pos.sort()
minus.sort() #小さい順番
途中式 = []
if N == 2:
    print(max(nums) - min(nums))
else:
    #正の数を一つにして、そこから引きまくる
    if m_count == 0: #マイナスが無かったら作る
        x = min(pos)
        y = max(pos)
        途中式.append((x, y))
        minus.append(x - y)
        pos.remove(x)
        pos.remove(y)
        p_count -=2
        m_count += 1

    if p_count > 1: # 正が複数あったら、マイナスから引くことで減らしていく
        for i in range(p_count - 1):
            #マイナスから正が1個になるまで引いていく
            x = minus.pop()
            y = pos.pop()
            途中式.append((x,y))
            minus.append(x- y)
    elif p_count == 0 : #正が一つも無かったら、作る
        x = minus.pop()
        y = minus.pop()
        途中式.append((x, y))
        pos.append(x - y)

    x = pos.pop()
    for i in minus:
        y = i
        途中式.append((x, y))
        x -=y
print(x)
for temp in 途中式:
    x,y = temp
    print(x,y)
Problem p03024 (python)

Fixed submission:
s = input()
nokori = 15 -len(s)
should = 8 -nokori 
num = s.count("o")
if num >= should:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
s = input()
nokori = 15 -len(s)
should = 8 -nokori 
num = s.count("o")
if num >= should:
  print("YES")
else:
  print(""NO)
Problem p03043 (python)

Fixed submission:
import math
N,K = list(map(int,input().split(" ")))


ans = 0

for p in range(1,N+1): # p 目
    if p >= K:
        ans += 1
    else:
        temp = K/p
        n = math.ceil(math.log2(temp))
        ans += (1/2)**n

ans /= N
print(ans)

Buggy submission (verdict: Runtime Error):
import math
N,K = list(map(int,input().split(" ")))


ans = 0

for p in range(1,N+1): # p 目
    if p >= K:
        ans += 1
    else:
        temp = K/p
        n = math.ceil(math.log2(temp))
        ans += (1/2)**n

ans /= N
print(ans)
Problem p03128 (python)

Fixed submission:
N,M = list(map(int,input().split(" ")))
As = list(map(int,input().split(" ")))

# N → 10^4 数字0-9 → 10^5

match= [-1,2,5,5,4,5,6,3,7,6]

dp = [-1 for _ in range(N + 100)] #N 本使ったときの最大値
dp[0] = 0
for num in As:
    dp[match[num] ]  = 1

for i in range(N + 1):
    for num in As:
        match_num = match[num]
        if i - match_num >= 0:
            #数字numを使うときのマッチの本数
            dp[i] = max( dp[i - match_num] + 1 , dp[i])
# print(dp)

ans = []
cot = N
As.sort(reverse=True)
while True:
    if cot == 0:
        break
    for num in As:
        if dp[cot - match[num]]  == dp[cot] - 1:
            ans.append(str(num))
            cot -= match[num]
            break
print("".join(ans))

Buggy submission (verdict: Runtime Error):
N,M = list(map(int,input().split(" ")))
As = list(map(int,input().split(" ")))

# N → 10^4 数字0-9 → 10^5

match= [-1,2,5,5,4,5,6,3,7,6]

dp = [-1 for _ in range(N + 1)] #N 本使ったときの最大値
dp[0] = 0
for num in As:
    dp[match[num] ]  = 1

for i in range(N + 1):
    for num in As:
        match_num = match[num]
        if i - match_num >= 0:
            #数字numを使うときのマッチの本数
            dp[i] = max( dp[i - match_num] + 1 , dp[i])
# print(dp)

ans = []
cot = N
As.sort(reverse=True)
while True:
    if cot == 0:
        break
    for num in As:
        if dp[cot - match[num]]  == dp[cot] - 1:
            ans.append(str(num))
            cot -= match[num]
            break
print("".join(ans))
Problem p03161 (python)

Fixed submission:
N,K = list(map(int,input().split(" ")))
hs = list(map(int,input().split(" ")))
dp = [9999999999999] * N

dp[0] = 0
for i in range(1,N):
#ind → i-1 ~ i-stepLim -1   [i-stepLim -1:i]
    stepLim = min(K,i)
    temp = 9999999999999999999
    dp[i] = min([d+abs(hs[i]-h) for d,h in zip(dp[i-stepLim:i],hs[i-stepLim:i])])
print(dp[-1])

Buggy submission (verdict: Runtime Error):
N,K = list(map(int,input().split(" ")))
hs = list(map(int,input().split(" ")))
dp = [] 

dp[0] = 0
for i in range(1,N):

    stepLim = min(K,i)
    temp = 9999999999999999999
    for j in range(1,stepLim + 1):
        c = dp[i-j]+abs(hs[i]-hs[i-j])
        if temp >c:
                temp = c
    dp.append(temp)
print(dp[-1])
Problem p03166 (python)

Fixed submission:
import math
import sys
import collections
import sys

sys.setrecursionlimit(200000)




N,M = list(map(int,input().split(" ")))

dp =[-1] * (N + 1)

def rec(v):
    if dp[v] != -1:
        return dp[v]


    res = 0
    for nv in di[v]:
        res = max(rec(nv) + 1 ,res)  # × dp[nv] ○ rec(nv) ∵ dp[nv]が未計算の場合があるから
    dp[v] = res
    return res

qs = [ list(map(int,input().split(" "))) for _ in range(M)]

# print(qs)
di = collections.defaultdict(lambda :[])
for q in qs:
    x,y = q
    di[x].append(y)
    #dp[y] → yを終点としたlongest path

for i in range(N + 1):
    rec(i)
print(max(dp))

Buggy submission (verdict: Runtime Error):
import math
import sys
import collections


N,M = list(map(int,input().split(" ")))

dp =[-1] * (N + 1)

def rec(v):
    if dp[v] != -1:
        return dp[v]


    res = 0
    for nv in di[v]:
        res = max(rec(nv) + 1 ,res)  # × dp[nv] ○ rec(nv) ∵ dp[nv]が未計算の場合があるから
    dp[v] = res
    return res

qs = [ list(map(int,input().split(" "))) for _ in range(M)]

# print(qs)
di = collections.defaultdict(lambda :[])
for q in qs:
    x,y = q
    di[x].append(y)
    #dp[y] → yを終点としたlongest path

for i in range(N + 1):
    rec(i)
print(max(dp))
Problem p03261 (python)

Fixed submission:
n = int(input())
words = []
before= input()
words.append(before)
flag = True
for _ in range(n-1):
  
  s = input()
  if before[-1] != s[0]:
    flag = False
  before = s
  words.append(s)

l = len(set(words))
if l != n:
  flag = False
if flag:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
n = int(input())
words = []
before= input()
words.append(first)
flag = True
for _ in range(n-1):
  s = input()
  if before[-1] != s[0]:
    flag == False
  before = s
l = len(set(words))
if l != n:
  flag = False
if flag:
  print("Yes")
else:
  print("No")
Problem p03393 (python)

Fixed submission:


def main():
    temp=input()
    t1=""
    t2=""
    if temp=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        exit()
    elif len(temp)==26:
        temp=list(temp)
        p=0
        for i in range(25):
            if temp[25-i]>temp[25-i-1]:
                p=25-i-1
                # print(p)
                # print(temp[p:])
                q=[k for k in temp[p:] if k>temp[p]] 
                print("".join(temp[:p])+min(q))
                exit()       
    else:
        alps=[chr(ord('a') + i) for i in range(26)]
        for w in list(temp):
            alps.remove(w)
        temp=temp+alps[0]
        print(temp)
        exit()       

    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):


def main():
    temp=input()
    t1=""
    t2=""
    # if temp=="zyxwvutsrqponmlkjihgfedcba":
    #     print(-1)
    #     exit()
    
    # elif "z" in temp and len(temp)==26:
    #     t1,t2=temp.split("z")
    #     temp=t1[:-1]
    #     temp+=sorted(list(t2))[0]
    #     print(temp)
    #     exit()       
    # else:
    alps=[chr(ord('a') + i) for i in range(26)]
    for w in list(temp):
        alps.remove(w)
    temp=temp+alps[0]
    print(temp)
    exit()       

    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):


def main():
    temp=input()
    t1=""
    t2=""
    if temp=="zyxwvutsrqponmlkjihgfedcba":
        print(-1)
        exit()
    
    elif "z" in temp and len(temp)==26:
        t1,t2=temp.split("z")
        temp=t1[:-1]
        temp+=sorted(list(t2))[0]
        print(temp)
        exit()       
    else:
        alps=[chr(ord('a') + i) for i in range(26)]
        for w in list(temp):
            alps.remove(w)
        temp=temp+alps[0]
        print(temp)
        exit()       

    

if __name__ == '__main__':
    main()
Problem p03469 (python)

Fixed submission:
a=input()

print(a[0:3]+"8"+a[4:])

Buggy submission (verdict: Runtime Error):
a=input()
a[3]='8'
print(a)
Problem p03473 (python)

Fixed submission:
temp=input()
b=int(temp)
print(48-b)

Buggy submission (verdict: Runtime Error):
temp=input()
b=int(temp)
print(48-temp)
Problem p03502 (python)

Fixed submission:
S = input()
q = 0
for i in list(S):
  q += int(i)
if int(S)% q == 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
S = input()
q = 0
for i in list(S):
  q += i
if int(S)% q == 0:
  print("Yes")
else:
  print("No")
Problem p03504 (python)

Fixed submission:
import numpy as np

LIM = int(10e5)
time = [0] * (LIM + 1)
N, C = list(map(int, input().split(" ")))
schs = []
for _ in range(N):
    s, t, c = list(map(int, input().split(" ")))
    schs.append((s,t,c))
schs.sort(key = lambda x:x[0])

schs.sort(key = lambda x:x[2])

# print(schs)
for i,temp in enumerate(schs):
    s,t,c = temp

    s_p,t_p,c_p = schs[i-1]
    if i != 0 and c_p == c and t_p == s:
        time[t_p + 1] += 1
        time[t + 1] -= 1

    else:
        time[s] += 1
        time[t + 1] -= 1
# print(time[:100])
ruiseki = np.cumsum(time)

# print(ruiseki[:10])x
print(np.max(ruiseki[1:]))

Buggy submission (verdict: Runtime Error):
temp_in=input()
temp_in=temp_in.split(" ")
temp_in=list(map(int,temp_in))
a,b=temp_in
times=[0]*(10**5+1)
times_sum=[0]*(10**5+1)
for i in range(a):
    temp_in=input()
    temp_in=temp_in.split(" ")
    temp_in=list(map(int,temp_in))
    times[temp_in[0]]+=1
    times[temp_in[1]+1]-=1
for i in range(len(times_sum)-1):
    times_sum[i]+=times_sum[i-1]+times[i]
print(max(times_sum))
Problem p03569 (python)

Fixed submission:
S = input()
S = list(S)
S_no_x = []
def is_kaibun(kaibun):
    for i in range(len(kaibun)//2):
        if kaibun[i] != kaibun[-i-1]:
            return False
    return True
inds = []
for i,c in enumerate(S):
    if c != "x":
        S_no_x.append(c)
        inds.append(i)
if not is_kaibun(S_no_x):
    print(-1)
else:
    l = len(S_no_x)

    if l == 0:
        print(0)
    else:
        mae = ""
        usiro = ""
        if l % 2 == 0:
            mae_ind = inds[l // 2 - 1]
            usiro_ind = inds[l // 2]
            mae = S[:mae_ind +1]
            usiro = S[usiro_ind :]
        else:
            center = inds[l // 2]
            mae = S[:center]
            usiro = S[center +1:]

        usiro.reverse()
        usiro_x = []
        mae_x = []
        cot = 0
        usiro.append("@")
        for c in usiro:
            if c == "x":
                cot += 1
            else:
                usiro_x.append(cot)
                cot = 0
        cot = 0
        mae.append("@")
        for c in mae:
            if c == "x":
                cot += 1
            else:
                mae_x.append(cot)
                cot = 0
        ans = 0
        for a,b in zip(mae_x,usiro_x):
            ans += abs(a-b)
        print(ans)

Buggy submission (verdict: Runtime Error):
S = input()
S = list(S)
S_no_x = []
def is_kaibun(kaibun):
    for i in range(len(kaibun)//2):
        if kaibun[i] != kaibun[-i-1]:
            return False
    return True
inds = []
for i,c in enumerate(S):
    if c != "x":
        S_no_x.append(c)
        inds.append(i)
if not is_kaibun(S_no_x):
    print(-1)
else:
    l = len(S_no_x)



    mae = ""
    usiro = ""
    if l % 2 == 0:
        mae_ind = inds[l // 2 - 1]
        usiro_ind = inds[l // 2]
        mae = S[:mae_ind +1]
        usiro = S[usiro_ind :]
    else:
        center = inds[l // 2]
        mae = S[:center]
        usiro = S[center +1:]

    usiro.reverse()
    usiro_x = []
    mae_x = []
    cot = 0
    usiro.append("@")
    for c in usiro:
        if c == "x":
            cot += 1
        else:
            usiro_x.append(cot)
            cot = 0
    cot = 0
    mae.append("@")
    for c in mae:
        if c == "x":
            cot += 1
        else:
            mae_x.append(cot)
            cot = 0
    ans = 0
    for a,b in zip(mae_x,usiro_x):
        ans += abs(a-b)
    print(ans)
Problem p03608 (python)

Fixed submission:

import itertools

def do():
    N,M,R = list(map(int,input().split(" ")))
    rs = list(map(int,input().split(" ")))
    INF = 10 ** 20
    graph = [ [INF for _ in range(N + 1)]for _ in range(N + 1)]
    for _ in range(M):
        a,b,c = (map(int, input().split(" ")))
        graph[a][b] = c
        graph[b][a] = c
    for k in range(1,N+1):
        for j in range(1, N + 1):
            for i in range(1, N + 1):
                graph[j][i] = min(graph[j][i] , graph[j][k] + graph[k][i])

    perms = itertools.permutations(rs)
    ans = INF
    for temp in perms:
        cand = 0
        for i in range(0,R-1):
            fr = temp[i]
            to = temp[i + 1]
            cand+= graph[fr][to]
        ans = min(cand,ans)
    print(ans)

if __name__ == "__main__":
    do()

Buggy submission (verdict: Runtime Error):

import itertools
from scipy.sparse.csgraph import floyd_warshall as wf

def do():
    N,M,R = list(map(int,input().split(" ")))
    rs = list(map(int,input().split(" ")))
    INF = float('inf')

    graph = [ [INF for _ in range(N + 1)]for _ in range(N + 1)]
    for _ in range(M):
        a,b,c = (map(int, input().split(" ")))
        graph[a][b] = c
        graph[b][a] = c

    graph = wf(graph)

    perms = itertools.permutations(rs)
    ans = INF
    for temp in perms:
        cand = 0
        for i in range(0,R-1):
            fr = temp[i]
            to = temp[i + 1]
            cand+= graph[fr][to]
        ans = min(cand,ans)
    print(int(ans))

if __name__ == "__main__":
    do()
Problem p03612 (python)

Fixed submission:
N=int(input())
p=list(map(int,input().split(" ")))
i=0
c=0
while i<N:
    if p[i]==i+1:
        if i<N-1 and p[i+1]==i+2:
            c+=1
            i+=1
        else:
            c+=1
    i+=1

print(c)

Buggy submission (verdict: Runtime Error):
N=int(input())
p=list(map(int,input().split(" ")))
i=0
c=0
while i<N:
    if p[i]==i+1:
        if i<N and p[i+1]==i+2:
            c+=1
            i+=1
        else:
            c+=1
    i+=1

print(c)
Problem p03637 (python)

Fixed submission:
import itertools
import math
N = int(input())
As =list(map(int,input().split(" ")))
odds = 0
two = 0
four = 0
nums = []
for a in As:
    if a % 2 == 1:
        odds += 1
    elif a % 4 == 0:
        four += 1
    else:
        two += 1
if odds > 0:
    nums.append(1)
    odds -= 1
elif two > 0:
    nums.append(2)
    two -=1
else:
    nums.append(4)
    four-=1
ans = "Yes"

if N==2:
    if As[0] * As[1]%4 !=0:
       ans = "No"
else:
    for i in range(1,N):
        if nums[i-1] == 1:
            if four > 0:
                nums.append(4)
                four -=1
            else:
                ans = "No"
                break
        elif nums[i - 1] == 2:
            if two> 0:
                nums.append(2)
                two -= 1
            elif four > 0:
                nums.append(4)
                four -=1
            else:
                ans = "No"
                break
        elif nums[i - 1] == 4:
            if odds> 0:
                nums.append(1)
                odds -= 1
            elif two> 0:
                nums.append(2)
                two -= 1
            elif four > 0:
                nums.append(4)
                four -=1

print(ans)

Buggy submission (verdict: Runtime Error):
import itertools
import math
N = int(input())
As =list(map(int,input().split(" ")))
odds = 0
two = 0
four = 0
nums = []
for a in As:
    if a % 2 == 1:
        odds += 1
    elif a % 4 == 0:
        four += 1
    else:
        two += 1
if odds > 0:
    nums.append(1)
    odds -= 1
elif two > 0:
    nums.append(2)
    two -=1
else:
    nums.append(4)
    four-=1
ans = "Yes"

if N==2:
    if As[0] * As[1]%4 !=0:
       ans = "No"
else:
    for i in range(1,N):
        if nums[i-1] == 1:
            if four > 0:
                nums.append(4)
                four -=1
            else:
                ans = "No"
        elif nums[i - 1] == 2:
            if two> 0:
                nums.append(2)
                two -= 1
            elif four > 0:
                nums.append(4)
                four -=1
            else:
                ans = "No"

        elif nums[i - 1] == 4:
            if odds> 0:
                nums.append(1)
                odds -= 1
            elif two> 0:
                nums.append(2)
                two -= 1
            elif four > 0:
                nums.append(4)
                four -=1

print(ans)
Problem p03651 (python)

Fixed submission:
import fractions

N,K =list(map(int,input().split(" ")))
As= list(map(int,input().split(" ")))
g = As[0]
ma = -1
for a in As:
    g = fractions.gcd(g,a)
    ma = max(ma,a)
    if K == a:
        print("POSSIBLE")
        exit()
if K % g == 0 and ma >= K:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Buggy submission (verdict: Runtime Error):
import math

N,K =list(map(int,input().split(" ")))
As= list(map(int,input().split(" ")))
g = As[0]
ma = -1
for a in As:
    g = math.gcd(g,a)
    ma = max(ma,a)
    if K == a:
        print("POSSIBLE")
        exit()
if K % g == 0 and ma >= K:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")
Problem p03662 (python)

Fixed submission:

import math
import sys
sys.setrecursionlimit(1000000)
N = int(input())
graph = {}
SCORE = 0
def dfs(visted,v,depth):
    visted[v] = depth
    for next_v in graph[v]:
        if  visted[next_v]  == -1 :
            dfs(visted,next_v,depth + 1)




for _ in range(N-1):
    a,b = map(int,input().split(" "))
    if a not in graph:
        graph[a] = [b]
    else:
        graph[a].append(b)

    if b not in graph:
        graph[b] = [a]
    else:
        graph[b].append(a)

vF = [-1] * (N + 1)
vF[1] = 0
dfs(vF,1,0)
# print(vF)

vS = [-1] * (N + 1)
vS[N] = 0

dfs(vS,N,0)
# print(vS)

fc = 0
sc = 0

for f,s in zip(vF[1:N + 1],vS[1:N + 1]):
    if f <= s:
        fc += 1
    else:
        sc += 1

# print(fc,sc)
if fc > sc:
    print("Fennec")
else:
    print("Snuke")

Buggy submission (verdict: Runtime Error):

import math
N = int(input())
graph = {}
SCORE = 0
def dfs(visted,v,depth):
    visted[v] = depth
    for next_v in graph[v]:
        if  visted[next_v]  == -1 :
            dfs(visted,next_v,depth + 1)




for _ in range(N-1):
    a,b = map(int,input().split(" "))
    if a not in graph:
        graph[a] = [b]
    else:
        graph[a].append(b)

    if b not in graph:
        graph[b] = [a]
    else:
        graph[b].append(a)

vF = [-1] * (N + 1)
vF[1] = 0
dfs(vF,1,0)
# print(vF)

vS = [-1] * (N + 1)
vS[N] = 0

dfs(vS,N,0)
# print(vS)

fc = 0
sc = 0

for f,s in zip(vF[1:N + 1],vS[1:N + 1]):
    if f <= s:
        fc += 1
    else:
        sc += 1

# print(fc,sc)
if fc > sc:
    print("Fennec")
else:
    print("Snuke")
Problem p03762 (python)

Fixed submission:

n,m =list(map(int,input().split(" ")))
xs  =list(map(int,input().split(" ")))
ys =list(map(int,input().split(" ")))
MOD = (10**9) + 7
x_diff = [abs(i - j) for i,j in zip(xs[:n-1],xs[1:n]) ]
y_diff = [abs(i - j) for i,j in zip(ys[:m-1],ys[1:m]) ]

cot = 1
x = 0
for i in range(n -1 ):
    x +=cot * (n-i -1) * x_diff[i]
    cot += 1

cot = 1
y = 0
for i in range(m -1):
    y += cot * (m-i -1) * y_diff[i]
    cot += 1



print (x* y % MOD )

Buggy submission (verdict: Runtime Error):

n,m =list(map(int,input().split(" ")))
xs  =list(map(int,input().split(" ")))
ys =list(map(int,input().split(" ")))
MOD = (10**9) + 7
x_diff = [abs(i - j) for i,j in zip(xs[:n-1],xs[1:n]) ]
y_diff = [abs(i - j) for i,j in zip(ys[:n-1],ys[1:n]) ]

cot = 1
x = 0
for i in range(n -1 ):
    x +=cot * (n-i -1) * x_diff[i]
    cot += 1

cot = 1
y = 0
for i in range(m -1):
    y += cot * (m-i -1) * y_diff[i]
    cot += 1



print (x* y % MOD )