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

import sys
sys.setrecursionlimit(10**7)
import copy
def myhash(v):
    r = 0
    for i in v:
        r += pow(2, i)
    return r
def myhash2(r, N):
    vv = set()
    for i, v in enumerate(format(r, '0'+str(N)+'b')):
        if v == '1':
            vv.add(N-i-1)
    return vv
def main():
    N, M  = map(int, input().split())
    l = [[] for _ in range(N)]
    r = []
    for _ in range(M):
        a, b = map(int, input().split())
        l[a-1].append(b-1)
    a = []
    def cyclic(n, l, r):
        ans = []
        r += pow(2, n)
        v = myhash2(r, N)
        for i in  l[n]:
            if i in v:
                a.append(r)
                return
                #return True, v
        for i in l[n]:
            cyclic(i, l, r)
        return
    for i in range(N):
        r = 0
        cyclic(i, l, r)
    if a:
        m = 100000
        rr = None
        for i in a:
            x = len(myhash2(i, N))
            if m > x:
                m = x
                rr = i
        print(m)
        for i in myhash2(rr, N):
            print(i+1)
    else:
        print(-1)
    return -1
main()


### FIXED CODE ###

import sys
sys.setrecursionlimit(10**7)
def main():
    N, M = map(int, input().split())
    l = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        l[a-1].append(b-1)
    c = [0] * N
    loop = []
    def cyclic(n):
        if c[n] == 2:
            return False
        if c[n] == 1:
            loop.append(n)
            return True
        c[n] = 1
        for i in l[n]:
            if cyclic(i):
                loop.append(n)
                return True
        c[n] = 2
        return False
    for i in range(N):
        if cyclic(i):
            break
    if len(loop) == 0:
        print(-1)
        return
    print(0)
    return
main()
### BUGGY CODE ###

from collections import deque
n = int(input())
tree = [[] for _ in range(n)]
edge = []
max_c = [0]*n
color = [set() for _ in range(n)]
ans = dict()
for i in range(n-1):
    a,b = map(int,input().split())
    edge.append([a,b])
    tree[a-1].append(b)
    tree[b-1].append(a)
    max_c[a-1] += 1
    max_c[b-1] += 1
print(max(max_c))


def breadth_first_search(start,W):
    work_q = deque([])
    visited = set()
    work_q.append(start)
    visited.add(start)
    while work_q:
        here = work_q.popleft()
        for i in W[here-1]:
            if i not in visited:
                work_q.append(i)
                visited.add(i)
                col = 1
                while col in color[here-1]:
                    col += 1
                color[here-1].add(col)
                color[i-1].add(col)
                ans[(here-1,i-1)] = col
    return visited

breadth_first_search(1,tree)
for i in range(n-1):
    start = edge[i][0]
    goal = edge[i][1]
    print(ans[start-1,goal-1])


### FIXED CODE ###

import sys
from collections import deque
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

n = int(input())
edge = [[] for _ in range(n+1)]
for i in range(n-1):
    a, b = map(int,input().split())
    edge[a].append((b, i))
    edge[b].append((a, i))
colors = 0
for i, line in enumerate(edge):
    colors = max(colors, len(line))
print(colors)
work_q = deque()
work_q.append((1, -1, -1))
color = [-1] * (n - 1)

while work_q:
    here, prev, col = work_q.popleft()
    cnt = 1
    for to, ind in edge[here]:
        if to == prev:
            continue
        if cnt == col:
            cnt += 1
        color[ind] = cnt
        work_q.append((to, here, cnt))
        cnt += 1
print(*color, sep="\n")
### BUGGY CODE ###

N = int(input())
L = list(map(int,input().split()))
j = set(L)
ans = 0
for i in j:
    if L.count(i) >= i:
        ans += L.count(i) - i
    else:
        ans += L.count(i)
print(ans)

### FIXED CODE ###

import collections
input()
c = collections.Counter(list(map(int,input().split())))
ans = 0
for i,j in c.items():
        if j >= i:
            ans += j - i
        else:
            ans += j
print(ans)
### BUGGY CODE ###

n = int(input())

print(0)
s0 = str(input())

print(n-1)

def is_ok(x):
    print(x)
    s = str(input())
    if s == s0:
        return False
    else:
        return True

l = 0
r = n-2
while l+1 < r:
    c = (l+r)//2
    if is_ok(c):
        r = c
    else:
        l = c


### FIXED CODE ###

def main():
    n = int(input())

    def q(i):
        print(i, )
        s = str(input())
        if s == 'Vacant':
            exit()
        else:
            return s

    x = q(n-1)
    x = q(0)

    def ok(m):
        if m == 0:
            return False
        else:
            if (m%2 == 0 and q(m) != x) or (m%2 == 1 and q(m) == x):
                return True
            else:
                return False

    l = 0
    r = n-1
    while l+1 < r:
        c = (l+r)//2
        if ok(c):
            r = c
        else:
            l = c

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

import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

a = int(arr_data[0][0])
b = int(arr_data[0][1])
x = int(arr_data[0][2])


#print(a, b, x)

cnt = 0
for i in range(a, b + 1):

    if i % x == 0:
        
        cnt += 1
        
        
print(cnt)

### FIXED CODE ###

from collections import Counter


def getinputdata():
    # 配列初期化
    array_result = []

    data = input()

    array_result.append(data.split(" "))

    flg = 1

    try:

        while flg:

            data = input()

            array_temp = []

            if (data != ""):

                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:

        return array_result

arr_data = getinputdata()

a = int(arr_data[0][0])
b = int(arr_data[0][1])
x = int(arr_data[0][2])

# print(a, b, x)

print(b // x - (a-1)//x)
### BUGGY CODE ###

input_n = int(input())
num_list = [int(i) for i in (input().split())]

count = 0
while True:
    if all(i % 2 == 0 for i in num_list):
        nom_list = map(lambda x: x / 2, num_list)
        count += 1
    else:
        break
print(count)

### FIXED CODE ###

_ = int(input())

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

count = 0
is_all_even = None 
while True:
    for num in num_list:
        if num % 2 != 0:
            is_all_even = False
            break
    if is_all_even is not None:
        break
    count += 1
    num_list = list(map(lambda x: x / 2, num_list))
print(count)
### BUGGY CODE ###

N = int(input())
a = [int(input()) for x in range(N)]

ans = max(a)
mx = max(a)
iteration = 1 
while (ans <= 1000000000000000000):
    flag = True 
    for item in a:
        if not (ans%item == 0):
           flag = False
    if flag:
        print(ans)
        break
    else:
        iteration = iteration + 1
        ans = iteration * mx

### FIXED CODE ###

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
 
def lcm(a, b):
    return a * b // gcd(a,b)
 
N = int(input())
Ts = []
c = 1
for i in range(N):
    c = lcm(c, int(input()))
 
print(int(c))
### BUGGY CODE ###

nkq = list(map(int, (input().split())))
ans = [int(input()) for i in range(nkq[2])]
hold_point = []
[hold_point.append(nkq[1]) for i in range(nkq[0])]
for i in range(nkq[2]):
    for v in range(nkq[0]):
        hold_point[v] -= 1
for i in ans:
    hold_point[i - 1] += 1
for i in hold_point:
    if i > 0:
        print('Yes')
    else:
        print('No')

### FIXED CODE ###

import numpy as np
nkq = list(map(int, (input().split())))
ans = [int(input()) for i in range(nkq[2])]
total = nkq[1] - nkq[2]
hold_point = np.array([total]*nkq[0])
for i in ans:
    hold_point[i - 1] += 1
for i in hold_point:
    if i <= 0:
        print('No')
    else:
        print('Yes')
### BUGGY CODE ###

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

def main():
    k = int(input())
    ans = 0

    if k % 2 == 0 or k % 5 == 0:
        print(-1)
    else:
        a = 7
        while 1:
            if a % k == 0:
                print(len(str(a)))
                break
            else:
                a = a * 10 + 7

if __name__ == '__main__':
    main()


### FIXED CODE ###

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

def main():
    k = int(input())
    ans = 1

    if k % 2 == 0 or k % 5 == 0:
        print(-1)
    else:
        a = 7
        while 1:
            if a % k == 0:
                print(ans)
                break
            else:
                a = (a % k) * 10 + 7
                ans += 1
if __name__ == '__main__':
    main()
### BUGGY CODE ###

import re
s = input()
s = s.replace('01','10')
cnt=0
t = re.subn('10','',s)
while t[1]!=0:
    a = t[0].replace('01','10')
    cnt += t[1]
    t = re.subn('10','',a)
print(int(cnt*2))

### FIXED CODE ###

s = input()
print(int(2*min(s.count('0'),s.count('1'))))
### BUGGY CODE ###

while 1:
        try:
                n, p = input(), 0
        except EOFError:
                break

        for x in xrange(1,n+1,2):
                for y in xrange(3,int(x**0.5)+1,2):
                        if x % y == 0:
                                break
                else:
                        p += 1
        print p

### FIXED CODE ###

p = [0 for x in range(999999)]
for x in xrange(1,999999,2):
        z = int(x**0.5)+1
        for y in xrange(3,z,2):
                if x % y == 0:
                        break
        else:
                p[x] = 1
p[1], p[2] = 0, 1

while 1:
        try:
                n = input()
                print sum(p[:n+1])
        except EOFError:
                break
### BUGGY CODE ###

n = int(input())
re =1

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

for i in l:
    re *= i
    
if(re > 1000000000000000000):
    print("-1")
else:
    print(re)

### FIXED CODE ###

n =int(input())
limit = 10**18
re =1
 
l = list(map(int, input().split()))
 
l.sort()
#print(l)
if(l[0] == 0):
    re = 0
else:
  for i in l:
    re *= i
    #print(re)
    if(re > limit):
      re = -1
      break
print(re)
### BUGGY CODE ###

num = int(input())
new = []

for i in range(num):
    a = list(input())
    a.sort()
    narr = ''.join(a)
    new.append(narr)

k = 0

for i in range(num):
    for j in range(i+1 , num):
        if new[i] == new[j]:
            k += 1

print(k)

### FIXED CODE ###

num = int(input())
arr = []
d = {}

for i in range(num):
    s = sorted(list(input()))
    ss = ''.join(s)
    arr.append(ss)

#print(arr)
ans = 0

for i in range(num):
    if arr[i] in d:
        ans += d[arr[i]] 
        d[arr[i]] += 1
    else:
        d[arr[i]] = 1

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

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# dp[i+1][j] i番目までの魔法を使ってモンスターへの攻撃jにする魔力の最小値
# (j=0の時まだ攻撃していない)
H, N = lr()
INF = 10 ** 10
dp = [[INF] * (H+10**4+10) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    a, b = lr()
    dp[i+1] = dp[i]
    for j in range(1, H+a+1):
        dp[i+1][j] = min(dp[i+1][j], dp[i+1][j-a] + b)

answer = min(dp[N][H:])
print(answer)


### FIXED CODE ###

import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# dp[i+1][j] i番目までの魔法を使ってモンスターへの攻撃jにする魔力の最小値
# (j=0の時まだ攻撃していない)
H, N = lr()
INF = 10 ** 10
dp = [INF] * (H+10**4+10)
dp[0] = 0
for i in range(N):
    a, b = lr()
    for j in range(a, H+a+1):
        if dp[j-a] == INF:
            continue
        dp[j] = min(dp[j], dp[j-a] + b)

answer = min(dp[H:])
print(answer)
### BUGGY CODE ###

from bisect import bisect
import sys

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

if n != len(set(a)) or m!= len(set(b)):
  print(0)
  sys.exit()
a.sort()
b.sort()

q = 1
for x in range(n*m, 0, -1):
  if x in a and x in b:
    q *= 1
  elif x in a:
    q = q * max(m - bisect(b, x), 0)  % p
  elif x in b:
    q = q * max(n - bisect(a, x), 0) % p
  else:
    u = bisect(a, x)
    v = bisect(b, x)
    q = q * max((n-u) * (m-v) - (n * m - x), 0) % p
print(q)
    
    
    

### FIXED CODE ###

from bisect import bisect
import sys

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

if n != len(set(a)) or m!= len(set(b)):
  print(0)
  sys.exit()
A = set(a)
B = set(b)
a.sort()
b.sort()

q = 1
for x in range(n*m, 0, -1):
  if x in A and x in B:
    q *= 1
  elif x in A:
    q = q * max(m - bisect(b, x), 0)  % p
  elif x in B:
    q = q * max(n - bisect(a, x), 0) % p
  else:
    u = bisect(a, x)
    v = bisect(b, x)
    q = q * (max((n-u) * (m-v) - (n * m - x), 0) % p) % p
print(q)
### BUGGY CODE ###

N,Q = map(int,input().split())
S = str(input())
lists = []
for i in range(Q):
    l,r = map(int,input().split())
    m = S[l-1:r]
    lists.append(m.count("AC"))
for i in range(len(lists)):
    print(lists[i]) 

### FIXED CODE ###

N, Q = map(int, input().split())
ruisekiwa = [0]
lists = []
cnt = 0
S = str(input())
for t in range(1, N):
    if S[t - 1] == "A" and S[t] == "C":
        cnt += 1
    ruisekiwa.append(cnt)
ruisekiwa.append(cnt)
for i in range(Q):
    l, r = map(int, input().split())
    ans = ruisekiwa[r - 1] - ruisekiwa[l - 1]
    lists.append(ans)
for m in range(len(lists)):
    print(lists[m])
### BUGGY CODE ###

import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=input()

for _ in range(q):
    l,r=map(int, input().split())
    ps=s[l - 1:r]
    cnt=0
    for i in range(0,len(ps)-1):
        if ps[i: i+2] == 'AC':
            cnt+=1
    print(cnt)

### FIXED CODE ###

import sys
input = sys.stdin.readline
n,q=map(int,input().split())
s=input()
cnt = 0
list=[0]
for i in range(0,len(s)-1):
    if s[i: i + 2] == 'AC':
        cnt += 1
    list.append(cnt)

for _ in range(q):
    l,r=map(int, input().split())
    print(list[r-1]-list[l-1])
### BUGGY CODE ###

N,K=[int(i) for i in input().split()]
A=[int(i) for i in input().split()]
s=[0 for i in range(200000)]
for i in range(200000):
    t=A.count(i)
    s[i]+=t
s.sort()
s.reverse()
p=0
for i in range(K):
    p+=s[i]
print(N-p)

### FIXED CODE ###

s=0
R=[]
N,K=[int(i) for i in input().split()]
A=[int(i) for i in input().split()]
import collections
c=collections.Counter(A).most_common()
# for i in c.values():
#     R.append(i)
if len(c)>K:
    for i in range(K):
        s+=c[i][1]
    print(N-s)
else:
    print("0")
### BUGGY CODE ###

s = list(input())

q = int(input())

reverse = 0

for i in range(q):
  query = list(input().split())
  if query[0] == '1':
    reverse ^= 1
    continue
  else:
    if query[1] == '1':
      if reverse:
        s.append(query[2])
      else:
        s.insert(0, query[2])
    else:
      if reverse:
        s.insert(0, query[2])
      else:
        s.append(query[2])
if reverse:
  s = s[::-1]
print(''.join(s))

### FIXED CODE ###

from collections import deque

s = deque(list(input()))

q = int(input())

reverse = 0

for i in range(q):
  query = list(input().split())
  if query[0] == '1':
    reverse ^= 1
    continue
  else:
    if query[1] == '1':
      if reverse:
        s.append(query[2])
      else:
        s.appendleft(query[2])
    else:
      if reverse:
        s.appendleft(query[2])
      else:
        s.append(query[2])
if reverse:
  print(''.join(s)[::-1])
else:
  print(''.join(s))
### BUGGY CODE ###

N = int(input())
A = [int(x) for x in input().split()]

mult = 1
for i in range(N):
    mult = mult*A[i]

if mult > 10**18:
    print('-1')
else:
    print(mult)
    

### FIXED CODE ###

import sys
N = int(input())
A = list(map(int,input().split()))
mult = 1

if 0 in A:
    print(0)
    sys.exit()
else:
    for i in A:
        mult *= i
        if mult > 10**18:
            print('-1')
            sys.exit()

print(mult)
### BUGGY CODE ###

n,m=map(int,input().split())
M=[1 for i in range(n)]
F=[]
for i in range(m):
    a,b=map(int,input().split())
    a,b=min(a,b),max(a,b)
    if [a,b] not in F:
        F.append([a,b])
for f in F:
    M[f[0]-1]+=1
print(max(M))


### FIXED CODE ###

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def unite(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 find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def size(self, x):
        return -self.parents[self.find(x)]

n, m = map(int,input().split())
uf = UnionFind(n)
for i in range(m):
    a,b = map(int,input().split())
    uf.unite(a-1, b-1)

ans = 0
for i in range(n):
    ans = max(ans,uf.size(i))

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

N,K = map(int,input().split())
a = list(map(int,input().split()))

d = 60
dp = [[-1]*N for _ in range(d+1)]
for i in range(N):
    dp[0][i] = a[i]-1

for i in range(d):
    for j in range(N):
        dp[i+1][j] = dp[i][dp[i][j]]

ans = 0

for i in range(d):
    if K & (1<<i):
        ans = dp[i][ans]

print(ans+1)




### FIXED CODE ###

n,k=map(int,input().split())
a=list(map(int,input().split()))
visited=[]
o=(n+1)*[-1]
cycle,l=1,0
v=1
while o[v]==-1:
  o[v]=len(visited)
  visited.append(v)
  v=a[v-1]
cycle=len(visited)-o[v]
l=o[v]
if k<l:
  print(visited[k])
else:
  k-=l
  k%=cycle
  print(visited[l+k])
### BUGGY CODE ###

N=int(input())
l=[]
l.append(input())
for i in range(1,N):
  s=input()
  for j in range(len(l)):
    if s==l[j]:
      break
    if j == len(l)-1:
      l.append(s)
  
print(len(l))

### FIXED CODE ###

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

print(len(set(l)))
### BUGGY CODE ###

n,*s=[t[:-1]for t in open(0)]
n=int(n)
c=0
for _ in range(n):
  c+=all(x==''.join(y)for x,y in zip(s,zip(*s)))*n
  s=s[1:]+s[:1]
print(c)

### FIXED CODE ###

n,*s=[t[:-1]for t in open(0)]
n=int(n)
c=0
for _ in range(n):
  c+=all(x==''.join(y)for x,y in zip(s,zip(*s)))*n
  s=s[1:]+s[:1]
print(c)
### BUGGY CODE ###

def resolve():
	# N: 足場の個数, K: 1回で右にジャンプできる足場の数
	N, K = map(int, input().split())
	# h: 各足場の高さ
	# dpテーブル宣言: dp[今いる足場の番号-1]=[最小コスト, 足場の高さ]
	dp = [
		[float('inf'), int(h_)]
		for h_ in input().split()
	]
	dp[0][0] = 0
	dp[1][0] = abs(dp[0][1] - dp[1][1])

	# k個左の足場からジャンプして来た時の最小コストを調べる
	for n in range(2, N):
		index_0 = max(0, n-K)
		h_ = dp[n][1]
		dp[n][0] = min(
			[
				abs( h_ - dp_[1] ) + dp_[0]
				for dp_ in set(map(tuple, dp[index_0:n]))
			]
		)
	print(dp[N-1][0])

resolve()

### FIXED CODE ###

def resolve():
	# N: 足場の個数, K: 1回で右にジャンプできる足場の数
	N, K = map(int, input().split())
	# h: 各足場の高さ
	# dpテーブル宣言: dp[今いる足場の番号-1]=[最小コスト, 足場の高さ]
	dp = [
		[float('inf'), int(h_)]
		for h_ in input().split()
	]
	dp[0][0] = 0
	dp[1][0] = abs(dp[0][1] - dp[1][1])

	# k個左の足場からジャンプして来た時の最小コストを調べる
	for n in range(2, N):
		index_0 = max(0, n-K)
		h_ = dp[n][1]
		dp[n][0] = min(
			[
				abs( h_ - dp_[1] ) + dp_[0]
				for dp_ in dp[index_0:n]
			]
		)
	print(dp[N-1][0])

resolve()
### BUGGY CODE ###

from sys import stdin

n, k = [int(x) for x in stdin.readline().strip().split()]
h_lst = [int(x) for x in stdin.readline().strip().split()]
min_cost_lst = [0] + [10**10] * (n-1)

for i in range(n):
  for j in range(1, k+1):
    if i + j < n:
      min_cost_lst[i + j] = min(min_cost_lst[i + j], min_cost_lst[i] + abs(h_lst[i+j] - h_lst[i]))

print(min_cost_lst[-1])

### FIXED CODE ###

import numpy as np

def main():
  N, K = map(int, input().split())
  h = list(map(int, input().split()))

  INF = 10**10

  dp = [INF]*N
  dp[0] = 0

  dp = np.array(dp)
  h = np.array(h)

  for i in range(N):
    T = min(N,i+K+1)
    dp[i+1:T] = np.minimum(dp[i+1:T], dp[i] + abs(h[i+1:T]-h[i]))

  print(dp[N-1])
  
if __name__ == '__main__':
    main()
### BUGGY CODE ###

N = int(input())
H = [int(e) for e in input().split()]
count_max = 0
for i in range(N):
  count = 0
  for j in range(i,N-1):
    if H[j] >= H[j+1]:
      count += 1
    else:
      i += j
      break;

  if count_max < count:
    count_max = count
  if count_max > N / 2:
    break;

print(count_max)

### FIXED CODE ###

N = int(input())
H = [int(e) for e in input().split()]
count_max = 0
i = 0
while i < N:
  judge = True
  count = 0
  tmp = i
  for j in range(tmp,N):
    if j < N-1:
      if H[j] >= H[j+1]:
        count += 1
      else:
        break;

  #print(count)
  if count_max < count:
    count_max = count
  if judge == True:
    i += count + 1

print(count_max)
### BUGGY CODE ###

from collections import deque

def bfs(maze, visited, sy, sx, gy, gx):
  queue = deque([[sy, sx]])
  visited[sy][sx] = 0
  while queue :
    y,x = queue.popleft()
    if [y, x] == [gy, gx]:
      return visited[y][x]
    for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
      new_y, new_x = y+j, x+k
      if new_y < 0 or new_y >= h or new_x < 0 or new_x >= w :
        continue
      if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
        visited[new_y][new_x] = visited[y][x] + 1
        queue.append([new_y, new_x])

h,w = map(int,input().split())
maze = [input() for i in range(h)]

ans = 0
for i in range(0,h) :
  for j in range(0,w):
    for k in range(0,h) :
      for l in range(0,w) :
        sy = i ; sx = j
        gy = k ; gx = l
        if maze[sy][sx] == '#' or maze[gy][gx] == '#' :
          continue
        visited = [[-1]*w for _ in range(h)]
        temp = bfs(maze, visited, sy, sx, gy, gx)
        if ans < temp :
          ans = temp

print(ans)

### FIXED CODE ###

from collections import deque

def bfs(maze, visited, sy, sx):
  queue = deque([[sy, sx]])
  visited[sy][sx] = 0
  va = 0
  while queue:
    y,x = queue.popleft()
    if visited[y][x] > va :
      va = visited[y][x]
    for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
      new_y, new_x = y+j, x+k
      if maze[new_y][new_x] == "." and visited[new_y][new_x] == -1:
        visited[new_y][new_x] = visited[y][x] + 1
        queue.append([new_y, new_x])
  return va

h,w = map(int,input().split())
wall = ''
for i in range(w+2):
  wall += '#'
maze = [wall]
for i in range(h) :
  m1 = input()
  maze.append('#'+m1+'#')
maze .append(wall)

ans = []
for sy in range(1,h+1) :
  for sx in range(1+w+1):
    if maze[sy][sx] == '#' :
      continue
    visited = [[-1]*(w+2) for _ in range(h+2)]
    ans.append(bfs(maze, visited, sy, sx))

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

from math import sqrt
n, m = list(map(int, input().split()))
i = 1
lst = []
while i <= sqrt(m):
    if m % i == 0:
        j = m // i
        if i >= n:
            lst.append(i)
        if j >= n:
            lst.append(j)
        i += 1
print(m//min(lst))

### FIXED CODE ###

from math import sqrt
n, m = list(map(int, input().split()))
i = 1
lst = []
while i <= sqrt(m):
    if m % i == 0:
        j = m // i
        if i >= n:
            lst.append(i)
        if j >= n:
            lst.append(j)
    i += 1
print(m//min(lst))
### BUGGY CODE ###

S=raw_input()
l=len(S)

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

mod=10**9+7


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

print dp[-1][5]


### 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]