Harryxun/stf_run huggingface dataset:
from collections import Counter

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

s = int(input())

a = 0
t = []

while s > 0:
    d = s // 10
    r = s % 10
    t.append(r)
    s = d

if p == 2:
    for i in range(len(t)):
        if t[i] % 2 == 0:
            a += len(t) - i 
elif p == 5:
        if t[i] % 5 == 0:
            a += len(t) - i 

else:
    u = []
    k = 1
    for i in range(len(t)):
        if i == 0:
            u.append(t[i]*k % p)
        else:
            u.append((u[i-1] + t[i]*k) % p)
        k *= 10
    c = Counter(u)

    a += c[0]
    for i in c.values():
        if i > 1:
            a += i * (i-1) // 2


print(a)




### FIXED CODE ###

from collections import Counter

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

s = input()


a = 0
t = list(map(int, list(s)))
t.reverse()


if p == 2:
    for i in range(n):
        if t[i] % 2 == 0:
            a += len(t) - i 
elif p == 5:
    for i in range(n):
        if t[i] % 5 == 0:
            a += len(t) - i 

else:
    u = []
    k = 1
    l = 0
    for i in t:
        l = (l + i*k) % p
        u.append(l)
        k = k * 10 % p

    c = Counter(u)
    a += c[0]
    for i in c.values():
        if i > 1:
            a += i * (i-1) // 2


print(a)
import math
import fractions

# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X > B :
        return 0
    minX = max(math.ceil(A / X),0)
    maxX = max(math.floor(B / X),0)
    return maxX - minX + 1
  
if D == 1 :
  print(z)

A , B , C , D = map(int,input().split())

ans = B - A + 1

# 最小公倍数
Z = int(C * D / fractions.gcd(C,D))

ans -= countX(C)
ans -= countX(D)
ans += countX(Z)

print(int(ans))



### FIXED CODE ###

import math
import fractions

# A以上B以下の数でXの倍数の個数
def countX(X) :
    if X > B :
        return 0

    minX = (A - 1) // X
    maxX = B // X

    return maxX - minX

A , B , C , D = map(int,input().split())

ans = B - A + 1

# 最小公倍数
Z = int(C * D / fractions.gcd(C,D))

ans -= countX(C)
ans -= countX(D)
ans += countX(Z)

print(int(ans))
import sys
import math

x_list = []

for line in sys.stdin.readlines()
  x_list.append(int(line.strip()))

count = 0

num_list.remove(x_list[0])

for i in x_list:
  flag = 0
  for j in range(2, math.sqrt(i)+1):
    if i % j == 0:
      flag = 1
      break
    if flag == 0:
      count ++

print count
    

### FIXED CODE ###

import sys
import math

x_list = []

for line in sys.stdin.readlines():
  x_list.append(int(line.strip()))

count = 0

x_list.remove(x_list[0])

for i in x_list:
  flag = 0
  for j in range(2, int(math.sqrt(i))+1):
    if i % j == 0:
      flag = 1
      break
  if flag == 0:
    count += 1

print count
import <math.h>
r = float(input())
a = math.pi * r * r
l = 2 * math.pi * r
print(f'{a} {l}')



### FIXED CODE ###

import math
r = float(input())
a = math.pi * r * r
l = 2 * math.pi * r
print(f'{a} {l}')
b = input()
if b=='A';
    print('T')
elif b=='C';
    print('G')
elif b=='G';
    print('C')
elif b=='T';
    print('A')

### FIXED CODE ###

b = input()
A='A'
T='T'
C='C'
G='G'
if b==A:
    print(T)
elif b==C:
    print(G)
elif b==G:
    print(C)
elif b==T:
    print(A)
import numpy as np
N = int(input())
a = list(map(int, input().split()))
V = np.zeros((max(a)+3, N))

for i, v in enumerate(a):
    V[v:v+3, i] = 1
print(np.max(np.sum(V, axis=1, dtype=np.int)))

### FIXED CODE ###

import numpy as np
N = int(input())
a = list(map(int, input().split()))
V = np.zeros((max(a)+4))

for v in a:
    V[v:v+3] += 1 
print(int(np.max(V)))
n = input()
print(' 'end='')
print(*[i for in range(1,1+n) if i%3==0 or'3' in str(i)])


### FIXED CODE ###

n = int(input())
print(" ",end="")
print(*[i for i in range(1,1+n) if i%3==0 or'3' in str(i)])
n = input()
l = list(map(int, input().split()))

lm = 0
ls = 0
for i in range(0, n):
  if lm < l[i]:
    lm = l[i]
  ls = ls + l[i]
ls = ls - lm

if lm < ls:
  print("Yes")
else:
  print("No")


### FIXED CODE ###

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

n = len(l)

lm = 0
ls = 0
for i in range(0, n):
  if lm < l[i]:
    lm = l[i]
  ls = ls + l[i]
ls = ls - lm

if lm < ls:
  print("Yes")
else:
  print("No")
n, m = [int(i) for i in input().split()]

matrix = []
for ni in range(n):
    matrix.append([int(a) for a in input().split()])

vector = []
for ni in range(n):
    vector.append(int(input()))

for ni in range(n):
    sum = 0
    for mi in range(m):
        sum += matrix[ni][mi] * vector[mi]

    print(sum)

### FIXED CODE ###

n, m = [int(i) for i in input().split()]

matrix = []
for ni in range(n):
    matrix.append([int(a) for a in input().split()])

vector = []
for mi in range(m):
    vector.append(int(input()))

for ni in range(n):
    sum = 0
    for mi in range(m):
        sum += matrix[ni][mi] * vector[mi]

    print(sum)
import itertools
import numpy as np
N = input(N)
digit = len(N)
ans = 0
if int(N) < 357:
    print(ans)
else:
    for i in range(3, len(N)):
        ans += 3**i - 3 * 2**i + 3
    print(ans)
    for v in itertools.product('753', repeat=digit):
        if (len(set(list(v)))==3) & (int(''.join(list(v))) <= int(N)):
            ans +=1
    print(ans)

### FIXED CODE ###

import itertools
import numpy as np
N = input()
digit = len(N)
ans = 0
if int(N) < 357:
    print(ans)
else:
    for i in range(3, len(N)):
        ans += 3**i - 3 * 2**i + 3
    for v in itertools.product('753', repeat=digit):
        if (len(set(list(v)))==3) & (int(''.join(list(v))) <= int(N)):
            ans +=1
    print(ans)
# -*- coding: utf-8 -*-
import sys
import math
from numpy import arange

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	if x==0 and y==0: continue
	si=float(y)/(x**2+y**2)**0.5
	L.append( (math.degrees(math.asin(si)),(x**2+y**2)**0.5) )


ans=0
for d_kouho in arange(0.0,360.1,0.01):
	ans_kouho=0
	for d,l in L:
		#print d,d-d_kouho,math.cos(math.radians(d-d_kouho)),l*math.cos(math.radians(d-d_kouho))
		ans_kouho+=l*math.cos(math.radians(d-d_kouho))
	ans=max(ans,ans_kouho)

print ans


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
import math

N=input()
A=[ map(int, sys.stdin.readline().split()) for _ in range(N) ]
L=[]

for x,y in A:
	L.append( (math.atan2(y,x),x,y) )

L.sort()
L=L+L

ans=0
for start in range(N):
	for end in range(start,start+N):
		kyori=0
		X=0
		Y=0
		for i in range(start,end+1):
			x=L[i][1]
			y=L[i][2]
			X+=x
			Y+=y
		kyori=(X**2+Y**2)**0.5
		ans=max(ans,kyori)

print ans
import math
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
gcd = reduce(math.gcd, A)
print(gcd)

### FIXED CODE ###

import fractions
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
gcd = reduce(fractions.gcd, A)
print(gcd)
a,b,c=map(int,intput().split())
print(a," ",b," ",c)

### FIXED CODE ###

a,b,c=map(int,input().split())
print(c,a,b)
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

score = {
  'r': r,
  's': s,
  'p': p
}

win_map = {
  'r': 'p',
  's': 'r',
  'p': 's'
}

lose_map = {
  'r': 's',
  's': 'p',
  'p': 'r'
}

result = [''] * n
result_num = 0
for j in range(n):
  if j >= k and result[j - k] == win_map[t[j]]:
    if j < k + 2 and t[j] == win_map[t[j + k]]:
      result[j] = lose_map[t[j]]
    else:
      result[j] = t[j]
  else:
    result[j] = win_map[t[j]]
    result_num += score[win_map[t[j]]]


print(result_num)

### FIXED CODE ###

n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())

score = {
  'r': r,
  's': s,
  'p': p
}

win_map = {
  'r': 'p',
  's': 'r',
  'p': 's'
}

lose_map = {
  'r': 's',
  's': 'p',
  'p': 'r'
}

result = [''] * n
result_num = 0
for j in range(n):
  if j >= k and result[j - k] == win_map[t[j]]:
    if j + k < n and t[j] == win_map[t[j + k]]:
      result[j] = lose_map[t[j]]
    else:
      result[j] = t[j]
  else:
    result[j] = win_map[t[j]]
    result_num += score[win_map[t[j]]]


print(result_num)
n = int(input())
print("Yes" if n[0] == n[2] else "No")

### FIXED CODE ###

n = input()
print("Yes" if n[0] == n[2] else "No")
import sys
sys.setrecursionlimit(1000000000000)

def process():
    data = []
    for line in get_data():
        line = line.split()
        if len(line) == 2:
            if line[0] == line[1] == '0':
                data = []
                continue
            H = int(line[0])
            W = int(line[1])
        elif len(line) == 0:
            pass
        else:
            data.append(line[0])
            if len(data) == H:
                field = create_field(H, W)
                print search(H, W, data, field)


def search(H, W, data, field):
    count = 0
    for i in xrange(H):
        for j in xrange(W):
            if field[i][j] == 0:
                continue
            _search(i, j, H, W, data[i][j], data, field)
            count += 1
    return count


def _search(i, j, H, W, cell, data, field):
    field[i][j] = 0
    for a in xrange(i-1, i+2):
        if -1 < a < H:
            pass
        else:
            continue
        for b in xrange(j-1, j+2):
            if -1 < b < W:
                pass
            else:
                continue

            if a != i and b != j:
                continue

            if field[a][b] == 0:
                continue
            if cell == data[a][b]:
                _search(a, b, H, W, cell, data, field)
    return


def create_field(H, W):
    field = []
    for i in xrange(H):
        raw = []
        for j in xrange(W):
            raw.append(1)
        field.append(raw)
    return field


print 0

### FIXED CODE ###

import sys
sys.setrecursionlimit(100000000)


def main():
    solve()


def solve():
    for data in get_dataset():
        print search(data)


def search(data):
    count = 0
    H = len(data)
    W = len(data[0])
    for i in xrange(H):
        for j in xrange(W):
            if data[i][j] == '.':
                continue
            _search(i, j, H, W, data[i][j], data)
            count += 1
    return count


def _search(i, j, H, W, cell, data):
    data[i][j] = '.'
    for a in xrange(i-1, i+2):
        if not -1 < a < H:
            continue
        for b in xrange(j-1, j+2):
            if not -1 < b < W:
                continue

            if a != i and b != j:
                continue

            if data[a][b] == '.':
                continue

            if cell == data[a][b]:
                _search(a, b, H, W, cell, data)
    return


def get_dataset():
    dataset = []
    while True:
        line = raw_input().rstrip().split()
        H = int(line[0])
        if H == 0:
            break

        data = []
        for i in xrange(H):
            data.append(list(raw_input().rstrip()))
        dataset.append(data)
    return dataset


if __name__ == '__main__':
    main()
import math

A,B,C,D = (int(i) for i in input().split())

E =int(C*D/math.gcd(C,D))

if A%C == 0:
    C_div = B//C - A//C + 1
else:
    C_div = B//C - A//C

if A%D == 0:
    D_div = B//D - A//D + 1
else:
    D_div = B//D- A//D


if A%E == 0:
    CandD_div  = B//E - A//E + 1
else:
    CandD_div  = B//E- A//E


ans = B - A + 1 - (C_div + D_div - CandD_div)
print(ans)


### FIXED CODE ###

import fractions

A,B,C,D = map(int,input().split())

E =C*D//fractions.gcd(C,D)

if A%C == 0:
    C_div = B//C - A//C + 1
else:
    C_div = B//C - A//C

if A%D == 0:
    D_div = B//D - A//D + 1
else:
    D_div = B//D- A//D


if A%E == 0:
    CandD_div  = B//E - A//E + 1
else:
    CandD_div  = B//E- A//E


ans = B - A + 1 - (C_div + D_div - CandD_div)
print(ans)
# -*- coding:utf-8 -*-
def get_data():
    array = []
    for i in range(8):
        array.append(input())
    return array

def judge():
    array = get_data()
    count = [[0 for i in range(8)] for i in range(8)]
    for i in range(8):
        x = 0
        for j in array[i]:
            if int(j) == 1:
                count[i][x] += 1
            x += 1

    a = 0
    p = []
    for i in range(8):
        for j in range(8):
            if count[i][j] != 0:
                p.append(a)
            a += 1

    if p[0]+1 != p[1]:
        if p[0] + 8*3 == p[3]:
            print('B')
        else:
            if p[0] + 8*2 + 1 == p[3]:
                print('F')
            else:
                print('D')
    else:
        if p[0]+1 == p[1] and p[1]+1 == p[2]:
            print('C')
        else:
            if p[0] + 8 == p[2] and p[1] + 8 == p[3]:
                print('A')
            else:
                if p[0]+8*2 == p[2]:
                    print('G')
                else:
                    print('E')
                    
while True:
    try:
        judge()
    except EOFError:
        break

### FIXED CODE ###

def judge(array):
    count = [[0 for i in range(8)] for i in range(8)]
    for i in range(8):
        x = 0
        for j in array[i]:
            if int(j) == 1:
                count[i][x] += 1
            x += 1

    a = 0
    p = []
    for i in range(8):
        for j in range(8):
            if count[i][j] != 0:
                p.append(a)
            a += 1

    if p[0]+1 != p[1]:
        if p[0] + 8*3 == p[3]:
            print('B')
        else:
            if p[0] + 8*2 + 1 == p[3]:
                print('F')
            else:
                print('D')
    else:
        if p[0]+1 == p[1] and p[1]+1 == p[2]:
            print('C')
        else:
            if p[0] + 8 == p[2] and p[1] + 8 == p[3]:
                print('A')
            else:
                if p[0]+8 == p[3]:
                    print('G')
                else:
                    print('E')
                    
while True:
    try:
        array = []
        for i in range(8):
            array.append(input())
        judge(array)
        input()
    except:
        break
n = int(input())
g = [[-1 for j in range(n)] for i in range(n)]

for i in range(n):
    for _ in range(int(input())):
        x,y = map(int,input().split())
        g[i][x-1] = y

ans = 0
for s in range(2**n):#bit全探索
    ok = True
    for i in range(n):#行ごとのfor
        if (s>>i&1) == 1:#iが正直者であったら
            for j in range(n):#列の要素のfor,iの言っていることが矛盾がないか確かめる
                if g[i][j] == -1:continue
                if (s>>j&1) != g[i][j]:ok = False#breakにしないのは、breakでは抜けきれないから
    if ok:
        t = str(bin(x)).count("1")
        ans = max(ans,t)
print(ans)

### FIXED CODE ###

n = int(input())
 
g = [[-1 for j in range(n)] for i in range(n)]
 
for i in range(n):
	a = int(input())
	for _ in range(a):
		x, y = map(int, input().split())
		g[i][x-1] = y
 
ans = 0
for s in range(2**n):
    ok = True
    for i in range(n):
        if (s>>i&1) == 1:
            for j in range(n):
                if g[i][j] == -1: continue
                if (s>>j&1) != g[i][j]: ok = False
    if ok:#あっているなら、ビット内に何個1があるかを数える
        #print("s = ", s)
        t = 0
        x = s#xを変えてもsは変化しない
        t = str(bin(x)).count("1")
        ans = max(ans, t)
print(ans)
s=input()
print(2*min(s.count(0),s.count(1)))

### FIXED CODE ###

s=input()
print(2*min(s.count('0'),s.count('1')))
num_room, num_path = map(int, input().split())

room_paths_dict = {}

start_room_to_paths = set()
result = {}

for i in range(num_path):
    a_room_num, b_room_num = map(int, input().split())
    if a_room_num == 1:
        start_room_to_paths.add(b_room_num)
        continue
    elif b_room_num == 1:
        start_room_to_paths.add(a_room_num)
        continue

    result[a_room_num] = 0
    result[b_room_num] = 0

    if not room_paths_dict.get(a_room_num):
        room_paths_dict[a_room_num] = set()
    if not room_paths_dict.get(b_room_num):
        room_paths_dict[b_room_num] = set()

    room_paths_dict[a_room_num].add(b_room_num)
    room_paths_dict[b_room_num].add(a_room_num)

def search(room_num):
    targets = []
    for next_room in room_paths_dict[room_num]:
        if result[next_room] == 0:
            result[next_room] = room_num
            targets.append(room_num)

    for t in targets:
        search(t)

for start_room_to_path in start_room_to_paths:
    result[start_room_to_path] = 1
    search(start_room_to_path)

if 0 in result.values():
    print('No')
else:
    print('Yes')
    for key in sorted(result.keys()):
        print(result[key])


### FIXED CODE ###


from collections import deque

N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]

links = [[] for _ in range(N + 1)]
for a, b in AB:
    links[a].append(b)
    links[b].append(a)

result = [-1] * (N + 1)
q = deque([1])
while q:
    i = q.popleft()
    for j in links[i]:
        if result[j] == -1:
            result[j] = i
            q.append(j)
print('Yes')
print('\n'.join(str(i) for i in result[2:]))
a = input()
print(a * (a + 1)/2)

### FIXED CODE ###

a = input()
print(a * (a + 1)/2)
n=int(input())
s=[]
for i in range(n):
    s.append(input())

#n=7
#s.append("beat")
#s.append("vet")
#s.append("beet")
#s.append("bed")
#s.append("vet")
#s.append("bet")
#s.append("beet")

s.sort()

t=[]
icnt=0
t.append([1,s[0]])
for i in range(1,len(s)):
    if s[i-1]==s[i]:
        t[icnt][0]=t[icnt][0]+1
    else:
        icnt=icnt+1
        t.append([1,s[i]])
        
#print(t)
t.sort(reverse=True)
#print(t)

u=[]
u.append(t[0][1])
for i in range(len(t)):
    if t[i][0]==t[i+1][0]:
        u.append(t[i+1][1])
    else:
        break
    
u.sort()

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

### FIXED CODE ###

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

s.sort()

t=[]
icnt=0
t.append([1,s[0]])
for i in range(1,len(s)):
    if s[i-1]==s[i]:
        t[icnt][0]=t[icnt][0]+1
    else:
        icnt=icnt+1
        t.append([1,s[i]])
        
#print(t)
t.sort(reverse=True)
#print(t)

u=[]
u.append(t[0][1])
for i in range(len(t)-1):
    if t[i][0]==t[i+1][0]:
        u.append(t[i+1][1])
    else:
        break

if len(u)==0:
    print(u[0])    
else:
    u.sort()
    for i in range(len(u)):
        print(u[i])
import numpy as np
import scipy.sparse
N,X,Y = (int(x) for x in input().split())
lil = scipy.sparse.lil_matrix((N, N), dtype=int)
for i in range(N-1):
    lil[i, i+1] = 1
    lil[i+1, i] = 1
lil[X, Y] = 1
lil[Y, X] = 1
shortest = scipy.sparse.csgraph.floyd_warshall(lil)
for i in range(N-1):
    print(np.count_nonzero(shortest == i))

### FIXED CODE ###

import numpy as np
import scipy.sparse
N,X,Y = (int(x) for x in input().split())
lil = scipy.sparse.lil_matrix((N, N), dtype = int)
for i in range(N-1):
    lil[i, i+1] = 1
    lil[i+1, i] = 1
lil[X-1, Y-1] = 1
lil[Y-1, X-1] = 1
lil2 = scipy.sparse.csgraph.dijkstra(lil, directed = False).astype(int)
ans = np.bincount(lil2.ravel(), minlength = N) // 2
for i in range(1,N):
    print(ans[i])
li = list(map(int,input().split()))

def count(s):
    a = int(s[0])
    b = int(s[1])
    t = int(s[2])
    a_now = a
    sum_ = 0
    while a_now< t+0.5:
        sum_ += b
        a_now += a
    
    return t
  
 print(count(li))

### FIXED CODE ###

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

def count(s):
    a = int(s[0])
    b = int(s[1])
    t = int(s[2])
    a_now = a
    sum_ = 0
    while a_now< t+0.5:
        sum_ += b
        a_now += a
    
    return sum_

print(count(li))
print(max(int(input())-int(input())*2,0))

### FIXED CODE ###

x,y=map(int,input().split())
print(max(x-2*y,0))
H, W = map(int, input().split())

# コーナーケースに注意！1行 or 1列の時は動けないよ！
if H == 1 or W == 1:
    print(1)
    return

if H % 2 == 0:
    ans = (H / 2) * W
else:
    ans = (H // 2) * W + W // 2
    if W % 2 != 0:
        ans += 1

print(int(ans))

### FIXED CODE ###

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

# コーナーケースに注意！1行 or 1列の時は動けないよ！
if H == 1 or W == 1:
    print(1)
    exit()

if H % 2 == 0:
    ans = (H / 2) * W
else:
    ans = (H // 2) * W + W // 2
    if W % 2 != 0:
        ans += 1

print(int(ans))
import sys

for line in sys.stdin:
    l = line.rstrip('\n').split('')
    l.reverse()
    print ''.join(l)

### FIXED CODE ###

import sys

for line in sys.stdin:
    l = [ c for c in line.rstrip('\n') ]
    l.reverse()
    print ''.join(l)
N = int(input())
T = [int(input()) for _ in range(5)]
print(5 + ceil(N // min(T)))

### FIXED CODE ###

from math import ceil
N = int(input())
T = [int(input()) for _ in range(5)]
print(4 + ceil(N / min(T)))
import math
N=int(input())
nmax = math.floor(math.sqrt(N))
Bdigimax = 1
for i in range(1,nmax):
	if N % i == 0:
		Bdigi = math.floor(math.log10(N/i))
		if Bdigimax < Bdigi:
			Bdigimax = Bdigi
print(int(Bdigimax))
		

### FIXED CODE ###

num = list(map(int, input().split()))
a = num[0] + num[1]
print(int(a%24))
n = int(input())
h = list(map(int, input().split()))

minimum = 1000000000
for i in range(n-1, -1, -1):
  minimum = min(s[i], minimum)
  if s[i] > minimum + 1:
    print("No")
print("Yes")

### FIXED CODE ###

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

minimum = 1000000000
for i in range(n-1, -1, -1):
  minimum = min(h[i], minimum)
  if h[i] > minimum + 1:
    print("No")
    exit()
print("Yes")
a, b, c = map(input().split(), int)
print(c-a+b)

### FIXED CODE ###

a, b, c = map(int, input().split())
print(max(c-a+b,0))
a = int(input())
b = int(input())
c = int(input())

if c>a and c<b:
    print("Yes")
else:
    print("No")

### FIXED CODE ###

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



if a[2]>a[0] and a[2]<a[1]:
    print("Yes")
elif a[1]<a[2] and a[2]<a[0]:
    print("Yes")
else:
    print("No")
N, M = map(int, input().split())
A, B = [], []
for _ in range(N):
    a, b = list(map(int, input().split()))
    A.append(a)
    B.append(b)
    
import numpy as np
dp = np.zeros([N+1, max(max(A), M)+1])
    
for i in range(1, N+1):
    for j in range(A[i-1], M+1):
        dp[i][j] = B[i-1]

ans = 0
for j in range(1, M+1):
    i = np.argmax(dp[:, j])
    ans += dp[i, j]
    dp[i, :] = 0
print(int(ans))

### FIXED CODE ###

N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB = sorted(AB, key=lambda x: x[0])  # sort by days

import heapq
que = []
heapq.heapify(que)

ans = 0
i = 0
for day in range(1, M+1):
    while i < len(AB) and AB[i][0] <= day:
        heapq.heappush(que, (-1)*AB[i][1])
        i += 1
    if que:
        ans += (-1)*heapq.heappop(que)
print(ans)
n=int(input())
s=0
for i in range(1,n):
    for j in range(1,i):
        a=0
        if i%j==0:
            a+=1
    if a==8:
        s+=1
print(s)

### FIXED CODE ###

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

n=int(input())
#print(make_divisors(n))
s=0
for i in range(1,n+1,2):
    if len(make_divisors(i))==8:
        s+=1
print(s)
while True:
	H,W = list(map(int, input().split()))
	if (H == 0 and W == 0):
		break
	else:
		for n in range(0, H):
			s = ""
			for m in range(0, W):
				s += "#"
			print(s)
		print(""

### FIXED CODE ###

while True:
    a,b = map(int, input().split())
    if (a == 0) and (b == 0):
        break
    else:
        for i in range(a):
            for j in range(b):
                print('#', end='')
            print()
        print()
import sys
N = 8
ptn = [18,48,6,30,20,34,16]
def f(D):
    i = 0
    s = 0
    D = D[D.index("1"):]
    for c in D:
        if c=="1": s += i
        i += 1
    p = "ABCDEF"[ptn.index(s)]
    return p
 
i=0
D=""
for s in sys.stdin:
    if i<8:
        D+=s[:-1]
        i+=1
    else:
        print f(D)
        i=0
        D=""
if D!="": print f(D)

### FIXED CODE ###

import sys
ptn = [18,48,6,30,20,34,16]

def f(D):
    i = 0
    s = 0
    D = D[D.index("1"):]
    for c in D:
        if c=="1": s += i
        i += 1
    p = "ABCDEFG"[ptn.index(s)]
    return p

i=0
D=""
for s in sys.stdin:
    if i<8:
        i+=1
        D+=s[:-1]
    else:
        print f(D)
        i=0
        D=""
print f(D)
def main():
	import sys
	input = sys.stdin.readline
	import fractions
	from functools import reduce
	n = int(input())
	A = []
	A = list(map(int, input().split()))
	mod = 10**9 + 7
	def lcm_base(x, y):
    	return (x * y) // fractions.gcd(x, y)

	def lcm(*numbers):
    	return reduce(lcm_base, numbers, 1)
	Z = lcm(*A)
	ans = sum(Z//a%mod for a in A)%mod
	print(ans)

if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
input = sys.stdin.readline
import fractions
N=int(input())
A=list(map(int,input().split()))
c=1
a=0
w=10**9+7
for A_ in A:
    c=c*A_//fractions.gcd(c,A_)
for A_ in A:
    a+=c//A_
print(int(a%w))