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

Fixed submission:
S = input()
N = len(S)

ans = N//2 + bool(N%2)


# 奇数
if N%2 == 1:
    left = S[:N//2]
    left = left[::-1]
    right = S[N//2+1:]
    cent = S[N//2]
    
    i = 0
    while i < N//2:
        if left[i] == cent and right[i] == cent:
            ans += 1
            i += 1
        else:
            break
        
else:
    left = S[:N//2]
    left = left[::-1]
    right = S[N//2:]
    cent = S[N//2]
    
    i = 0
    while i < N//2:
        if left[i] == cent and right[i] == cent:
            ans += 1
            i += 1
        else:
            break
        
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m = li()

graph = [[] for _ in range(n)]
for _ in range(m):
    l,r,d = li()
    l -= 1
    r -= 1
    graph[l].append((d,r))
    graph[r].append((-d,l))
    
searched = [False]*n
dist = [float("inf") for _ in range(n)]

exist = True
for i in range(n):
    if not searched[i]:
        dist[i] = 0
        searched[i] = True
        stack = [(0,i)]
        
        while stack:
            cost, cur = stack.pop()
            for nex_cost, nex_node in graph[cur]:
                if searched[nex_node]:
                    if cost + nex_cost != dist[nex_node]:
                        exist = False
                        
                else:
                    stack.append((cost+nex_cost, nex_node))
                    dist[nex_node] = cost + nex_cost
                    searched[nex_node] = True
                    
print("Yes") if exist else print("No")
Problem p03546 (python)

Fixed submission:
from heapq import heappush, heappop

#1. 入力
H,W = map(int, input().split())

INF = float("inf")
graph1 = []

for i in range(10):
    graph1.append(list(map(int, input().split())))

graph2 = [[] for _ in range(10)]
for i in range(10):
    for j in range(10):
        graph2[i].append((graph1[i][j], j))

A = []
for i in range(H):
    A.append(list(map(int, input().split())))

#2. ダイクストラ
def dijkstra(graph:list, node:int, start:int) -> list:
    # 未探索のノードは距離INF
    INF = float("inf")
    dist = [INF]*node
    
    # 始点ノードの距離を0とし、dfsのためのpriority queを作成
    dist[start] = 0
    heap = [(0,start)]
    
    # 未探索のノードをpriority queueに入れる
    while heap:
        cost, cur_node = heappop(heap)
        
        for nex_cost, nex_node in graph[cur_node]:
            dist_cand = dist[cur_node] + nex_cost
            if dist_cand < dist[nex_node]:
                dist[nex_node] = dist_cand
                heappush(heap, (dist[nex_node], nex_node))
    
    return dist

dist_to1 = []
for i in range(10):
    dist = dijkstra(graph2, 10, i)
    dist_to1.append(dist[1])

ans = 0
for h in range(H):
    for w in range(W):
        if A[h][w] == -1:
            continue
        else:
            ans += dist_to1[A[h][w]]
    
print(ans)

Buggy submission (verdict: Runtime Error):
h,w = map(int, input().split())
cost = [list(map(int, input().split())) for _ in range(10)]
wall = [list(map(int, input().split())) for _ in range(h)]

nuns = 10

for k in range(nums):
  for i in range(nums):
    for j in range(nums):
      cost[i][j] = min(cost[i][j],
                       cost[i][k] + cost[k][j])

ans = 0
for wi in wall:
  for wij in wi:
    ans += 0 if wij == 0 else cost[wij][1]
    
print(ans)

Buggy submission (verdict: Runtime Error):
h,w = map(int, input().split())
cost = [lh,w = map(int, input().split())
cost = [list(map(int, input().split())) for _ in range(10)]
wall = [list(map(int, input().split())) for _ in range(h)]

nuns = 10

for k in range(nums):
  for i in range(nums):
    for j in range(nums):
      cost[i][j] = min(cost[i][j],
                       cost[i][k] + cost[k][j])

ans = 0
for wi in wall:
  for wij in wi:
    ans += 0 if wij == 0 else cost[wij][1]
    
print(h,w = map(int, input().split())
cost = [list(map(int, input().split())) for _ in range(10)]
wall = [list(map(int, input().split())) for _ in range(h)]

nuns = 10

for k in range(nums):
  for i in range(nums):
    for j in range(nums):
      cost[i][j] = min(cost[i][j],
                       cost[i][k] + cost[k][j])

ans = 0
for wi in wall:
  for wij in wi:
    ans += 0 if wij == 0 else cost[wij][1]
    
print(ans)
Problem p03569 (python)

Fixed submission:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import deque

s = deque(lc())
lens = len(s)

ok = True
ans = 0

while len(s):
    if len(s) == 1:
        s.pop()
    
    elif s[0] == s[-1]:
        s.pop()
        s.popleft()
        
    else:
        if s[0] == "x":
            s.append("x")
            ans += 1
        elif s[-1] == "x":
            s.appendleft("x")
            ans += 1
        else:
            ok = False
            break
    
if ok:
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


# 回文判定
def judge(s):
    news = ""
    for si in s:
        if si != 'x':
            news += si

    if news == news[::-1]:
        return True
    else:
        return False

# 操作の最小値
def min_insertion(s):
    news = ""
    for si in s:
        if si != 'x':
            news += si

    n = len(news)
    fir = [0] * ((n+1)//2)
    lat = [0] * ((n + 1) // 2)

    # 前半
    cursor = 0
    for si in s:
        if si == 'x':
            fir[cursor] += 1
        else:
            cursor += 1

        if cursor == (n+1)//2:
            break

    # 後半
    cursor = 0
    for si in s[::-1]:
        if si == 'x':
            lat[cursor] += 1
        else:
            cursor += 1

        if cursor == (n + 1) // 2:
            break

    ans = 0
    for firi, lati in zip(fir, lat):
        ans += abs(firi - lati)

    return ans


# 入力
s = ns()

# x以外の回文判定
is_kaibun = judge(s)

# 回文でないならおわり
# 回文ならば最小値出す
if is_kaibun:
    print(min_insertion(s))
else:
    print(-1)
Problem p03599 (python)

Fixed submission:
a,b,c,d,e,f = map(int, input().split())

ab_list = set()

for i in range(0,f//100+1,a):
    for j in range(0, f//100-i+1, b):
        ab_list.add(100*(i+j))

ab_max = max(ab_list)

sug_max = int(ab_max*(e/100))

cd_list = set()

for i in range(0,sug_max+1, c):
    for j in range(0, sug_max-i+1, d):
        cd_list.add(i+j)

water = list(ab_list)
water.sort()

sugar = list(cd_list)
sugar.sort()

max_noudo = -1
ans = [0,-1]
for w in water:
    for s in sugar:
        if w==0 and s==0:
            continue
        if 100*s <= e*w and w+s <= f:
            noudo = s/(w+s)
            if noudo > max_noudo:
                max_noudo = noudo
                ans = [w+s, s]
                
print(*ans)

Buggy submission (verdict: Runtime Error):
a,b,c,d,e,f = map(int, input().split())

ab_list = set()

for i in range(0,f//100+1,a):
    for j in range(0, f//100-i+1, b):
        ab_list.add(100*(i+j))

ab_max = max(ab_list)

sug_max = int(ab_max*(e/100))

cd_list = set()

for i in range(0,sug_max+1, c):
    for j in range(0, sug_max-i+1, d):
        cd_list.add(i+j)


water = list(ab_list)
water.sort()

sugar = list(cd_list)
sugar.sort()

s = 0
ans = [0,0]
max_noudo = 0
for w in water[1:]:
    while (sugar[s+1] <= int(w*e/100)):
        if (s+1) >= len(sugar)-1:
            break
        s += 1
        
    noudo = sugar[s]/(w+sugar[s])
    if noudo > max_noudo:
        max_noudo = noudo
        ans = [w+sugar[s], sugar[s]]
        
print(*ans)
Problem p03600 (python)

Fixed submission:
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
import sys
sdin = sys.stdin.readline

n = int(sdin())
graph = np.array([[0 for _ in range(n)] for _ in range(n)], dtype=float)
for i in range(n):
    graph[i] = np.array(list(map(int, sdin().split())))
    
# ワーシャルフロイドで最短距離出す
shortest = floyd_warshall(graph, directed=False)


if any([graph[i,j] != shortest[i,j] for i in range(n) for j in range(n)]):
    print(-1)
    
else:
    total = 0
    INF = float("inf")
    
    for i in range(n):
        graph[i,i] = INF
    
    for i in range(n):
        for j in range(i+1,n):
            via_k = np.min(graph[i] + graph[j])
            
            if via_k > graph[i,j]:
                total += graph[i,j]
                
    print(int(total))

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import floyd_warshall
import numpy as np

file = open("ABC074D.txt", "r")

n = int(file.readline())
graph = np.array([[0 for _ in range(n)] for _ in range(n)], dtype=float)
for i in range(n):
    graph[i] = np.array(list(map(int, file.readline().split())))
    
# ワーシャルフロイドで最短距離出す
shortest = floyd_warshall(graph, directed=False)


if any([graph[i,j] != shortest[i,j] for i in range(n) for j in range(n)]):
    print(-1)
    
else:
    total = 0
    INF = float("inf")
    
    for i in range(n):
        graph[i,i] = INF
    
    for i in range(n):
        for j in range(i+1,n):
            via_k = np.min(graph[i] + graph[j])
            
            if via_k > graph[i,j]:
                total += graph[i,j]
                
    print(int(total))
Problem p03628 (python)

Fixed submission:
MOD = 1000000007

N = int(input())
S = []
for i in range(2):
    S.append(input())
    

# make XYline
xy = ""
for i in range(len(S[0])):
    if S[0][i] == S[1][i]:
        xy += "X"
    elif i==len(S[0])-1:
        break
    elif S[0][i] == S[0][i+1]:
        xy += "Y"

# proceed
if xy[0] == "X":
    ans = 3
else:
    ans = 6

if len(xy)==1:
    pass
else:
    for i in range(1,len(xy)):
        if xy[i-1] == "X" and xy[i] == "X":
            ans *= 2
        elif xy[i-1] == "X" and xy[i] == "Y":
            ans *= 2
        elif xy[i-1] == "Y" and xy[i] == "X":
            ans *= 1
        elif xy[i-1] == "Y" and xy[i] == "Y":
            ans *= 3

        ans = ans%MOD
print(ans)

Buggy submission (verdict: Runtime Error):
MOD = 1000000007

N = int(input())
S = []
for i in range(2):
    S.append(input())
    

# make XYline
xy = ""
for i in range(len(S[0])):
    if S[0][i] == S[1][i]:
        xy += "X"
    elif S[0][i] == S[0][i+1]:
        xy += "Y"

# proceed
if xy[0] == "X":
    ans = 3
else:
    ans = 6

if len(xy)==1:
    pass
else:
    for i in range(1,len(xy)):
        if xy[i-1] == "X" and xy[i] == "X":
            ans *= 2
        elif xy[i-1] == "X" and xy[i] == "Y":
            ans *= 2
        elif xy[i-1] == "Y" and xy[i] == "X":
            ans *= 1
        elif xy[i-1] == "Y" and xy[i] == "Y":
            ans *= 3

        ans = ans%MOD

    
print(ans)
Problem p03639 (python)

Fixed submission:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

odd = 0
ml2 = 0
ml4 = 0

for ai in a:
    if ai % 2:
        odd += 1
    elif ai % 4:
        ml2 = 1
    else:
        ml4 += 1

print("Yes" if (odd + ml2) <= (ml4 + 1) else "No")

Buggy submission (verdict: Runtime Error):
import sys
#stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
a = list(li())

odd = 0
ml2 = 0
ml4 = 0

for ai in a:
    if ai % 2:
        odd += 1
    elif ai % 4:
        ml2 = 1
    else:
        ml4 += 1

print("Yes" if (odd + ml2) <= (ml4 + 1) else "No")
Problem p03673 (python)

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

if N%2 == 0:
    b = A[N-1::-2] + A[0::2]
else:
    b = A[N-1::-2] + A[1::2]
    
print(*b)

Buggy submission (verdict: Runtime Error):
from collections import deque

n = int(input())
a = list(map(int,input().split()))

b = deque([])

for i,ai in enumerate(a):
  if i%2 == 0:
    b.append(ai)
    
  else:
    b.appendleft(ai)
    
if n%2 == 1:
  print(*b[::-1])
else:
  print(*b)
Problem p03687 (python)

Fixed submission:
from collections import Counter

s = input()

cnt = Counter(s)

if len(cnt.keys()) == 1:
    print(0)
    
else:
    al_set = set(s)
    c = list(s)
    
    dic = {}
    for alpha in al_set:
        c_prev = [ci for ci in c]
        count = 0
        while any([ci != alpha for ci in c_prev]):
            c_new = []
            for j in range(len(c_prev) - 1):
                if c_prev[j] == alpha or c_prev[j+1] == alpha:
                    c_new.append(alpha)
                else:
                    c_new.append("0")
                    
            c_prev = c_new
            count += 1

            
        dic[alpha] = count
        
    print(min(dic.values()))

Buggy submission (verdict: Runtime Error):
from collections import Counter

s = input()

cnt = Counter(s)

if len(cnt.keys()) == 1:
    print(0)
    
else:
    al_set = set(s)
    c = list(s)
    
    dic = {}
    for alpha in al_set:
        c_prev = [ci for ci in c]
        count = 0
        while any([ci != alpha for ci in c_prev]):
            c_new = []
            for j in range(len(c_prev) - 1):
                if c_prev[j] == alpha or c_prev[j+1] == alpha:
                    c_new.append(alpha)
                else:
                    c_new.append("0")
                    
            c_prev = c_new
            count += 1

            
        dic[alpha] = count
        
print(min(dic.values()))
Problem p03695 (python)

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

p_num = [0]*9

for a in A:
    if a<3200:
        p_num[a//400] += 1
    else:
        p_num[-1] += 1
    
ans = 0
for p in p_num[:-1]:
    if p:
        ans +=1
        
ans_min = max(ans,1) 
ans_max = ans + p_num[-1]

print(ans_min, ans_max)

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

p_num = [0]*9

for a in A:
    p_num[a//400] += 1
    
ans = 0
for p in p_num[:-1]:
    if p:
        ans +=1
        
ans_min = ans
ans_max = ans + p_num[-1]

print(ans_min, ans_max)
Problem p03732 (python)

Fixed submission:

from collections import defaultdict

N,W = map(int, input().split())
WV = []
for i in range(N):
    WV.append(list(map(int, input().split())))

dp = defaultdict(int)

dp[0] = 0

for w,v in WV:
    for nw, nv in list(dp.items()):
        if nw+w <= W:
            dp[nw+w] = max(dp[nw+w], nv+v)
            
print(max(dp.values()))

Buggy submission (verdict: Runtime Error):
#import sys
#stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

from itertools import accumulate

n,w = li()
wi,vi = li()
w0 = wi
v_list = [[0] for _ in range(4)]
v_list[0].append(vi)

for _ in range(n-1):
    wi,vi = li()
    v_list[wi-w0].append(vi)
    
for i in range(4):
    v_list[i].sort(reverse=True)
    v_list[i] = list(accumulate(v_list[i]))
    
ans = 0
res = w
for w1 in range(len(v_list[0])):
    
    if w - w0*(w1) < 0:
        pass
    else:
        res1 = w - w0*(w1)
        ans1 = v_list[0][w1]
        ans = max(ans, ans1)
    

    for w2 in range(len(v_list[1])):

        if res1 - (w0+1)*(w2) < 0:
            pass
        
        else:
            res2 = res1 - (w0+1)*(w2)
            ans2 = ans1 + v_list[1][w2]
            ans = max(ans, ans2)

        
        
        for w3 in range(len(v_list[2])):
            
            if res2 - (w0+2)*(w3) < 0:
                pass
            
            else:
                res3 = res2 - (w0+2)*(w3)
                ans3 = ans2 + v_list[2][w3]
                ans = max(ans, ans3)
                
            
            for w4 in range(len(v_list[3])):

                if res3 - (w0+3)*(w4) < 0:
                    pass
                
                else:
                    res4 = res3 - (w0+3)*(w4)
                    ans4 = ans3 + v_list[3][w4]
                    ans = max(ans, ans4)

                
print(ans)
Problem p03780 (python)

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

# K以上のものはAから省く
B = []
for a in A:
    if a<K:
        B.append(a)

B.sort(reverse=True)

isNeeded = [False]*(len(B))
# iをスタックに入れる
for i in range(len(B)-1):
    res = B[i]
    stack = [i]
    for j in range(i+1,len(B)):
        res += B[j]
        stack.append(j)
        if res >= K:
            for s in stack:
                isNeeded[s] = True
            stack.pop()
            res -= B[j]
            
noNeed = len(B) - sum(isNeeded)
print(noNeed)

Buggy submission (verdict: Runtime Error):
# 入力
file = open("g080D.txt", "r")
stdin = file

import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

from collections import Counter

n,k = li()
a = li()

a_ltk = [ai for ai in a if ai < k]
a_ltk.sort(reverse=True)
need = {ai:False for ai in a_ltk}

# 貪欲に足していく
for i in range(len(a_ltk)):
    cur = 0
    stack = []
    for j in range(i,len(a_ltk)):
        cur += a_ltk[j]
        stack.append(a_ltk[j])
        if cur >= k:
            for key in stack:
                need[key] = True
            stack.pop()
            cur -= a_ltk[j]

                
cnt = Counter(a_ltk)
ans = 0

for k,v in need.items():
    if not v:
        ans += cnt[k]
        
print(ans)
Problem p03826 (python)

Fixed submission:
import sys
stdin = sys.stdin

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

a,b,c,d = li()

if a*b < c*d:
    print(c*d)
else:
    print(a*b)

Buggy submission (verdict: Runtime Error):
import math

prime = {}

N = int(input())

if N==1:
    print(1)
    exit()

isPrime = [True]*(N+1)
isPrime[0] = False
isPrime[1] = False
for i in range(2,int(math.sqrt(N))+2):
    if isPrime[i]:
        n = 2*i
        while n<=N:
            isPrime[n] = False
            n += i

for i in range(N+1):
    if isPrime[i]:
        prime[i] = 0

key_list = list(prime.keys())

for num in range(2,N+1):
    res = num
    idx = 0
    while res>1:
        k = key_list[idx]
        if res%k == 0:
            prime[k] += 1
            res = res//k
        else:
            idx += 1
    
ans = 1
for v in prime.values():
    ans *= (v+1) 
    ans = ans % (10**9+7)
    if ans==0:
        ans = 1
    
print(ans)
Problem p03828 (python)

Fixed submission:
import math

prime = {}

N = int(input())

def judge(N):

    if N==1:
        print(1)
        return 0

    isPrime = [True]*(N+1)
    isPrime[0] = False
    isPrime[1] = False
    for i in range(2,int(math.sqrt(N))+2):
        if isPrime[i]:
            n = 2*i
            while n<=N:
                isPrime[n] = False
                n += i
    
    for i in range(N+1):
        if isPrime[i]:
            prime[i] = 0
    
    key_list = list(prime.keys())
    
    for num in range(2,N+1):
        res = num
        idx = 0
        while res>1:
            k = key_list[idx]
            if res%k == 0:
                prime[k] += 1
                res = res//k
            else:
                idx += 1
        
    ans = 1
    for v in prime.values():
        ans *= (v+1) 
        ans = ans % (10**9+7)
        if ans==0:
            ans = 1
        
    print(ans)
    return 0

judge(N)

Buggy submission (verdict: Runtime Error):
import math

prime = {}

N = int(input())

isPrime = [True]*(N+1)
isPrime[0] = False
isPrime[1] = False
for i in range(2,int(math.sqrt(N))+2):
    if isPrime[i]:
        n = 2*i
        while n<=N:
            isPrime[n] = False
            n += i

for i in range(N+1):
    if isPrime[i]:
        prime[i] = 0

key_list = list(prime.keys())

for num in range(2,N+1):
    res = num
    idx = 0
    while res>1:
        k = key_list[idx]
        if res%k == 0:
            prime[k] += 1
            res = res//k
        else:
            idx += 1
    
ans = 1
for v in prime.values():
    ans *= (v+1) 
    ans = ans % (10**9+7)
    if ans==0:
        ans = 1
    
print(ans)

Buggy submission (verdict: Runtime Error):
import math

prime = {}

N = int(input())

isPrime = [True]*(N+1)
isPrime[0] = False
isPrime[1] = False
for i in range(2,int(math.sqrt(N))+2):
    if isPrime[i]:
        n = 2*i
        while n<=N:
            isPrime[n] = False
            n += i

for i in range(N+1):
    if isPrime[i]:
        prime[i] = 0

key_list = list(prime.keys())

for num in range(2,N+1):
    res = num
    idx = 0
    while res>1:
        k = key_list[idx]
        if res%k == 0:
            prime[k] += 1
            res = res//k
        else:
            idx += 1
    
ans = 1
for v in prime.values():
    ans *= (v+1) 
    ans = ans % (10**9+7)
    
print(ans)
Problem p03829 (python)

Fixed submission:
from collections import deque

N,A,B = map(int, input().split())
X = list(map(int, input().split()))

INF = float("inf")

dist = deque(X)

next_x = +1
i = 0
ans = 0
while len(dist) != 1:

    if A*abs(dist[i+next_x] - dist[i]) <= B:
        ans += A*abs(dist[i+next_x] - dist[i])
        if next_x == 1:
            dist.popleft()
            i = 0
        else:
            dist.pop()
            i = len(dist)-1
    else:
        ans += B
        if next_x == 1:
            dist.popleft()
            i = len(dist)-1
        else:
            dist.pop()
            i = 0
        
        next_x = -next_x
        
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque

N,A,B = map(int, input().split())
X = list(map(int, input().split()))

INF = float("inf")

dist = deque(X)

next_x = +1
i = 0
ans = 0
while len(dist) != 1:

    if A*abs(dist[i+next_x] - dist[i]) <= B:
        ans += A*abs(dist[i+next_x] - dist[i])
        if next_x == 1:
            dist.popleft()
            i = 0
        else:
            dist.pop()
            i = len(dist)
    else:
        ans += B
        if next_x == 1:
            dist.popleft()
            i = len(dist)-1
        else:
            dist.pop()
            i = 0
        
        next_x = -next_x
        
print(ans)