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

import copy
H,W = map(int, input().split())
field = [list(input()) for _ in range(H)]
dy = [1,-1,0,0]
dx = [0,0,1,-1]

queue = []
# sy,sx = 0,0
# gy,gx = H-1,W-1
seen = [[0 for i in range(W)] for j in range(H)]
for i in range(H):
    for j in range(W):
        if field[i][j] == '#':
            seen[i][j] = 1
            queue.append([i,j])
# queue = [[sy,sx]]
flag = False
count = 0
while True:
    count += 1
    nqueue = []
    while queue:
        h,w = queue.pop(0)
        for i in range(4):
            nh = h + dy[i]
            nw = w + dx[i]
            if (0<=nh<H) and (0<=nw<W):
                if field[nh][nw] != '#':
                    if seen[nh][nw] == 0:
                        seen[nh][nw] = 1
                        nqueue.append([nh,nw])
    if nqueue:
        queue = copy.copy(nqueue)
    else:
        break
print(count-1)
    

### FIXED CODE ###

from collections import deque
import copy

def main():
    h, w = map(int, input().split())
    a = [[j == "#" for j in input()] for _ in range(h)]


    # スタート地点をqueueに追加
    que = deque([(i, j) for i in range(h) for j in range(w) if a[i][j]])

    count = 0
    while True:
        count += 1
        nque = deque()
        while que:
            y, x = que.popleft()
            if x > 0 and not a[y][x-1]:
                a[y][x-1] = True
                nque.append((y,x-1))
            if x < w-1 and not a[y][x+1]:
                a[y][x+1] = True
                nque.append((y,x+1))
            if y > 0 and not a[y-1][x]:
                a[y-1][x] = True
                nque.append((y-1,x))
            if y < h-1 and not a[y+1][x]:
                a[y+1][x] = True
                nque.append((y+1,x))

        if nque:
            que = copy.copy(nque)
        else:
            break

    print(count - 1)

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

import bisect
a,b,q = map(int,input().split())
INF = 10**18
s=[-INF]+[int(input()) for _ in range(a)]+[INF]
t=[-INF]+[int(input()) for _ in range(b)]+[INF]

def dis(x,p,q):
    return min(abs(x-s[p])+abs(s[p]-t[q]),abs(x-t[q])+abs(s[p]-t[q]))

def kai(x):
    res = INF
    s1 = bisect.bisect_right(s,x)
    ls = [s1,s1 - 1]
    t1 = bisect.bisect_right(t,x)
    lt = [t1,t1 - 1]
    for ss in ls:
        for st in lt:
            res = min(res,dis(x,ss,st))
    return res

for _ in range(q):
    x = int(input())
    print(kai(x))


### FIXED CODE ###

import bisect
a,b,q = map(int,input().split())
INF = 10**18
s=[-INF]+[int(input()) for _ in range(a)]+[INF]
t=[-INF]+[int(input()) for _ in range(b)]+[INF]

def kai(x):
    res = INF
    s1 = bisect.bisect_right(s,x)
    ls = [s1,s1 - 1]
    t1 = bisect.bisect_right(t,x)
    lt = [t1,t1 - 1]
    for ss in ls:
        for st in lt:
            res = min(res,abs(x-s[ss])+abs(s[ss]-t[st]),abs(x-t[st])+abs(s[ss]-t[st]))
    return res

lx = [int(input()) for _ in range(q)]
for x in lx:
    print(kai(x))
### BUGGY CODE ###

n, k = [int(_) for _ in input().split()]
s = input()
x = []

cnt = 0
c0 = '1'
for c in s:
    if c == c0:
        cnt += 1
    else:
        x.append(cnt)
        c0 = c
        cnt = 1
else:
    if cnt != 0:
        x.append(cnt)

if s[-1] == '0':
        x.append(0)

if len(x) <= k*2+1:
    print(sum(x))
else:
    y = [sum(x[i:i+k*2+1]) for i in range(0,len(x)-k*2,2)]
    print(max(y))


### FIXED CODE ###

n, k = [int(_) for _ in input().split()]
s = input()
x = []

cnt = 0
c0 = '1'
for c in s:
    if c == c0:
        cnt += 1
    else:
        x.append(cnt)
        c0 = c
        cnt = 1
else:
    if cnt != 0:
        x.append(cnt)

if s[-1] == '0':
        x.append(0)

if len(x) <= k*2+1:
    print(sum(x))
else:
    y = sum(x[0:k*2+1])
    ans = y
    for i in range(2,len(x)-k*2,2):
        y = y - sum(x[i-2:i]) + sum(x[i+2*k-1:i+2*k+1])
        if ans < y:
            ans = y
    print(ans)
### BUGGY CODE ###

t = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [a[0] - b[0], a[1] - b[1]]
w = t[0] * d[0] + t[1] * d[1]
if w < 0:
    d[0] *= -1
    d[1] *= - 1
    w *= -1
if t[0] * d[0] + t[1] * d[1] == 0:
    print("infinity")
else:
    now = 0
    ans = 0
    i, last = 0, 0
    while True:
        new = now + d[i] * t[i]
        last += 1
        if (now < 0 and new > 0) or (now > 0 and new < 0) or new == 0:
            ans += 1
            last = 0
        now = new
        i = 1 - i
        if last > 2:
            break
    print(ans)


### FIXED CODE ###

t = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = [a[0] - b[0], a[1] - b[1]]
w = t[0] * d[0] + t[1] * d[1]
if w < 0:
    d[0] *= -1
    d[1] *= - 1
    w *= -1
if t[0] * d[0] + t[1] * d[1] == 0:
    print("infinity")
else:
    min, max = 0, 1000000000000000
    while max - min > 1:
        mid = (min + max) // 2
        dest = w * mid
        ok = False
        for i in range(2):
            dest += d[i] * t[i]
            if dest <= 0:
                ok = True
        if ok:
            min = mid
        else:
            max = mid
    now = w * (min - 10)
    ans = 2 * (min - 10) - 1
    if ans < 0:
        ans = 0
        now = 0
    i, last = 0, 0
    while True:
        new = now + d[i] * t[i]
        last += 1
        if (now < 0 and new > 0) or (now > 0 and new < 0) or new == 0:
            ans += 1
            last = 0
        now = new
        i = 1 - i
        if last > 2:
            break
    print(ans)
### BUGGY CODE ###

n,x = map(int, input().split())
a = [int(i) for i in input().split()]
b = []
if a[0]>x:
  b.append(x)
else:
  b.append(a[0])
j = 1
while j <= n-1:
  if b[j-1]+a[j]<=x:
    b.append(a[j])
  else:
    b.append(x-b[j-1])
k = 0
ans =0
while k < n:
  ans += a[k]-b[k]
  k += 1
print(ans)

### FIXED CODE ###

n,x = map(int, input().split())
a = [int(i) for i in input().split()]
ans = 0
if a[0]>x:
  ans += a[0]-x
  a[0]=x  
else:
  pass
j = 1
while j <= n-1:
  if a[j-1]+a[j]<=x:
    j += 1
  else:
    ans += a[j]-x+a[j-1]
    a[j]=x-a[j-1]
    j += 1
print(ans)
### BUGGY CODE ###

n = int(input())
s = [str(input()) for _ in range(n)]
abc_str = 'abcdefghijklmnopqrstuvwxyz'
anagram_lst = []
number = 0

def count_lst(x):
    count_lst = [0]*26
    for j in range(10):
        abc = x[j]
        for k in range(26):
            if abc==abc_str[k]:
                count_lst[k] += 1
                break
    return count_lst

def addition(n):
    answer = 0
    for i in range(1,n+1):
        answer += i
    return answer

for i in range(n):
    string = s[i]
    anagram_lst.append(count_lst(string))
anagram_lst.sort()

count = 1
for i in range(n-1):
    anagram1 = anagram_lst[i]
    anagram2 = anagram_lst[i+1]
    if anagram1==anagram2:
        count +=1
        if i==n-2:
            number += addition(count-1)
    else:
        number += addition(count-1)
        count = 1

print(number)

### FIXED CODE ###

n = int(input())
s = [str(input()) for _ in range(n)]
abc_str = 'abcdefghijklmnopqrstuvwxyz'
anagram_lst = []
number = 0

def count_lst(x):
    count_lst = [0]*26
    for j in range(10):
        abc = x[j]
        for k in range(26):
            if abc==abc_str[k]:
                count_lst[k] += 1
                break
    return count_lst

def addition(n):
    answer = 0
    for i in range(1,n+1):
        answer += i
    return answer

for i in range(n):
    string = s[i]
    anagram_lst.append(count_lst(string))

anagram_lst.sort()
count = 1
for i in range(n-1):
    anagram1 = anagram_lst[i]
    anagram2 = anagram_lst[i+1]
    if anagram1==anagram2:
        count +=1
        if i==n-2:
            number += addition(count-1)
    else:
        number += addition(count-1)
        count = 1

print(number)
### BUGGY CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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


def dfs(l, le):
    ret = 0
    if le == 1:
        return l[0]
    elif le == 0:
        return 0
    else:
        mi = min(l)
        min_ind = l.index(mi)
        ret += mi*(min_ind+1)*(le-min_ind)
        return ret + dfs(l[:min_ind], min_ind)+dfs(l[min_ind+1:], le-min_ind-1)


ans = dfs(A, N)
print(ans)


### FIXED CODE ###

# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


class UnionFind:
    """
    sizeによる実装
    """

    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.size = [1 for _ in range(N)]

    def find(self, x):
        if self.parent[x] == x:
            return x
        else:
            return self.find(self.parent[x])

    def union(self, x, y):
        px = self.find(x)
        py = self.find(y)
        if px == py:
            return
        if self.size[px] < self.size[py]:
            self.parent[px] = py
            self.size[py] += self.size[px]
        else:
            self.parent[py] = px
            self.size[px] += self.size[py]

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


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

Un = UnionFind(N+1)
pos = [-1]*(N+1)
for i, a in enumerate(A):
    pos[a] = i

ans = 0
for i in reversed(range(1, N+1)):
    ind = pos[i]
    left = 0
    right = 0
    if ind > 0 and A[ind] < A[ind-1]:
        left = Un.size[Un.find(ind-1)]
        Un.union(ind, ind-1)
    if ind+1 < N and A[ind+1] > A[ind]:
        right = Un.size[Un.find(ind+1)]
        Un.union(ind, ind+1)
    ans += (left+1)*(right+1)*A[ind]

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

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from collections import defaultdict
import sys
sys.setrecursionlimit(10**6)



## input
N,Q = map(int, sys.stdin.readline().rstrip().split())
cnt = [0 for _ in range(N)]
route = defaultdict(lambda:set([]))
for _ in range(N-1):
  a,b = map(int, sys.stdin.readline().rstrip().split())
  route[a-1].add(b-1)
  route[b-1].add(a-1)
for _ in range(Q):
  p,x = map(int, sys.stdin.readline().rstrip().split())
  cnt[p-1] += x

## solve
def dfs(p,q):
  if p in route[q]:
    route[q].remove(p)
  for r in route[q]:
    cnt[r] += cnt[q]
    dfs(q,r)

dfs(-1,0)
for c in cnt[:-1]:
  print(c,end=" ")
print(cnt[-1])

### FIXED CODE ###

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from collections import defaultdict,deque


## input
N,Q = map(int, input().split())
cnt = [0 for _ in range(N)]
route = defaultdict(lambda:set([]))
for _ in range(N-1):
  a,b = map(int, input().split())
  route[a-1].add(b-1)
  route[b-1].add(a-1)
for _ in range(Q):
  p,x = map(int, input().split())
  cnt[p-1] += x

## solve
stk = deque([0])
cost = [-1 for _ in range(N)]
cost[0] = cnt[0]
while len(stk) > 0:
  p = stk.pop()
  for q in route[p]:
    if cost[q] >= 0:
      continue
    cost[q] = cost[p] + cnt[q]
    stk.append(q)

print(*cost)
### BUGGY CODE ###

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

cnt = 0

for i in range(n):
    i_ = (n+i)%n
    s_ = s[i_:] + s[:i_]
    for k in range(n):
        for l in range(n):
            if s_[k][l] != s_[l][k]:
                break
        else:
            continue
        break
    else:
        cnt += 1

print(cnt*n)

### FIXED CODE ###

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

cnt = 0

def is_symmetry(s_):
    for k in range(n):
        for l in range(k+1, n):
            if s_[k][l] != s_[l][k]:
                return False
    return True

for i in range(n):
    i_ = (n+i)%n
    s_ = s[i_:] + s[:i_]
    if is_symmetry(s_):
        cnt += 1

print(cnt*n)
### BUGGY CODE ###

import numpy as np
from scipy.sparse.csgraph import dijkstra
def get_path(start, goal, pred):
    return get_path_row(start, goal, pred[start])

def get_path_row(start, goal, pred_row):
    path = []
    i = goal
    while i != start and i >= 0:
        path.append(i)
        i = pred_row[i]
    if i < 0:
        return []
    path.append(i)
    return path[::-1]
N, M = map(int,input().split())
g = [[np.inf]*(2*N) for _ in range(2*N)]
for i in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    g[a][b] = 1
    g[a][b+N] = 1
    g[a+N][b] = 1

ans = -1
d = dijkstra(g,return_predecessors=True)

for i in range(N):
    if d[0][i][i+N] != np.inf:
        path = get_path(i,i+N,d[1])[::-1][:-1]
        path = [node%N for node in path]
        if len(path)==len(set(path)):
            if ans==-1 or len(ans) > len(path):
                ans = path

if ans != -1:
    print(len(ans))
    for i in range(len(ans)):
        print(ans[i]+1)
else:
    print(ans)

### FIXED CODE ###

import numpy as np
from scipy.sparse.csgraph import dijkstra

def get_path(start, goal, pred):
    return get_path_row(start, goal, pred[start])

def get_path_row(start, goal, pred_row):
    path = []
    i = goal
    while i != start and i >= 0:
        path.append(i)
        i = pred_row[i]
    if i < 0:
        return []
    path.append(i)
    return path[::-1]
N, M = map(int,input().split())
g = [[np.inf]*(2*N) for _ in range(2*N)]
for i in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    g[a][b] = 1
    g[a][b+N] = 1
    g[a+N][b] = 1

ans = np.inf
j = -1
d = dijkstra(g,return_predecessors=True)

for i in range(N):
    if d[0][i][i+N] < ans:
        ans = int(d[0][i][i+N])
        j = i

if ans != np.inf:
    path = get_path(j,j+N,d[1])[::-1][:-1]
    path = [node%N for node in path]
    print(ans)
    for node in path:
        print(node+1)
else:
    print(-1)
### BUGGY CODE ###

n=int(input())
ans=0
for i in range(1,n):
    ans+=i
print(ans)

### FIXED CODE ###

n=int(input())
print(n*(n-1)//2)
### BUGGY CODE ###

a,b,c=map(int,input().split())
for i in range(a,b+1):
  if i<a+c or i>b-c:
    print(i)

### FIXED CODE ###

a,b,c=map(int,input().split())
if c>(b-a)//2:
  for i in range(a,b+1):
    print(i)
else:
  for i in range(a,a+c):
    print(i)
  for i in range(b-c+1,b+1):
    print(i)
### BUGGY CODE ###

n = int(input())
a = [0]*n
a = input().split()
sum = int(a[0])
for k in range(len(a)-1):
  sum =sum*int(a[k+1])
if sum >1000000000000000000:
  print(-1)
else:
  print(sum)


### FIXED CODE ###

n = int(input())
a = [0]*n
a = input().split()
n0 = a.count('0')
sum = int(a[0])
if n0 == 0:
  for k in range(len(a)-1):
    sum =sum*int(a[k+1])
    if sum >1000000000000000000:
      print(-1)
      break
  if sum <=1000000000000000000:
    print(sum)
else:
  print(0)
### BUGGY CODE ###

n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
total = r * g * b
subs = 0
for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i
        if k <= n - 1:
            if len(set([s[i], s[j], s[k]])) == 3:
                subs += 1
        else:
            break
ans = total - subs
print(ans)

### FIXED CODE ###

n = int(input())
s = input()
r = 0
g = 0
b = 0
for letter in s:
    if letter == "R":
        r +=1
    elif letter == "G":
        g +=1
    elif letter == "B":
        b +=1
total = r * g * b
subs = 0
for i in range(n):
    for j in range(i + 1, n):
        k = 2 * j - i
        if k <= n - 1:
            if s[i] == s[j]:
                continue
            elif s[j] == s[k]:
                continue
            elif s[k] == s[i]:
                continue
            else:
                subs += 1
        else:
            break
ans = total - subs
print(ans)
### BUGGY CODE ###

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

if n%2==0:
    b=list(range(1,n,2))
    for i in range(n//2):
        if a.count(b[i])!=2:
            print("0")
            flag+=1
            break
if n%2==1:
    c=list(range(0,n,2))
    for i in range(n//2):
        if i==0:
            if a.count(c[i])!=1:
                print("0")
                flag+=1
                break

        else:
            if a.count(c[i])!=2:
                print("0")
                flag+=1
                break
        
if flag==0:
    print(2**(n//2)%(10**9+7))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
flag=0
A=a.sort()
num=[]

if n%2==0:
    for i in range(1,n,2):
        num.append(i)
        num.append(i)

if n%2==1:
    num=[0]
    for i in range(2,n,2):
        num.append(i)
        num.append(i)

if num==a:
    print(2**(n//2)%(10**9+7))

else:
    print("0")
### BUGGY CODE ###

N = int(input())
s = [input().split() for i in range(N)]

count = 0
s = [''.join(sorted(str(i))) for i in s]
s_set = list(set([x for x in s if s.count(x) > 1]))
for i in range(len(s_set)):
    s_count = s.count(s_set[i])
    count += (s_count * (s_count - 1)) // 2
print(count)


### FIXED CODE ###

N = int(input())
s = [''.join(sorted(input())) for i in range(N)]
s.sort()
count = 0
num = 1
for i in range(N-1):
    if s[i] == s[i+1]:
        num += 1
    else:
        count += num * (num - 1) // 2
        num = 1
print(count + num * (num - 1) // 2)
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, D, A = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]

S.sort()
cnt = 0

for i, item in enumerate(S):
    if item[1] <= 0:
        continue
    if item[1] % A == 0:
        dmg = item[1]
        cnt += item[1] // A
    else:
        dmg = A * (item[1]//A + 1)
        cnt += item[1]//A + 1
    max_X = item[0] + D*2
    for j in range(i+1, N):
        if S[j][0] > max_X:
            break
        S[j][1] -= dmg

print(cnt)


### FIXED CODE ###

from collections import deque
import math

import sys
input = sys.stdin.readline

N, D, A = map(int, input().split())
S = [0]*N
atack = deque()
for i in range(N):
    x, h = map(int, input().split())
    S[i] = [x, h]

S.sort()
cnt = 0
dmg = 0
for i in range(N):
    while atack:
        if atack[0][0] < S[i][0]:
            x, d = atack.popleft()
            dmg -= d
        else:
            break

    if S[i][1] <= dmg:
        continue
    bomb = math.ceil((S[i][1]-dmg)/A)
    atack.append([S[i][0]+2*D, A*bomb])
    cnt += bomb
    dmg += A*bomb

print(cnt)
### BUGGY CODE ###

import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
		s = s[::-1]
        if( str[0] == '2'):
          if( str[2] == '1'):
	    s = str[4] + s
          if( str[2] == '2'):
	    s = s + str[4]

print s
sys.stdout.flush()


### FIXED CODE ###

import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

flag = 0
prev=""
end=""
for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
          flag += 1
        if( str[0] == '2'):
          if( str[2] == '1'):
	    if( flag % 2 == 0):
	      prev = str[4] + prev
	    else:
	      end = end + str[4]
          if( str[2] == '2'):
	    if( flag % 2 == 0):
	      end = end + str[4]
	    else:
	      prev = str[4] + prev

ss = prev + s + end
if( flag % 2 == 1):
  ss = ss[::-1]

print ss
sys.stdout.flush()
### BUGGY CODE ###

k, s = list(map(int, input().split()))
ans = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z == s:
                ans += 1
print(ans)

### FIXED CODE ###

k, s = list(map(int, input().split()))
ans = 0
for x in range(k+1):
    for y in range(k+1):
            if 0 <= s-x-y <= k: 
                ans += 1
print(ans)
### BUGGY CODE ###

a,b=map(int,input().split())
lista=[]
import fractions
gcd=fractions.gcd(a,b)

for i in range(2,gcd+1): 
    if a% i == 0 and b % i == 0: 
        lista.append(i)

#print(lista)
listb=[]
for i in range(len(lista)):
    flag = True
    for j in range(len(listb)):
        if lista[i]%listb[j]==0:
            flag = False    
    if flag==True:
        listb.append(lista[i])

print(len(listb)+1)



### FIXED CODE ###

a,b=map(int,input().split())
lista=[]
import fractions
import math
gcd=fractions.gcd(a,b)

for i in range(1,int(gcd**0.5)+1): 
    if gcd% i == 0: 
        lista.append(i)
        if i!=int(gcd/i):
            lista.append(int(gcd/i))

#print(lista)
lista=lista[1:]
lista.sort()
listb=[]
for i in range(len(lista)):
    flag = True
    for j in range(len(listb)):
        if lista[i]%listb[j]==0:
            flag = False    
    if flag==True:
        listb.append(lista[i])

print(len(listb)+1)
### BUGGY CODE ###

N = int(input())
count = 0

if N % 2 != 0:
    print(0)
    exit()

for i in range(0, int(N//2)):
    if (N - 2*i) % 5 == 0:
        count += 1
    
print(count)

### FIXED CODE ###

N = int(input())
count = 0

if N % 2 != 0:
    print(0)
    exit()
P = 1
k = 2 * 5

while k <= N:  
    count += N//k
    k *= 5
    
print(count)
### BUGGY CODE ###

hoge = input().split()
n = int(hoge[0])
m = int(hoge[1])

l = []
r = []

for i in range(m):
  hoge = input().split()
  l.append(hoge[0])
  r.append(hoge[1])

ok_card = []
for i in range(m):
  for j in range(int(r[i]) - int(l[i])+1):
    ok_card.append(int(l[i])+j)

big_a = list(set(ok_card))
super_card = []
for i in range(len(big_a)):
  if ok_card.count(big_a[i]) >= m:
    super_card.append(big_a[i])

print(len(super_card))

### FIXED CODE ###

hoge = input().split()
N = int(hoge[0])
M = int(hoge[1])

mi = 0
ma = N

for j in range(M):
    i = input().split(" ")
    l = int(i[0])
    r = int(i[1])
    if l >= mi:
        mi = l
    if r <= ma:
        ma = r
r = ma - mi + 1
if r > 0:
    print(r)
else:
    print(0)
### BUGGY CODE ###

s=input()
ans=[0]*len(s)
rl_list=[]
rl=s[0]
c=0
for ts in s[1:]:
  c+=1
  if rl!=ts:
    rl_list.append(c)
    rl=ts
    c=0
rl_list.append(c+1)
for i in range(0,len(rl_list),2):
  index=sum(rl_list[:i+1])
  num=rl_list[i]//2
  if rl_list[i]%2==0:
    ans[index]+=num
    ans[index-1]+=num
  else:
    ans[index-1]+=num+1
    ans[index]+=num
for i in range(1,len(rl_list),2):
  index=sum(rl_list[:i])
  num=rl_list[i]//2
  if rl_list[i]%2==0:
    ans[index-1]+=num
    ans[index]+=num
  else:
    ans[index]+=num+1
    ans[index-1]+=num
print(*ans)
    

### FIXED CODE ###

s=input()
ans=[0]*len(s)
rl_list=[]
ind=[]
rl=s[0]
c=0
for i,ts in enumerate(s[1:]):
  c+=1
  if rl!=ts:
    rl_list.append(c)
    if ts=='L':
      ind.append(i+1)
    rl=ts
    c=0
rl_list.append(c+1)
for i in range(0,len(rl_list),2):
  index=ind[i//2]
  num=rl_list[i]//2
  if rl_list[i]%2==0:
    ans[index]+=num
    ans[index-1]+=num
  else:
    ans[index-1]+=num+1
    ans[index]+=num
  num=rl_list[i+1]//2
  if rl_list[i+1]%2==0:
    ans[index-1]+=num
    ans[index]+=num
  else:
    ans[index]+=num+1
    ans[index-1]+=num
print(*ans)
### BUGGY CODE ###

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

c=[[0]*w for i in range(h)]
for i in range(h):
  for j in range(w):
    c[i][j]=abs(a[i][j]-b[i][j])

dp=[[[] for i in range(w)] for j in range(h)]
dp[0][0].append(c[0][0])
for i in range(h):
  for j in range(w):
    for k in range(len(dp[i-1][j])):
      dp[i][j].append(abs(dp[i-1][j][k]-c[i][j]))
      dp[i][j].append(dp[i-1][j][k]+c[i][j])
    for k in range(len(dp[i][j-1])):
      dp[i][j].append(abs(dp[i][j-1][k]-c[i][j]))
      dp[i][j].append(dp[i][j-1][k]+c[i][j])
    dp[i][j]=list(set(dp[i][j]))
print(min(dp[h-1][w-1]))

### FIXED CODE ###

import sys
input=sys.stdin.readline

def main():
  h,w=map(int,input().split())
  a=[list(map(int,input().split())) for i in range(h)]
  b=[list(map(int,input().split())) for i in range(h)]
  dp=[[[0]*(80*(h+w+1)+1) for i in range(w)] for j in range(h)]
  dp[0][0][abs(a[0][0]-b[0][0])]=1
  for i in range(h):
    for j in range(w):
      c=abs(a[i][j]-b[i][j])
      if i!=0 or j!=0:
        for k in range(80*(i+j+1)+1):
          dp[i][j][k]=dp[i-1][j][abs(k-c)]|dp[i-1][j][k+c]|dp[i][j-1][abs(k-c)]|dp[i][j-1][k+c]
  for i in range(80*(h+w+1)+1):
    if dp[h-1][w-1][i]==1:
      print(i)
      break

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

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

MOD = 10**9 + 7

from functools import reduce
from fractions import gcd
def lcm(x,y):return x*y//gcd(x,y)
def lcmm(l):return reduce(lcm,l)

x = lcmm(A)

B = []
for a in A:
    B.append(x//a)

print(sum(B) % MOD)

### FIXED CODE ###

from functools import reduce
from fractions import gcd

N = int(input())
A = list(map(int, input().split()))
 
MOD = 10 ** 9 + 7
 
lcm = reduce(lambda x,y: x*(y//gcd(x,y)), A)
lcm %= MOD

coef = sum(pow(a, MOD-2, MOD) for a in A)
ans = lcm * coef % MOD

print(ans)