Harryxun/stf_run huggingface dataset:
H, W = map(int, input().split())

HW_list = []
for i in range(H):
    x = input()
    char_list = list(x)
    if "#" in char_list:
        HW_list.append(char_list)
    else:
        pass

i = 0
while True:
    count = 0
    for j in range(len(HW_list)):
        if HW_list[j][i] == ".":
            count += 1
        
    if count == len(HW_list):
        for j in range(len(HW_list)):
            del HW_list[j][i]
    else:
        i += 1
    if i > len(HW_list) - 1:
        break
    
for j in range(len(HW_list)):
    print("".join(HW_list[j]))

### FIXED CODE ###

H, W = map(int, input().split())

HW_list = []
for i in range(H):
    x = input()
    char_list = list(x)
    if "#" in char_list:
        HW_list.append(char_list)
    else:
        pass

i = 0
while True:
    count = 0
    for j in range(len(HW_list)):
        if HW_list[j][i] == ".":
            count += 1
        
    if count == len(HW_list):
        for j in range(len(HW_list)):
            del HW_list[j][i]

    else:
        i += 1
    if i > len(HW_list[0]) - 1:
        break
    
for j in range(len(HW_list)):
    print("".join(HW_list[j]))
# -*- coding: utf-8 -*-

n = int(raw_input())
for i in range(n):
    A, B, C = [], [0], [0]
    A = map(int, raw_input().split())
    for i in range(10):
        if A[i] > B[0]:
            B.insert(0, num[i])
        elif A[i] > C[0]:
            C.insert(0, num[i])
        else:
            break
    if len(A) + len(B) == 12:
        print "YES"
    else:
        print "NO"

### FIXED CODE ###

# -*- coding: utf-8 -*-

n = int(raw_input())
for i in range(n):
    A, B, C = [], [0], [0]
    A = map(int, raw_input().split())
    for i in range(10):
        if A[i] > B[0]:
            B.insert(0, A[i])
        elif A[i] > C[0]:
            C.insert(0, A[i])
        else:
            break
    if len(B) + len(C) == 12:
        print "YES"
    else:
        print "NO"
from math import *

def fib(n):
    return ((1+sqrt(5))**(n+1)  -  (1-sqrt(5))**(n+1)) // (2**(n+1)*sqrt(5))


def how_many_ways(lst_of_broken_steps,goal):

    for i in range(len(lst_of_broken_steps)-1):#連続しているbrokenステップがあった時
        if lst_of_broken_steps[i]+1==lst_of_broken_steps[i+1]:
            return 0
    if len(lst_of_broken_steps)==0:#brokenstepがない場合
        return fib(goal)%1000000007
    #1回目のbrokenステップの処理
    ans = fib(lst_of_broken_steps[0]-1)
    ans = ans % 1000000007

    for i in range(1,len(lst_of_broken_steps)):#2回目以降のbrokenステップの処理
        ans *= fib((lst_of_broken_steps[i]-1)-(lst_of_broken_steps[i-1]+1))
        ans = ans%1000000007
    

    #最後のbrokenステップの処理の後からゴールまで
    ans *= fib(goal-(lst_of_broken_steps[-1]+1))

    return ans % 1000000007



goal,n = map(int,input().split())
lst_of_broken_steps = []
for i in range(n):
    lst_of_broken_steps.append(int(input()))

print(int(how_many_ways(lst_of_broken_steps,goal)))

### FIXED CODE ###

n,m = map(int,input().split())
brokensteps = set([int(input()) for x in range(m)])
dp = [0] * (n+1)
for i in range(n+1):
    if i in brokensteps:
        dp[i] = 0
        continue
    
    elif i <= 1:
        dp[i] = 1

    else:
        dp[i] = (dp[i-1] + dp[i-2])%(10**9+7)

print(dp[n])
from itertools import combinations
N, M = map(int, input().split())

a = list(combinations(range(N), 2))
b = list(combinations(range(M), 2))
print(len(a)+len(b))

### FIXED CODE ###

S = str(input())
N = len(S)
num = (N-1)/2
num1 = (N+2)/2
if(S[:int(num)]==S[int(num1):]):
    print("Yes")
else:
    print("No")
def main():
    from math import gcd
    import sys

    n, m = map(int, input().split())
    s, t = input(), input()
    l = n * m // gcd(n, m)
    a = [l // n * i + 1 for i in range(n)]
    b = [l // m * i + 1 for i in range(m)]
    c = set(a) & set(b)
    for x in list(c):
        i = a.index(x)
        j = b.index(x)

        if s[i] != t[j]:
            print(-1)
            exit()
    else:
        print(l)


if __name__ == '__main__':
    main()


### FIXED CODE ###

def main():
    from fractions import gcd

    n, m = map(int, input().split())
    s, t = input(), input()
    l = n * m // gcd(n, m)
    a = [l // n * i + 1 for i in range(n)]
    b = [l // m * i + 1 for i in range(m)]
    c = set(a) & set(b)
    for x in list(c):
        i = a.index(x)
        j = b.index(x)

        if s[i] != t[j]:
            print(-1)
            exit()
    else:
        print(l)


if __name__ == '__main__':
    main()
s=list(input())
t=list(input())

l=list(set(t)-set(s))

if l[0]==t[-1] and len(l)==1:
  print('Yes')
  
else:
  print('No')


### FIXED CODE ###

import string

l=list(string.ascii_lowercase)


s=input()
t=input()
a=0

for i in range(26):
  if t==s+l[i]:
    print('Yes')
    a+=1
    break
    

if a==0:
  print('No')
import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    (N, M) = map(int, input().split())
    neighbor = {}
    for _ in range(M):
        (A,B) = map(int, input().split())
        na = neighbor.get(A, [])
        nb = neighbor.get(B, [])
        neighbor.update({A:na+B})
        neighbor.update({B:nb+A})

    guide = {1:1}

    # 1の部屋から幅優先で道しるべを置く
    
    # 探索候補
    target = [1]
    while len(target) > 0:
        # 候補の先頭から取る
        n = target.pop(0)
        # nから伸びる行き先
        dests = neighbor.get(n, [])
        # すでに道しるべがあるものは除く
        dests = list(filter(lambda d: not d in guide.keys(), dests))
        # 道しるべを置く
        for d in dests:
            guide.update({d:n})
            # 探索候補の末尾に追加
            target += d,

    if set(range(1,N+1)) <= set(guide.keys()):
        print('Yes')
        for i in range(2,N+1):
            print(guide[i])
    else:
        print('No')

main()


### FIXED CODE ###

#import numpy as np
#import math
#from decimal import *
#from numba import njit

#@njit
def main():
    (N, M) = map(int, input().split())
    neighbor = [[] for _ in range(N+1)]
    for _ in range(M):
        (A,B) = map(int, input().split())
        neighbor[A] += B,
        neighbor[B] += A,

    guide = [0 for _ in range(N+1)]

    # 1の部屋から幅優先で道しるべを置く
    
    # 探索候補
    target = [1]
    checked = [1]
    while len(target) > 0:
        # 候補の先頭から取る
        n = target.pop(0)
        # nから伸びる行き先
        dests = neighbor[n]
        # すでに道しるべがあるものは除く
        dests = filter(lambda d: guide[d] == 0, dests)
        # 道しるべを置く
        for d in dests:
            guide[d] = n
            checked += d,
            # 探索候補の末尾に追加
            target += d,

    print('Yes')
    for i in range(2,N+1):
        print(guide[i])

main()
n=int(input())
a=[int(input())for _ in[0]*n]
s=[1]
c=0
while s[-1]*3<n:s+=[s[-1]*3+1]
s=s[::-1]
for g in s:
 for i in range(g,n):
  v=a[i]
  j=i-g
  while j>=0 and a[j]>v:a[j+g]=a[j];j-=g;c+=1
  a[j+g]=v
print(len(s))
print(*s)
print(c)
print(*a,sep='\n')


### FIXED CODE ###

import sys
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j + g] = A[j]
            j = j - g
            cnt += 1
        A[j + g] = v
def solve():
    n = int(input())
    A = list(map(int, sys.stdin))
    G = [int((2.25**i - 1) / 1.25)for i in range(17, 0, -1)]
    G = [v for v in G if v <= n]
    for g in G:
        insertionSort(A, n, g)
    print(len(G))
    print(*G)
    print(cnt)
    print('\n'.join(map(str, A)))
if __name__ == '__main__':
    cnt = 0
    solve()
N = int(input())
A = list(map(int, input().split()))
kabu = 0
money = 1000
for i in range(N):
  money += kabu*A[i]
  kabu = 0
  if i!=N-1:
    if A[i]<A[i+1]:
      kabu += money//A[i]
      money %= 0
    else:
      continue
print(money)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
kabu = 0
money = 1000
for i in range(N):
  money += kabu*A[i]
  kabu = 0
  if i!=N-1:
    if A[i]<=A[i+1]:
      kabu += money//A[i]
      money %= A[i]
    else:
      pass
print(money)
A=int(intput())
print('Yes' if A in list(range(3,8,2)) else 'No')

### FIXED CODE ###

X=int(input())
print('YES' if X in [7,5,3] else 'NO')
x, y, z = map(int, intput().split())
print(x*y//2)

### FIXED CODE ###

x, y, z = map(int, input().split())
print(x*y//2)
N, M. X, Y = map(int, input().split())
x_lst = list(map(int, input().split()))
y_lst = list(map(int, input().split()))
if (X < Y and max(x_lst) < min(y_lst) and X < min(y_lst) and max(x_lst) < Y):
  print("No War")
else:
  print("War")

### FIXED CODE ###

N, M, X, Y = map(int, input().split())
x_lst = list(map(int, input().split()))
y_lst = list(map(int, input().split()))
if (X < Y and max(x_lst) < min(y_lst) and X < min(y_lst) and max(x_lst) < Y):
  print("No War")
else:
  print("War")
N = int(input())
list = [None]*N
for i in range(N):
  s, P = input().split()
  list[i]=(i,s,int(p)*-1)
for i in sorted(list, key = lamda x: (x[1],x[2])):
  print(i[0]+1)

### FIXED CODE ###

N = int(input())
list = [None]*N
for i in range(N):
  s, p = input().split()
  list[i]=(i,s,int(p)*-1)
for i in sorted(list, key = lambda x: (x[1],x[2])):
  print(i[0]+1)
import math

def lcm(a, b):
	return a * b // math.gcd(a, b)

n = int(input())
t = [int(input()) for i in range(n)]

ans = t[0]
for t_i in t[1:]:
	ans = lcm(ans, t_i)

print(ans)

### 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())
t = [int(input()) for i in range(n)]

ans = t[0]
for t_i in t[1:]:
	ans = lcm(ans, t_i)

print(ans)
NK = input().split();
N,K = int(NK[0]),int(NK[1]);
min = N;

#桁が大きい時の処理
while(int(len(str(N))) > 2):
    N = int(N - K * int(N / 2));
    print("N=");
    print(N);
    print("K=");
    print(K);

flag = True;
while flag == True:
    N = abs(N - K);
    if(N <= min):
        min = N;
    else:
        flag = False;
    
print(min);

### FIXED CODE ###

import math

NK = input().split();
N,K = int(NK[0]),int(NK[1]);
min = N;

#桁が大きい時の処理
if(K == 1):
    while(int(len(str(N))) > 2):
        N = int(N - K * (N / 2));
else:
    border = math.floor(N / K);
    N = N - K * border;
        
flag = True;
while flag == True:
    N = abs(N - K);
    if(N <= min):
        min = N;
    else:
        flag = False;
    
print(min);
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


# Nの素因数分解を辞書で返す
def prime_fact(n):
    root = int(math.sqrt(n))
    prime_dict = {}
    for i in range(2, root+1):
        cnt = 0
        for j in range(root+1):
            if n % i == 0 and n != 0:
                cnt += 1
                n = n // i
            else:
                break
        if cnt:
            prime_dict[i] = cnt
    if n != 1:
        prime_dict[n] = 1
    return prime_dict


def main():
    N = NI()
    A = NLI()
    L = {}
    primes_a = {}
    for a in A:
        prime_a = prime_fact(a)
        primes_a[a] = prime_a
        for p, n in prime_a.items():
            L.setdefault(p, 0)
            L[p] = max(L[p], n)
    ans = 0
    l = 1
    for p, n in L.items():
        l = l * pow(p, n, MOD) % MOD

    for i, a in enumerate(A):
        ans += l * pow(a, -1, MOD) % MOD
    print(ans % MOD)



if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


# Nの素因数分解を辞書で返す
def prime_fact(n):
    root = int(math.sqrt(n))
    prime_dict = {}
    for i in range(2, root+1):
        cnt = 0
        for j in range(root+1):
            if n % i == 0 and n != 0:
                cnt += 1
                n = n // i
            else:
                break
        if cnt:
            prime_dict[i] = cnt
    if n != 1:
        prime_dict[n] = 1
    return prime_dict


def main():
    N = NI()
    A = NLI()
    L = {}
    primes_a = {}
    for a in A:
        prime_a = prime_fact(a)
        primes_a[a] = prime_a
        for p, n in prime_a.items():
            L.setdefault(p, 0)
            L[p] = max(L[p], n)
    ans = 0
    l = 1
    for p, n in L.items():
        l = l * pow(p, n, MOD) % MOD

    for i, a in enumerate(A):
        ans += l * pow(a, MOD-2, MOD) % MOD
    print(ans % MOD)



if __name__ == "__main__":
    main()
a,b,c = map(int,input().split())
if (a<c and c<b) or (a>c and c>b):
print("Yes")
else:
print("No")

### FIXED CODE ###

a,b,c = map(int,input().split())
if (a<c and c<b) or (a>c and c>b):
       print("Yes")
else:
       print("No")
n,k=map(int,input().split())
a=list(map(int,input().split())) 

x=[0]*(n)
before = 0
now = 0
while x[now] == 0:
    x[now]=1+x[before]
    before=now
    now = a[now]-1
    
y=x[now]-x[0]
z=x[before]-y
l=(k-y)%z+1
for i in range(n):
    if x[i] == l+y:
        print(1+i)
        break

### FIXED CODE ###

s=input()
t=input()
l=len(s)
if len(s)+1 == len(t):
    si=s+t[l]
else:
    si=""
if si == t and len(si) == len(t):
    print("Yes")
else:
    print("No")
n = input()

data = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

q, mod = divmod(n-1, 26)
print(q, mod)
answer = data[mod]

while q >= 1:
    q, mod = divmod(q-1, 26)
    print(q, mod)
    answer = data[mod] + answer

print(answer)



### FIXED CODE ###

n = int(input())

data = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]

q, mod = divmod(n-1, 26)
answer = data[mod]

while q >= 1:
    q, mod = divmod(q-1, 26)
    answer = data[mod] + answer

print(answer)
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))

if N == 1:
    ans = max(X) - min(X)
    print(ans)
    exit()

if M == 1:
    ans = 0
    print(ans)
    exit()

Xs = sorted(X)

diff = []
for i in range(M - 1):
    tmp = Xs[i + 1] - Xs[i]
    diff.append(tmp)

rest = N - 2
for _ in range(rest):
    if diff[0] > diff[len(diff) - 1]:
        diff.pop(0)
    else:
        diff.pop()

ans = 0

for _ in range(len(diff) - 1):
    if diff[0] > diff[len(diff) - 1]:
        ans += diff[len(diff) - 1]
        diff.pop()
    else:
        ans += diff[0]
        diff.pop(0)

print(ans)


### FIXED CODE ###

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

if N == 1:
    ans = max(X) - min(X)
    print(ans)
    exit()

if ((M == 1) or (N >= M)):
    ans = 0
    print(ans)
    exit()

Xs = sorted(X)

diff = []
for i in range(M - 1):
    tmp = Xs[i + 1] - Xs[i]
    diff.append(tmp)

diffs = sorted(diff)
print(sum(diffs[:(M - 1) - (N - 1)]))
from collections import deque

def pIsAccptbl(w,k,p):
    tr = 0
    c = 0
    while(w):
        tmp = w.popleft()
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp

    c+=1
    if c>k:
        return False
    else:
        return True
    
n,k = input().split()
w = collections.deque()
'''
for i in range(int(n)):
    w.append(int(input()))

p = max(w)

while(1):
    x=w.copy()
    if(pIsAccptbl(x,int(k),p)):
        print(p)
        break
    else:
        p+=1
'''

### FIXED CODE ###

from collections import deque

def isPa(w,k,p):
    tr = 0
    c = 0
    d = deque(w)
    while(d):
        tmp = d.popleft()
        if(tmp > p):
            return False
        
        if( tr + tmp > p):
            tr = tmp
            c += 1
        else:
            tr += tmp
        if c+1>k:
            return False
    return True

def MaxInP(w,k,p):
    maxinp = 0
    tmp = 0
    d = deque(w)
    while(d):
        tmp += d.popleft();
        if(tmp > p):
            if(tmp > maxinp):
                maxinp = tmp
            tmp = 0
    return maxinp

n,k = [int(x) for x in input().split()]
w = deque()
for i in range(n):
    w.append(int(input()))
    
mean = int(sum(w)/k)
maxinp = MaxInP(w,k,mean)

if k == 1:
    print(mean)
else:
    minP = mean
    maxP = maxinp
    while(True):
        m = int ((minP + maxP)/2)
        if ( isPa(w,k,m) ):
            maxP = m
        else:
            minP = m
        if (minP+1 == maxP or minP == maxP):
            print(maxP)
            break
a = input("Enter word:")
if a == 'redcoder':
  printf("1")
elif a == 'vvvvv':
  print("0")
elif a == "abcdabc":
  print("2")

### FIXED CODE ###

s = input()
count = 0
first_half, second_half = s[:len(s)//2], s[(len(s)+1)//2:]
if first_half == reversed(second_half):
    print(count)
else:
    for x in range(len(first_half)):
        if first_half[x] != second_half[len(second_half)-x-1]:
            count += 1
    print(count)
x,y=map(int, input().split())


a = [0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1]

if a[x] == a[y]:
    print("YES")
else:
    print("NO")
)

### FIXED CODE ###

x,y=map(int, input().split())


a = [0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1]

if a[x] == a[y]:
    print("Yes")
else:
    print("No")
n = int(input())
line = list(map(int, input().split()))

max = line[0]
min = line[0]
sum = line[0]

for i in range(1, n):
    if max < line[i]:
        max = line[i]
    elif min > line[i]:
        min = line[i]
    sum += line[i]

print(min, max, sum)


### FIXED CODE ###

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

max = line[0]
min = line[0]
sum = line[0]

for i in range(1, n):
    if max < line[i]:
        max = line[i]
    elif min > line[i]:
        min = line[i]
    sum += line[i]

print(min, max, sum)
l=input()
if((int(l[:2])>0 or int(l[2:])>0) and int(l[:2])<=12 and int(l[2:])<=12):
    print('AMBIGUOUS')
elif((int(l[:2])>0 or int(l[2:])>0) and int(l[2:])<=12 and int(l[:2])>=13):
    print("YYMM")
elif((int(l[:2])>0 or int(l[2:])>0) and int(l[2:]>=13) and int(l[:2])<=12):
    print("MMYY")
else:
    print('NA')

### FIXED CODE ###

s = input()
first = int(s[0:2])
second = int(s[2:4])
if 1 <= first <= 12 and 1 <= second <= 12:
    print('AMBIGUOUS')
elif 1 <= first <= 12:
    print('MMYY')
elif 1 <= second <= 12:
    print('YYMM')
else:
    print('NA')
a=int(input())
if(a%2==0):
  ans=(a/2)**2
  return
else:
  ans=((a-1)/2)*((a+1)/2)
  return
print(ans)

### FIXED CODE ###

a=int(input())
if a%2==0:
  ans=int((a/2)**2)
else:
  ans=int(((a-1)/2)*((a+1)/2))
print(ans)
def getlist():
	return list(map(int, input().split()))

a = int(input())
x = input()

if a >= 3200:
	print(s)
else:
	print("red")


### FIXED CODE ###

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

a = int(input())
s = input()

if a >= 3200:
	print(s)
else:
	print("red")
X,Y  = input().split()
X = int(X)
Y = int(Y)
if (X+Y)%3 != 0:
    print(0)
else:
    n = (2*X-Y)/3
    m = (2*Y-X)/3
    top = 1
    bot = 1
    n = int(n)
    m = int(m)
    for i in range(n):
        top *= (n + m) - i
        bot *= n - i

result = (top/bot) % ((10**9)+7)
result = int(result)
print(result)


### FIXED CODE ###

r = int(input())

print(r**2)
def solve():
    n, m = map(int, input().split())
    lists = []

    for _ in range(m):
        lists += input().split()
    
    for i in range(i, n + 1):
        print(lists.count(str(i)))


solve()

### FIXED CODE ###

def solve():
    n, m = map(int, input().split())
    lists = []

    for _ in range(m):
        lists += input().split()
    
    for i in range(1, n + 1):
        print(lists.count(str(i)))


solve()
k=int(input())
s=input()
l=len(s)
if l<=k:
  print(s)
else:
  p=s[1:k]
  q='...'
  r=p+q
  print(r)

### FIXED CODE ###

n=int(input())
a=n%10
if a==3:
  print('bon')
elif a==0:
  print('pon')
elif a==1:
  print('pon')
elif a==6:
  print('pon')
elif a==8:
  print('pon')
else:
  print('hon')
N=int(input())
A=list(map(int, input().split()))
B=A[:]
i=0
while i < N:
    if A[i] % 2 == 0:
        A[i] = A[i]//2
        print(A[i])
        if i == N - 1:
            B = A[:]
            i = -1
        i += 1
    else:
        break
print(B)

### FIXED CODE ###

L = input()
n=0
for i in range(len(L)):
    if int(L[i]) ==1:
        n += 1
print(n)
n=int(input())
x=0
for i in range(n):
  a,b=input().split()
  if b=="JPY":
    x+=int(input())
  else:
    x+=float(input())*380000
print(x)

### FIXED CODE ###

n=int(input())
x=0
for i in range(n):
  a,b=input().split()
  if b=="JPY":
    x+=int(a)
  else:
    x+=float(a)*380000
print(x)
def main():
  N = int(input())
  K = int(input())

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

  price.sort()

  part = price[0:K]

  print(sum(part))

if __name__ == '__main__':
  main()

### FIXED CODE ###

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

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

  price.sort()

  part = price[0:K]

  print(sum(part))

if __name__ == '__main__':
  main()
X = input()
if X == "A":
  	print("T")
elif X == "T":
  	print("A")
elif X == "C":
  	print("G")
else
	print("C")

### FIXED CODE ###

X = input()
if X == "A":
  	print("T")
elif X == "T":
  	print("A")
elif X == "C":
  	print("G")
elif X == "G":
	print("C")
INF = float('inf')

H, N = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


# i個目までを使って与えた魔力の総和がj以下の時の最小コスト
dp = [[INF for j in range(H + 1)] for i in range(N + 1)]

dp[0][0] = 0

for i in range(N):
    for j in range(H + 2):
        dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - A[i]] + B[i])

if dp[N][H] == INF:
    print(dp[N][H + 1])
else:
    print(dp[N][H])


### FIXED CODE ###

INF = float('inf')

H, N = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)


# i個目までを使って与えた魔力の総和がjの時の最小コスト
dp = [[INF for j in range(H + 1)] for i in range(N + 1)]

dp[0][0] = 0

for i in range(N):
    for j in range(H + 1):
        if j < A[i]:
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][0] + B[i])
        else:
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - A[i]] + B[i])

print(dp[N][H])
mat = [[False]*3 for i in range(3)]
a_mat = []
for i in range(3):
  a_list = list(map(int, input().split()))
  a_mat.append(a_list)
n = int(input())
for i in range(n):
  b = int(input())
  for x in range(3):
    for y in range(3):
      if a_mat[x][y] == b:
        mat[x][y] = True

if mat[0][0] and mat[0][1] and mat[0][2] ¥
or mat[1][0] and mat[1][1] and mat[1][2] ¥
or mat[2][0] and mat[2][1] and mat[2][2] ¥
or mat[0][0] and mat[1][0] and mat[2][0] ¥
or mat[0][1] and mat[1][1] and mat[2][1] ¥
or mat[0][2] and mat[1][2] and mat[2][2] ¥
or mat[0][0] and mat[1][1] and mat[2][2] ¥
or mat[0][2] and mat[1][1] and mat[2][0]:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

mat = [[False]*3 for i in range(3)]
a_mat = []
for i in range(3):
  a_list = list(map(int, input().split()))
  a_mat.append(a_list)
n = int(input())
for i in range(n):
  b = int(input())
  for x in range(3):
    for y in range(3):
      if a_mat[x][y] == b:
        mat[x][y] = True

if mat[0][0] and mat[0][1] and mat[0][2] \
or mat[1][0] and mat[1][1] and mat[1][2] \
or mat[2][0] and mat[2][1] and mat[2][2] \
or mat[0][0] and mat[1][0] and mat[2][0] \
or mat[0][1] and mat[1][1] and mat[2][1] \
or mat[0][2] and mat[1][2] and mat[2][2] \
or mat[0][0] and mat[1][1] and mat[2][2] \
or mat[0][2] and mat[1][1] and mat[2][0]:
  print("Yes")
else:
  print("No")