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

n, m = map(int, input().split())
h_list = list(map(int, input().split()))
loads = []
count = 0
for k in range(m):
    load = list(map(int, input().split()))
    loads.append(load)

for h in range(n):
    for load in loads:
        if h+1 in load:
            op = sum(load)-(h+1)-1
            if h_list[h] <= h_list[op]:
                break
    else:
        count += 1

print(count)

### FIXED CODE ###

n, m = map(int, input().split())
h_list = list(map(int, input().split()))
loads = [[0] for i in range(n)]
count = 0
for k in range(m):
    start, end = map(int, input().split())
    loads[start-1].append(h_list[end-1])
    loads[end-1].append(h_list[start-1])

for k in range(n):
    if h_list[k] > max(loads[k]):
        count += 1

print(count)
### BUGGY CODE ###

[N,K]=list(map(int, input().split()))
p=list(map(int, input().split()))

def ex(p,n):
    return (p[n]+1)/2

def  sum(p,n):
    s=0
    for i in range (0,n+1):
        s=s+ex(p,i)
    return s

list=[]
for i in range (0,N):
    list.append(sum(p,i))

max=list[K-1]
for i in range (0,N-K):
   if list[i+K]-list[i] >= max:
        max=list[i+K]-list[i]
        
print(max)

### FIXED CODE ###

[N,K]=list(map(int, input().split()))
p=list(map(int, input().split()))

def ex(p,n):
    return (p[n]+1)/2


list=[]
s=0
for i in range (0,N):
    s=s+ex(p,i)
    list.append(s)

max=list[K-1]
for i in range (0,N-K):
   if list[i+K]-list[i] >= max:
        max=list[i+K]-list[i]
        
print(max)
### BUGGY CODE ###

N, K, Q = [int(value) for value in input().split(' ')]
A = [int(input()) for _ in range(Q)]

points = [K] * N

for value in A:
    for i in range(len(points)):
        if i != value - 1:
            points[i] = points[i] - 1

for point in points:
    if point > 0:
        print('Yes')
    else:
        print('No')


### FIXED CODE ###

import sys
input = sys.stdin.readline
N, K, Q = [int(value) for value in input().split(' ')]
A = [int(input()) for _ in range(Q)]

points = [K - Q] * N

for value in A:
    points[value - 1] += 1

for point in points:
    if point <= 0:
        print('No')
    else:
        print('Yes')
### BUGGY CODE ###

N = int(input())
S = list(input())
ans = 0

for i in range(N-3):
  for j in range(i+1, N-1):
    if S[i] != S[j]:
      for k in range(j+1, N):
       if S[j] != S[k] and S[k] != S[i] and j-i != k-j:
        ans += 1
        
      

print(ans)


    




### FIXED CODE ###

N = int(input())
S = input()
A = S.count("R") * S.count("G") * S.count("B")

for i in range(N):
  for j in range(i+1, N):
    k = j-i+j
    if k<N and S[k] != S[j] and S[k] != S[i] and S[i] !=S[j]:
      A -= 1    

print(A)
### BUGGY CODE ###

N=int(input())
A=[sorted(input()) for i in range(N)]

#Nのみを見ればよい
ans=0
for i in range(1,N):
  for j in range(i):
    if A[i]==A[j]:
      ans+=1
print(ans)

### FIXED CODE ###

N=int(input())
m=dict()
ans=0
for	i in range(N):
  s=input()
  s=''.join(sorted(s))
  if s in m:
    ans += m[s]
    m[s] += 1
  else:
    m[s] = 1
print(ans)
### BUGGY CODE ###

N, K = map(int, input().split())
P = [int(p) for p in input().split()]

me = 0
for i in range(N - K + 1):
    e = sum((1 + p) / 2 for p in P[i: i + K])
    me = max(e, me)

print(me)

### FIXED CODE ###

N, K = map(int, input().split())
P = [int(p) for p in input().split()]
P_cum = [0] * N
P_cum[0] = P[0]
for i in range(1, len(P)):
    P_cum[i] = P_cum[i - 1] + P[i]

me = 0
for i in range(N - K + 1):
    if i >= 1:
        e = (P_cum[i + K - 1] - P_cum[i - 1] + K) / 2
    else:
        e = (P_cum[i + K - 1] + K) / 2
    me = max(e, me)

print(me)
### BUGGY CODE ###

import heapq
def Dijkstra(edge,start):
    d = [float('inf')]*n
    d[start] = 0
    pq = [(0,start)]
    heapq.heapify(pq)
    while pq:
        dist,p = heapq.heappop(pq)
        for to,cost in edge[p].items():
            if d[to] <= dist + cost:continue
            d[to] = dist + cost
            heapq.heappush(pq, (d[to], to))
    return d

def Dijkstra(start):
    inf = float('inf')
    d = [[inf]*(A+1) for _ in range(n)]
    d[start][min(s,A)] = 0
    pq = [(0,start,min(s,A))]
    heapq.heapify(pq)
    while pq:
        dist,p,money = heapq.heappop(pq)
        while True:
            if money >= A:
                money = A
            for to,(cost,time) in path[p].items():
                if money < cost or d[to][money - cost] <= dist + time:continue
                d[to][money - cost] = dist + time
                heapq.heappush(pq, (d[to][money - cost],to,money - cost))
            if money == A:break
            money += C[p]
            dist += D[p]
        for to in path[p].keys():
            m = inf
            for i in range(A+1)[::-1]:
                m = min(m,d[to][i])
                d[to][i] = m
    return d

n,m,s = map(int,input().split())
path = [{} for _ in range(n)]
A = 0
for i in range(m):
    u,v,a,b = map(int,input().split())
    A += a
    u -= 1
    v -= 1
    path[u][v] = (a,b)
    path[v][u] = (a,b)
A *= 2
C = [0]*n
D = [0]*n
for i in range(n):
    C[i],D[i] = map(int,input().split())
ans = Dijkstra(0)
for a in ans[1:]:
    print(min(a))


### FIXED CODE ###

import heapq
def Dijkstra(edge,start):
    d = [float('inf')]*(n*(A+1))
    d[start] = 0
    pq = [(0,start)]
    heapq.heapify(pq)
    while pq:
        dist,p = heapq.heappop(pq)
        for to,cost in edge[p].items():
            if d[to] <= dist + cost:continue
            d[to] = dist + cost
            heapq.heappush(pq, (d[to], to))
    return d

n,m,s = map(int,input().split())
edge = [{} for _ in range(n)]
A = 2500
for i in range(m):
    u,v,a,b = map(int,input().split())
    # A += a
    u -= 1
    v -= 1
    edge[u][v] = (a,b)
    edge[v][u] = (a,b)


A *= 2
C = [0]*n
D = [0]*n
for i in range(n):
    C[i],D[i] = map(int,input().split())

path = [{} for _ in range(n*(A+1))]
for i in range(n):
    for j in range(A+1):
        for to,(a,b) in edge[i].items():
            if j - a >= 0:
                path[i*(A+1)+j][to*(A+1)+j-a] = b
        path[i*(A+1)+j][i*(A+1)+min(j+C[i],A)] = D[i]

ans = Dijkstra(path,min(s,A))
for i in range(1,n):
    print(min(ans[i*(A+1):i*(A+1)+A+1]))
### BUGGY CODE ###

from collections import deque
import sys
input = sys.stdin.readline

# スタック最大数をセット
sys.setrecursionlimit(10**6)

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

queue = deque([(i, j, 0) for i in range(h)
               for j in range(w) if a[i][j]])

ans = 0

d = ((1, 0), (0, 1), (0, -1), (-1, 0))


# def bfs(y, x, cnt):

# if (y < 0 or h <= y or x < 0 or w <= x or not a[y][x]):
#    return
#print(y, x, cnt)


while (queue):
    y, x, cnt = queue.popleft()
    # print(l)
    ans = max(ans, cnt)
    for ddx, ddy in d:
        #print(ddx, ddy)
        if (0 <= y+ddy < h and 0 <= x+ddx < w and not a[y+ddy][x+ddx]):
            a[y+ddy][x+ddx] = True
            queue.append((y + ddy, x+ddx, cnt+1))
    # print(queue)
print(ans)


### 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 ###

K = int(input())

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a % b)

s = 0
for i in range(1, K + 1):
  for j in range(1, K + 1):
    for k in range(1, K + 1):
      s += gcd(i, gcd(j, k))

print(s)


### FIXED CODE ###

K = int(input())

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a % b)


gcds = [[0 for _ in range(K + 1)] for _ in range(K + 1)]

for i in range(1, K + 1):
  for j in range(1, K + 1):
    gcds[i][j] = gcd(i, j)

s = 0
for i in range(1, K + 1):
  for j in range(1, K + 1):
    for k in range(1, K + 1):
      s += gcds[gcds[i][j]][k]

print(s)
### BUGGY CODE ###

x=input()
x0=x.split()
n=int(x0[0])
k=int(x0[1])
if k>100:
    k=100
a0=input()
a0=a0.split()
a=[int(s) for s in a0]
a1=list(range(n+1))
for f in range(k):
    a1=[0 for s in a1]
    for x in range(n):
        y=max(0,x-a[x])
        a1[y]=a1[y]+1    
        z=min(n-1,x+a[x])
        a1[z+1]=a1[z+1]-1
    a[0]=a1[0]
    for x in range(1,n):    
        a[x]=a[x-1]+a1[x]
a=[str(s) for s in a]
a=" ".join(a)
print(a)

### FIXED CODE ###

from numba import njit

@njit(cache=True)
def aaa(n,k,a):
    for f in range(k):
        a1=[0]*(n+1)
        for x in range(n):
            y=max(0,x-a[x])
            a1[y]=a1[y]+1    
            z=min(n-1,x+a[x])
            a1[z+1]=a1[z+1]-1
        a[0]=a1[0]
        for x in range(1,n):    
            a[x]=a[x-1]+a1[x]
        if a==[n]*n:
            break
    return a

x=input()
x0=x.split()
n=int(x0[0])
k=int(x0[1])
a0=input()
a0=a0.split()
a=[int(s) for s in a0]

b=aaa(n,k,a)
for i in range(n):
    print(b[i])
### BUGGY CODE ###

import copy

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

ls = []

for i in range(M):
    L, R = map(int,input().split())
    l = [k+L for k in range(R-L+1)]
    ls.append(l)

for i in range(M-1):
    l_set = set(ls[i]) & set(ls[i+1])
    ls[i+1] = copy.deepcopy(l_set)

print(len(ls[-1]))

### FIXED CODE ###

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

Ls, Rs = [0 for _ in range(M)],  [0 for _ in range(M)]

for i in range(M):
    L, R = map(int,input().split())
    Ls[i] = L
    Rs[i] = R
    
L_prime = max(Ls)
R_peime = min(Rs)

if L_prime > R_peime:
    print(0)
else:
    print(R_peime - L_prime + 1)
### BUGGY CODE ###

N = int(input())
A = list(map(int,input().split()))
over_value = 10 ** 18 + 1
total = 1
if A.count(0):
    print(0)
else:
    for i in A:
        total *= i
    if total >= over_value:
        total = -1
    print(total)

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
over_value = 10 ** 18
total = 1
cnt = 0
while cnt < N:
    total *= A[cnt]
    if total > over_value:
        total = -1
        break
    cnt += 1
    
for i in range(N):
    if A[i] == 0:
        total = 0
print(total)
### BUGGY CODE ###

import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
K = int(input())
a = 0
for i in range(K):
    for j in range(K):
        for k in range(K):
            a += gcd(i+1,j+1,k+1)
print(a)

### FIXED CODE ###

K = int(input())
A = [1, 9, 30, 76, 141, 267, 400, 624, 885, 1249, 1590, 2208, 2689, 3411, 4248, 5248, 6081, 7485, 8530, 10248, 11889, 13687, 15228, 17988, 20053, 22569, 25242, 28588, 31053, 35463, 38284, 42540, 46581, 50893, 55362, 61824, 65857, 71247, 76884, 84388, 89349, 97881, 103342, 111528, 120141, 128047, 134580, 146316, 154177, 164817, 174438, 185836, 194157, 207927, 218812, 233268, 245277, 257857, 268182, 288216, 299257, 313635, 330204, 347836, 362973, 383709, 397042, 416448, 434025, 456967, 471948, 499740, 515581, 536073, 559758, 583960, 604833, 633651, 652216, 683712, 709065, 734233, 754734, 793188, 818917, 846603, 874512, 909496, 933081, 977145, 1006126, 1041504, 1073385, 1106467, 1138536, 1187112, 1215145, 1255101, 1295142, 1342852, 1373253, 1422195, 1453816, 1502376, 1553361, 1595437, 1629570, 1691292, 1726717, 1782111, 1827492, 1887772, 1925853, 1986837, 2033674, 2089776, 2145333, 2197483, 2246640, 2332104, 2379085, 2434833, 2490534, 2554600, 2609625, 2693919, 2742052, 2813988, 2875245, 2952085, 3003306, 3096024, 3157249, 3224511, 3306240, 3388576, 3444609, 3533637, 3591322, 3693924, 3767085, 3842623, 3912324, 4027884, 4102093, 4181949, 4270422, 4361548, 4427853, 4548003, 4616104, 4718640, 4812789, 4918561, 5003286, 5131848, 5205481, 5299011, 5392008, 5521384, 5610705, 5739009, 5818390, 5930196, 6052893, 6156139, 6239472, 6402720, 6493681, 6623853, 6741078, 6864016, 6953457, 7094451, 7215016, 7359936, 7475145, 7593865, 7689630, 7886244, 7984165, 8130747, 8253888, 8403448, 8523897, 8684853, 8802826, 8949612, 9105537, 9267595, 9376656, 9574704, 9686065, 9827097, 9997134, 10174780, 10290813, 10493367, 10611772, 10813692]
print(A[K-1])
### BUGGY CODE ###

from collections import deque
N,M=map(int, input().split())
alist = []
blist = []
for _ in range(M):
    a,b=map(int, input().split())
    alist.append(a)
    blist.append(b)
rdic = {}
d = deque()
def find_index(n):
    returnlist = []
    for indexa,i in enumerate(alist):
        if i == n:
            returnlist.append(blist[indexa])
    for indexb,i in enumerate(blist):
        if i == n:
            returnlist.append(alist[indexb])
    return returnlist
d.append(1)
rdic[1] = 0
while len(rdic)!=N:
    getlist = find_index(d[0])
    for i in getlist:
        if i not in rdic:
            rdic[i] = d[0]
            d.append(i)
    d.popleft()
print('Yes')
for n in range(2,N+1):
    print(rdic[n])

### FIXED CODE ###

from collections import deque
N,M=map(int, input().split())
alist = []
blist = []
T = [ [] for _ in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    T[a-1].append(b)
    T[b-1].append(a)
# T[i]にはi+1が接続してる数のリスト
rdic = [0]*(N)
d = deque()
d.append(1)
c = 0
ans = [0]*N
while len(d)>0:
    getlist = T[d[0]-1]
    for i in getlist:
        if rdic[i-1]==0:
            rdic[i-1] = d[0]
            d.append(i)
    d.popleft()
print('Yes')
for n in range(2,N+1):
    print(rdic[n-1])
### BUGGY CODE ###

import itertools,sys
for a in sys.stdin:
  c=0
  n,s=map(int,a.split())
  for e1 in itertools.combinations(range(10),n):
    for e2 in itertools.permutations(e1,n):
      i=n
      x=0
      for e3 in e2:
        x+=i*e3
        i-=1
        if x>s:break
      else:
        if x==s:c+=1
  print c

### FIXED CODE ###

import sys
K=1024
N=331
R=range(K)
B=[1,2,4,8,16,32,64,128,256,512]
C=[0]*K
D=[[0 for i in range(N)]for j in R]

for i in R:
  s=format(i,'b')
  n=s.count('1')
  C[i]=n
  if n==1:D[i][B.index(i)]=1
  else:
    for j in range(len(s)):
      if s[-j-1]=='1':
        dp=n*j
        i2=i-B[j]
        for k in range(N-dp):
          D[i][k+dp]+=D[i2][k]
   
for a in sys.stdin:
  n,s=map(int,a.split())
  x=0
  if s<N:x=sum([D[i][s] for i in R if C[i]==n])
  print x
### BUGGY CODE ###

N,C=map(int, raw_input().split())
X=[ tuple( map(int, raw_input().split()) ) for i in range(N)]
T=[]
R=[]

a=[]
for i in range(N):
	temp=[]
	for j in range(i+1):
		temp.append(X[j])

	back=X[i][0]

	for j in range(N-1,i,-1):
		x=C-X[j][0]
		v=X[j][1]
		temp.append( (x+back*2,v) )
	val=0
	for x,y in temp:
		val+=y
		a.append(val-x)


for i in range(N):
	
	temp=[]
	for j in range(N-1,N-i-2,-1):
		x=C-X[j][0]
		v=X[j][1]
		#print j
		temp.append( (x,v) )
	back=C-X[N-1-i][0]

	for j in range(N-i-1):
		x=X[j][0]
		v=X[j][1]
		temp.append( (x+back*2,v) )
	val=0
	for x,y in temp:
		val+=y
		a.append(val-x)


print max(0,max(a))
		


### FIXED CODE ###

N,C=map(int, raw_input().split())
X=[ tuple( map(int, raw_input().split()) ) for i in range(N)]
T=[]
R=[]

a=[]

v_sum=0
for x,v in X:
	v_sum+=v
	T.append(v_sum-x)

a+=T

v_sum=0
for x,v in X[::-1]:
	v_sum+=v
	R.append(v_sum-(C-x))

a+=R



T_MAX=[]
val=float("-inf")
for i in T:
	val=max(val,i)
	T_MAX.append(val)


R_MAX=[]
val=float("-inf")
for i in R:
	val=max(val,i)
	R_MAX.append(val)


for i in range(N):
	extra_x=X[i][0]
	if N-i-2>=0:
		val=T[i]+R_MAX[N-i-2]-extra_x
		a.append(val)


for i in range(N):
	extra_x=C-X[N-i-1][0]
	if N-i-2>=0:
		val=R[i]+T_MAX[N-i-2]-extra_x
		a.append(val)


print max(0,max(a))
### BUGGY CODE ###

import collections


def solve(N, Q, ABs, PXs):
    # print(N, ",", Q, ",", ABs, ",", PXs)
    vertexes = {}
    values = {i: 0 for i in range(N + 1)}
    for a, b in ABs:
        vertexes.setdefault(a, []).append(b)
        vertexes.setdefault(b, []).append(a)
    for p, x in PXs:
        values[p] += x

    ans = [-1 for i in range(N + 1)]

    queue = collections.deque()
    queue.append((1, 0))
    while queue:
        index, parent_value = queue.popleft()
        value = parent_value + values[index]
        ans[index] = value
        for child in vertexes[index]:
            if ans[child] == -1:
                queue.append((child, value))
    return " ".join([str(a) for a in ans[1:]])


# assert (solve(4, 3, [(1, 2), (2, 3), (2, 4)], [(2, 10), (1, 100), (3, 1)]) == "100 110 111 110")
# assert (solve(6 , 2 , [(1, 2), (1, 3), (2, 4), (3, 6), (2, 5)] , [(1, 10), (1, 10)]) == "20 20 20 20 20 20")

if __name__ == "__main__":
    N, Q = tuple(map(int, input().split(" ")))
    ABs = [tuple(map(int, input().split(" "))) for _ in range(N - 1)]
    PXs = [tuple(map(int, input().split(" "))) for _ in range(Q)]
    print(solve(N, Q, ABs, PXs))


### FIXED CODE ###


def solve(N, Q, ABs, PXs):
    values = {i: 0 for i in range(N + 1)}
    ans = [-1 for i in range(N + 1)]
    vertexes = {}
    for a, b in ABs:
        vertexes.setdefault(a, []).append(b)
        vertexes.setdefault(b, []).append(a)

    for p, x in PXs:
        values[p] += x

    queue = []
    queue.append((1, 0))
    while queue:
        index, parent_value = queue.pop()
        value = parent_value + values[index]
        ans[index] = value
        for child in vertexes[index]:
            if ans[child] == -1:
                queue.append((child, value))
    return " ".join([str(a) for a in ans[1:]])


if __name__ == "__main__":
    N, Q = tuple(map(int, input().split(" ")))
    ABs = [tuple(map(int, input().split(" "))) for _ in range(N - 1)]
    PXs = [tuple(map(int, input().split(" "))) for _ in range(Q)]
    print(solve(N, Q, ABs, PXs))
### BUGGY CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
s = input()
ct = 0
for p in range(1000):
    step = 0
    p = str(p).zfill(3)
    for i in range(n):
        if s[i] == p[0]:
            step += 1
            idx = i
            break
    if step == 1:
        for i in range(idx+1, n):
            if s[i] == p[1]:
                step += 1
                idx = i
                break
    if step == 2:
        for i in range(idx+1, n):
            if s[i] == p[2]:
                #print(p)
                ct += 1
                break
print(ct)

### FIXED CODE ###

import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
s = input()
ct = 0
for p in range(1000):
    step = 0
    p = str(p).zfill(3)
    for i in range(n):
        if s[i] == p[0]:
            step += 1
            idx = i
            break
    if step == 1:
        for i in range(idx+1, n):
            if s[i] == p[1]:
                step += 1
                idx = i
                break
    if step == 2:
        for i in range(idx+1, n):
            if s[i] == p[2]:
                #print(p)
                ct += 1
                break
print(ct)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
A = [0] + LI()

from functools import lru_cache

@lru_cache(maxsize=None)
def dfs(n,money):
    if n == N+1:
        return money
    else:
        res = money
        for i in range(n,N):  # 購入
            for j in range(i+1,N+1):  # 売却
                if A[i] == min(A[i:j+1]) and A[j] == max(A[i:j+1]) and A[i] < A[j]:
                    res = max(res,dfs(j+1,money+(A[j]-A[i])*(money//A[i])))
        return res

print(dfs(1,1000))


### FIXED CODE ###

import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N = I()
B = [0] + LI()

A = [0,B[1]]
for i in range(1,N):
    if B[i] != B[i+1]:
        A.append(B[i+1])

N = len(A)-1

MAX = [0,1000] + [0]*N

from functools import lru_cache

@lru_cache(maxsize=None)
def dfs(n,money):
    if n == N+1:
        return money
    else:
        res = money
        for i in range(n,N):  # 購入
            for j in range(i+1,N+1):  # 売却
                if A[i] == min(A[i:j+1]) and A[j] == max(A[i:j+1]) and A[i] < A[j]:
                    if money+(A[j]-A[i])*(money//A[i]) > MAX[j+1]:
                        res = max(res,dfs(j+1,money+(A[j]-A[i])*(money//A[i])))
                        MAX[j+1] = money+(A[j]-A[i])*(money//A[i])
        return res

print(dfs(1,1000))
### BUGGY CODE ###

import copy

n = int(input())
s = str(input())
r_list = []
g_list = []
b_list = []
count = 0
for i in range(len(s)):
    if s[i] == "R":
        r_list.append(i)
    elif s[i] == "G":
        g_list.append(i)
    else:
        b_list.append(i)

for r in r_list:
    for g in g_list:
        x = abs(r-g)
        b_list_copy = copy.copy(b_list)
        try:
            b_list_copy.remove(max(r,g)+x)
        except ValueError:
            pass
        try:
            b_list_copy.remove(min(r,g)-x)
        except ValueError:
            pass
        try:
            b_list_copy.remove((r+g)/2)
        except ValueError:
            pass
        count += len(b_list_copy)
        
print(count)

### FIXED CODE ###

n = int(input())
s = list(input())
ans = (s.count("R")*s.count("G")*s.count("B"))

for i in range(n):
    for j in range(n-2*i):
        if {s[j], s[j+i], s[j+2*i]} == {"R", "G", "B"}:
            ans -= 1
print(ans)
### BUGGY CODE ###


#かけて最小公倍数になる　そのために必要な数がB
from fractions import gcd
N=int(input())
if N==1:
  print(1)
  exit()

mod=10**9+7
A=list(map(int, input().split()))
def lcm(a,b):
  return (a*b)/gcd(a,b)

if N==2:
  LCM=lcm(A[0],A[1])
  ans=((LCM//A[0])+(LCM//A[1]))%mod
  print(ans)
  exit()

LCM=lcm(A[0],A[1])
#LCM%=mod
for i in range(2,N):
  LCM=lcm(LCM, A[i])
  #LCM%=mod
  
#print(LCM)
ans=0
for a in A:
  ans+=LCM//a
  ans%=mod

print(int(ans%mod))



### FIXED CODE ###


#かけて最小公倍数になる　そのために必要な数がB
from fractions import gcd
N=int(input())
if N==1:
  print(1)
  exit()

mod=10**9+7
A=list(map(int, input().split()))
def lcm(a,b):
  return a//gcd(a,b)*b

if N==2:
  LCM=lcm(A[0],A[1])
  ans=((LCM//A[0])+(LCM//A[1]))%mod
  print(ans)
  exit()

LCM=1
#LCM%=mod
for a in A:
  LCM=lcm(LCM, a)
  #LCM%=mod
  
#print(LCM)
ans=0
for a in A:
  ans+=LCM//a
  #ans%=mod

print(int(ans%mod))