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

# -*- coding: utf-8 -*-
import sys
S=sys.stdin.readline().strip()
N=len(S)
mod=10**9+7
S=S[::-1]

dp=[ [ 0 for j in range(13) ] for i in range(N) ]

for i,x in enumerate(S):  #i桁目
    if i==0:
        if x!="?":
            x=int(x)
            dp[i][(x*pow(10,i,13))%13]=1
        else:
            for x in range(10):
                dp[i][(x*pow(10,i,13))%13]=1
    else:
        if x!="?":
            x=int(x)
            for j in range(13):
                n=(x*pow(10,i,13)+j)%13
                dp[i][n]+=dp[i-1][j]
                dp[i][n]%=mod
        else:
            for j in range(13):
                for x in range(10):
                    n=(x*pow(10,i,13)+j)%13
                    dp[i][n]+=dp[i-1][j]
                    dp[i][n]%=mod
print dp[N-1][5]%mod


### FIXED CODE ###

S=raw_input()
S=S[::-1]
l=len(S)

dp=[ 0 for j in range(13) ]
dp[0]=1

mod=10**9+7

dp2=[ 0 for _ in range(13) ]

keta=1

for i in range(1,l+1):
	dp2=[0]*13
	for j in range(13):
		if dp[j]!=0:
			if S[i-1]=="?":
				for k in range(10):
					next=(k*keta+j)%13 
					dp2[next]+=dp[j]
					dp2[next]%=mod
			else:
				k=int(S[i-1])
				next=(k*keta+j)%13
				dp2[next]+=dp[j]
				dp2[next]%=mod

	dp=dp2
	keta=(keta*10)%13

print dp[5]
### BUGGY CODE ###

N,K = map(int, input().split())
A = [int(i) for i in input().split()]

l=[]
for i in range(N+1):
  l.append(A.count(i))

ls = sorted(l,reverse=True)

print(sum(ls[K:]))

### FIXED CODE ###

import collections as co
N,K = map(int, input().split())
A = list(map(int, input().split()))

ldic = co.Counter(A)        
l = list(ldic.values())
ls = sorted(l,reverse=True)

print(sum(ls[K:]))
### BUGGY CODE ###

import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
K=int(input())
count=0
for t in range(K):
    for s in range(K):
        for v in range(K):
            count+=(gcd(t+1,s+1,v+1))
print(count)

### FIXED CODE ###

import math
K=int(input())
count=0
for t in range(1,K+1):
    for s in range(t,K+1):
        for v in range(s,K+1):
            if t!=s!=v:
                count+=(6*math.gcd((math.gcd(t,s)),v))
            elif (t==s and t!=v) or (t==v and t!=s)or (s==v and s!=t):
                count+=(3*math.gcd((math.gcd(t,s)),v))
            else:
                count+=math.gcd((math.gcd(t,s)),v)
print(count)
### BUGGY CODE ###

def main():
    s=input()
    k=int(input())
    tank=[]
    n=len(s)
    for length in range(1,n+1):
        for i in range(n-length+1):
            if s[i:i+length] not in tank:
                tank.append(s[i:i+length])
    tank.sort()
    print(tank[k-1])      
    
if __name__ == "__main__":
    main()


### FIXED CODE ###

def main():
    s=input()
    m=int(input())
    tank=[]
    n=len(s)
    alpha=[chr(i) for i in range(97, 97+26)]
    for i in range(26):
        for j in range(n):
            if alpha[i]==s[j]:
                for k in range(min(n-j,m)):
                    if s[j:j+k+1] not in tank:
                        tank.append(s[j:j+k+1])
        if len(tank)>=m:
            break
    tank.sort()
    print(tank[m-1])
    
if __name__ == "__main__":
    main()
### BUGGY CODE ###

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

if 0 in A:
    print(0)
else:
    ans = 1
    for a in A:
        ans *= a
    
    if ans > 10**18:
        print(-1)
    else:
        print(ans)

### FIXED CODE ###

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

flag = 0

if 0 in A:
    print(0)
else:
    ans = 1
    for a in A:
        ans *= a
        if ans > 10**18:
            flag = 1
            break
    if flag == 0:
        print(ans)
    else:
        print(-1)
### BUGGY CODE ###

import numpy as np

N = int(input())
dp = np.array([ [0] * (N+1), [0] * (N+1), [0] * (N+1) ])

for i in range(1, N+1):
	a, b, c = map(int, input().split())
	dp[0, i] = dp[1:, i-1].max() + a
	dp[1, i] = dp[::2, i-1].max() + b
	dp[2, i] = dp[:2, i-1].max() + c
	#print('i, dp[i] =',i, dp[:, i])

print(dp[:, N].max())


### FIXED CODE ###

# numpyだとTLE。よって普通の2次元リストで。
# import numpy as np

N = int(input())
# dp = np.array([ [0] * (N+1), [0] * (N+1), [0] * (N+1) ])
dp = [ [0] * (N+1), [0] * (N+1), [0] * (N+1) ]

for i in range(1, N+1):
	a, b, c = map(int, input().split())
	dp[0][i] = max(dp[1][i-1], dp[2][i-1]) + a
	dp[1][i] = max(dp[0][i-1], dp[2][i-1]) + b
	dp[2][i] = max(dp[0][i-1], dp[1][i-1]) + c
	# dp[0, i] = dp[1:, i-1].max() + a
	# dp[1, i] = dp[::2, i-1].max() + b
	# dp[2, i] = dp[:2, i-1].max() + c	
	# print('i, dp[i] =',i, dp[:, i])

#print(dp[:, N].max())
print(max(dp[0][N], dp[1][N], dp[2][N]))
### BUGGY CODE ###


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

def main():
    h,w=map(int,input().split())
    ls=[input() for _ in range(h)]
    s=[[] for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if ls[i][j]=="#":
                s[i].append(1)
            else:
                s[i].append(0)

    u=UnionFind(h*w)

    for i in range(h):
        for j in range(w):
            if j !=0:
                if s[i][j-1] != s[i][j]:
                    u.union(i*w+j-1,i*w+j)
            if i !=0:
                if s[i-1][j] != s[i][j]:
                    u.union((i-1)*w+j,i*w+j)
    res = 0
    for i in range(h*w):
        for j in range(i,h*w):
            if s[i//w][i%w] != s[j//w][j%w]:
                if u.same(i,j):
                    res += 1
    print(res)

main()

### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)

h,w=map(int,input().split())
s=[input() for _ in range(h)]
flag = [[0]*w for _ in range(h)]

def dfs(th,tw):
    global flag,h,w,s
    flag[th][tw] = True
    tblack = 0
    twhite = 0
    if s[th][tw] == "#":
        tblack += 1
    else:
        twhite += 1 
    for x,y in ([0,1],[0,-1],[1,0],[-1,0]):
        nth = th + x
        ntw = tw + y
        if nth >= 0 and nth < h and ntw >= 0 and ntw < w:
            if not flag[nth][ntw] and s[th][tw] != s[nth][ntw]:
                ttb,ttw = dfs(nth,ntw)
                tblack += ttb
                twhite += ttw
    return [tblack,twhite]
                
def main():
    global flag,h,w,s
    res = 0
    for i in range(h):
        for j in range(w):
            if not flag[i][j]:
                black,white = dfs(i,j)
                res += black * white 

    return res
print(main())
### BUGGY CODE ###

s=input()
A=[]
B=[]
for i in range(len(s)):
    for j in range(len(s)):
        if i<j and s[i]=='A' and s[j]=='Z':
            A.append(s[i:j+1])
for i in range(len(A)):
    B.append(len(A[i]))
print(max(B))

### FIXED CODE ###

s=input()
A=[]
B=[]
for i in range(0,len(s)):
    if s[i]=='A':
        a=i
        break
S=list(reversed(s))
for j in range(0,len(S)):
    if S[j]=='Z':
        b=j
        break
print(len(s)-a-b)
### BUGGY CODE ###

def main():
  s=input()
  k=int(input())
  substr=[]
  l=len(s)
  
  for i in range(l):
    substring=''
    for j in range(i,l):
      substring+=s[j]
      substr.append(substring)
  substr.sort()
  #print(substr)
  cnt,i=1,0
  ans=substr[0]
  while cnt<k :
    if substr[i]!=substr[i+1]:
      cnt+=1
      if cnt==k:
        ans=substr[i+1]
        break
    i+=1
  print(ans)
if __name__=='__main__':
  main()

### FIXED CODE ###

def main():
  s=input()
  k=int(input())
  l=len(s)
  
  substr=set()
  for alpha in 'abcdefghijklmnopqrstuvwxyz':
    for i in range(l):
      if s[i]==alpha:
        sub=s[i]
        substr.add(sub)
        j=i+1
        cnt=0
        while j<l and cnt<6:
          sub+=s[j]
          substr.add(sub)
          j+=1
          cnt+=1
    if len(substr)>k:
      break
      
  substr=list(substr)
  substr.sort()
  print(substr[k-1])
if __name__=='__main__':
  main()
### BUGGY CODE ###

N = int(input())
s = []
ans = 0
for _ in range(N):
    si = input()
    sortedSi = "".join(sorted(list(si)))
    ans += s.count(sortedSi)
    s.append(sortedSi)

print(ans)


### FIXED CODE ###

N = int(input())
dic = {}
ans = 0
for _ in range(N):
    si = input()
    sortedSi = "".join(sorted(si))
    if sortedSi in dic:
        dic[sortedSi] += 1
    else:
        dic[sortedSi] = 1

for val in dic.values():
    ans += val * (val - 1) // 2

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

import math
from functools import reduce

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

def main():
    #n, k = map(int,input().split())
    k = int(input())
    lists = []
    sum = 0
    for i in range(1,k+1):
        for j in range(1,k+1):
            for l in range(1,k+1):
                #print(i,j,l)
                sum = sum + gcd(i,j,l)
    print(sum)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import math

def main():
    #n, k = map(int,input().split())
    k = int(input())
    lists = []
    sum = 0
    for i in range(k):
        for j in range(k):
            for l in range(k):
                sum = sum + math.gcd(math.gcd(i+1 ,j+1), l+1)
    print(sum)

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

import sys

n, q = list(map(int, input().split()))
MOD = 10 ** 9 + 7
INV2 = (MOD + 1) // 2
lines = sys.stdin.readlines()
aaa = list(map(int, lines[:n]))
mat = [[0] * n for _ in [0] * n]
for i in range(n):
    for j in range(n):
        mat[i][j] = int(aaa[i] < aaa[j])
# print(*mat, sep='\n')
for line in lines[n:]:
    x, y = map(int, line.split())
    x -= 1
    y -= 1
    mat[x][y] = mat[y][x] = (mat[x][y] + mat[y][x]) * INV2 % MOD
    for i in range(n):
        if i == x or i == y:
            continue
        mat[x][i] = mat[y][i] = (mat[x][i] + mat[y][i]) * INV2 % MOD
        mat[i][x] = mat[i][y] = (mat[i][x] + mat[i][y]) * INV2 % MOD
    # print(x, y)
    # print(*mat, sep='\n')

ans = sum(sum(row[:i]) for i, row in enumerate(mat)) % MOD
ans = (ans << q) % MOD
print(ans)


### FIXED CODE ###

import sys

n, q = list(map(int, input().split()))
MOD = 10 ** 9 + 7
INV2 = (MOD + 1) // 2
lines = sys.stdin.readlines()
aaa = list(map(int, lines[:n]))
mat = [[0] * n for _ in [0] * n]
for i in range(n):
    for j in range(n):
        mat[i][j] = int(aaa[i] < aaa[j])
# print(*mat, sep='\n')
for line in lines[n:]:
    x, y = map(int, line.split())
    x -= 1
    y -= 1
    mat[x][y] = mat[y][x] = (mat[x][y] + mat[y][x]) * INV2 % MOD
    for i in range(n):
        if i == x or i == y:
            continue
        mat[x][i] = mat[y][i] = (mat[x][i] + mat[y][i]) * INV2 % MOD
        mat[i][x] = mat[i][y] = (mat[i][x] + mat[i][y]) * INV2 % MOD
    # print(x, y)
    # print(*mat, sep='\n')

ans = sum(sum(row[:i]) for i, row in enumerate(mat)) % MOD
ans = (ans << q) % MOD
print(ans)
### BUGGY CODE ###

x = int(input())
a = 1
b = 0
A = []

while True:
    if a ** 5 - x > 0:
        A.append(a ** 5 - x)
        break
    A.append(a ** 5 - x)
    a = a + 1

while True:
    if b ** 5 in A:
        break
    elif -b ** 5 in A:
        b = -b
        break
    b = b + 1

a = int((x + b ** 5) ** 0.2)

print(a, b)

### FIXED CODE ###

x = int(input())
a = 2
b = 0
A = []
A.append(1 ** 5 - x)

while True:
    if (a + 1) ** 5 - a ** 5 > 10 ** 10:
        break
    A.append(a ** 5 - x)
    a = a + 1

while True:
    if b ** 5 in A:
        break
    elif -b ** 5 in A:
        b = -b
        break
    b = b + 1

a = int((x + b ** 5) ** 0.2)

print(a, b)
### BUGGY CODE ###

N, M =  map(int, input().split())
a_list = [int(input()) for _ in range(M)]
ans_list = [1] + [0] * N

for i in range(1, N+1):
    if i == 1:
        if 1 not in a_list:
            ans_list[1] += ans_list[i-1]
    else:
        if i not in a_list:
            ans_list[i] += ans_list[i-2]
            ans_list[i] += ans_list[i-1]

print(int(ans_list[-1]%1000000007))

### FIXED CODE ###

import sys

N, M =  map(int, input().split())
a_list = [int(input()) for _ in range(M)]

if N == 1:
    print(1)

else:
    a = 1
    ans = 1

    if M == 0:
        b = 1
        for i in range(2, N+1):
            ans = (a+b)%1000000007
            a, b = b, ans

    elif M == 1:
        if a_list[0] == 1:
            b = 0
            m = 1
        else:
            b = 1
            m = 0
        for i in range(2, N+1):
            if a_list[0] == i:
                a, b = b, 0
            else:
                ans = (a+b)%1000000007
                a, b = b, ans

    else:
        if a_list[0] == 1:
            b = 0
            m = 1
        else:
            b = 1
            m = 0
        for i in range(2, N+1):
            if m < M-1:
                if a_list[m+1] - a_list[m] == 1:
                    print(0)
                    sys.exit()

                if a_list[m] == i:
                    a, b = b, 0
                    m += 1
                else:
                    ans = (a+b)%1000000007
                    a, b = b, ans

            else:
                if a_list[m] == i:
                    a, b = b, 0
                else:
                    ans = (a+b)%1000000007
                    a, b = b, ans

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

import collections
import sys

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = [int(x) for x in readline().split()]
ac = collections.Counter(A)
assert set(ac.keys()).issubset({1, 2, 3})
K = sum(ac.values())


dp = [[[None] * (K + 1) for _ in range(K + 1)] for _ in range(K + 1)]


def solve(c1, c2, c3):
    csum = c1 + c2 + c3
    if csum == 0:
        return 0.0
    cached = dp[c1][c2][c3]
    if cached is not None:
        return cached
    ans = 0.0
    if c1 > 0:
        ans += c1 / csum * (1.0 + solve(c1 - 1, c2, c3))
    if c2 > 0:
        ans += c2 / csum * (1.0 + solve(c1 + 1, c2 - 1, c3))
    if c3 > 0:
        ans += c3 / csum * (1.0 + solve(c1, c2 + 1, c3 - 1))
    c0 = N - csum
    ans += c0 / csum
    dp[c1][c2][c3] = ans
    return ans


if __name__ == "__main__":
    print(solve(ac[1], ac[2], ac[3]))


### FIXED CODE ###

import collections
import sys

sys.setrecursionlimit(10 ** 8)
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
A = [int(x) for x in readline().split()]
ac = collections.Counter(A)
assert set(ac.keys()).issubset({1, 2, 3})


def solve(c1, c2, c3):
    K = c1 + c2 + c3
    L = K + 1
    L2 = L ** 2
    dp = [0.0] * L ** 3
    for i3 in range(c3 + 1):
        for i2 in range(c2 + c3 + 1):
            for i1 in range(N - i2 - i3 + 1):
                isum = i1 + i2 + i3
                if isum == 0:
                    continue
                i0 = N - i1 - i2 - i3
                if i0 < 0:
                    continue
                e = i0
                if i1 > 0:
                    e += i1 * (1.0 + dp[(i1 - 1) * L2 + i2 * L + i3])
                if i2 > 0 and i1 <= K:
                    e += i2 * (1.0 + dp[(i1 + 1) * L2 + (i2 - 1) * L + i3])
                if i3 > 0 and i2 + 1 <= c2 + c3:
                    e += i3 * (1.0 + dp[i1 * L2 + (i2 + 1) * L + i3 - 1])
                dp[i1 * L2 + i2 * L + i3] = e / isum
    return dp[c1 * L2 + c2 * L + c3]


if __name__ == "__main__":
    print(solve(ac[1], ac[2], ac[3]))
### BUGGY CODE ###

n = [i for i in input()]
ans = 0

while 'W' in n:
    #print(n)
    if n[0] =='W':
        n = n[1:]

    for i, s in enumerate(n):
        if s == 'W':
            n[i] = 'B'
            n = n[1:]
            ans += i
            break
print(ans)


### FIXED CODE ###

S = [i for i in input()]
ans = 0
c = 0
'''while S[0] == 'W':
    S = S[1:]
    '''
for i,s in enumerate(S):
    if s == 'B':
        c += 1
    else:
        ans += c
print(ans)
### BUGGY CODE ###

import sys
from itertools import permutations

def warshall_floyd(d):
    n = len(d)
    for i in range(n):
        for j in range(n):
            for k in range(n):
                d[j][k] = min(d[j][k], d[j][i] + d[i][k])
    return d


def main():
    input = sys.stdin.readline
    N, M, R = map(int, input().split())
    r = list(map(int, input().split()))

    INF = 10**9
    A = [[INF for _ in range(N)] for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        A[a-1][b-1] = c
        A[b-1][a-1] = c

    A = warshall_floyd(A)

    ans = INF
    for start in r:
        passed = [start]
        temp_ans = 0
        while len(passed) < len(r):
            cur = INF
            next_start = -1
            for dest in r:
                if dest in passed:
                    continue

                if A[start-1][dest-1] < cur:
                    next_start = dest
                    cur = A[start-1][dest-1]

            passed.append(next_start)
            start = next_start
            temp_ans += cur

        ans = min(ans, temp_ans)

    return ans


if __name__ == '__main__':
    print(main())


### FIXED CODE ###

import sys
import numpy as np
from scipy.sparse.csgraph import floyd_warshall
from itertools import permutations


def main():
    input = sys.stdin.readline
    N, M, R = map(int, input().split())
    r = list(map(int, input().split()))

    INF = 10**9
    A = [[INF for _ in range(N)] for _ in range(N)]
    for _ in range(M):
        a, b, c = map(int, input().split())
        A[a-1][b-1] = c
        A[b-1][a-1] = c

    D = np.array(A, dtype=int)
    G = floyd_warshall(D)

    """
    ans = INF
    for start in r[:2]:
        passed = [start]
        temp_ans = 0
        while len(passed) < len(r):
            cur = INF
            next_start = -1
            for dest in r:
                if dest in passed:
                    continue

                if A[start-1][dest-1] < cur:
                    next_start = dest
                    cur = A[start-1][dest-1]

            passed.append(next_start)
            start = next_start
            temp_ans += cur

        ans = min(ans, temp_ans)
    """

    ans = INF
    for root in permutations(r):
        cur = 0
        for i in range(R-1):
            s, g = root[i] -1, root[i+1] - 1
            cur += G[s][g]

        ans = min(ans, cur)

    return int(ans)


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

n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
    b.append(a[i])
    b.reverse()
for i in range(n):
    print(b[i], end=" ")

### FIXED CODE ###

n = int(input())
a = list(map(int,input().split()))
b = a[::2]
c = a[1::2]
if n %2 == 0:
    c.reverse()
    ans =c + b
else:
    b.reverse()
    ans = b + c
for i in range(n):
    print(ans[i], end =' ')
### BUGGY CODE ###

import heapq
def SME(start,end):
    A = []
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] == 0:
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * 0.995 : break
    for i in range(L):
        if ANS[i] == 0 : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] == 0 : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
Whole = [int(x) for x in input().split()]
ANS = [0]*N
ANS = SME(0, N)
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
### BUGGY CODE ###

from itertools import permutations
INF = float('inf')
n, m, R = map(int, input().split())
r = list(map(int, input().split()))
dist = [[INF]*(n+1) for _ in range(n+1)]
for i in range(n+1):
    dist[i][i] = 0
for i in range(m):
    a, b, c = map(int, input().split())
    dist[a][b] = c
    dist[b][a] = c
    
for k in range(1, n+1):
    for i in range(1, n+1):
        for j in range(i, n+1):
            dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
            dist[j][i] = dist[i][j]
# for d in dist: print(d)

ans = INF
for p in permutations(r):
    ans_ = 0
    for i in range(R-1):
        ans_ += dist[p[i]][p[i+1]]
    if ans_ > ans:
	    break
    ans = min(ans, ans_)
print(ans)


### FIXED CODE ###

from itertools import permutations

INF = float('inf')
n, m, R = list(map(int, input().split()))
r = list(map(int, input().split()))
dist = [[INF]*(n+1) for _ in range(n+1)]
for i in range(1, n+1):
    dist[i][i] = 0
for i in range(m):
    a, b, c = map(int, input().split())
    dist[a][b] = c
    dist[b][a] = c

from scipy.sparse import csgraph
dist = csgraph.floyd_warshall(dist)
# for k in range(n):
#     for i in range(n):
#         for j in range(n):
#             dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j])
# for d in dist: print(d)

ans = INF
for p in permutations(r):
    ans_ = 0
    for i in range(R-1):
        ans_ += dist[p[i]][p[i+1]]
    ans = min(ans, ans_)
print(int(ans))
### BUGGY CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
sum=[0]*n
sum[0]=a[0]
for i in range(1,n):
        sum[i]=sum[i-1]*a[i]
        if i>=k:
            sum[i]/=a[i-k]
       
for i in range(k,n):
    if sum[i]>sum[i-1]:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

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

for i in range(k,n):
    if a[i]>a[i-k]:
        print('Yes')
    else:
        print('No')
### BUGGY CODE ###

n = int(input())
x = list(map(int, input().split()))
ans = x[0]
for i in range(1,n):
	ans = ans * x[i]
	if ans > 10 ** 18 and 0 not in x:
		ans = -1
		break
print(ans)

### FIXED CODE ###

n = int(input())
x = list(map(int, input().split()))
ans = x[0]
if 0 in x:
	ans = 0
else:
	for i in range(1,n):
		ans = ans * x[i]
		if ans > 10 ** 18:
			ans = -1
			break
print(ans)