Harryxun/stf_run huggingface dataset:
N,K=map(int,input().split())
p = list(map(int,input().split()))
ans = 0

p.sort()
for i in range(1,K+1):
  ans += p[i]
print(ans)

### FIXED CODE ###

N,K=map(int,input().split())
p = list(map(int,input().split()))
ans = 0

p.sort()
for i in range(K):
  ans += p[i]
print(ans)
s=input()
if S=="ABC":
    print("ARC")
else:
    print("ARC")

### FIXED CODE ###

S=input()
B="ABC"
if S==B:
    print("ARC")
else:
    print("ABC")
import sys
from collections import Counter
from math import factorial
import numpy as np
def main():
    input = sys.stdin.readline
    N = int(input())
    S = ["".join(sorted(list(input()))).strip() for _ in range(N)]
    #print(S)
    c = Counter(S)
    mosc = c.most_common()
    
    ans = 0
    for i in range(len(mosc)):
        elem = mosc[i]
        if elem[1] > 1:
          n = elem[1]
          r = 2
          ans += factorial(n) / factorial(r) / factorial(n - r)
          #ans +=  scipy.special.comb(n, r, exact=True)
    print(np.int64(ans))
 
if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
from collections import Counter
from math import factorial
import numpy as np
from scipy.misc import comb
def main():
    input = sys.stdin.readline
    N = int(input())
    S = ["".join(sorted(list(input()))).strip() for _ in range(N)]
    #print(S)
    c = Counter(S)
    mosc = c.most_common()
    
    ans = np.int64(0)
    for i in range(len(mosc)):
        elem = mosc[i]
        if elem[1] > 1:
          n = elem[1]
          r = 2
          #ans += np.int64(factorial(n) / factorial(r) / factorial(n - r))
          ans +=  comb(n, r, exact=True)
    print(ans)
 
if __name__ == '__main__':
    main()
N , M = map(int, input().split())

def mkmap(N, M):
    mapdic = {}
    for i in range(1, M+1):
        mapdic[str(i)] = [] 
    for j in range(N):
        pathA, pathB = map(str, input().split())
        mapdic[pathA] = mapdic[pathA] + [pathB]
        mapdic[pathB] = mapdic[pathB] + [pathA]
    return mapdic

mapdic = mkmap(N, M)
import copy

roots = [[]]*N
roots[0] = ["1"]
for i in range(N-1):
    root = copy.deepcopy(roots[i])
    for nowroot in root:
        for nextroot in mapdic[nowroot[-1]]:
            if  i >= 1:
                if not nextroot in nowroot:                    
                    roots[i+1] = roots[i+1] + [nowroot + nextroot]
                else:
                    pass
            else:
                roots[i+1] = roots[i+1] + [nowroot + nextroot]


List = [str(n+1) for n in range(N)]
check = "".join(List)
ans = 0
for i in roots[-1]:
    TF = "".join(sorted(list(i))) == check
    if TF:
        ans = ans + 1

print(ans)


### FIXED CODE ###


N , M = map(int, input().split())

def mkmap(N, M):
    mapdic = {}
    for i in range(1, N+1):
        mapdic[str(i)] = [] 
    for j in range(M):
        pathA, pathB = map(str, input().split())
        mapdic[pathA] = mapdic[pathA] + [pathB]
        mapdic[pathB] = mapdic[pathB] + [pathA]
    return mapdic

mapdic = mkmap(N, M)
import copy

roots = [[]]*N
roots[0] = ["1"]
for i in range(N-1):
    root = copy.deepcopy(roots[i])
    for nowroot in root:
        for nextroot in mapdic[nowroot[-1]]:
            if  i >= 1:
                if not nextroot in nowroot:                    
                    roots[i+1] = roots[i+1] + [nowroot + nextroot]
                else:
                    pass
            else:
                roots[i+1] = roots[i+1] + [nowroot + nextroot]


List = [str(n+1) for n in range(N)]
check = "".join(List)
ans = 0
for i in roots[-1]:
    TF = "".join(sorted(list(i))) == check
    if TF:
        ans = ans + 1

print(ans)
import math
A,B,C,D = list(map(int,input().split()))
A -= 1
lcn = C * D / math.gcd(C,D) 
m_n = B - B // C - B // D + B // lcn
min_n = A - A // C - A // D + A // lcn
print(m_n-min_n)

### FIXED CODE ###

A,B,C,D = list(map(int,input().split()))
import fractions
E = C * D // fractions.gcd(C,D)
total = B - B // C - B // D + B // E
F = A-1
total -= F - F // C - F // D + F // E
print(total)
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(0)
S = str(input())
N = len(S)
M = 13
c = [0]*(N)
for i in range(N):
    c[i] = (10**i)%M
#    c[i] = pow(10,i,M)
#print(c)
c.reverse()
#print(c)
"""
dp = [[0]*M for _ in range(N+1)]
i = int(0)
for j in range(M):
    dp[0][j] = 1
for s in S:
    if s == "?":
        for l in range(10):
            m = l * c[i] % M
            dp[i+1][(M - m) % M] += dp[i][j]
    else:
        m = int(s) * c[i] % M
        dp[i][(M - m) % M] +=dp[i][j]
    i +=1




dp = [[0]*M for _ in range(N)]
c = (10**(N-1))%M
if S[0] == "?":
    for l in range(10):
        dp[0][l*c%M] += 1
else:
    m = int(S[0]) * c%M
    dp[0][m] = 1
S = S[1:]
i = int(1)
for s in S:
    c = (10 ** (N - 1-i)) % M
    if s == "?":
        for j in range(13):
            for l in range(10):
                dp[i][j] += dp[i-1][(j-l*c)%13]
    else:
        st = int(s)
        for j in range(13):
            dp[i][j] = dp[i-1][(j-st*c)%13]
    i +=1

"""
dp = [[0]*M for _ in range(N)]
if S[0] == "?":
    for l in range(10):
        m = l * c[0]%M
        dp[0][m] += 1
else:
    m = int(S[0]) * c[0]%M
    dp[0][m] = 1

for i in range(1,N):
    if S[i] == "?":
        for j in range(M):
            for l in range(10):
                m = l*c[i]%M
                dp[i][j] += dp[i-1][(M+j-m)%M]%mod
    else:
        for j in range(M):
            m = int(S[i])*c[i]%M
            dp[i][j] = dp[i-1][(M+j-m)%M]%=mod

#print(dp)
print(dp[-1][5]%mod)

### FIXED CODE ###

import sys
 
 
def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    s = str(input().rstrip('\n'))
    ls = [[0] * 13 for _ in range(len(s))]
    for i in range(len(s)):
        if i == 0:
            if s[-i-1] == "?":
                for j in range(10):
                    ls[i][j] += 1
            else:
                ls[i][int(s[-i-1])] += 1
        else:
            mult = pow(10, i, 13)
            if s[-i-1] == "?":
                for j in range(13):
                    for k in range(10):
                        ls[i][(k * mult + j) % 13] += ls[i-1][j]
            else:
                st = int(s[-i-1])
                for j in range(13):
                    ls[i][(st * mult + j) % 13] += ls[i-1][j]
        for j in range(13):
            ls[i][j] = ls[i][j] % mod
    print(ls[-1][5])
 
 
if __name__ == '__main__':
    solve()
a = input().split()
x = int(a[0])
y = int(a[1])
if x>=10:
    print(y)
else:
    print(y+1000-100x)

### FIXED CODE ###

a = input().split()
x = int(a[0])
y = int(a[1])
if x>=10:
    print(y)
else:
    print(y+1000-100*x)
N=int(input()),A=int(input())
print("Yes" if N%500<=A else "No")


### FIXED CODE ###

N=int(input())
A=int(input())
if N%500<=A:
    print("Yes")
else:
    print("No")
from fractions import gcd
N , X = (map(int , input().split()))
x = list(map(int , input().split()))
x.sort()
ans_list = [x[i+1] - x[i] for i in range(0,len(x)-1)]
if X == 1 or len(ans_list) == 1:
    ans = ans_list[0]
    print(ans)
elif len(ans_list) >= 2:
    gcd_list = [gcd(ans_list[i], ans_list[i+1]) for i in range(0,len(ans_list)-1)]
    ans = min(gcd_list)
    print(ans)
else:
    ans = gcd(ans_list[0] , ans_list[1])
    print(ans)

### FIXED CODE ###

from fractions import gcd
N , X = (map(int , input().split()))
x = list(map(int , input().split()))
ans = 0
for i in x:
    ans = gcd(ans , abs(X-i))
print(ans)
x, n = map(int, input().split())
a = set(map(int, input().split()))
print(min(i for i in range(102) if i not in a, key=lambda y:abs(x-y)))


### FIXED CODE ###

x, n = map(int, input().split())
a = set(map(int, input().split()))
print(min([i for i in range(102) if i not in a], key=lambda y:abs(x-y)))
n = list(input())
for i range(len(n)):
  n[i] = "1" if n[i]==9 else "9"
ans = ','.join(n)
print(ans)

### FIXED CODE ###

n = list(input())
for i in range(len(n)):
  n[i] = "1" if n[i]=="9" else "9"
ans = ''.join(n)
print(ans)
import numpy as np
H,W=map(int,input().split(' '))
maze = [list(input()) for i in range(H)]
maze_w=[]
maze_h=[]
for i in maze:
    cnt = 0
    l = 0
    r = 0
    tmp = ''
    for j in i:
        if j != "#":
            cnt += 1
            r += 1
        elif cnt:
            tmp += str(cnt)*cnt+'0'
            l = r+1
            r = r+1
            cnt = 0
        else:
            tmp +='0'
    if cnt:
        tmp +=str(cnt)*cnt
    maze_w.append(list(tmp))

for i in range(W):
    cnt = 0
    h = 0
    t = 0
    tmp = ""
    for j in range(H):
        if maze[j][i]!='#':
            cnt += 1
            t +=1
        elif cnt:
            tmp += str(cnt)*cnt+'0'
            h = t+1
            t = t+1
            cnt = 0
        else:
            tmp += '0'
    if cnt:
        tmp += str(cnt)*cnt
    maze_h.append(list(tmp))
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,int(maze_h[j][i])+int(maze_w[i][j])-1)
print(ans)

### FIXED CODE ###

import numpy as np
H,W=map(int,input().split(' '))
maze = [list(input()) for i in range(H)]
maze = (np.array(maze) == '.')*1
L=np.zeros((H,W),dtype=int)
R=np.zeros((H,W),dtype=int)
U=np.zeros((H,W),dtype=int)
D=np.zeros((H,W),dtype=int)
for i in range(W):
    if i==0:
        L[:,i]=maze[:,i]
        R[:,W-i-1]=maze[:,W-i-1]
    else:
        L[:,i]=(L[:,i-1]+1)*maze[:,i]
        R[:,W-i-1]=(R[:,W-i]+1)*maze[:,W-i-1]
for i in range(H):
    if i==0:
        U[i,:]=maze[i,:]
        D[H-i-1,:]=maze[H-i-1,:]
    else:
        U[i,:]=(U[i-1,:]+1)*maze[i,:]
        D[H-i-1,:]=(D[H-i]+1)*maze[H-i-1,:]
print(max(np.max(U+D+L+R-3),0))
n = input().split()
max = max(int(n))
min = min(int(n))
sum = sum(int(n))
answer = "{} {} {}"
print(answer.format(max, min, sum))

### FIXED CODE ###

num = input()
nums = list(map(int, input().split()))
print("{} {} {}".format(min(nums), max(nums), sum(nums)))
# coding:utf-8
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
time = 0

if sum(a) + sum(b) <= k:
    print(len(a) + len(b))
    exit()

while time < k:
    if len(a) == 0:
        book = b[0]
    elif len(b) == 0:
        book = a[0]
    else:
        book = min(a[0], b[0])

    time += book
    if time > k:
        break

    ans += 1
    if book == a[0]:
        a.pop(0)
    else:
        b.pop(0)
print(ans)


### FIXED CODE ###

# coding:utf-8
import itertools
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ans = 0
j = m

aa = [0] + list(itertools.accumulate(a))
bb = [0] + list(itertools.accumulate(b))
# print(aa)
# print(bb)


# しゃくとり法 / Aの山だけ読みつつ、そこにBからいくつ取り出すかで考える
for i, a_item in enumerate(aa):
    if a_item > k:
        break
    while a_item + bb[j] > k:
        j -= 1
    ans = max(i + j, ans)
print(ans)
s = input()

if len(list(set(s))) >= 3:
  print("No")
else:
  s_s = list(set(s))
  if s.count(s_s[0]) == s.count(s_s[1]):
    print("Yes")
  else:
    print("No")

### FIXED CODE ###

s = input()
s_s = list(set(s))

if len(s_s) == 2:
  if s.count(s_s[0]) == s.count(s_s[1]):
    print("Yes")
else:
    print('No')
import sys
sys.setrecursionlimit(5000)
N=int(input())
A=[int(input())-1 for _ in range(N)]
result=[]
app=result.append
def next(k):
	newlight=A[k]
	if k==1:
		return(1)
	elif k in result:
		return(0)
	else:
		app(k)
		return(next(newlight))
if not next(0):
	print(-1)
else:print(len(result))

### FIXED CODE ###

import sys
sys.setrecursionlimit(500000)
N=int(input())
A=[int(input())-1 for _ in range(N)]
result=[False]*N
def next(k):
	newlight=A[k]
	if k==1:
		return(1)
	elif result[k]:
		return(0)
	else:
		result[k]=True
		return(next(newlight))
if not next(0):
	print(-1)
else:print(sum(result))
i = 1
while True:
    x = int (raw_input())
    if x == 0:
    break
    print ("case {0}: {1} ").format(i,x)
i=i+1

### FIXED CODE ###

def main():
    loop_count = 0
    while 1:
        loop_count +=1
        param = raw_input()
        if param == "0":
            break
        else:
            print "Case %s: %s" % (loop_count,param)

if __name__ == '__main__':
    main()
N = int(input())
array = list(map(int, input().strip().split()))
array.sort
ansarray = []
ansnum = 1
ans = 0
ansindex = 0
for i in range (1,N+1):
    for j in range(ansindex,N-1):
        if (array[j] == i):
            ans += 1
            ansindex += 1
        else:
            ansarray.append(ans)
            ans = 0
            break
        if(j == N-2):
            ansarray.append(ans)
for i in range(N-ansindex):
    ansarray.append("0")
for i in range(N):
    print(ansarray[i])

### FIXED CODE ###

N = int(input())
array = list(map(int, input().strip().split()))
array.sort()
ansarray = []
ansnum = 1
ans = 0
ansindex = 0
for i in range (1,N):
    for j in range(ansindex,N-1):
        if (array[j] == i):
            ans += 1
            ansindex += 1
        else:
            ansarray.append(ans)
            ans = 0
            break
        if(j == N-2):
            ansarray.append(ans)
            ansindex += 1
for i in range(N-len(ansarray)):
    ansarray.append("0")
for i in range(N):
    print(ansarray[i])
n, a = map(int, input().split())
xlist = list(map(int, input().split()))

j = n
k = n
t = n * a
maxv = max(xlist)


dp = [[[0 for t in range(n*maxv + 1)] for k in range(k + 1)] for j in range(j + 1)]

dp[1][0][0] = 1
dp[0][0][0] = 1

# for d in dp:
#     print(d)
# print(dp[1][1][15])

for ji in range(0, j + 1):
    for ki in range(0, ji + 1):
        for ti in range(0, ki * maxv + 1):
            # print('now', ji, ki, ti)
            if ji == 0 and ki == 0 and ti == 0:
                # print('branch 1')
                dp[ji][ki][ti] = 1
            elif ji >= 1 and ti < xlist[ji - 1]:
                dp[ji][ki][ti] = dp[ji - 1][ki][ti]
                # print('branch 2')
            elif ji >= 1 and ki >= 1 and ti >= xlist[ji - 1]:
                # print('branch 3', ji - 1)
                dp[ji][ki][ti] = dp[ji - 1][ki][ti] + dp[ji - 1][ki - 1][ti - xlist[ji - 1]]
            # print(dp[ji][ki][ti])

count = 0
for i in range(1, k + 1):
    count += dp[j][i][i*a]

print(count)

### FIXED CODE ###

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

j = n
k = n
t = n * a
maxv = max(a, max(xlist))


dp = [[[0 for t in range(n*maxv + 1)] for k in range(k + 1)] for j in range(j + 1)]

dp[1][0][0] = 1
dp[0][0][0] = 1

# for d in dp:
#     print(d)
# print(dp[1][1][15])

for ji in range(0, j + 1):
    for ki in range(0, ji + 1):
        for ti in range(0, ki * maxv + 1):
            # print('now', ji, ki, ti)
            if ji == 0 and ki == 0 and ti == 0:
                # print('branch 1')
                dp[ji][ki][ti] = 1
            elif ji >= 1 and ti < xlist[ji - 1]:
                dp[ji][ki][ti] = dp[ji - 1][ki][ti]
                # print('branch 2')
            elif ji >= 1 and ki >= 1 and ti >= xlist[ji - 1]:
                # print('branch 3', ji - 1)
                dp[ji][ki][ti] = dp[ji - 1][ki][ti] + dp[ji - 1][ki - 1][ti - xlist[ji - 1]]
            # print(dp[ji][ki][ti])

count = 0
for i in range(1, k + 1):
    count += dp[j][i][i*a]

print(count)
def how_many_AC(count_summary, str):
  index = str.find('AC')
  if index == -1:
  	return (count_summary, "")
  else:
    return (count_summary+1, str[index+2:])

def how_many_AC_recursive(count1, str1):
  (count2, str2) = how_many_AC(count1, str1)
  if len(str2) <= 1:
    return count2
  else:
    x = how_many_AC_recursive(count2, str2)
    return x

import sys
sys.setrecursionlimit(1000000)
(N, Q) = input().split()
S = input()
for i in range(1, int(Q)+1):
  (l_str, r_str) = input().split()
  l = int(l_str)
  r = int(r_str)
  substr = S[l-1:r]
  out = how_many_AC_recursive(0, substr)
  print(out)



### FIXED CODE ###

b = input()
dict = {"A":"T", "T":"A", "C":"G", "G":"C"}
print(dict[b])
#!/usr/bin/env python3
import sys


def f(b: int, n: int) -> int:
    if n < b:
        return n
    return f(b, n // b) + n % b


def solve(n: int, s: int):
    for b in range(2, int(n ** 0.5) + 1):
        if f(b, n) == s:
            print(b)
            return
    for p in reversed(range(int(n ** 0.5))):
        q = s - p
        if p == 0:
            b, r = n + 1, 0
        else:
            b, r = divmod(n - q, p)
            if r != 0 or b == 1:
                continue
        if f(b, n) == s:
            print(b)
            return
    print(-1)


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
    s = int(next(tokens))  # type: int
    solve(n, s)


if __name__ == '__main__':
    main()


### FIXED CODE ###

#!/usr/bin/env python3
import sys


def f(b: int, n: int) -> int:
    if n < b:
        return n
    return f(b, n // b) + n % b


def sqrt(n: int):
    lb = 0
    hb = n + 1
    while hb - lb > 1:
        m = (lb + hb) // 2
        if m * m <= n:
            lb = m
        else:
            hb = m
    return lb


def solve(n: int, s: int):
    if s == n:
        print(n + 1)
        return
    sn = sqrt(n)
    for b in range(2, sn + 1):
        if f(b, n) == s:
            print(b)
            return
    for p in reversed(range(1, sn + 1)):
        q = s - p
        if q < 0:
            continue
        b, r = divmod(n - q, p)
        if r != 0 or b <= p:
            continue
        if f(b, n) == s:
            print(b)
            return
    print(-1)


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
    s = int(next(tokens))  # type: int
    solve(n, s)


if __name__ == '__main__':
    main()
n = int(input())
a,b,c,d =0
for i in range(n):
  e = input()
  if e == 'AC':
    a+=1
  elif e == 'WA':
    b +=1
  elif e == 'TLE':
    c+=1
  else:
    d+=1

print('AC ×'+str(a)+'\n'+'WA ×' +str(b) + '\n'
      +'TLE ×'+str(c) +'\n' + 'RE ×'+str(d))
  

### FIXED CODE ###

n = int(input())
a=b=c=d=0
for i in range(n):
  e = input()
  if e == 'AC':
    a+=1
  elif e == 'WA':
    b +=1
  elif e == 'TLE':
    c+=1
  else:
    d+=1

    

print('AC x '+str(a)+'\n'+'WA x ' +str(b) + '\n'
      +'TLE x '+str(c) +'\n' + 'RE x '+str(d))
def main():
    h, w = map(int, input().split())
    k = [["."]+list(input())+["."] for _ in range(h)]
    s = [[None]*(w+2) for _ in range(h+2)]
    s[0] = ["."]*(w+2)
    s[-1] = ["."]*(w+2)
    s[1:h+1] = k
    d = [[0, 1], [0, -1], [1, 0], [-1, 0]]
    for i in range(1, w+1):
        for j in range(1, h+1):
            if s[i][j] == ".":
                continue
            flag = True
            for (di, dj) in d:
                if s[i+di][j+dj] == "#":
                    flag = False
                    break
            if flag:
                print("No")
                return
    print("Yes")

if __name__ == "__main__":
    main()

### FIXED CODE ###

import numpy as np
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
s = np.array(s)
out = "Yes"
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            continue
        if i == 0 and j == 0:
            up = s[i][j]
            down = s[i + 1][j]
            left = s[i][j]
            right = s[i][j + 1]
        elif i == 0 and j == w-1:
            up = s[i][j]
            down = s[i + 1][j]
            left = s[i][j - 1]
            right = s[i][j]
        elif i == h-1 and j == 0:
            up = s[i - 1][j]
            down = s[i][j]
            left = s[i][j]
            right = s[i][j + 1]
        elif i == h-1 and j == w-1:
            up = s[i - 1][j]
            down = s[i][j]
            left = s[i][j - 1]
            right = s[i][j]
        elif i == 0 and j != 0 and j != w-1:
            up = s[i][j]
            down = s[i + 1][j]
            left = s[i][j - 1]
            right = s[i][j + 1]
        elif i == h-1 and j != 0 and j != w-1:
            up = s[i - 1][j]
            down = s[i][j]
            left = s[i][j - 1]
            right = s[i][j + 1]
        elif j == 0 and i !=  0 and i != h-1:
            up = s[i - 1][j]
            down = s[i + 1][j]
            left = s[i][j]
            right = s[i][j + 1]
        elif j == w-1 and i != 0 and i!= h-1:
            up = s[i - 1][j]
            down = s[i + 1][j]
            left = s[i][j - 1]
            right = s[i][j]
        else:
            up = s[i-1][j]
            down = s[i+1][j]
            left = s[i][j-1]
            right = s[i][j+1]
        if s[i][j] != up and s[i][j] != down and s[i][j] != left and s[i][j] != right:
            out = "No"
print(out)
import networkx as nx
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
g=nx.Graph()
g.add_edges_from(s)

#各部屋の通じてる部屋番のリストを作る
l=[[] for _ in range(n)]
for i in range(m):
    a,b=s[i][0],s[i][1]
    l[a-1].append(b)
    l[b-1].append(a)
#深さのリストを作る
l1=sum(l, []) #一次元化
l1.insert(0,1)
l_depth=list(dict.fromkeys(l1))#深さのリスト

# スタート地点からゴール地点までのすべての単純路 (同じ頂点を通らないパス)
k=list(nx.all_simple_paths(G, source=1, target=l_depth[-1]))

c=0
ma=0
for i in range(k):
    if len(k[i])>ma:
        ma=len(k[i])
        c-=c+1
    elif len(k[i])==ma:
        c+=1
print(c)

### FIXED CODE ###

n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]

#各部屋の通じてる部屋番のリストを作る
l=[[] for _ in range(n)]
for i in range(m):
    a,b=s[i][0],s[i][1]
    l[a-1].append(b)
    l[b-1].append(a)

def dfs(now, prev, visited):
    visited.append(now)#行った頂点を追加していって全て行ったなら+1
    if len(visited) == n:
        return 1
 
    ret = 0 #条件を満たす数の初期値
    for edge in l[now-1]:#今の場所からいける頂点がまだ行ったことのない場合そこを同様に再度探索
        if edge == prev:
            continue
        if edge in visited:
            continue
 
        ret += dfs(edge, prev, visited[:])#そこで全ての頂点を網羅したなら+1(dfs文最初の部分)
 
    return ret #総計値を返す

print(dfs(1, 0, []))
# AOJ 0502: Dice
# Python3 2018.6.29 bal4u

d = { "North":1, "East":2, "West":3, "South":4, "Right":5, "Left":6 }

rot = ((0,1,2,3,4,5,6),(0,2,6,3,4,1,5),(0,4,2,1,6,5,3),(0,3,2,6,1,5,4), \
       (0,5,1,3,4,6,2),(0,1,3,5,2,4,6),(0,1,4,2,5,3,6))

while True:
	n = int(input())
	if n == 0: break
	dice = [[i for i in range(7)] for j in range(2)]
	ans = 1
	for i in range(n):
		j = d[input()]
		for k in range(1, 7): dice[1-(i&1)][k] = dice[i&1][rot[j][k]];
		ans += dice[1-(i&1)][1]
	print(ans)


### FIXED CODE ###

# AOJ 0502: Dice
# Python3 2018.6.29 bal4u

d = { "North":1, "East":2, "West":3, "South":4, "Right":5, "Left":6 }

rot = ((0,1,2,3,4,5,6),(0,2,6,3,4,1,5),(0,4,2,1,6,5,3),(0,3,2,6,1,5,4), \
       (0,5,1,3,4,6,2),(0,1,3,5,2,4,6),(0,1,4,2,5,3,6))

import sys
while True:
	n = int(input())
	if n == 0: break
	dice = [[j for j in range(7)] for i in range(2)]
	ans = 1
	for i in range(n):
		j = d[input().strip()]
		for k in range(1, 7): dice[1-(i&1)][k] = dice[i&1][rot[j][k]]
		ans += dice[1-(i&1)][1]
	print(ans)
import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

s = list(reversed(input()))
n = len(s)
mod = 10 ** 9 + 7
digits=[0]*n

for i in range(n):
    digits[i] = (10 ** i) % 13


cache = [[-1]*13 for _ in range(n+1)]

def solve(pos, now):
    if pos >= n:
        return 1 if now == 5 else 0
    res = cache[pos][now]
    if res >= 0:
        return res
    res = 0
    if s[pos] == '?':
        for i in range(10):
            m = (now + i * digits[pos]) % 13
            res += solve(pos + 1, m)
    else:
        d = ord(s[pos]) - ord('0')
        m = (now + d * digits[pos]) % 13
        res += solve(pos + 1, m)
    res %= mod
    cache[pos][now] = res

    return res

for i in range(n-1,0,-1):
    solve(0,0)

print(solve(0, 0))

### FIXED CODE ###

import itertools

def getint(): return int(input())
def getints(): return list(map(int, input().split()))

s = input()
n = len(s)
mod = 10 ** 9 + 7

dp = [[0]*13 for _ in range(n+1)]
dp[0][0]=1

for i in range(n):
    c = -1 if s[i] == '?' else ord(s[i]) - ord('0')
    for j in range(10):
        if c != -1 and c != j:
            continue
        for ki in range(13):
            dp[i+1][(ki*10+j)%13] += dp[i][ki]
    for j in range(13):
        dp[i+1][j] %= mod

res = dp[n][5]

print(res)