Harryxun/stf_run huggingface dataset:
from collections import deque
#import numpy as np

h,w=map(int,input().split())
#sy,sx=map(int,input().split())
#sy=sy-1
#sx=sx-1
#gy,gx=map(int,input().split())
#gy=gy-1
#gx=gx-1
maze=[list("#"*(w+2))]+[list("#"+input()+"#") for i in range(h)]+[list("#"*(w+2))]
INF=10800 #>50*50
visited=[[-INF]*(w+2) for i in range(h+2)]

ss=[]

for i in range(1,h+1):
  for j in range(1,w+1):
    if maze[i][j]==".":
      ss.append((i,j))



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[gy][gx]
    for i,j in ((-1,0),(1,0),(0,1),(0,-1)):
      #もともと壁があって、はみ出す心配はない。
      y_new,x_new=y+i,x+j
      if maze[y_new][x_new]=="." and visited[y_new][x_new]==-INF:
        visited[y_new][x_new]=visited[y][x]+1
        queue.append([y_new,x_new])

        
        
ans=0
for i,j in ss:
  bfs(maze,visited,3,1)
  for i in range(1,h+1):
    for j in range(1,w+1):
      ans=max(ans,visited[i][j])

    
    
print(ans)



### FIXED CODE ###

from collections import deque

h,w=map(int,input().split())

maze=[list("#"*(w+2))]+[list("#"+input()+"#") for i in range(h)]+[list("#"*(w+2))]
INF=10800 #>50*50
visited=[[-INF]*(w+2) for i in range(h+2)]

ss=[]

for i in range(1,h+1):
  for j in range(1,w+1):
    if maze[i][j]==".":
      ss.append((i,j))



def bfs(maze,visited,sy,sx):#,gy,gx):
  queue=deque([[sy,sx]])
  visited[sy][sx]=0
  while queue:
    [y,x]=queue.popleft()
    for i,j in ((-1,0),(1,0),(0,1),(0,-1)):
      y_new,x_new=y+i,x+j
      if maze[y_new][x_new]=="." and visited[y_new][x_new]==-INF:
        visited[y_new][x_new]=visited[y][x]+1
        queue.append([y_new,x_new])

        
        
ans=0
for i,j in ss:
  visited=[[-INF]*(w+2) for i in range(h+2)]
  bfs(maze,visited,i,j)
  for i in range(1,h+1):
    for j in range(1,w+1):
      ans=max(ans,visited[i][j])

    
    
print(ans)
n,m=map(int,input().split())
pen=0
A=[0 for i in range(n)]
for i in range(m):
  a,b=map(str,input().split())
  a=int(a)
  if b=="AC":
    A[a-1]=1
for i in range(m):
  a,b=map(int,input().split())
  a=int(a)
  if b=="WA" and A[a-1]==1:
    pen+=1
print(sum(A),pen)


### FIXED CODE ###

n,m=map(int,input().split())
A=[[0,0] for i in range(n)] #ACしたか、WA数
AC=0
pen=0
for i in range(m):
    a,b=map(str,input().split())
    a=int(a)
    if b=="AC":
        A[a-1][0]=1
    elif b=="WA" and A[a-1][0]==0:
        A[a-1][1]+=1
for i in range(n):
    if A[i][0]==1:
        AC+=1
        pen+=A[i][1]
print(AC,pen)
a,b,c = map(int, input().split(" "))

if a == b and a!=c:
    print("Yes")
elif a == c and a!=b:
    print("Yes")
elif b == c and b != a:
    print("Yes")  
else:
    print("No")


### FIXED CODE ###

a,b,c = map(int, input().split(" "))

if a == b and a!=c:
    print("Yes")
elif a == c and a!=b:
    print("Yes")
elif b == c and b != a:
    print("Yes")  
else:
    print("No")
While True:
    m,f,r=map(int,input().split())
    if m==f==r==-1:break
    a=m+f
    if m==-1 or f==-1:print('F')
    elif a >= 80:print('A')
    elif a >= 65:print('B')
    elif a >= 50:print('C')
    elif a >= 30:
        if r >= 50:print('C')
        else:print('D')
    else:print('F')

### FIXED CODE ###

while True:
    m,f,r=map(int,input().split())
    if m==f==r==-1:break
    a=m+f
    if m==-1 or f==-1:print('F')
    elif a >= 80:print('A')
    elif a >= 65:print('B')
    elif a >= 50:print('C')
    elif a >= 30:
        if r >= 50:print('C')
        else:print('D')
    else:print('F')
N,D,A = map(int,input().split())
import numpy as np
import math
XH = [list(map(int,input().split())) for _ in range(N)]
XH = sorted(XH)
ans = 0
ma = XH[-1][0]
l = np.array([0]*(ma+5))
for xh in XH:
  l[xh[0]]=xh[1]
  

for xh in XH:
  x = xh[0]
  if x+D<=ma:
    a = l[x]
    if a<=0:
      continue
    else:
      b = math.ceil(a/A)
      ans += b
      l[x:x+2*D+1:]-=b*a
  else:
    a = l[x]
    if a<=0:
      continue
    else:
      b=math.ceil(a/A)
      ans += b
      l[x::]-=b*a
      
print(ans)

### FIXED CODE ###

def main():
  N,D,A = map(int,input().split())
  XH = [list(map(int,input().split())) for _ in range(N)]
  XH = sorted(XH)
  ans = 0
  S = [0]*(N+1)
  x = XH[0][0]
  h = XH[0][1]
  j = 0
  b = (h+A-1)//A
  ans += b
  y = b*A
  while True:
    if j+1>=N:
      break
    if XH[j+1][0]<=x+2*D:
      j+=1
    else:
      break
  S[0]+=y
  S[j+1]-=y
  S[1]+=S[0]
  for i in range(1,N):
    xh = XH[i]
    h = xh[1]
    s = S[i]
    rec = h-s
    if rec<=0:
      S[i+1]+=s
      continue
    else:
      x = xh[0]
      j = max(j,i)
      while True:
        if j+1>=N:
          break
        if XH[j+1][0]<=x+2*D:
          j+=1
        else:
          break
      b = (rec+A-1)//A
      ans += b
      y = b*A
      S[i]+=y
      S[j+1]-=y
      S[i+1]+=s+y
  print(ans)
main()
s=input()
gou=0
if s[0]=="R" and s[1]=="R":
  gou=2
if s[1]=="R" and s[2]=="R":
  gou=2
if s[1]=="R" and s[2]=="R" and s[3]=="R":
  gou=3
print(gou)

### FIXED CODE ###

s=input()
gou=0
if s[0]=="R" or s[1]=="R" or s[2]=="R":
  gou=1
if s[0]=="R" and s[1]=="R":
  gou=2
if s[1]=="R" and s[2]=="R":
  gou=2
if s[1]=="R" and s[2]=="R" and s[0]=="R":
  gou=3
print(gou)
n,x = map(int,input().split())
l = list(map(int,input().split()))
c = 1
D = 0
li = []
for i in range(1,n+1):
  D = D + l[i]
  if D <= x:
    c += 1
print(c)

### FIXED CODE ###

n,x = map(int,input().split())
l = list(map(int,input().split()))
c = 1
D = 0
li = []
for i in range(1,n+1):
  D = D + l[i-1]
  if D <= x:
    c += 1
print(c)
import itertools
s=['S','H','C','D']
n=range(1,14)
c=[x y for x,y in itertools.product(s,n)]
for _ in range(input()):
 c.remove(input())
print(*c)

### FIXED CODE ###

n=int(input())
e=[input()for _ in[0]*n]
for s in"SHCD":
 for r in range(1,14):
  if f'{s} {r}'not in e:print(s,r)
from heapq import heappop
from heapq import heappush
q=int(input())
L,R=[],[]
b_sum=0
l_sum,r_sum=0,0
count=0
mid=0
for _ in range(q):
  
  Q=list(map(int,input().split()))
  if Q[0]==1:
    a,b=Q[1],Q[2]
    count+=1
    b_sum+=b
    if count==1:
      mid=a
    elif count%2==0:
      if a<=mid:
        heappush(L,-a)
        l_sum+=a
        heappush(R,mid)
        r_sum+=mid
      else:
        heappush(L,-mid)
        l_sum+=mid
        heappush(R,a)
        r_sum+=a
    else:
      l,r=-heappop(L),heappop(R)
      if a<l:
        heappush(L,-a)
        l_sum+=a-l
        mid=l
        heappush(R,r)
      elif r<a:
        heappush(L,-l)
        mid=r
        heappush(R,a)
        r_sum+=a-r
      else:
        heappush(L,-l)
        mid=a
        heappush(R,r)

  else:
    if count%2==1:
      print(mid,r_sum-l_sum+b_sum)
    else:
      print(-heappop(L),r_sum-l_sum+b_sum)



### FIXED CODE ###

from heapq import heappop
from heapq import heappush
q=int(input())
L,R=[],[]
b_sum=0
l_sum,r_sum=0,0
count=0
mid=0
for _ in range(q):
  
  Q=list(map(int,input().split()))
  if Q[0]==1:
    a,b=Q[1],Q[2]
    count+=1
    b_sum+=b
    if count==1:
      mid=a
    elif count%2==0:
      if a<=mid:
        heappush(L,-a)
        l_sum+=a
        heappush(R,mid)
        r_sum+=mid
      else:
        heappush(L,-mid)
        l_sum+=mid
        heappush(R,a)
        r_sum+=a
    else:
      l,r=-heappop(L),heappop(R)
      if a<l:
        heappush(L,-a)
        l_sum+=a-l
        mid=l
        heappush(R,r)
      elif r<a:
        heappush(L,-l)
        mid=r
        heappush(R,a)
        r_sum+=a-r
      else:
        heappush(L,-l)
        mid=a
        heappush(R,r)

  else:
    if count%2==1:
      print(mid,r_sum-l_sum+b_sum)
    else:
      l=-heappop(L)
      print(l,r_sum-l_sum+b_sum)
      heappush(L,-l)
ans=o
n,k=map(int,input().split())
while True:
  n=n//k
  ans+=1
  if n==0:
    break
print(ans)

### FIXED CODE ###

n,k=map(int,input().split())
ans=0
while n!=0:
  n=n//k
  ans+=1
print(ans)
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int(input().strip().split())))

a.sorted(reverse=True)

alice = 0
bob = 0
for i in range(n-1):
    if i % 2 is 0:
        alice = alice + int(a[i])
    else:
        bob = bob + int(a[i])
        
print(alice - bob)

### FIXED CODE ###

n = int(input())
a = input().strip().split()
a = [ int(a[i]) for i in range(len(a)) ]

a.sort(reverse=True)

alice = 0
bob = 0
for i in range(n):
    if i % 2 is 0:
        alice = alice + int(a[i])
    else:
        bob = bob + int(a[i])
        
print(alice - bob)
import sys
input=sys.stdin.buffer.readline
n,c=map(int,input().split())
a=[ [0 for _ in range(10**5+2)] for _ in range(c)]
for _ in range(n):
    s,t,cc=map(int,input().split())
    cc-=1
#    print(s-1,end=' s-1\n')
    a[cc][s-1]+=1
    a[cc][t]-=1
    '''for i in range(s-1,t):
        a[cc][i]=1'''
for i in range(c):
    for j in range(1,10**5+1):
#        print(i,j)
        a[i][j]+=a[i][j-1]
        assert a[i][j]<=1

ans=1
for j in range(0,10**5):
    su=0
#    print(c,'hello')
    for i in range(c):
#        print('asdf hello')
#        print(j,i,a[i][j])
        su+=a[i][j]
    ans=max(ans,su)
print(ans)


### FIXED CODE ###

import sys
input=sys.stdin.buffer.readline
n,c=map(int,input().split())
a=[ [0 for _ in range(10**5+2)] for _ in range(c)]
for _ in range(n):
    s,t,cc=map(int,input().split())
    cc-=1
#    print(s-1,end=' s-1\n')
    #a[cc][s-1]+=1
    #a[cc][t]-=1
    for i in range(s-1,t):
        a[cc][i]=1
'''for i in range(c):
    for j in range(1,10**5+1):
        a[i][j]+=a[i][j-1]
'''
ans=1
for j in range(0,10**5+1):
    su=0
#    print(c,'hello')
    for i in range(c):
#        print('asdf hello')
#        print(j,i,a[i][j])
        su+=a[i][j]
    ans=max(ans,su)
print(ans)
from math import gcdnbv
K=int(input())
if K%7==0:
  K=K//7
if gcd(10,K)!=1:
  print(-1)
  return
x=1%K
cnt=1
while x!=0:
  x=(10*x+1)%K
  cnt+=1
print(cnt)


### FIXED CODE ###

K = int(input())
x = 7 % K #mod(K)
if K == 1 or K == 7:
  print(1)
  exit()
ans = 1
i = 0
while i < K:
  ans += 1
  x = (x * 10 + 7) % K
  
  
  if x == 0:
    print(ans)
    exit()
  i += 1
print('-1')
a,b = map(int, input().split())
if (a*b)% == 1:
    print('Odd')
else:
    print('Even')

### FIXED CODE ###

a,b = map(int, input().split())
if (a*b)% 2 == 1:
    print('Odd')
else:
    print('Even')
n,m,k = map(int,input().split())

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

# まずaを全部読む
# 全部読めたならbも読む
# 最後の本を捨てて、それがなければどこまでいけるかを試す

ans = 0
cost = 0
b_i = 0
while cost <= k:
  ans += 1
  if ans >= n:
    cost += b[n-ans]
    b_i += 1
  else:
    cost += a[ans]

max_ans = ans
if b_i == 0:
  for i in range(ans-1,-1,-1):
    ans -= 1
    cost -= a[i]
    while cost <= k and b_i < m:
      ans += 1
      cost += b[b_i]
      b_i += 1
    max_ans = max(max_ans, ans)
else:
  for i in range(n-1,-1,-1):
    ans -= 1
    cost -= a[i]
    while cost <= k and b_i < m:
      ans += 1
      cost += b[b_i]
      b_i += 1
    max_ans = max(max_ans, ans)
    
if not (a[0] >= k and b[0] >= k):
  print(max_ans)
else:
  print(0)

### FIXED CODE ###

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

a, b=[0], [0]
for i in range(N):
  a.append(a[i]+A[i])
for i in range(M):
    b.append(b[i]+B[i])
    
ans, j=0, M
for i in range(N+1):
  if a[i]>K:
    break
  while b[j]>K-a[i]:
    j-=1
  ans=max(ans, i+j)
  
print(ans)
n, k = map(int, input().split())
s = input()
s[k] = s[k].lower()
print(s)

### FIXED CODE ###

n, k = map(int, input().split())
k -= 1
s = list(input())
s[k] = s[k].lower()
print("".join(s))
#encoding utf-8

import math
from functools import reduce


#複数の最大コゥ約数
def gcd(numbers):
    return reduce(math.gcd, numbers)

n,X = map(int, input().split())

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

x.append(X)

x.sort()

minus=[]

for i in range(len(x)-1):
    minus.append(x[i+1]-x[i])

D = gcd(minus)

print(D)


### FIXED CODE ###

#encoding utf-8

import math
from functools import reduce

#複数の最大コゥ約数
def gcd(a,b):
    l = max(a,b)
    m = min(a,b)
    while m != 0:
        extra = l%m
        l = m
        m = extra
    return l

def gcd_multi(numbers):
    return reduce(gcd,numbers)

n,X = map(int, input().split())

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

x.append(X)

x.sort()

minus=[]

for i in range(len(x)-1):
    minus.append(x[i+1]-x[i])


D = gcd_multi(minus)

print(int(D))
dic={}
a=[[0 for i in range(3)]for j in range(3)]
for i in range(1,100):
  dic[i]=[-1,-1]
for i in range(3):
  for j in range(3):
    x=int(input())
    a[i][j]=3
    dic[x]=[i,j]
n=int(input())
for i in range(n):
  x=int(input())
  if(dic[x]!=[-1,-1]):
    a[dic[x][0],dic[x][1]]=0
flag=0
for i in range(3):
  if(max(a[i][1],a[i][2],a[i][0])==0):
    flag=1
    break
  elif(max(a[1][i],a[2][i],a[3][i])==0):
    flag=1
    break
if(max(a[0][0],a[1][1],a[2][2])==0):
  flag=1
elif(max(a[0][2],a[1][1],a[2][0])==0):
  flag=1
if(flag==1):
  print ('Yes')
else:
  print ('No')

    


### FIXED CODE ###

dic={}
a=[]
for i in range(1,100):
    dic[i]=[-1,-1]
for i in range(3):
    a.append(list(map(int,input().split())))
    for j in range(3):
        dic[a[i][j]]=[i,j]
n=int(input())
for i in range(n):
    x=int(input())
    if(dic[x]!=[-1,-1]):
        a[dic[x][0]][dic[x][1]]=0
flag=0
for i in range(3):
    if(max(a[i][1],a[i][2],a[i][0])==0):
        flag=1
        break
    elif(max(a[1][i],a[2][i],a[0][i])==0):
        flag=1
        break
if(max(a[0][0],a[1][1],a[2][2])==0):
    flag=1
elif(max(a[0][2],a[1][1],a[2][0])==0):
    flag=1
if(flag==1):
    print ('Yes')
else:
    print ('No')
8
27 23 76 2 3 5 62 52

### FIXED CODE ###

n = int(input())

w = list(map(int,input().split()))
count = 0
min = 1000
for t in range(1,n):
  count =  abs(sum(w[:t]) - sum(w[t:n])) 
  if count < min:
    min = count
print(min)
s=list(input())
print((s.index('z')-s.index('a'))+1)


### FIXED CODE ###

s=input()
a=[]
z=[]
for num in range(len(s)):
  if s[num]=='A':
    a.append(num)
  if s[num]=='Z':
    z.append(num)
print(max(z)-min(a)+1)
s = input()
return s[:-8]

### FIXED CODE ###

s = input()
print(s[:-8])
A, B, C = map(int, input().split())
if A == B == C:
  print(-1)
else:
  count = 0
  while 0 == A % 2 == B % 2 == C % 2:
	A = (B + C) // 2
    B = (C + A) // 2
    C = (A + B) // 2
    count += 1
  print(count)
    

### FIXED CODE ###

A, B, C = map(int, input().split())
if A == B == C and A % 2 == 0:
  print(-1)
else:
  count = 0
  while 0 == A % 2 == B % 2 == C % 2:
    _A = (B + C) // 2
    _B = (C + A) // 2
    _C = (A + B) // 2
    A = _A
    B = _B
    C = _C
    count += 1
    # print("A: {}, B: {}, C: {}".format(A, B, C))
  print(count)
h_1,m_1_h_2,m_2,k = map(int,input().split())
H = 60*h_2+m_2-(60*h_1+m_1)-k
if(H<=0):
  print(0)
else:
  print(H)



### FIXED CODE ###

h_1,m_1,h_2,m_2,k = map(int,input().split())
H = 60*h_2+m_2-(60*h_1+m_1)-k
if(H<=0):
  print(0)
else:
  print(H)
print(pow(int(input())), 3)

### FIXED CODE ###

x = int(input())
y = 3
p = pow(x, y)
print(p)
# input
N = int(input())
A = list(map(int, input().split()))

i = 0
ans = 0

while i < N - 1:
    if A[i + 1] == A[i]:
        A[i + 1] == A[i] + A[i + 2]
        i += 1
        ans += 1
    i += 1

print(ans)
        


### FIXED CODE ###

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

i = 0
ans = 0

while i < N - 1:
    if A[i + 1] == A[i]:
        if i < N - 2:
            A[i + 1] == A[i] + A[i + 2]
        if i == N - 1:
            A[i + 1] += 1
        i += 1
        ans += 1
    i += 1

print(ans)
N = int(input())
A = list(map(int,input().split()))
print(*A)
for i in range(1,N):
    v = A[i]
    j = i - 1
    while j > = 0 and A [j] > v :
        A[j + 1] = A[j]
        j -= 1
    A[j+1] = v
    print(*A)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
print( *A )
for i in range(1,N):
    v = A[i]
    j = i - 1
    while j >= 0 and A [j] > v :
        A[j + 1] = A[j]
        j -= 1
    A[j + 1] = v
    print( *A )
n,m=map(int,input().split())
ans=0
import math
for i in range(1,min(m//n+1,int(math.sqrt(m))+1):
  if m%i==0:
    ans=max(i,ans)
print(ans)


### FIXED CODE ###

n,m=map(int,input().split())
ans=0
import math
for i in range(1,int(math.sqrt(m))+1):
  if m%i!=0:
    continue
  i2=m//i
  if i*n<=m:
    ans=max(ans,i)
  if i2*n<=m:
    ans=max(ans,i2)
print(ans)
n = int(input())
a = list(map(int,input().split()))

a.sort()

max_a = a[-1]
is_available = [True] * (max_a + 1)

ans = 0

for i, x in enumerate(a[:-1]):
    if not a[i+1] == x and is_available[x]:
        ans += 1
    for b in range(x, m + 1, x):
        is_available[b] = False

if is_available[a[-1]]:
    ans += 1

print(ans)

### FIXED CODE ###

n = int(input())

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

a.sort()

dp = [True] * (a[-1] + 1)

ans = 0

m = a[-1]

for i, x in enumerate(a[:-1]):
    if not a[i+1] == x and dp[x]:
        ans += 1
    for b in range(x, m + 1, x):
        dp[b] = False

if dp[a[-1]]:
    ans += 1

print(ans)
n,k=map(int,input().split())
l=list(map(int,input().split()))
m=0
zf=0
for i in range(n):
    if l[i]==0:
        zf=1
if zf==0:
    l.append(0)
    l.sort()
else:
    k-=1
    
n=len(l)
pl=[]
nl=[]
for i in range(n):
    if l[i]==0:
        m=i
    elif l[i]>0:
        pl.append(l[i])
    else:
        nl.append(-l[i])
        
ans=1e10
for i in range(min(k,len(pl))):
    a=len(nl)-k-i+1
    if a>=0 and a<len(nl):
        ans=min(ans,2*pl[i]+nl[len(nl)-k-i+1])
for i in range(min(k,len(nl))):
    a=len(nl)-i-1
    b=k-i-2
    if b>=0 and b<len(pl):
        ans=min(ans,2*nl[a]+pl[k-i-2])
if k<=len(pl):
    ans=min(ans,pl[k-1])
if k<=len(nl):
    ans=min(ans,nl[len(nl)-k])
print(ans)




### FIXED CODE ###

n,k=map(int,input().split())
l=list(map(int,input().split()))
m=0
zf=0
for i in range(n):
    if l[i]==0:
        zf=1
if zf==0:
    l.append(0)
    l.sort()
else:
    k-=1
if k==0:
    print(0)
    exit()
n=len(l)
pl=[]
nl=[]
for i in range(n):
    if l[i]==0:
        m=i
    elif l[i]>0:
        pl.append(l[i])
    else:
        nl.append(-l[i])
        
ans=1e10
for i in range(min(k-1,len(pl))):
    a=len(nl)-k+i+1
    if a>=0 and a<len(nl):
        ans=min(ans,2*pl[i]+nl[len(nl)-k+i+1])
for i in range(min(k-1,len(nl))):
    a=len(nl)-i-1
    b=k-i-2
    if b>=0 and b<len(pl):
        ans=min(ans,2*nl[a]+pl[k-i-2])
if k<=len(pl):
    ans=min(ans,pl[k-1])
if k<=len(nl):
    ans=min(ans,nl[len(nl)-k])
print(ans)
# coding: utf-8
# Your code here!

import fractions
import sys

N, M = map(int, input().rstrip().split(' '))
S = [x for x in input()]
T = [x for x in input()]

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

L = lcm(N, M)

dp = [-1] * (L + 10)
'''   
for i, s in enumerate(S):
    dp[i*L//N] = s

for i, t in enumerate(T):
    if dp[i*L//M] != -1:
        if dp[i*L//M] != t:
            print(-1)
            sys.exit()
print(L)
'''

### FIXED CODE ###

# coding: utf-8
# Your code here!

import fractions
import sys
from collections import defaultdict

N, M = map(int, input().rstrip().split(' '))
S = [x for x in input()]
T = [x for x in input()]

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

L = lcm(N, M)

dp = defaultdict(lambda: -1)

for i, s in enumerate(S):
    dp[i*L//N] = s

for i, t in enumerate(T):
    if dp[i*L//M] != -1:
        if dp[i*L//M] != t:
            print(-1)
            sys.exit()
print(L)
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()
aa = Counter(LIST())
aa = sorted(aa.items(), key=itemgetter(0))
a = [[aa[i][1], aa[i][0]] for i in range(len(aa))]
b = sorted([LIST() for i in range(m)], key=itemgetter(1), reverse=True)

ans = 0
i = j = 0
while i < m and j < n and b[i][1] > a[j][1]:
    if b[i][0] >= a[j][0]:
        ans += b[i][1]*a[j][0]
        b[i][0] -= a[j][0]
        a[j][0] = 0
        j += 1
    else:
        ans += b[i][1]*b[i][0]
        a[j][0] -= b[i][0]
        b[i][0] = 0
        i += 1
reg = j
if reg < len(a):
    for i in range(j, len(a)):
        ans += a[i][0]*a[i][1]
print(ans)

### FIXED CODE ###

from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, m = MAP()
aa = Counter(LIST())
aa = sorted(aa.items(), key=itemgetter(0))
a = [[aa[i][1], aa[i][0]] for i in range(len(aa))]
b = sorted([LIST() for i in range(m)], key=itemgetter(1), reverse=True)

ans = 0
i = j = 0
while i < len(b) and j < len(a) and b[i][1] > a[j][1]:
    if b[i][0] >= a[j][0]:
        ans += b[i][1]*a[j][0]
        b[i][0] -= a[j][0]
        a[j][0] = 0
        j += 1
    else:
        ans += b[i][1]*b[i][0]
        a[j][0] -= b[i][0]
        b[i][0] = 0
        i += 1
reg = j
if reg < len(a):
    for i in range(j, len(a)):
        ans += a[i][0]*a[i][1]
print(ans)
A = input('Aを入力してください')
B = input('Bを入力してください')
K = input('Cを入力してください')
#print('A= ', A)
#print('B= ', B)
#print('K= ', K)

#A = 1
#B = 10
#K = 6

ANS = []

for i in range(K + 1):
    ANS.append(A + i)


for j in range(K + 1):
    if B - j not in ANS:
        ANS.append(B - j)

ANS.sort()

#print(ANS)

for i in range(len(ANS)):
    print(ANS[i])


### FIXED CODE ###

import sys

#A = input('Aを入力してください')
#B = input('Bを入力してください')
#K = input('Cを入力してください')
#print('A= ', A)
#print('B= ', B)
#print('K= ', K)

#A = 1
#B = 10
#K = 6

#S = input('ABKを入力してください')
S = input()
S = S.split(' ')

#for i in range(len(S)):
#    print(S[i])

#sys.exit()

A = int(S[0])
B = int(S[1])
K = int(S[2])

ANS = []
for i in range(K):
    if A + i <= B:
        ANS.append(A + i)


for j in range(K):
    if B - j not in ANS and B - j >= A:
        ANS.append(B - j)

ANS.sort()

#print(ANS)

for i in range(len(ANS)):
    print(ANS[i])
import collections as c
import sys
s = input()
l = len(s)

if l == 1:
	print("YES")
else:
	S = c.Counter(list(map(str,s)))
	if len(S.key()) == 1:
		print("NO")
		sys.exit()
	elif len(S.keys()) == 2:
		if l == 2:
			print("YES")
		else:
			print("NO")
		sys.exit()

	cnt = set(list(S.values()))

	if len(cnt) == 3:
		print("NO")
	elif len(cnt) == 2:
		a,b = cnt
		if abs(a-b) <= 1:
			print("YES")
		else:
			print("NO")
	else:
		print("YES")

### FIXED CODE ###

import collections as c
import sys
s = input()
l = len(s)

if l == 1:
	print("YES")
else:
	S = c.Counter(list(map(str,s)))
	if len(S.keys()) == 1:
		print("NO")
		sys.exit()
	elif len(S.keys()) == 2:
		if l == 2:
			print("YES")
		else:
			print("NO")
		sys.exit()

	cnt = set(list(S.values()))

	if len(cnt) == 3:
		print("NO")
	elif len(cnt) == 2:
		a,b = cnt
		if abs(a-b) <= 1:
			print("YES")
		else:
			print("NO")
	else:
		print("YES")
s = input()
t = input()

ans = 0
for i in range(len(s)):
  if s[i] == t[i]:
    ans += 1
print ans


### FIXED CODE ###

s = input()
t = input()
ans = 0
for i in range(len(s)):
  if s[i] == t[i]:
    ans += 1
print(ans)