Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    from scipy.sparse.csgraph import dijkstra
    n = int(input())
    G = [[float('inf') for i in range(n)] for i in range(n)]
    for _ in range(n-1):
        a,b,c = map(int,input().split())
        G[a-1][b-1] = G[b-1][a-1] = c
    q,k = map(int,input().split())
    d = dijkstra(G)[k-1]
    for _ in range(q):
        x,y = map(int,input().split())
        print(int(d[x-1]+d[y-1]))

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    G = {}
    for i in range(n):
        G[i+1] = []
    for _ in range(n-1):
        a,b,c = map(int,input().split())
        G[a] += [[b,c]]
        G[b] += [[a,c]]
    q,k = map(int,input().split())
    dist = [-1]*n
    dist[k-1] = 0
    que = [k]
    while len(que) > 0:
        s = que.pop(0)
        for [nv,c] in G[s]:
            if dist[nv-1] != -1:
                continue
            dist[nv-1] = dist[s-1]+c
            que.append(nv)
    for _ in range(q):
        x,y = map(int,input().split())
        print(dist[x-1]+dist[y-1])

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
def dijkstra(g,n,s):
    '''
    input
        g: n x n　list
        n: int
        s: start index
    '''
    d = [float('inf')]*n
    U = [i for i in range(n)]
    d[s] = 0
    while len(U)>0:
        w = U[0]
        for u in U:
            if d[u]<d[w]:
                w = u
        U.pop(U.index(w))
        for v in U:
            d[v] = min(d[v],d[w]+g[w][v])
    return d

def main():
    n = int(input())
    G = [[float('inf') for i in range(n)] for i in range(n)]
    for _ in range(n-1):
        a,b,c = map(int,input().split())
        G[a-1][b-1] = G[b-1][a-1] = c
    q,k = map(int,input().split())
    d = dijkstra(G, n, k-1)
    for _ in range(q):
        x,y = map(int,input().split())
        print(d[x-1]+d[y-1])

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    n = int(input())
    G = {}
    for i in range(n):
        G[i+1] = []
    for _ in range(n-1):
        a,b,c = map(int,input().split())
        G[a] += [[b,c]]
        G[b] += [[a,c]]
    q,k = map(int,input().split())
    dist = [-1]*n
    dist[k-1] = 0
    que = [k]
    while len(que) > 0:
        s = que.pop(0)
        for [nv,c] in G[s]:
            if dist[nv-1] != -1:
                continue
            dist[nv-1] = dist[s-1]+c
            que.append(nv)
    for _ in range(q):
        x,y = map(int,input().split())
        print(dist[x-1]+dist[y-1])

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
K=int(input())

a,b = map(int, input().split())

def m(a,b,c):
	for i in (a, b+1):
  		if i%k==0:
          print("OK")
          return
    print("NG")
    return
m(a,b,k)

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

def m(a,b,c):
    for i in range(a, b+1):
        if i%c==0:
            print("OK")
            return
    print("NG")
    return

m(a,b,k)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = lambda: sys.stdin.readline().rstrip()

# 迷路読み込み
H,W = map(int, input().split())
c1,c2= map(int, input().split())
d1,d2= map(int, input().split())
A=[list(input()) for i in range(H)]
edges = [[] for i in range(H * W)]

for i in range(H):
    for j in range(W):
        for di in range(-2,3):
            for dj in range(-2, 3):
                ni, nj = i + di, j + dj
                if 0 <= ni < H and 0 <= nj < W and A[i][j]!='#' and A[ni][nj]!='#':
                    if di==0 and dj==0:
                        continue
                    elif (di==0 and dj==1) or (di==1 and dj==0) or (di==-1 and dj==0) or (di==0 and dj==-1):
                        edges[i * W + j].append((ni * W + nj,0))
                    else:
                        edges[i * W + j].append((ni * W + nj,1))


#ダイクストラ法
from heapq import heappush, heappop

def dijkstra(edges, size, source):
    # edge=探索するグラフ
    # size=グラフの点の数
    # source=スタート点
    distance = [float('inf')] * size
    distance[source] = 0
    visited = [False] * size
    pq = []
    heappush(pq, (0, source))
    while pq:
        dist_v, v = heappop(pq)
        visited[v] = True
        for u, weight in edges[v]:
            if not visited[u]:
                new_dist = dist_v + weight
                if distance[u] > new_dist:
                    distance[u] = new_dist
                    heappush(pq, (new_dist, u))
    return distance[g]

s=(c1-1)*W+(c2-1)
g=(d1-1)*W+d2-1
ans=dijkstra(edges,H*W,s)
if ans==float('inf'):
    print(-1)
else:
    print(ans)


Fixed submission:
import sys
input = lambda: sys.stdin.readline().rstrip()
from collections import deque

# 迷路読み込み
H,W = map(int, input().split())
c1,c2= map(int, input().split())
d1,d2= map(int, input().split())
A=[list(input()) for i in range(H)]
edges = [[] for i in range(H * W)]

for i in range(H):
    for j in range(W):
        for di in range(-2,3):
            for dj in range(-2, 3):
                ni, nj = i + di, j + dj
                if 0 <= ni < H and 0 <= nj < W and A[i][j]!='#' and A[ni][nj]!='#':
                    if di==0 and dj==0:
                        continue
                    elif (di==0 and dj==1) or (di==1 and dj==0) or (di==-1 and dj==0) or (di==0 and dj==-1):
                        edges[i * W + j].append((ni * W + nj,0))
                    else:
                        edges[i * W + j].append((ni * W + nj,1))

s=(c1-1)*W+c2-1
g=(d1-1)*W+d2-1
dist = [10**9]*(H*W)
dist[s] = 0
que = deque()
que.append(s)

while len(que) > 0:
    i = que.popleft()
    for j, c in edges[i]:
        d = dist[i] + c
        if d < dist[j]:
            dist[j] = d
            if c == 1:
                que.append(j)
            else:
                que.appendleft(j)


ans=dist[g]
if ans==pow(10,9):
    print(-1)
else:
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())

# mod k で考える
mod=k

for i in range(1,10**6+1):
    if mod>7*int(str(1)*i):
        continue
    else:
        if mod==k:
            mod = 7 * int(str(1) * i) % mod
            if mod == 0:
                print(i)
                exit()
        else:
            mod= (mod*10+7)%k
            if mod==0:
                print(i)
                exit()

print(-1)


Fixed submission:
k=int(input())

cur=0
for i in range(k+2):
    cur=(cur*10+7)%k
    if cur==0:
        print(i+1)
        exit()

print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())

# mod k で考える
mod=k
cnt=7
for i in range(1,k+2):
    if mod>cnt:
        cnt = cnt * 10 + 7
        continue
    else:
        mod = cnt % k
        if mod == 0:
            print(i)
            exit()
        cnt = cnt * 10 + 7

print(-1)

Fixed submission:
k=int(input())

cur=0
for i in range(k+2):
    cur=(cur*10+7)%k
    if cur==0:
        print(i+1)
        exit()

print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())

# mod k で考える
mod=k

for i in range(1,k+2):
    if mod>7*int(str(1)*i):
        continue
    else:
        mod = 7 * int(str(1) * i) % k
        if mod == 0:
            print(i)
            exit()

print(-1)

Fixed submission:
k=int(input())

cur=0
for i in range(k+2):
    cur=(cur*10+7)%k
    if cur==0:
        print(i+1)
        exit()

print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())

# mod k で考える
mod=k

for i in range(1,k+2):
    if mod>7*int(str(1)*i):
        continue
    else:
        if mod==k:
            mod = 7 * int(str(1) * i) % mod
            if mod == 0:
                print(i)
                exit()
        else:
            mod= (mod*10+7)%k
            if mod==0:
                print(i)
                exit()

print(-1)

Fixed submission:
k=int(input())

cur=0
for i in range(k+2):
    cur=(cur*10+7)%k
    if cur==0:
        print(i+1)
        exit()

print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
k=int(input())

# mod k で考える
mod=k

for i in range(1,k+2):
    if mod>7*int(str(1)*i):
        continue
    else:
        if mod==k:
            mod = 7 * int(str(1) * i) % mod
            if mod == 0:
                print(i)
                exit()
        else:
            mod= (mod*10+7)%k
            if mod==0:
                print(i)
                exit()

print(-1)

Fixed submission:
k=int(input())

cur=0
for i in range(k+2):
    cur=(cur*10+7)%k
    if cur==0:
        print(i+1)
        exit()

print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,m= map(int, input().split())
a= list(map(int, input().split()))
a.sort()
mod=998244353

def get_integral_value_combination(list, target):
    def a(idx, l, r, t):
        if t == sum(l): r.append(l)
        elif t < sum(l): return
        for u in range(idx, len(list)):
            a((u + 1), l + [list[u]], r, t)
        return r
    return a(0, [], [], target)

x=get_integral_value_combination(a, m)

ans=0
for i in range(len(x)):
    ans+=pow(2,(n-len(x[i])))
    ans%=mod
print(ans)

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

mod=998244353
#dp[i][j]:i番目まで見て値がjである集合の個数
dp=[[0]*(s+1) for i in range(n+1)]
dp[0][0]=1

for i in range(n):
    for j in range(s+1):
        dp[i+1][j]+=dp[i][j]*2
        dp[i+1][j]%=mod
        if j+a[i]<=s:
            dp[i+1][j+a[i]]+=dp[i][j]
            dp[i+1][j+a[i]]%=mod

print(dp[-1][-1])
Buggy python submission (verdict: Runtime Error):
# ABC 164 E 草案
import sys
sys.setrecursionlimit(10**6)

n,m,s= map(int, input().split())
g= [list(map(int, input().split())) for i in range(m)]
# 両替所
c= [list(map(int, input().split())) for i in range(n)]

x=2501
# 作るグラフ (点,所有銀貨,必要時間)
gg=[[]*x for i in range(n)]
for i in range(n):
    for j in range(x-1):
        # 金貨を銀貨に交換
        y=j+c[i][0]
        if y>=x-1:
            y=x-1
        gg[i][j].append((i,y,c[i][1]))


for i in range(1,x):
    for u,v,a,b in g:
        u-=1
        v-=1
        # 銀貨足りる時移動できる
        if i-a>=0:
            gg[v][i].append((u,i-a,b))
            gg[u][i].append((v,i-a,b))





#ダイクストラ法
from heapq import heappush, heappop

def dijkstra(edges, size, source,gold):
    # edge=探索するグラフ
    # size=グラフの点の数
    # source=スタート点
    distance = [[float('inf')]*x for i in range(n)]
    distance[source][gold] = 0
    visited = [[False]*x for i in range(n)]
    pq = []
    heappush(pq, (0, source,gold))
    while pq:
        dist_v, u,v = heappop(pq)
        visited[u][v] = True
        for u,v, weight in edges[u][v]:
            if not visited[u][v]:
                new_dist = dist_v + weight
                if distance[u][v] > new_dist:
                    distance[u][v] = new_dist
                    heappush(pq, (new_dist, u,v))
    return distance
s=min(2500,s)
ans=dijkstra(gg,n,0,s)

for i in range(1,n):
    print(min(ans[i]))

Fixed submission:
# ABC 164 E 草案
import sys
sys.setrecursionlimit(10**6)

n,m,s= map(int, input().split())
g= [list(map(int, input().split())) for i in range(m)]
# 両替所
c= [list(map(int, input().split())) for i in range(n)]

x=2501
# 作るグラフ (辺*所有銀貨,必要時間)
gg=[[] for i in range(n*x)]
for i in range(n):
    for j in range(x-1):
        # 金貨を銀貨に交換
        y=j+c[i][0]
        if y>=x-1:
            y=x-1
        gg[i*x+j].append((i*x+y,c[i][1]))


for i in range(1,x):
    for u,v,a,b in g:
        u-=1
        v-=1
        # 銀貨足りる時移動できる
        if i-a>=0:
            gg[v*x+i].append((u*x+i-a,b))
            gg[u*x+i].append((v*x+i-a,b))




#ダイクストラ法
from heapq import heappush, heappop

def dijkstra(edges, size, source):
    # edge=探索するグラフ
    # size=グラフの点の数
    # source=スタート点
    distance = [float('inf')] * size
    distance[source] = 0
    visited = [False] * size
    pq = []
    heappush(pq, (0, source))
    while pq:
        dist_v, v = heappop(pq)
        visited[v] = True
        for u, weight in edges[v]:
            if not visited[u]:
                new_dist = dist_v + weight
                if distance[u] > new_dist:
                    distance[u] = new_dist
                    heappush(pq, (new_dist, u))
    return distance
s=min(s,2500)
ans=dijkstra(gg,n*x,s)

for i in range(1, n):
    print(min(ans[x * i:x * (i + 1)]))
Buggy python submission (verdict: Runtime Error):
n,k= map(int, input().split())
print(min(n%k,abs(n%k-k))

Fixed submission:
n,k= map(int, input().split())
print(min(n%k,abs(n%k-k)))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
import sys
input = lambda: sys.stdin.readline().rstrip()

n=int(input())
s= list(input())
q=[]
qq=int(input())
for i in range(qq):
    q.append(list(input().split()))

# アルファベットごとに出現位置を記録
x=[[] for i in range(26)]
for i,j in enumerate(s):
    x[ord(j)-97].append(i)

# 終点対策
for i in range(26):
    x[i].append(float('inf'))


for i,j,k in q:
    if int(i)==1:
        if s[int(j)-1]!=k:
            v=s[int(j)-1]
            s[int(j)-1]=k
            # 変更前の要素を削除
            index=bisect.bisect_right(x[ord(v)-97], int(j)-1) - 1
            x[ord(v)-97].pop(index)
            # 変更後の要素を加える
            bisect.insort_right(x[ord(k)-97],int(j)-1)
    else:
        cnt=0
        j=int(j)-1
        k=int(k)-1
        for l in range(26):
            index=bisect.bisect_left(x[l],j)
            if x[l][index]<=k:
                cnt+=1


        print(cnt)

Fixed submission:
import bisect
import sys
input = lambda: sys.stdin.readline().rstrip()

n=int(input())
s= list(input())
q=[]
qq=int(input())
for i in range(qq):
    q.append(list(input().split()))

# アルファベットごとに出現位置を記録
x=[[] for i in range(26)]
for i,j in enumerate(s):
    x[ord(j)-97].append(i)

# 終点対策
for i in range(26):
    x[i].append(5*10**5)


for i,j,k in q:
    if int(i)==1:
        if s[int(j)-1]!=k:
            v=s[int(j)-1]
            s[int(j)-1]=k
            # 変更前の要素を削除
            index=bisect.bisect_right(x[ord(v)-97], int(j)-1) - 1
            x[ord(v)-97].pop(index)
            # 変更後の要素を加える
            bisect.insort_right(x[ord(k)-97],int(j)-1)
    else:
        cnt=0
        j=int(j)-1
        k=int(k)-1
        for l in range(26):
            index=bisect.bisect_left(x[l],j)
            if x[l][index]<=k:
                cnt+=1


        print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n,a,b= map(int, input().split())
mod = 10 ** 9 + 7
def power_func(a,n,mod):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %mod
    if bi[i]=="1":
      res=(res*a) %mod
  return res


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r=min(r,n-r)

    return g1[n] * g2[r] * g2[n - r] % mod


N =10 ** 9 # 出力の制限
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

ans=(power_func(2,n,mod)-1-cmb(n,a,mod)-cmb(n,b,mod))%mod
print(ans)

Fixed submission:
import math
n,c,d= map(int, input().split())
mod = pow(10,9)+7

def comb(n,k):
    x=1
    y=1
    for i in range(1,k+1):
        x*=(n+1-i)
        x%=mod
        y*=i
        y%=mod
    return x*pow(y,mod-2,mod)


ans=(pow(2,n,mod)-1-comb(n,c)-comb(n,d))%mod
print(ans)

Buggy python submission (verdict: Runtime Error):
import math
n,a,b= map(int, input().split())
mod = 10 ** 9 + 7
def power_func(a,n,mod):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %mod
    if bi[i]=="1":
      res=(res*a) %mod
  return res


def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r=min(r,n-r)

    return g1[n] * g2[r] * g2[n - r] % mod


N =10 ** 6 # 出力の制限
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

for i in range(2, N + 1):
    g1.append((g1[-1] * i) % mod)
    inverse.append((-inverse[mod % i] * (mod // i)) % mod)
    g2.append((g2[-1] * inverse[-1]) % mod)

ans=(power_func(2,n,mod)-1-cmb(n,a,mod)-cmb(n,b,mod))%mod
print(ans)

Fixed submission:
import math
n,c,d= map(int, input().split())
mod = pow(10,9)+7

def comb(n,k):
    x=1
    y=1
    for i in range(1,k+1):
        x*=(n+1-i)
        x%=mod
        y*=i
        y%=mod
    return x*pow(y,mod-2,mod)


ans=(pow(2,n,mod)-1-comb(n,c)-comb(n,d))%mod
print(ans)
Buggy python submission (verdict: Runtime Error):
from typing import List, Any, Union


def clear_maze(sx, sy, maze):

    INF=-10**9
    global cnt
    cnt=0


    distance = [[INF for i in range(w+1)] for j in range(h+1)]
    #    distance = [[None]*field_x_length]*field_y_length



    def bfs():
        global cnt
        queue = []

        queue.insert(0, (sx, sy))

        distance[sx][sy] = 0

        while len(queue):
            x, y = queue.pop()



            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]


                if (0 <= nx and  0 <= ny  and maze[nx][ny] != '#' and distance[nx][ny] == INF):
                    queue.insert(0, (nx, ny))

                    distance[nx][ny] = distance[x][y] + 1
                    if cnt<=distance[nx][ny]:
                        cnt=distance[nx][ny]





        return cnt

    cnt=0
    distance = [[INF for i in range(w + 1)] for j in range(h + 1)]




    return bfs()

h,w = map(int, input().split())
maze=[list(input()) for i in range(h)]
t=[[0]*w for i in range(h)]
for i in range(h):
    maze[i]=['#']+maze[i]+['#']

maze=[['#' for i in range(w+2)]]+maze+[['#' for i in range(w+2)]]




ans=0

for i in range(1,h+1):
    for j in range(1,w+1):
        if maze[i][j]=='#':
            continue
        v=(clear_maze(i, j, maze))

        if ans<=v:
            ans=v
print(ans)

Fixed submission:


def clear_maze(sx, sy, maze):

    INF=-10**9
    global cnt
    cnt=0


    distance = [[INF for i in range(w+1)] for j in range(h+1)]
    #    distance = [[None]*field_x_length]*field_y_length



    def bfs():
        global cnt
        queue = []

        queue.insert(0, (sx, sy))

        distance[sx][sy] = 0

        while len(queue):
            x, y = queue.pop()



            for i in range(0, 4):
                nx, ny = x + [1, 0, -1, 0][i], y + [0, 1, 0, -1][i]


                if (0 <= nx and  0 <= ny  and maze[nx][ny] != '#' and distance[nx][ny] == INF):
                    queue.insert(0, (nx, ny))

                    distance[nx][ny] = distance[x][y] + 1
                    if cnt<=distance[nx][ny]:
                        cnt=distance[nx][ny]





        return cnt

    cnt=0
    distance = [[INF for i in range(w + 1)] for j in range(h + 1)]




    return bfs()

h,w = map(int, input().split())
maze=[list(input()) for i in range(h)]
t=[[0]*w for i in range(h)]
for i in range(h):
    maze[i]=['#']+maze[i]+['#']

maze=[['#' for i in range(w+2)]]+maze+[['#' for i in range(w+2)]]




ans=0

for i in range(1,h+1):
    for j in range(1,w+1):
        if maze[i][j]=='#':
            continue
        v=(clear_maze(i, j, maze))

        if ans<=v:
            ans=v
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
v = math.factorial(n - 1)


for i in range(1, n):
    w = (v//i)%mod
    ans += ((x[n - 1] - x[i - 1]) * w)mod


print(int(ans))

Fixed submission:
import math

n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
f = 1
for i in range(1,n):
  f *= i
  f %= mod

for i in range(n-1):
    ans+=(x[n-1]-x[i])*pow(i+1,mod-2,mod)

ans*=f
ans%=mod


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math

n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
v = math.factorial(n - 1)


for i in range(1, n):
    w = (v//i)%mod
    ans += (x[n - 1] - x[i - 1]) * w
    ans %= mod

print(int(ans))

Fixed submission:
import math

n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
f = 1
for i in range(1,n):
  f *= i
  f %= mod

for i in range(n-1):
    ans+=(x[n-1]-x[i])*pow(i+1,mod-2,mod)

ans*=f
ans%=mod


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math

n=int(input())
x = list(map(int, input().split()))
ans=0
mod=10**9+7
v=math.factorial(n-1)

for i in range(1,n):
    ans+=(x[n-1]-x[i-1])*v//i
    ans%=mod

print(int(ans))

Fixed submission:
import math

n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
f = 1
for i in range(1,n):
  f *= i
  f %= mod

for i in range(n-1):
    ans+=(x[n-1]-x[i])*pow(i+1,mod-2,mod)

ans*=f
ans%=mod


print(ans)

Buggy python submission (verdict: Runtime Error):
import math

n=int(input())
x = list(map(int, input().split()))
ans=0
mod=10**9+7


for i in range(1,n):
    ans+=(x[n-1]-x[i-1])/i
    ans%=mod

ans*=math.factorial(n-1)
ans%=mod

print(int(ans))

Fixed submission:
import math

n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
f = 1
for i in range(1,n):
  f *= i
  f %= mod

for i in range(n-1):
    ans+=(x[n-1]-x[i])*pow(i+1,mod-2,mod)

ans*=f
ans%=mod


print(ans)

Buggy python submission (verdict: Runtime Error):
import math

n=int(input())
x = list(map(int, input().split()))
ans=0
mod=10**9+7


for i in range(1,n):
    print(x[n-1],x[i])
    ans+=(x[n-1]-x[i-1])/i
    ans%=mod

ans*=math.factorial(n-1)
ans%=mod

print(int(ans))

Fixed submission:
import math

n = int(input())
x = list(map(int, input().split()))
ans = 0
mod = 10 ** 9 + 7
f = 1
for i in range(1,n):
  f *= i
  f %= mod

for i in range(n-1):
    ans+=(x[n-1]-x[i])*pow(i+1,mod-2,mod)

ans*=f
ans%=mod


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce
import collections

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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n, m = map(int, input().split())
a = list(map(int, input().split()))
a=set(a)
a=list(a)
n1=len(a)

v=[]

x=lcm_list(a)

for i in range(n1):
    for j in range(x//a[i]):
        v.append(a[i]*j+a[i]//2)

v = collections.Counter(v)
v=v.most_common()

if v[0][1]!=n1:
    print(0)
else:
    print((m-v[0][0])//x+1)

Fixed submission:
import fractions
from functools import reduce
import collections

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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)



n, m = map(int, input().split())
a = list(map(int, input().split()))
a=set(a)
b=list(a)
n1=len(b)
count=0
v=[]

x=lcm_list(b)

for i in range(n1):
    while b[i]%2==0:
        b[i]=b[i]//2
        count+=1
    v.append(count)
    count=0

for i in range(n1-1):
    if v[i]!=v[i+1]:
        print(0)
        exit()

print((m-x//2)//x+1)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
from functools import reduce
import collections

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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

n, m = map(int, input().split())
a = list(map(int, input().split()))
b =[]
v=[]
for i in range(n):
    b.append(a[i]*1.5)

x=lcm_list(a)


for i in range(n):
    for j in range(x//a[i]):
        v.append(a[i]*j+a[i]//2)

v = collections.Counter(v)
v=v.most_common()

if v[0][1]!=n:
    print(0)
else:
    print((m-v[0][0])//x+1)

Fixed submission:
import fractions
from functools import reduce
import collections

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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)



n, m = map(int, input().split())
a = list(map(int, input().split()))
a=set(a)
b=list(a)
n1=len(b)
count=0
v=[]

x=lcm_list(b)

for i in range(n1):
    while b[i]%2==0:
        b[i]=b[i]//2
        count+=1
    v.append(count)
    count=0

for i in range(n1-1):
    if v[i]!=v[i+1]:
        print(0)
        exit()

print((m-x//2)//x+1)
Buggy python submission (verdict: Runtime Error):
import math

a, b = map(int, input().split())
x=a*b//(math.gcd(a,b))
print(x)

Fixed submission:
import fractions

a, b = map(int, input().split())
x=a*b//(fractions.gcd(a,b))
print(x)