Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse.csgraph import dijkstra
from scipy.sparse.csgraph import floyd_warshall
n=int(input())
g=[[float('inf') for i in range(n)]for j in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    g[a-1][b-1]=c
    g[b-1][a-1]=c
q,k=map(int,input().split())
k-=1
cost=dijkstra(g,unweighted=False,directed=False)
for i in range(q):
    a,b=map(int,input().split())
    print(int(cost[a-1][k]+cost[k][b-1]))


Fixed submission:
n=int(input())
ro=[{}for i in range(n)]
dis=[-1]*n
for i in range(n-1):
    a,b,c=map(int,input().split())
    ro[a-1][b-1]=c
    ro[b-1][a-1]=c
q,k=map(int,input().split())
dis[k-1]=0
stack=[k-1]
while stack:
    s=stack.pop()
    for i,j in ro[s].items():
        if dis[i] == -1:
            dis[i]=dis[s]+j
            stack.append(i)
for i in range(q):
    x,y=map(int,input().split())
    x,y=x-1,y-1
    print(dis[x]+dis[y])

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse.csgraph import dijkstra
from scipy.sparse.csgraph import floyd_warshall
n=int(input())
g=[[float('inf') for i in range(n)]for j in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    g[a-1][b-1]=c
q,k=map(int,input().split())
k-=1
cost=dijkstra(g,unweighted=False,directed=False)
for i in range(q):
    a,b=map(int,input().split())
    print(int(cost[a-1][k]+cost[k][b-1]))


Fixed submission:
n=int(input())
ro=[{}for i in range(n)]
dis=[-1]*n
for i in range(n-1):
    a,b,c=map(int,input().split())
    ro[a-1][b-1]=c
    ro[b-1][a-1]=c
q,k=map(int,input().split())
dis[k-1]=0
stack=[k-1]
while stack:
    s=stack.pop()
    for i,j in ro[s].items():
        if dis[i] == -1:
            dis[i]=dis[s]+j
            stack.append(i)
for i in range(q):
    x,y=map(int,input().split())
    x,y=x-1,y-1
    print(dis[x]+dis[y])

Buggy python submission (verdict: Time Limit Exceeded):
from scipy.sparse.csgraph import dijkstra
from scipy.sparse.csgraph import floyd_warshall
n=int(input())
g=[[float('inf') for i in range(n)]for j in range(n)]
for i in range(n-1):
    a,b,c=map(int,input().split())
    g[a-1][b-1]=c
q,k=map(int,input().split())
k-=1
cost=dijkstra(g,unweighted=False,directed=False)
z=[]
for i in range(q):
    a,b=map(int,input().split())
    z.append((a-1,b-1))
for i,j in z:
    print(int(cost[i][k]+cost[k][j]))


Fixed submission:
n=int(input())
ro=[{}for i in range(n)]
dis=[-1]*n
for i in range(n-1):
    a,b,c=map(int,input().split())
    ro[a-1][b-1]=c
    ro[b-1][a-1]=c
q,k=map(int,input().split())
dis[k-1]=0
stack=[k-1]
while stack:
    s=stack.pop()
    for i,j in ro[s].items():
        if dis[i] == -1:
            dis[i]=dis[s]+j
            stack.append(i)
for i in range(q):
    x,y=map(int,input().split())
    x,y=x-1,y-1
    print(dis[x]+dis[y])
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input().split())
print['impossible','possible'][((a%3)+(b%3))%3==0]

Fixed submission:
a,b=map(int,input().split());print(["Impossible","Possible"][a%3==0 or b%3==0 or (a+b)%3==0])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(input().split())
b=[]
if n%2==0:
    for i in range(n):
        if i==0:
            b.append(a[i])
        elif i%2==0:
            b.append(a[i])
        else:
            b.insert(0,a[i])
else:
    for i in range(n):
        if i==0:
            b.append(a[i])
        elif i%2==0:
            b.insert(0,a[i])
        else:
            b.append(a[i])
print(' '.join(b))


Fixed submission:
n=int(input())
a=list(input().split())
b=a[::-2]+a[len(a)%2::2]
print(' '.join(b))

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=list(input().split())
b=[]
for i in range(n):
    b.append(a[i])
    b.reverse()
print(' '.join(b))


Fixed submission:
n=int(input())
a=list(input().split())
b=a[::-2]+a[len(a)%2::2]
print(' '.join(b))
Buggy python submission (verdict: Runtime Error):
n,t=map(int,input().split())
a=list(map(int,input().split()))
y=max(a)+10+t
b=[0]*y
c=[0]*y
for i in a:
    b[i]+=1
    b[i+t]-=1
for i in range(len(b)):
    if i!=0:
        b[i]+=b[i-1]
d=[i for i in b if i>0]
print(len(d))


Fixed submission:
n,t=map(int,input().split())
a=list(map(int,input().split()))
ans=t
for i in range(1,n):
    ans+=min(t,a[i]-a[i-1])
print(ans)

Buggy python submission (verdict: Runtime Error):
n,t=map(int,input().split())
a=list(map(int,input().split()))
y=a[-1]+10+t
b=[0]*y
c=[0]*y
for i in a:
    b[i]+=1
    b[i+t]-=1
for i in range(len(b)):
    if i!=0:
        b[i]+=b[i-1]
d=[i for i in b if i>0]
print(len(d))


Fixed submission:
n,t=map(int,input().split())
a=list(map(int,input().split()))
ans=t
for i in range(1,n):
    ans+=min(t,a[i]-a[i-1])
print(ans)

Buggy python submission (verdict: Runtime Error):
n,t=map(int,input().split())
a=list(map(int,input().split()))
y=a[-1]+1+t
b=[0]*y
c=[0]*y
for i in a:
    b[i]+=1
    b[i+t]-=1
for i in range(len(b)):
    if i!=0:
        b[i]+=b[i-1]
d=[i for i in b if i>0]
print(len(d))


Fixed submission:
n,t=map(int,input().split())
a=list(map(int,input().split()))
ans=t
for i in range(1,n):
    ans+=min(t,a[i]-a[i-1])
print(ans)
Buggy python submission (verdict: Runtime Error):
from scipy.sparse.csgraph import floyd_warshall
from scipy.sparse.csgraph import dijkstra
n,m=map(int,input().split())
dis=[[float('inf') for i in range(n)]for j in range(n)]
for i in range(n):
    dis[i][i]=0
for i in range(m):
    a,b,t=map(int,input().split())
    dis[a-1][b-1]=t
    dis[b-1][a-1]=t
cost=dijkstra(dis,directed=False,unweighted=False)
cnt=0
for i,j,k in dis:
    if k>costs[i-1][j-1]:
        cnt+=1
print(cnt)


Fixed submission:
cnt=0
n,m=map(int,input().split())
dis=[[float('inf') for i in range(n)]for j in range(n)]
tmp=[]
for i in range(m):
    tmp.append(list(map(int,input().split())))
for a,b,t in tmp:
    dis[a-1][b-1]=t
    dis[b-1][a-1]=t
for k in range(n):
    for i in range(n):
        for j in range(n):
            dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j])
for a,b,t in tmp:
    if t>dis[a-1][b-1]:
        cnt+=1
print(cnt)
Buggy python submission (verdict: Runtime Error):
w,h,n=map(int,input().split())
x=y=0
for i in range(n):
  xi,yi,a=map(int,input().split())
  if a==1:
    x=max(x,xi)
  elif a==2:
    w=min(W,xi)
  elif a==3:
    y=max(y,yi)
  elif a==4:
    h=min(H,yi)    
print(0 if x>=w or y>=h else (w-x)*(h-y))


Fixed submission:
w,h,n=map(int,input().split())
x=y=0
for i in range(n):
  xi,yi,a=map(int,input().split())
  if a==1:
    x=max(x,xi)
  elif a==2:
    w=min(w,xi)
  elif a==3:
    y=max(y,yi)
  elif a==4:
    h=min(h,yi)    
print(0 if x>=w or y>=h else (w-x)*(h-y))
Buggy python submission (verdict: Time Limit Exceeded):
import sys
x=input()
tmp=x.split("ST")
tmp=''.join(tmp)
a=len(tmp)
for i in range(100000):
    tmp=tmp.split("ST")
    tmp=''.join(tmp)
    if len(tmp)==a:
        print(len(tmp))
        break
    elif len(tmp)==0:
        print(0)
        break
    else:
        a=len(tmp)


Fixed submission:
if __name__ == '__main__':
    x = list(input())
    sl = []
    ans = 0
    for i in x:
        if i == "S":
            sl.append(1)
        else:
            if len(sl) != 0:
                ans += sl.pop()

    print(len(x) - ans * 2)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
x=input()
tmp=x.split("ST")
tmp=''.join(tmp)
a=len(tmp)
for i in range(2000000):
    tmp=tmp.split("ST")
    tmp=''.join(tmp)
    if len(tmp)==a:
        print(len(tmp))
        break
    elif len(tmp)==0:
        print(0)
        break
    else:
        a=len(tmp)


Fixed submission:
if __name__ == '__main__':
    x = list(input())
    sl = []
    ans = 0
    for i in x:
        if i == "S":
            sl.append(1)
        else:
            if len(sl) != 0:
                ans += sl.pop()

    print(len(x) - ans * 2)
Buggy python submission (verdict: Runtime Error):
print(sum(range(int(input())+1))

Fixed submission:
n=int(input());print(int(n*(1+n)/2))
Buggy python submission (verdict: Runtime Error):
from typing import List
N, M = map(int, input().split())
graph:List[List[int]] = [[] for _ in range(N)]
for _ in range(N):
    a,b = map(lambda x : int(x) -1 , input().split())
    graph[a].append(b)
    graph[b].append(a)
prev = [-1]*N
prev[0] = 0
import queue
qu = queue.Queue()
qu.put(0)
while not qu.empty():
    top = qu.get()
    for nxt in graph[top]:
        if prev[nxt] == -1:
            prev[nxt] = top
            qu.put(nxt)
if all(x != -1 for x in prev[1:]):
    print("Yes")
    print("\n".join(map(lambda x : str(x+1), prev[1:])))
else :
    print("No")

Fixed submission:
from typing import List
N, M = map(int, input().split())
graph:List[List[int]] = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(lambda x : int(x) -1 , input().split())
    graph[a].append(b)
    graph[b].append(a)
prev = [-1]*N
prev[0] = 0
import queue
qu = queue.Queue()
qu.put(0)
while not qu.empty():
    top = qu.get()
    for nxt in graph[top]:
        if prev[nxt] == -1:
            prev[nxt] = top
            qu.put(nxt)
if all(x != -1 for x in prev[1:]):
    print("Yes")
    print("\n".join(map(lambda x : str(x+1), prev[1:])))
else :
    print("No")

Buggy python submission (verdict: Runtime Error):
from typing import List
N, M = map(int, input().split())
graph:List[List[int]] = [[] for _ in range(N)]
for _ in range(N):
    a,b = map(lambda x : int(x) -1 , input().split())
    graph[a].append(b)
    graph[b].append(a)
prev = [-1]*N
prev[0] = 0
import queue
qu = queue.Queue()
qu.put(0)
while not qu.empty():
    top = qu.get()
    for nxt in graph[top]:
        if prev[nxt] == -1:
            prev[nxt] = top
            qu.put(nxt)
if all(x != -1 for x in prev[1:]):
    print("\n".join(map(lambda x : str(x+1), prev[1:])))
else :
    print("no")

Fixed submission:
from typing import List
N, M = map(int, input().split())
graph:List[List[int]] = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(lambda x : int(x) -1 , input().split())
    graph[a].append(b)
    graph[b].append(a)
prev = [-1]*N
prev[0] = 0
import queue
qu = queue.Queue()
qu.put(0)
while not qu.empty():
    top = qu.get()
    for nxt in graph[top]:
        if prev[nxt] == -1:
            prev[nxt] = top
            qu.put(nxt)
if all(x != -1 for x in prev[1:]):
    print("Yes")
    print("\n".join(map(lambda x : str(x+1), prev[1:])))
else :
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
mod = 10 ** 9 + 7


def pow(a, b, mod):
    if b == 0:
        return 1
    if b == 1:
        return a
    if b % 2 == 0:
        return (pow(a, b // 2, mod) ** 2) % mod
    else:
        return (a * pow(a, b // 2, mod) ** 2) % mod


def inv(x, mod):
    return pow(x, mod - 2, mod)


MAX = 2 * 10 ** 6 + 3
l = [1] * MAX
for i in range(1, MAX):
    l[i] = (l[i - 1] * i) % mod


def f(r, c):
    return (l[r + c] * inv(l[r], mod) * inv(l[c], mod)) % mod


def g(r, c):
    if r < 0 or c < 0:
        return 0
    ans = 0
    for i in range(r + 1):
        ans += f(i + 1, c)
    return ans % mod


r1, c1, r2, c2 = map(int, input().split())
print(((g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)) % mod + mod) % mod)


Fixed submission:
mod = 10 ** 9 + 7


def pow(a, b, mod):
    if b == 0:
        return 1
    if b == 1:
        return a
    if b % 2 == 0:
        return (pow(a, b // 2, mod) ** 2) % mod
    else:
        return (a * pow(a, b // 2, mod) ** 2) % mod


def inv(x, mod):
    return pow(x, mod - 2, mod)


MAX = 2 * 10 ** 6 + 3
l = [1] * MAX
for i in range(1, MAX):
    l[i] = (l[i - 1] * i) % mod


def f(r, c):
    return (l[r + c] * inv(l[r], mod) * inv(l[c], mod)) % mod


def g(r, c):
    if r < 0 or c < 0:
        return 0
    ans = f(r+1, c+1) - 1 + mod
    return ans % mod


r1, c1, r2, c2 = map(int, input().split())
print(((g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)) % mod + mod) % mod)

Buggy python submission (verdict: Time Limit Exceeded):
mod = 10 ** 9 + 7


def pow(a, b, mod):
    if b == 0:
        return 1
    if b == 1:
        return a
    if b % 2 == 0:
        return (pow(a, b // 2, mod) ** 2) % mod
    else:
        return (a * pow(a, b // 2, mod) ** 2) % mod


def inv(x, mod):
    return pow(x, mod - 2, mod)


MAX = 2 * 10 ** 6 + 3
l = [1] * MAX
for i in range(1, MAX):
    l[i] = (l[i - 1] * i) % mod


def f(r, c):
    return (l[r + c] * inv(l[r], mod) * inv(l[c], mod)) % mod


def g(r, c):
    if r < 0 or c < 0:
        return 0
    ans = 0
    for i in range(r + 1):
        ans += f(i + 1, c)
    return ans % mod


r1, c1, r2, c2 = map(int, input().split())
print(((g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)) % mod + mod) % mod)


Fixed submission:
mod = 10 ** 9 + 7


def pow(a, b, mod):
    if b == 0:
        return 1
    if b == 1:
        return a
    if b % 2 == 0:
        return (pow(a, b // 2, mod) ** 2) % mod
    else:
        return (a * pow(a, b // 2, mod) ** 2) % mod


def inv(x, mod):
    return pow(x, mod - 2, mod)


MAX = 2 * 10 ** 6 + 3
l = [1] * MAX
for i in range(1, MAX):
    l[i] = (l[i - 1] * i) % mod


def f(r, c):
    return (l[r + c] * inv(l[r], mod) * inv(l[c], mod)) % mod


def g(r, c):
    if r < 0 or c < 0:
        return 0
    ans = f(r+1, c+1) - 1 + mod
    return ans % mod


r1, c1, r2, c2 = map(int, input().split())
print(((g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1)) % mod + mod) % mod)
Buggy python submission (verdict: Runtime Error):
from typing import Dict

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


def pow(a, b, mod=10 ** 9 + 7):
    if b == 0:
        return 1
    elif b == 1:
        return a
    elif b % 2 == 0:
        return (pow(a, b // 2) ** 2) % mod
    else:
        return (a * pow(a, b // 2) ** 2) % mod


def inv(x, mod=10 ** 9 + 7):
    return pow(x, mod - 2, mod=mod)


def factorize(x):
    ans = {}
    v = 2
    while v * v <= x:
        if x % v == 0:
            ans[v] = 0
            while x % v == 0:
                x //= v
                ans[v] += 1
        v += 1
    if x != 1:
        ans[x] = 1
    return ans


def merge(d: Dict[int, int], c: Dict[int, int]):
    for k, v in c.items():
        if k not in d:
            d[k] = v
        d[k] = max(d[k], v)


tmp = {}
for v in A:
    merge(tmp, factorize(v))
t = 1
mod = 10 ** 9 + 7
for k, v in tmp.items():
    t *= k ** v
    t %= mod
ans = 0
for a in A:
    ans += t * inv(a)
print(ans % mod)


Fixed submission:

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


def pow(a, b, mod=10 ** 9 + 7):
    if b == 0:
        return 1
    elif b == 1:
        return a
    elif b % 2 == 0:
        return (pow(a, b // 2) ** 2) % mod
    else:
        return (a * pow(a, b // 2) ** 2) % mod


def inv(x, mod=10 ** 9 + 7):
    return pow(x, mod - 2, mod=mod)


def factorize(x):
    ans = {}
    v = 2
    while v * v <= x:
        if x % v == 0:
            ans[v] = 0
            while x % v == 0:
                x //= v
                ans[v] += 1
        v += 1
    if x != 1:
        ans[x] = 1
    return ans


def merge(d, c):
    for k, v in c.items():
        if k not in d:
            d[k] = v
        d[k] = max(d[k], v)


tmp = {}
for v in A:
    merge(tmp, factorize(v))
t = 1
mod = 10 ** 9 + 7
for k, v in tmp.items():
    t *= k ** v
    t %= mod
ans = 0
for a in A:
    ans += t * inv(a)
print(ans % mod)
Buggy python submission (verdict: Runtime Error):
N: int = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    graph[u].append((v, w))
    graph[v].append((u, w))
qu = [0]
colors = [0 for _ in range(N)]
visited = set()
while len(qu) != 0:
    cur = qu.pop()
    visited.add(cur)
    for nxt, weight in graph[cur]:
        if nxt not in visited:
            colors[nxt] = (colors[cur] + weight)%2
            qu.append(nxt)
for v in colors:print(v)


Fixed submission:
N = int(input())
graph = [[] for _ in range(N)]
for _ in range(N - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    graph[u].append((v, w))
    graph[v].append((u, w))
qu = [0]
colors = [0 for _ in range(N)]
visited = set()
while len(qu) != 0:
    cur = qu.pop()
    visited.add(cur)
    for nxt, weight in graph[cur]:
        if nxt not in visited:
            colors[nxt] = (colors[cur] + weight)%2
            qu.append(nxt)
for v in colors:print(v)
Buggy python submission (verdict: Time Limit Exceeded):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,d,a = mi()
lis = []
for  i in range(n):
    x,h = mi()
    h = (h + a - 1) // a
    lis.append([x,h])

lis.sort()
dis = []
hp = []
for i in range(n):
    dis.append(lis[i][0])
    hp.append(lis[i][1])
#bit
class BIT():
    """区間加算、区間取得クエリをそれぞれO(logN)で答える
    add: 区間[l, r)にvalを加える
    get_sum: 区間[l, r)の和を求める
    l, rは0-indexed
    """
    def __init__(self, n):
        self.n = n
        self.bit0 = [0] * (n + 1)
        self.bit1 = [0] * (n + 1)

    def _add(self, bit, i, val):
        i = i + 1
        while i <= self.n:
            bit[i] += val
            i += i & -i

    def _get(self, bit, i):
        s = 0
        while i > 0:
            s += bit[i]
            i -= i & -i
        return s

    def add(self, l, r, val):
        """区間[l, r)にvalを加える"""
        self._add(self.bit0, l, -val * l)
        self._add(self.bit0, r,  val * r)
        self._add(self.bit1, l,  val)
        self._add(self.bit1, r, -val)

    def get_sum(self, l, r):
        """区間[l, r)の和を求める"""
        return self._get(self.bit0, r) + r * self._get(self.bit1, r) \
               - self._get(self.bit0, l) - l * self._get(self.bit1, l)

import bisect
hp_now = 0
dis_now = 0

ans = 0
bit = BIT(n+1)
for i in range(n):
    diff = hp[i] - bit.get_sum(i+1,i+2)
    if diff > 0:
        ans += diff
        migi = bisect.bisect_right(dis,dis[i] + 2 *d)
        bit.add(1,migi+1,diff)
print(ans)



Fixed submission:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,d,a = mi()
lis = []
for  i in range(n):
    x,h = mi()
    h = (h + a - 1) // a
    lis.append([x,h])

lis.sort()
dis = []
hp = []
for i in range(n):
    dis.append(lis[i][0])
    hp.append(lis[i][1])
#imos?
from collections import deque
hiku = deque()
sums = hp[0]
ans = hp[0]
hiku.append([dis[0] + 2 * d,hp[0]])
imadis,imahp = hiku.popleft()
for i in range(1,n):
    while True:
        if dis[i] <= imadis:
            break
        else:
            sums -= imahp
            imahp = 0
            if hiku:
                imadis,imahp = hiku.popleft()
            else:
                break
    diff = hp[i] - sums
    if diff > 0:
        ans += diff
        sums += diff
        hiku.append([dis[i] + 2 * d,diff])

print(ans)
Buggy python submission (verdict: Runtime Error):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
dp = [0]*(n+1)
for i in range(1,n+1):
    s = str(i)
    if s[0] == s[-1]:
        dp[int(s[0])] += 1
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        dp[ima] += 1
ans = 0
for i in range(1,min(100,n+1)):
    s = str(i)
    if s[0] == s[-1]:
        ans += dp[int(s[0])]**2
        dp[int(s[0])] = 0
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        ima2 = int(s[-1])*10 + int(s[0])
        ans += dp[ima] * dp[ima2] *2
        dp[ima] = 0
        dp[ima2] = 0
print(ans)

Fixed submission:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
dp = [0]*max(101,(n+1))
for i in range(1,n+1):
    s = str(i)
    if s[0] == s[-1]:
        dp[int(s[0])] += 1
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        dp[ima] += 1
ans = 0
for i in range(1,min(100,n+1)):
    s = str(i)
    if s[0] == s[-1]:
        ans += dp[int(s[0])]**2
        dp[int(s[0])] = 0
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        ima2 = int(s[-1])*10 + int(s[0])
        ans += dp[ima] * dp[ima2] *2
        dp[ima] = 0
        dp[ima2] = 0
print(ans)

Buggy python submission (verdict: Runtime Error):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
dp = [0]*(n+1)
for i in range(1,n+1):
    s = str(i)
    if s[0] == s[-1]:
        dp[int(s[0])] += 1
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        dp[ima] += 1
ans = 0
for i in range(1,100):
    s = str(i)
    if s[0] == s[-1]:
        ans += dp[int(s[0])]**2
        dp[int(s[0])] = 0
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        ima2 = int(s[-1])*10 + int(s[0])
        ans += dp[ima] * dp[ima2] *2
        dp[ima] = 0
        dp[ima2] = 0
print(ans)



Fixed submission:
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
dp = [0]*max(101,(n+1))
for i in range(1,n+1):
    s = str(i)
    if s[0] == s[-1]:
        dp[int(s[0])] += 1
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        dp[ima] += 1
ans = 0
for i in range(1,min(100,n+1)):
    s = str(i)
    if s[0] == s[-1]:
        ans += dp[int(s[0])]**2
        dp[int(s[0])] = 0
    elif s[-1] == "0":
        continue
    else:
        ima = int(s[0])*10 + int(s[-1])
        ima2 = int(s[-1])*10 + int(s[0])
        ans += dp[ima] * dp[ima2] *2
        dp[ima] = 0
        dp[ima2] = 0
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
n = ii()
a = li()
aco = a
aco = list(set(aco))
lis = [0]*(10**3)
rootn = 10**3
for i in range(len(aco)):
    for nm in range(2,rootn):
        if aco[i] % nm != 0:
            continue
        ima = 0
        while(aco[i]%nm == 0):
            ima += 1
            aco[i] = aco[i] //nm
        lis[nm] = max(lis[nm],ima)
aco = list(set(aco))
mod = 10**9 + 7
gcd = 1
for i in range(2,rootn):
    gcd *= (i ** lis[i]) % mod
for i in range(len(aco)):
    gcd *= aco[i] % mod

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




Fixed submission:
P = 10**9 + 7
N = 1000001
inv_t = [0]+[1]
for i in range(2,N):
  inv_t += [inv_t[P % i] * (P - int(P / i)) % P]

n = int(input())
lili = list(map(int,input().split()))
import copy
lili2 = copy.copy(lili)
#a>b
inin = 1
lili = list(set(lili))
for i in range(2,10 ** 3+2):
    count = 0
    for j in range(len(lili)):
        if lili[j] % i != 0: continue
        now = 0
        while (lili[j] % i == 0):
            now += 1
            lili[j] = lili[j] // i
        count = max(count,now)
    inin = inin * (i ** count) % P
lili = list(set(lili))
for i in range(len(lili)):

    inin = inin * lili[i] %P

ans = 0
for i in range(n):
    ans += inin * (pow(lili2[i],P-2,P)) %P
    ans % P
print(ans %P)