Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

from collections import deque

def bfs(graph, start):
    visited = {start: None}
    unvisited = deque()
    unvisited.append(start)
    while unvisited:
        now = unvisited.popleft()
        for next in graph[now]:
            if not (next in visited):
                unvisited.append(next)
                visited[next] = now
    for key in visited.keys():
        graph[key].update(visited.keys())

n, m = map(int, input().split())
g = [set() for i in range(n)]

for i in range(m):
    a, b = map(int, input().split())
    g[a].add(b)
    g[b].add(a)

q = int(input())

for i in range(q):
    s, t = map(int, input().split())
    bfs(g, s)
    if t in g[s]:
        print("yes")
    else:
        print("no")

### FIXED CODE ###

from collections import deque

def bfs(graph, start):
    visited = {start: None}
    unvisited = deque()
    unvisited.append(start)
    while unvisited:
        now = unvisited.popleft()
        for next in graph[now]:
            if not (next in visited):
                unvisited.append(next)
                visited[next] = now
    return visited

n, m = map(int, input().split())
g = [set() for i in range(n)]
group = []

for i in range(m):
    a, b = map(int, input().split())
    g[a].add(b)
    g[b].add(a)

q = int(input())

for i in range(q):
    s, t = map(int, input().split())
    for j in range(len(group)):
        if s in group[j] and t in group[j]:
            print("yes")
            break
        elif s in group[j]:
            print("no")
            break
    else:
        group_tmp = set(bfs(g, s).keys())
        if t in group_tmp:
            print("yes")
        else:
            print("no")
        group.append(group_tmp)
### BUGGY CODE ###

N, M = map(int, input().split())
a = list(map(int, input().split()))
a = list(set(a))
N = len(a)
for k in range(N):
  a[k] //= 2


count = 0
foo = 1

while a[0]%2 == 0:
  foo *= 2
  a[0] // 2
for k in range(1, N):
  if a[k] % foo == 0 and a[k]%(2*foo) !=0:
    a[k] //= foo
    continue
  else:
    print(0)
    exit()
ans = 0

baisu = []

a.sort(reverse=True)



import math
lcm = a[0]
for k in range(1, N):
  lcm = lcm * a[k] // math.gcd(lcm, a[k])
  if lcm*foo  > M:
    print(0)
    exit()
lcm *= foo
ans = int((M / lcm -1)//2 + 1)
print(ans)


### FIXED CODE ###

N, M = map(int, input().split())
a = list(map(int, input().split()))
for k in range(N):
  a[k] //= 2

foo = 1
while a[0]%2 == 0:
  foo *= 2
  a[0] //= 2
for k in range(1, N):
  if a[k] % foo == 0 and a[k]%(2*foo) !=0:
    a[k] //= foo
    continue
  else:
    print(0)
    exit()
ans = 0

import math
lcm = a.pop()
for k in range(1, N):
  b = a.pop()
  lcm = lcm * b // math.gcd(lcm, b)
  if lcm* foo > M:
    print(0)
    exit()
lcm *= foo
ans = int((M / lcm -1)//2 + 1)
print(ans)
### BUGGY CODE ###

import numpy as np

def run():
  H, W = map(int, input().split())
  df = np.zeros((H, W)).astype(int)
  M = min(H, W)
  dp = [[[] for w in range(W)] for h in range(H)]
  for h in range(H):
      for w, v in enumerate(map(int, input().split())):
          df[h][w] = v
  for h in range(H):
      for w, v in enumerate(map(int, input().split())):
          df[h][w] = abs(df[h][w]-v)
  for h in range(H):
      for w in range(W):
          diff = df[h][w]
          if h == w and h == 0:
              dp[h][w] = [diff]
              continue
          temp = []
          for x, y in [[h-1, w], [h, w-1]]:
              if 0 > min(x, y): continue
              for v in dp[x][y]:
                  temp.append(abs(v + diff))
                  temp.append(abs(v - diff))
          dp[h][w] = set(temp)
  print(min(dp[-1][-1]))
  
if __name__ == '__main__':
  run()

### FIXED CODE ###

def run():
  ofs = 1000
  H, W = map(int, input().split())
  dp = [[0 for w in range(W)] for h in range(H)]
  a = [list(map(int, input().split())) for i in range(H)]
  b = [list(map(int, input().split())) for i in range(H)]
  c = [[abs(a[i][j] - b[i][j]) for j in range(W)] for i in range(H)]
  dp[0][0] = (1 << ofs + c[0][0]) | (1 << ofs - c[0][0])
  for h in range(1, H):
    dp[h][0] = (dp[h-1][0] << c[h][0]) | (dp[h-1][0] >> c[h][0])
  for w in range(1, W):
    dp[0][w] = (dp[0][w-1] << c[0][w]) | (dp[0][w-1] >> c[0][w])
  for h in range(1, H):
    for w in range(1, W):
      v = c[h][w]
      dp[h][w] = (dp[h-1][w] << v) | (dp[h-1][w] >> v)
      dp[h][w] |= (dp[h][w-1] << v) | (dp[h][w-1] >> v)
  s = list(bin(dp[-1][-1] >> ofs))
  for i in range(len(s)):
    if s[-1-i] == '1':
      print(i)
      break

if __name__ == '__main__':
  run()
### BUGGY CODE ###

s = input()
t = input()
ls=len(s)
lt=len(t)

#sの文字数行*tの文字数列のDP
dp=[[0]*(lt+1) for _ in range(ls+1)]


for i in range(1,ls+1):
    for j in range(1,lt+1):
        if s[i-1]==t[j-1]:
        # sとtの見た文字が一致
        # →sとtの双方の1個前までの共通最大連続数に+1追加
            dp[i][j]=dp[i-1][j-1]+1
        else:
        # 一致しないとき
        # sの1個前までか、tの1個前の共通最大連続数の
        # 大きいほうを採用
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])

# 復元はs,tとも後ろから見ていく
ans = ''
i=ls
j=lt
while i != 0 and j != 0:
    if dp[i][j] == dp[i-1][j]:
        # DP上でsの一個前から更新されてない
        # 即ちs[i-1]は共通列に入ってない
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        # 上と同じ論法でtの場合
        j -= 1
    else:
        # 今見ているs[i-1]とt[j-1]が共通になっているとき
        # 答えに採用（s[i-1]は頭につける）
        ans = s[i-1] + ans 
        i -= 1
        j -= 1
        
print(ans)

### FIXED CODE ###

s = input()
t = input()
ls=len(s)
lt=len(t)

#sの文字数行*tの文字数列のDP
dp=[[0]*(lt+1) for _ in range(ls+1)]

for i in range(1,ls+1):
    for j in range(1,lt+1):
        if s[i-1]==t[j-1]:
        # sとtの見た文字が一致
        # →sとtの双方の1個前までの共通最大連続数に+1追加
            dp[i][j]=dp[i-1][j-1]+1
        else:
        # 一致しないとき
        # sの1個前までか、tの1個前の共通最大連続数の
        # 大きいほうを採用
            dp[i][j]=max(dp[i-1][j],dp[i][j-1])

# 復元はs,tとも後ろから見ていく
ans = ''
i=ls
j=lt
while i != 0 and j != 0:
    if dp[i][j] == dp[i-1][j]:
        # DP上でsの一個前から更新されてない
        # 即ちs[i-1]は共通列に入ってない
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        # 上と同じ論法でtの場合
        j -= 1
    else:
        # 今見ているs[i-1]とt[j-1]が共通になっているとき
        # 答えに採用（s[i-1]は頭につける）
        ans = s[i-1] + ans 
        i -= 1
        j -= 1
        
print(ans)
### BUGGY CODE ###

import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline


def binarysearch1(r, q):
    l = len(r)
    mini = 0
    maxi = l - 1
    i = (maxi + mini) // 2
    col, pos = r[i]
    while maxi > mini:
        if col >= q:
            maxi = i
        else:
            mini = i + 1
        i = (maxi + mini) // 2
        col, pos = r[i]
    return i, col, pos



def binarysearch2(r, q):
    l = len(r)
    mini = 0
    maxi = l - 1
    i = (maxi + mini) // 2
    col, pos = r[i]
    while maxi > mini:
        if pos >= q:
            maxi = i
        else:
            mini = i + 1
        i = (maxi + mini) // 2
        col, pos = r[i]
    return i, col, pos






n, q = list(map(int, input().split()))
count = (n - 2) ** 2
c = [(n,n)]
r = [(n,n)]
mc = n
mr = n
for _ in range(q):
    m, q = list(map(int, input().split()))
    if m == 1:
        _, _, pos = binarysearch1(r,q)
        if q < mc:
            mc = q
            i, _, _ =binarysearch2(c, q)
            c.insert(i, (pos, q))
        if q not in [1,n]:
            count -= max(0, pos - 2)
    else:
        _, _, pos = binarysearch1(c,q)
        if q < mr:
            i, _, _ =binarysearch2(r, q)
            r.insert(i, (pos, q))
        if q not in [1,n]:
            count -= max(0, pos - 2)
print(count)



### FIXED CODE ###

import os
import io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline


n, q = list(map(int, input().split()))
count = (n - 2) ** 2
c = [n] * (n + 1)
r = [n] * (n + 1)
mc = n
mr = n
for _ in range(q):
    m,q = list(map(int, input().split()))
    if m == 1:
        if q <= mc:
            count -= mr -2
            for p in range(q+1, mc):
                c[p] = mr
            c[q] = 0
            mc = q
        else:
            count -= c[q] - 2
    else:
        if q <= mr:
            count -= mc -2
            for p in range(q+1, mr):
                r[p] = mc
            r[q] = 0
            mr = q
        else:
            count -= r[q] - 2
print(count)
### BUGGY CODE ###

n,a,b = map(int,input().split())
mod = 10**9+7

lfac = [1,1]
ifac = 1
for i in range(2,n+1):
    ifac = (ifac * i) % mod
    lfac.append(ifac)
    
def comb(n,m):
    res1 = pow(lfac[m],(mod-2),mod)
    res2 = pow(lfac[n-m],(mod-2),mod)
    return (((lfac[n] * res1) % mod) * res2) % mod

res = pow(2,n,mod)
res -= 1 + comb(n,a) + comb(n,b) + mod
print(res % mod)

### FIXED CODE ###

from functools import reduce

n, a, b = map(int, input().split())
mod = 10**9 + 7

def fast_comb(a,b,mod):
    up = reduce(lambda x,y: x*y%mod, range(a,a-b,-1))
    down = reduce(lambda x,y: x*y%mod, range(1,b+1))
    return (up * pow(down, mod-2, mod)) % mod

print((pow(2,n,mod) - fast_comb(n,a,mod) - fast_comb(n,b,mod) - 1) % mod)
### BUGGY CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())

count = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1, k+1):
            count += gcd(a,b,c)

print(count)

### FIXED CODE ###

from math import gcd 

num = int(input()) + 1

count = 0
for a in range(1, num):
    for b in range(1, num):
        t = gcd(a,b)
        for c in range(1, num):
                count += gcd(t, c)
print(count)
### BUGGY CODE ###

K = int(input())
seven = 7
count = 0

if(K % 2 == 0 or K % 5 == 0):
    print(-1)
if(K == 7):
    print(1)
else:
    while(seven % K != 0):
        seven = (seven * 10 + 7) % K
        count += 1

        # これだと10^5以降の計算が遅くなる。countのせい？？
        # count += 1
        # seven = seven + 7 * (10 ** count)
    print(count+1)

### FIXED CODE ###

K = int(input())
seven = 7
count = 0

if(K % 2 == 0 or K % 5 == 0):
    print(-1)
if(K == 7 or K == 1):
    print(1)
else:
    for i in range(1,10**6):
        seven = (seven * 10 + 7) % K
        if(seven % K == 0):
            print(i+1)
            break

        # これだと10^5以降の計算が遅くなる。countのせい？？
        # count += 1
        # seven = seven + 7 * (10 ** count)
### BUGGY CODE ###

#!/usr/bin/env python3
import sys

def solve(N: int):
    n = list(map(int,list(str(N))))
    pay = ""
    kuriage = 0
    LEN = len(n)
    pay_count = 0

    for i in range(LEN-1,-1,-1):
        if i != 0:
            if n[i-1] >= 5:
                if n[i]+kuriage <= 4:
                    pay += str(n[i]+kuriage)
                    pay_count += n[i]+kuriage
                    kuriage = 0
                else:
                    pay += "0" 
                    kuriage = 1
            else:
                if int(n[i])+kuriage <= 5:
                    pay += str(n[i]+kuriage)
                    pay_count += n[i]+kuriage
                    kuriage = 0
                else:
                    pay += "0" 
                    kuriage = 1
        else:
            if int(n[i])+kuriage <= 5:
                pay += str(n[i]+kuriage)
                pay_count += n[i]+kuriage
                kuriage = 0
            else:
                pay += "0" 
                kuriage = 1

    if kuriage == 1:
        pay += "1"
        pay_count += 1
    
    pay = pay[::-1]
    oturi = int(pay)-N
    oturi_count = 0
    
    for i in str(oturi):
        oturi_count += int(i)
    print(pay_count+oturi_count)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys

def solve(N: str):
    n = list(map(int,list(N)))
    kuriage = 0
    LEN = len(n)
    pay_count = 0

    for i in range(LEN-1,-1,-1):
        if i != 0:
            if n[i-1] >= 5:
                if n[i]+kuriage <= 4:
                    pay_count += n[i]+kuriage
                    kuriage = 0
                else:
                    pay_count += 10-(n[i]+kuriage)
                    kuriage = 1
            else:
                if n[i]+kuriage <= 5:
                    pay_count += n[i]+kuriage
                    kuriage = 0
                else:
                    pay_count += 10-(n[i]+kuriage)
                    kuriage = 1
        else:
            if n[i]+kuriage <= 5:
                pay_count += n[i]+kuriage
                kuriage = 0
            else:
                pay_count += 10-(n[i]+kuriage)
                kuriage = 1

    if kuriage == 1:
        pay_count += 1
    print(pay_count)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = next(tokens)
    solve(N)

if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
P_lis = list(map(int,input().split()))
 
count = 0
for i in range(N):
  lis = P_lis[0:i+1]
  for j in range(i):
    if lis[i] >= lis[j]:
      count += 1
      break
print(N - count)

### FIXED CODE ###

N = int(input())
P_lis = list(map(int, input().split()))
 
dummy = 2*10**5
answer = 0
 
for p in P_lis:
  if p <= dummy:
    answer += 1
    dummy = p
print(answer)
### BUGGY CODE ###

n = int(input())

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

a = 1

for i in b:
  c = a * i
  a = c
if c > 10**18:
  print(-1)
else:
  print(a)

### FIXED CODE ###

n = int(input())

l = list(map(int, input().split()))
l.sort()

if l[0] == 0:
  print(0)
  exit()
res = 1

for i in l:
  res *= i
  if res > 10 **18:
    print(-1)
    exit()
print(res)
### BUGGY CODE ###

from heapq import heappush,heappop
def main():
    h,w=map(int,input().split())
    sx,sy=map(int,input().split())
    sx-=1
    sy-=1
    gx,gy=map(int,input().split())
    gx-=1
    gy-=1
    g=[list(input()) for _ in range(h)]
    v=[[0 for j in range(w)] for i in range(h)]
    v2=[[0 for j in range(w)] for i in range(h)]
    q=[]
    heappush(q,[0,sx,sy])
    while q:
        c,x,y=heappop(q)
        if x==gx and y==gy:
            print(c)
            exit()
        if v[x][y]==1:
            continue
        v[x][y]=1
        for a in range(-2,3):
            for b in range(-2,3):
                if a==b==0:
                    continue
                if a*b==0 and abs(a+b)==1:
                    nx=x+a
                    ny=y+b
                    if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and v[nx][ny]==0:
                        heappush(q,[c,nx,ny])
                    continue
                nx=x+a
                ny=y+b
                if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and v[nx][ny]==0 and v2[nx][ny]==0:
                    heappush(q,[c+1,nx,ny])
                    v2[nx][ny]=1
    print(-1)
if __name__=='__main__':
    main()

### FIXED CODE ###

from collections import deque
def main():
    h,w=map(int,input().split())
    sx,sy=map(int,input().split())
    sx-=1
    sy-=1
    gx,gy=map(int,input().split())
    gx-=1
    gy-=1
    g=[tuple(input()) for _ in range(h)]
    v=[[0 for j in range(w)] for i in range(h)]
    q=deque([[sx,sy]])
    v[sx][sy]=1
    ans=0
    k=[[0,1],[0,-1],[1,0],[-1,0]]
    while True:
        l=[]
        while q:
            x,y=q.popleft()
            l.append([x,y])
            if x==gx and y==gy:
                print(ans)
                exit()
            for a,b in k:
                nx=x+a
                ny=y+b
                if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and v[nx][ny]==0:
                    q.append([nx,ny])
                    v[nx][ny]=1
        if len(l)==0:
            break
        for x,y in l:              
            for a in range(-2,3):
                for b in range(-2,3):
                    if a*b==0 and abs(a+b)<=1:
                        continue
                    nx=x+a
                    ny=y+b
                    if 0<=nx<h and 0<=ny<w and g[nx][ny]=='.' and v[nx][ny]==0:
                        q.append([nx,ny])
                        v[nx][ny]=1
        ans+=1 
    print(-1)
if __name__=='__main__':
    main()
### BUGGY CODE ###

N, K = input().split()
N = int(N)
K = int(K)
a = input().split()
A = [int(u) for u in a]
Prod = 1
G = []
for i in range(0, N):
	Prod *= A[i]
	if i >= K:
		Prod = Prod // A[i - K]
	if i >= K - 1:
		G.append(Prod)

for i in range(0, N - K):
	if G[i] < G[i + 1]:
		print("Yes")
	else:
		print("No")

### FIXED CODE ###

N, K = input().split()
N = int(N)
K = int(K)
a = input().split()
A = [int(u) for u in a]
for i in range(0, N):
	if i >= K:
		if A[i] > A[i - K]:
			print("Yes")
		else:
			print("No")
### BUGGY CODE ###

from sys import stdin

S = stdin.readline().rstrip()

count = 0
prev_S = ""
while(True):
    if S == prev_S or S == "":
        break
    prev_S = S
    S = S.replace("01", "").replace("10", "")
    count += len(prev_S) - len(S)

print(count)

### FIXED CODE ###

from sys import stdin

S = stdin.readline().rstrip()

stack = []
count = 0

for s in S:
    # スタックが空なら
    if not stack:
        stack.append(s)
    # スタックの一番上がsでなければ
    elif stack[-1] != s:
        stack.pop()
        count += 2
    else:
        stack.append(s)

print(count)
### BUGGY CODE ###

n=int(input())
o=list(i for i in range(1,n+1))
sum=0
for j in o:
    if j%5==0:
        o.remove(j)
for j in o:
    if j%3==0:
        o.remove(j)
for k in o:
    sum+=k
print(sum)

### FIXED CODE ###

n=int(input())
l=[]
o=list(i for i in range(1,n+1))
for j in o:
    if j%5 ==0 or j%3 ==0:
        l.append(j)
print(sum(o)-sum(l))
### BUGGY CODE ###

n, m = map(int, input().split())
a = [0]*m
for i in range(m):
  a[i] = int(input())


r1 = 1
if 1 in a:
  r = 0
else:
  r = 1
for i in range(2, n+1):
  r2 = r1
  r1 = r
  if i in a:
    r = 0
  elif r1 == 0 and r2 == 0:
    r = 0
    break
  else:
    r = r1 + r2

print(r%1000000007)

### FIXED CODE ###

n, m = map(int, input().split())
a = [0]*m
for i in range(m):
  a[i] = int(input())

up = [0]*(m+1)
if m == 0:
  up[0] = n
else:
  up[0] = a[0]-1
  up[m] = n - a[m-1]-1
  for i in range(m-1):
    up[i+1] = a[i+1]-a[i]-2

ans = 1
if -1 in up:
  ans = 0
else:
  f = [0]*(max(up)+1)
  f[0] = 1
  if max(up) > 0:
    f[1] = 1
    for i in range(2, max(up)+1):
      f[i] = f[i-1] + f[i-2]
  for i in range(m+1):
    ans *= f[up[i]]

print(ans % 1000000007)
### BUGGY CODE ###

n, k = map(int, input().split())
mod = 10 ** 9 + 7

# modify pow and inverse
# put inverse into val
class ModInt:
    def __init__(self, num, mod):
        self.num = num
        self.mod = mod

    def __str__(self):
        return str(self.num)

    def __repr__(self):
        return "ModInt(num: {}, mod: {}".format(self.num, self.mod)

    def __add__(self, other):
        ret = self.num + other.num
        ret %= self.mod
        return ModInt(ret, self.mod)

    def __sub__(self, other):
        ret = self.num - other.num
        ret %= self.mod
        return ModInt(ret, self.mod)

    def __mul__(self, other):
        ret = self.num * other.num
        ret %= self.mod
        return ModInt(ret, self.mod)

    def pow(self, times):
        if times == 0:
            return ModInt(1, self.mod)

        x = self.pow(times // 2)
        x *= x
        if times % 2:
            x *= self

        return x

    def inverse(self):
        return self.pow(self.mod - 2)

    def __truediv__(self, other):
        num = self * other.inverse()
        return ModInt(num, self.mod)


class Combination:
    def __init__(self, n, mod):
        self.mod = mod
        self.fact = [ModInt(1, mod)]
        self.inverse = [ModInt(1, mod)]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * ModInt(i, mod))
            self.inverse.append(self.inverse[-1] * ModInt(i, mod).inverse())

    def comb(self, n, k):
        if k < 0 or n < k:
            return ModInt(0, self.mod)

        return self.fact[n] * self.inverse[k] * self.inverse[n-k]


mx = min(k, n - 1)
comb = Combination(n, mod)
ans = ModInt(0, mod)

for i in range(mx + 1):
    ans += comb.comb(n, i) * comb.comb(n - 1, i)

print(ans)


### FIXED CODE ###

n, k = map(int, input().split())
mod = 10 ** 9 + 7

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 = 2 * 2 * 10 ** 5
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 )


mx = min(k, n - 1)
ans = 0
for i in range(mx + 1):
    ans += cmb(n, i, mod) * cmb(n - 1, n - i - 1, mod)
    ans %= mod

print(ans)
### BUGGY CODE ###

N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = input()
a = [0]*N

score = {'r':P,'s':R,'p':S}
T2 = ''
for i in range(N):
    if i+K<=N-1:
        if a[i]==0 and T[i]==T[i+K]:
            a[i+K]=1
    if a[i]==0:
        T2+=T[i]
ans = 0
for one in T2:
    ans+=score[one]
print(ans)

### FIXED CODE ###

N, K = list(map(int, input().split()))
R, S, P = list(map(int, input().split()))
T = input()
a = [0]*N

score = {'r':P,'s':R,'p':S}
ans = 0
for i in range(N):
    if i+K<=N-1:
        if a[i]==0 and T[i]==T[i+K]:
            a[i+K]=1
    if a[i]==0:
        ans+=score[T[i]]
print(ans)
### BUGGY CODE ###

import sys
input = sys.stdin.readline
import math
n = int(input())
a = list(map(int,input().split()))

ans = 10**18
prod = 1
for i in range(n):
    prod *= a[i]

if prod > ans:
    print(-1)
else:
    print(prod)

### FIXED CODE ###

import sys
input = sys.stdin.readline

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

ans = 1000000000000000000
prod = 1
f = 0
f2 = 0

for i in range(n):
    if a[i] == 0:
        f = 1
        break

for i in range(n):
    prod = prod * a[i]

    if prod > ans:
        f2 = 1
        break

if f == 1:
    print(0)

else:
    if f2 == 1:
        print(-1)
    else:
        print(prod)
### BUGGY CODE ###

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

for i in range(N):
  List.append(str(A.index(i+1)+1))



print(' '.join(List))

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
List = [0]*N


for i, a in enumerate(A):
  List[int(a)-1] = str(i+1)

  
print(" ".join(List))
### BUGGY CODE ###

N,Q=map(int,input().split())
tree={}
for i in range(N-1):
  a,b=map(int,input().split())
  if (a-1) in tree:
    tree[a-1].append(b-1)
  else:
    tree[a-1]=[b-1]
  if (b-1) in tree:
    tree[b-1].append(a-1)
  else:
    tree[b-1]=[a-1]

point={}

for i in range(Q):
  p,x=map(int,input().split())
  if (p-1) in point:
    point[p-1]+=x
  else:
    point[p-1]=x

ans=[0]*N
stack=[]
stack.append([0,0,-1])
while len(stack)>0:
  nodes=stack.pop()
  node=nodes[0]
  sump=nodes[1]
  parent=nodes[2]
  if node in point:
    sump=sump+point[node]
  ans[node]=sump
  if node in tree:
      childs=tree[node]
      for child in childs:
        if child!=parent:
          stack.append([child,sump,node])

print(*ans)

### FIXED CODE ###

N,Q=map(int,input().split())
tree={}
for i in range(N-1):
  a,b=map(int,input().split())
  if (a-1) in tree:
    tree[a-1].append(b-1)
  else:
    tree[a-1]=[b-1]
  if (b-1) in tree:
    tree[b-1].append(a-1)
  else:
    tree[b-1]=[a-1]

point=[0]*N

for i in range(Q):
  p,x=map(int,input().split())
  point[p-1]+=x

ans=[0]*N
stack=[]
stack.append([0,0,-1])
while len(stack)>0:
  nodes=stack.pop()
  node=nodes[0]
  sump=nodes[1]
  parent=nodes[2]
  sump=sump+point[node]
  ans[node]=sump
  if node in tree:
      childs=tree[node]
      for child in childs:
        if child!=parent:
          stack.append([child,sump,node])

print(*ans)