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


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

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

N = int(input())
A = list(map(int, input().split()))
l = A[0]
for a in A:
    l = lcm(l, a)
ans = 0
mod = 10**9+7
for a in A:
    ans += (l * pow(a, mod-2, mod))%mod
    ans %= mod
print(ans)


### FIXED CODE ###


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

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

if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    l = A[0]
    for a in A:
        l = lcm(l, a)
    ans = 0
    mod = int(1e9+7)
    for a in A:
        ans += (l * pow(a, mod-2, mod))%mod
        ans %= mod
    print(ans)
### BUGGY CODE ###

import sys

sys.setrecursionlimit(10000)
INF = float('inf')

H, W = list(map(int, input().split()))
A = [list(input()) for _ in range(H)]

counts = [[INF for _ in range(W)] for _ in range(H)]


def ok_range(h, w):
    return 0 <= h < H and 0 <= w < W


# 左上から右下へ DP してく
for i in range(H + W):
    for j in range(i + 1):
        h = j
        w = i - j
        if not ok_range(h, w):
            continue
        if A[h][w] == '#':
            counts[h][w] = 0
        else:
            counts[h][w] = min(
                counts[h][w],
                counts[h - 1][w] + 1 if ok_range(h - 1, w) else INF,
                counts[h][w - 1] + 1 if ok_range(h, w - 1) else INF,
            )

# 左下から右上へ
for i in range(H + W):
    for j in range(i + 1):
        h = H - j - 1
        w = i - j
        if not ok_range(h, w):
            continue
        if A[h][w] == '#':
            counts[h][w] = 0
        else:
            counts[h][w] = min(
                counts[h][w],
                counts[h + 1][w] + 1 if ok_range(h + 1, w) else INF,
                counts[h][w - 1] + 1 if ok_range(h, w - 1) else INF,
            )

# 右上から左下
for i in range(H + W):
    for j in range(i + 1):
        h = j
        w = W - (i - j) - 1
        if not ok_range(h, w):
            continue
        if A[h][w] == '#':
            counts[h][w] = 0
        else:
            counts[h][w] = min(
                counts[h][w],
                counts[h - 1][w] + 1 if ok_range(h - 1, w) else INF,
                counts[h][w + 1] + 1 if ok_range(h, w + 1) else INF,
            )

# 右下から左上
for i in range(H + W):
    for j in range(i + 1):
        h = H - j - 1
        w = W - (i - j) - 1
        if not ok_range(h, w):
            continue
        if A[h][w] == '#':
            counts[h][w] = 0
        else:
            counts[h][w] = min(
                counts[h][w],
                counts[h + 1][w] + 1 if ok_range(h + 1, w) else INF,
                counts[h][w + 1] + 1 if ok_range(h, w + 1) else INF,
            )

ans = 0
for c in counts:
    ans = max(ans, *c)
print(ans)


### FIXED CODE ###

import sys
import numpy as np

sys.setrecursionlimit(10000)
INF = float('inf')

H, W = list(map(int, input().split()))
A = np.array([list(input()) for _ in range(H)])

counts = np.zeros((H, W))
counts[A == '.'] = np.inf

for h in range(1, H):
    counts[h, :] = np.minimum(counts[h, :], counts[h - 1, :] + 1)
    counts[-1 - h, :] = np.minimum(counts[-1 - h, :], counts[-h, :] + 1)
for w in range(1, W):
    counts[:, w] = np.minimum(counts[:, w], counts[:, w - 1] + 1)
    counts[:, -1 - w] = np.minimum(counts[:, -1 - w], counts[:, -w] + 1)

print(int(np.max(counts)))
### BUGGY CODE ###

H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]

dp = [0] * (H + 1)

for i in range(1, H + 1):
    min_cost = 10 ** 8
    for j in range(N):
        damage, cost = magic[j]
        min_cost = min(dp[max(i - damage, 0)] + cost, min_cost)
    dp[i] = min_cost

ans = dp[H]

print(ans)


### FIXED CODE ###

import sys

input = sys.stdin.readline
H, N = map(int, input().split())
magic = [list(map(int, input().split())) for _ in range(N)]

max_damage = max(damage for damage, cost in magic)
dp = [0] * (H + max_damage)

for i in range(1, H + max_damage):
    dp[i] = min(dp[i - damage] + cost for damage, cost in magic)

ans = min(dp[H:])

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

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

memo = [10**9] * n
memo[0] = 0

for i in range(1, n):
  for j in range(1, k+1):
    if i - j < 0:
      break
    else:
      memo[i] = min(memo[i], memo[i-j] + abs(h[i] - h[i-j]))

print(memo[-1])

### FIXED CODE ###

n, k = map(int, input().split())
H = list(map(int, input().split()))

DP = [10 ** 9] * n
DP[0] = 0

for i in range(1, n):
    j = 1
    while i - j >= 0 and j <= k:
        DP[i] = min(DP[i], DP[i-j] + abs(H[i] - H[i-j]))
        j += 1
print(DP[-1])
### BUGGY CODE ###

n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

loop=set()
d=[-10**15 for _ in [0]*n]
d[0]=0
q=[[0,1]]
s=set()
l=[]
while q:
    item,depth=q.pop()
    if depth<=len(s):
        for _ in range(len(s)-depth+1):
            rmv=l.pop()
            s.remove(rmv)
    l.append(item)
    s.add(item)
    for i,dist in g[item]:
        if d[i]<d[item]+dist:
            if i in s:
                loop.add(i)
                continue
            d[i]=d[item]+dist
            q.append([i,depth+1])
    
def check(x):
    q=[x]
    c=[False for _ in [0]*n]
    c[x]=True
    while q:
        item=q.pop()
        for i,j in g[item]:
            if c[i]==False:
                c[i]=True
                q.append(i)
        if c[n-1]==True:
            return True
    else:
        return False
    
for x in loop:
    q=[x]
    c=[False for _ in [0]*n]
    c[x]=True
    while q:
        item=q.pop()
        for i,j in g[item]:
            if c[i]==False:
                c[i]=True
                q.append(i)
    if c[n-1]==True:
        print("inf")
        break
else:
    print(d[n-1])

### FIXED CODE ###

n,m=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
g=[[] for _ in [0]*n]
[g[a-1].append([b-1,c]) for a,b,c in abc]

dist=[-10**15 for _ in [0]*n]
dist[0]=0
a,b=-10**15,-10**15

for _ in range(n):
    for p in range(n):
        for i,j in g[p]:
            dist[i]=max(dist[i],dist[p]+j)
    a,b=b,dist[n-1]

if a==b:
    print(a)
else:
    print("inf")
### BUGGY CODE ###

# Typical Stairs

n, m = map(int, input().split())
a = []
for i in range(m):
    a.append(int(input()))
    
if n ==1:
    print(1)
    exit()

dp = [0] * (n + 1)
dp[0] = 1
if 1 in a:
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2, n+1):
    if i in a:
        dp[i] = 0
    else:
        dp[i] = dp[i-1] + dp[i-2]
        dp[i] = dp[i] % 1000000007

print(dp[-1])


### FIXED CODE ###

# Typical Stairs
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    n, m, *a = map(int, read().split())
    MOD = 10**9 + 7

    if n == 1:
        print(1)
        exit()

    dp = [0 for _ in range(n+1)]
    dp[0] = 1
    is_broken = [False] * (n+1)
    for i in a:
        is_broken[i] = True
    if 1 in a:
        dp[1] = 0
    else:
        dp[1] = 1

    for i in range(2, n + 1):
        if is_broken[i]:
            continue
        else:
            dp[i] = (dp[i - 1] + dp[i - 2]) % MOD

    print(dp[-1])

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

N = int(input())
C, S, F = [], [], []
for _ in range(N-1):
    c, s, f = tuple(map(int, input().split()))
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(N-1):
    total_time = 0
    for j, (c, s, f) in enumerate(zip(C[i:], S[i:], F[i:])):
        if j == 0:
            total_time += (c + s)
        else:
            while total_time < s:
                total_time += 1
            while total_time % f != 0:
                total_time += 1
            total_time += c
    print(total_time)
print(0)


### FIXED CODE ###

N = int(input())
C, S, F = [], [], []
for _ in range(N-1):
    c, s, f = tuple(map(int, input().split()))
    C.append(c)
    S.append(s)
    F.append(f)

for i in range(N-1):
    total_time = 0
    for j, (c, s, f) in enumerate(zip(C[i:], S[i:], F[i:])):
        if j == 0:
            total_time += (c + s)
        else:
            if total_time < s:
                total_time = s
            if total_time % f != 0:
                total_time += f - total_time % f
            total_time += c
    print(total_time)
print(0)
### BUGGY CODE ###

n=int(input())
l=[]
for i in range(300):
  l.append(i**2)
l=set(l)
for i in range(1,n+1):
  ct=0
  for j1 in range(1,int(n**0.5)+2):
    for j2 in range(1,int(n**0.5)+2):
      a=j1+j2
      b=i-j1**2-j2**2-j1*j2
      for k in range(len(l)):
        if a**2+4*b in l:
          k=int((a**2+4*b)**0.5)
          if (a+k)%2==0:
            j3=(-a+k)//2
            if j3>0:
              ct+=1
              break
  print(ct)

### FIXED CODE ###

n=int(input())
l=[]
for i in range(300):
  l.append(i**2)
l=set(l)
for i in range(1,n+1):
  ct=0
  for j1 in range(1,int(n**0.5)+2):
    for j2 in range(1,int(n**0.5)+2):
      a=j1+j2
      b=i-j1**2-j2**2-j1*j2
      if a**2+4*b in l:
        k=int((a**2+4*b)**0.5)
        if (a+k)%2==0:
          j3=(-a+k)//2
          if j3>0:
            ct+=1
  print(ct)
### BUGGY CODE ###

k, s = map(int, input().split())
count = 0
for l in range(k+1):
  for m in range(k+1):
    for n in range(k+1):
      if l+m+n == s:
        count += 1
        
print(count)

### FIXED CODE ###

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

import copy
import statistics
n = int(input())
x = list(map(int,input().split()))
l = len(x)-1
for i in range(n):
	l2 = copy.copy(x)
	l2.pop(i)
	print(statistics.median(l2))


### FIXED CODE ###

import copy
n = int(input())
x = list(map(int,input().split()))
x2 = copy.copy(x)
x2.sort()
num1,num2 = (len(x)//2)-1,(len(x)//2)
med1,med2 = x2[num1],x2[num2]
for i in range(n):
	if x[i] <= med1:
		print(med2)
	else:
		print(med1)
### BUGGY CODE ###

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

l = []
for i in range(n):
    hoge = A.index(min(A))
    print(hoge+1, end=' ')
    A[hoge] = n+1


### FIXED CODE ###

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

l = [0] * n
for i, x in enumerate(A):
    l[x-1] = i+1
for i in l:
    print(i, end=' ')
### BUGGY CODE ###

N = int(input())
S = input()

# 1を満たす数
# 1,~2を満たす数を求める

# def checkone(a,b,c):
# 	if (a!=b and b!=c and c!=a):
# 		return True
# 	else:
# 		return False

def check(i,j,N): # i,j,2j-iは違ったらTrue
	# i < jは保証
				# (0 > (2*i-j) or (2*i-j) >= N or checkone(S[i], S[j], S[2*i-j])) and
              	# (0 > (2*j-i) or (2*j-i) >= N or checkone(S[i], S[j], S[2*j-i])) #and
			  	# ( ((i+j)%2!=0) or checkone(S[i], S[j], S[abs(int((i+j)/2))]))
	if (0 > (2*j-i) or (2*j-i) >= N):
		# print("out of range")
		return False
	else:
		return (S[i] != S[j] and S[j] != S[2*j-i] and S[2*j-i] != S[i])
		# return checkone(S[i], S[j], S[2*j-i])

n_equal = 0
for i in range(N):
	for j in range(i,N):
		if( S[i]==S[j]):
			continue
		else:
			if(check(i,j,N)==True):
				n_equal+=1
				# print(i, j, 2*j-i)
				# print(S[i],S[j],S[2*j-i])
				# print("toukankaku")

# print("n_equal=",n_equal)

n_R = S.count('R')
n_G = S.count('G')
n_B = S.count('B')

n_all = n_R*n_G*n_B
# print("n_all=",n_all)

print(n_all-n_equal)


### FIXED CODE ###

N = int(input())
S = input()

# 1を満たす数
# 1,~2を満たす数を求める

# def checkone(a,b,c):
# 	if (a!=b and b!=c and c!=a):
# 		return True
# 	else:
# 		return False

def check(i,j,N): # i,j,2j-iは違ったらTrue
	# i < jは保証
				# (0 > (2*i-j) or (2*i-j) >= N or checkone(S[i], S[j], S[2*i-j])) and
              	# (0 > (2*j-i) or (2*j-i) >= N or checkone(S[i], S[j], S[2*j-i])) #and
			  	# ( ((i+j)%2!=0) or checkone(S[i], S[j], S[abs(int((i+j)/2))]))
	if (0 > (2*j-i) or (2*j-i) >= N):
		# print("out of range")
		return False
	else:
		return (S[j] != S[2*j-i] and S[2*j-i] != S[i])
		# return checkone(S[i], S[j], S[2*j-i])
# 2j-i <N
# j < (N+i)/2

n_equal = 0
for i in range(N):
	for j in range(i+1, int((N+i)/2)+1):
		if( S[i]==S[j]):
			continue
		else:
			if(check(i,j,N)==True):
				n_equal+=1
				# print(i, j, 2*j-i)
				# print(S[i],S[j],S[2*j-i])
				# print("toukankaku")

# print("n_equal=",n_equal)

n_R = S.count('R')
n_G = S.count('G')
n_B = S.count('B')

n_all = n_R*n_G*n_B
# print("n_all=",n_all)

print(n_all-n_equal)
### BUGGY CODE ###

n = int(input())
L = list(int(input()) for _ in range(n))
count = 0
x = L[0]
A = []
while True:
    if x == 2:
        count += 1
        print(count)
        break
    elif x in A:
        print(-1)
        break
    else:
        A.append(x)
        x = L[x-1]
        count += 1

### FIXED CODE ###

n = int(input())
A = [int(input()) for _ in range(n)]
B = []
cnt = 0
i = 0
while i != 1:
    i = A[i]-1
    B.append(i)
    cnt += 1
    if cnt > 10**5 + 1:
        print(-1)
        exit()
print(cnt)
### BUGGY CODE ###

import heapq
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**16
def dijkstra(s, V):
    color = [WHITE for i in range(N+1)]
    d = [INFTY for i in range(N+1)]
    d[s] = 0
    pq = []
    heapq.heappush(pq, (0, s))

    while len(pq) != 0:
        u = heapq.heappop(pq)[1]
        color[u] = BLACK

        for v in V[u]:
            if color[v] != BLACK:
                if d[u] + 1 < d[v]:
                    d[v] = d[u] + 1
                    color[v] = GRAY
                    heapq.heappush(pq, (d[v], v))

    return d

def rec(s, i, depth):
    if depth == 3:
        kkpgraph[s].append(i)
        return
    if not graph[i]:
        return
    for node in graph[i]:
        rec(s, node, depth+1)
    return

N, M = map(int, input().split())
graph = [[] for i in range(N+1)]
kkpgraph = [[] for i in range(N+1)]
for i in range(M):
    u, v = map(int, input().split())
    graph[u].append(v)
S, T = map(int, input().split())
for i in range(1, N+1):
    rec(i, i, 0)
d = dijkstra(S, kkpgraph)
if d[T] == INFTY:
    print(-1)
else:
    print(d[T])


### FIXED CODE ###

import queue
WHITE = 0
GRAY = 1
BLACK = 2
INFTY = 10**16
def bfs(s, V):
    color = [[WHITE for i in range(N+1)] for j in range(3)]
    d = [[INFTY for i in range(N+1)] for j in range(3)]
    d[0][s] = 0
    q = queue.Queue()
    q.put((0, s))
    
    while not q.empty():
        dv, u = q.get()
        color[dv%3][u] = BLACK

        for v in V[u]:
            if color[(dv+1)%3][v] != BLACK and d[(dv+1)%3][v] == INFTY:
                d[(dv+1)%3][v] = d[dv%3][u] + 1
                q.put((d[(dv+1)%3][v], v))

    return d

N, M = map(int, input().split())
graph = [[] for i in range(N+1)]
for i in range(M):
    u, v = map(int, input().split())
    graph[u].append(v)
S, T = map(int, input().split())
d = bfs(S, graph)
if d[0][T] == INFTY:
    print(-1)
else:
    print(d[0][T]//3)
### BUGGY CODE ###

from collections import*
from itertools import*
from copy import*
n,m=map(int,input().split())

grid=[list("#"*(m+2))]+[list("#"+input()+"#")for i in range(n)]+[list("#"*(m+2))]

#print(grid)

start=[]
for i in range(1,n+1):
    for j in range(1,m+1):
        start.append((i,j))

ans=0
for s,g in combinations(start,2):
    G=deepcopy(grid)
    G[s[0]][s[1]]=0
    Q=deque([s])
    while Q:
        y,x=Q.pop()
        for my,mx in (-1,0),(1,0),(0,-1),(0,1):
            if G[y+my][x+mx]==".":
                G[y+my][x+mx]=G[y][x]+1
                Q.appendleft((y+my,x+mx))
    
    if type(G[g[0]][g[1]])!=str:
        if ans<G[g[0]][g[1]]:
            ans=G[g[0]][g[1]]
print(ans)


### FIXED CODE ###

from collections import*
from copy import*
n,m=map(int,input().split())

grid=[list("#"*(m+2))]+[list("#"+input()+"#")for i in range(n)]+[list("#"*(m+2))]
#print(grid)

start=[]
for i in range(1,n+1):
    for j in range(1,m+1):
        start.append((i,j))

ans=0
for s in start:
    G=deepcopy(grid)
    if G[s[0]][s[1]]!="#":
        G[s[0]][s[1]]=0
    else:
        continue
    Q=deque([s])
    while Q:
        y,x=Q.pop()
        for my,mx in (-1,0),(1,0),(0,-1),(0,1):
            if G[y+my][x+mx]==".":
                G[y+my][x+mx]=G[y][x]+1
                Q.appendleft((y+my,x+mx))
    
    x=max( max([0]+[j for j in i  if type(j)==int]) for i in G)
    if x>ans:
        ans=x
print(ans)
### BUGGY CODE ###

N,M,L=map(int,input().split())
d=[[10**20 for i in range(0,N+1)] for i in range(0,N+1)]
for i in range(0,M):
    a,b,c=map(int,input().split())
    d[a][b]=c
    d[b][a]=c

for k in range(1,N+1):
    for i in range(1,N+1):
        for j in range(1,N+1):
            d[i][j]=min(d[i][j],d[i][k]+d[k][j])

e=[[10**20 for i in range(0,N+1)] for i in range(0,N+1)]
for i in range(1,N+1):
    for j in range(1,N+1):
        if L>=d[i][j]:
            e[i][j]=1

for k in range(1,N+1):
    for i in range(1,N+1):
        for j in range(1,N+1):
            e[i][j]=min(e[i][k]+e[k][j],e[i][j])

Q=int(input())
ans=[]
for i in range(Q):
    s,t=map(int,input().split())
    if e[s][t]!=10**20:
        ans.append(e[s][t]-1)
    else:
        ans.append(-1)

for i in range(0,Q):
    print(ans[i])


### FIXED CODE ###

import numpy as np
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson
from scipy.sparse import csr_matrix

N,M,L=map(int,input().split())
d=[[0 for i in range(0,N)] for i in range(0,N)]
for i in range(0,M):
    a,b,c=map(int,input().split())
    d[a-1][b-1]=c
    d[b-1][a-1]=c

csr1=csr_matrix(d)

a=floyd_warshall(csr1)

d=[[0 for i in range(0,N)] for j in range(0,N)]
for i in range(0,N):
    for j in range(0,N):
        if L>=a[i][j]:
            d[i][j]=1


csr2=csr_matrix(d)

data=floyd_warshall(csr2)
ans=[]
Q=int(input())
for i in range(0,Q):
    s,t=map(int,input().split())
    if data[s-1][t-1]!=float('inf'):
        ans.append(int(data[s-1][t-1])-1)
    else:
        ans.append(-1)

for i in range(Q):
    print(ans[i])
### BUGGY CODE ###

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

area = []
for i in range(K):
    L, R = map(int, input().split())
    area.append((L, R))

area.sort()
d = [0] * N


def func(pos):
    for a in area:
        for i in range(a[0], a[1]+1):
            if pos - i > -1:
                d[pos-i] += d[pos] % 998244353
            else:
                return


d[N-1] = 1
for i in range(N-1, -1, -1):
    if d[i] > 0:
        func(i)

print(d[0] % 998244353)


### FIXED CODE ###

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

area = []
for i in range(K):
    L, R = map(int, input().split())
    area.append((L, R))

area.sort()
d = [0] * N
a = [0] * N


def func(pos):
    for l, r in area:
        if pos + l - 1 < N:
            a[pos + l-1] += d[pos]
        if pos + r < N:
            a[pos + r] -= d[pos]
    d[pos+1] = (d[pos] + a[pos]) % 998244353


d[0] = 1
a[0] = -1
for i in range(0, N-1):
    func(i)

print(d[N-1] % 998244353)
### BUGGY CODE ###

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

K = int(input())
list_A=[]
for i in range(K-1):
    for j in range(K-1):
        for k in range(K-1):
            list_A.append(gcd(i+2,j+2,k+2))
print(sum(list_A)+K**2+(K**2-K)+(K**2-2*K)+1)

### FIXED CODE ###

import math


K = int(input())
S=0
for i in range(1,K+1):
    for j in range(1,K+1):
        s=math.gcd(i,j)
        for k in range(1,K+1):
            S += math.gcd(s,k)

print(S)
### BUGGY CODE ###

# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    ln = sorted(list(map(int, args[1].split())))

    s = 0
    for i in range(n):
        for j in range(i+1, n):
            for k in range(n-1, j, -1):
                if (
                    (ln[i] < ln[j] + ln[k]) and
                    (ln[j] < ln[i] + ln[k]) and
                    (ln[k] < ln[i] + ln[j])
                ):
                    s += 1

    return str(s)


if __name__ == "__main__":
    print(solve(*[input() for _ in range(2)]))


### FIXED CODE ###

# coding: utf-8
import bisect


def solve(*args: str) -> str:
    n = int(args[0])
    ln = sorted(list(map(int, args[1].split())))
    s = 0
    for i in range(n-1, 1, -1):
        for j in range(i-1, 0, -1):
            small = bisect.bisect_right(ln, ln[i] - ln[j])
            big = bisect.bisect_left(ln, ln[i] + ln[j], small, j)
            s += big - small

    return str(s)


if __name__ == "__main__":
    print(solve(*[input() for _ in range(2)]))
### BUGGY CODE ###

inp = input()
inp = inp[::-1]
m = 0
n = 0
li = ['dream','dreamer','erase','eraser']
li =[g[::-1] for g in li]
while True:
    for i in li:
        if inp.startswith(i):
    	    inpp = inp.replace(i,'',1)
    	    if inpp == '':
    		    m = 1
    		    break
    	    for k in li:
    	    	if inpp.startswith(k):
    		        inp = inpp
    		        n = 1
    		        break
    	    else:
                if k == 'eraser':
                	break
                continue
    	    break
    if m == 1:
    	print('YES')
    	break
    if n != 1:
    	print('NO')
    	break

### FIXED CODE ###

inp = input()
inp = inp[::-1]
li = ['dream','dreamer','erase','eraser']
li = [k[::-1] for k in li]
m = 0
while True:
    for i in li:
        if inp.startswith(i):
    	    inp = inp.replace(i,'',1)
    	    m = 0
    else:
    	if m == 1:
    		break
    	else:
    		m = 1
    		continue
    break
if inp == '':
	print("YES")
else:
	print("NO")
### BUGGY CODE ###

import sys

def solve():
    N = int(sys.stdin.readline())
    s = []
    for _ in range(N):
        s.append(int(sys.stdin.readline()))
    sums = [0]
    for num in s:
        sums = sums + [s + num for s in sums]
    for r in sorted(sums, reverse=True):
        if r % 10:
            return r
    return 0

print(solve())

### FIXED CODE ###

import sys


class Solution(object):
    def __init__(self):
        self.N = int(sys.stdin.readline())
        self.s = []
        for _ in range(self.N):
            self.s.append(int(sys.stdin.readline()))

    # def solve(self):
    def naive_solve(self):
        sums = [0]
        for num in self.s:
            sums.extend([s + num for s in sums])
        for r in sorted(sums, reverse=True):
            if r % 10:
                return r
        return 0

    def answer_solve(self):
        S = sum(self.s)
        if S % 10:
            return S
        smallest = float('inf')
        for num in self.s:
            if num % 10:
                smallest = min(smallest, num)
        if smallest != float('inf'):
            return S - smallest
        return 0




print(Solution().answer_solve())
### BUGGY CODE ###

n, m = map(int,input().split())
    
aaa = 0
tbin_1 = []
tbin_n = []
for i in range(m):
    xxx = list(map(int,input().split()))
    if xxx[0] == 1:
        tbin_1.append(xxx[1])
        if xxx[1] in tbin_n:
            aaa = 1
            break
            
    elif xxx[1] == n :
        tbin_n.append(xxx[0])
        if xxx[0] in tbin_1:
            aaa = 1
            break
    else:
        None


if aaa == 1 :
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

### FIXED CODE ###

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

boolins =[]
for i in range(n):
    boolins.append(0)
    
for i in range(m):
    xxx = list(map(int,input().split()))
    if xxx[0] == 1:
        boolins[xxx[1]] = boolins[xxx[1]] + 1
    elif xxx[1] == n :
        boolins[xxx[0]]=boolins[xxx[0]]+ 1
    else:
        None


if 2 in boolins:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')
### BUGGY CODE ###

mod = 10**9 + 7
n = int(input())
lx = list(map(int, input().split()))

from math import factorial as kj

d = 0
lk = [0] * n

for i in range(1, n):
  d += kj(n-1) // i
  lk[i] = (lx[i] - lx[i-1]) * d

print(sum(lk) % mod)

### FIXED CODE ###

mod = 10**9 + 7
n = int(input())
lx = list(map(int, input().split()))

d = 0
ans = 0

for i in range(1, n):
  f = 1 if i == 1 else f * (i-1) % mod
  d = (d * i + f) % mod
  ans = (ans * i + (lx[i] - lx[i-1]) * d) % mod

print(ans)