Harryxun/stf_run huggingface dataset:
#!/user/bin/env pypy3
import itertools
import sys


def fast_input():
    return sys.stdin.readline()[:-1]


def print_format(b: bool) -> str:
    return "YES" if b else "NO"


def solve(s: str) -> bool:
    tokens = ["dream", "erase", "eraser", "dreamer"]

    def dfs(pos: int) -> bool:
        if pos == len(s):
            return True
        for token in tokens:
            if (pos + len(token)) > len(s):
                break
            if s[pos:pos + len(token)] == token:
                if dfs(pos + len(token)):
                    return True

    return dfs(0)


def main():
    result = solve(fast_input())
    print(print_format(result))


main()


### FIXED CODE ###

#!/user/bin/env pypy3
import itertools
import sys


def fast_input():
    return sys.stdin.readline()[:-1]


def print_format(b: bool) -> str:
    return "YES" if b else "NO"


def solve(s: str) -> bool:
    for p in itertools.permutations(["dreamer", "eraser", "dream", "erase"]):
        work = s
        for token in p:
            work = work.replace(token, '')
        if work == "":
            return True
    return False


def main():
    result = solve(fast_input())
    print(print_format(result))


main()
N = int(input())
A = list(map(int, input().split(' ')))
num_sum = 0
for i in range(1, N+1):
    c = A.count(i)
    num_sum += int(c * (c - 1) / 2)

for j in A:
    if A.count(j) == 1:
        print(sum(num_sum))
    else:
        print(sum(num_sum) - (A.count(j) - 1))

### FIXED CODE ###

'''
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split(' '))))
num_sum = 0
remove_array = np.array([], int)
for i in range(N):
    c1 = np.count_nonzero(A == i + 1)
    c2 = np.count_nonzero(A == A[i])
    if c2 <= 1:
        remove_array = np.append(remove_array, 0)
    else:
        remove_array = np.append(remove_array, c2 - 1)
    num_sum += int(c1 * (c1 - 1) / 2)
print(*(num_sum - remove_array), sep='\n')
'''
import collections
N = int(input())
A = list(map(int, input().split()))
cnt = collections.Counter(A)
total = 0
for key in cnt.keys():
    total += cnt[key] * (cnt[key] - 1) // 2
for i in range(N):
    tmp = total
    tmp -= cnt[A[i]] * (cnt[A[i]] - 1) // 2
    tmp += (cnt[A[i]] - 1) * (cnt[A[i]] - 2) // 2
    print(tmp)
from math import factorial
n,a,b,k=map(int,input().split())
def gcd(x,y):
  if y==0:
    return x
  else:
    return gcd(y,x%y)
ans=0
p=998244353
x=gcd(a,b)
if k%x==0:
  A=a//x
  B=b//x
  K=k//x
  for i in range(n):
    if K-A*i>=0 and (K-A*i)%B==0:
      ans+= (((factorial(n)//factorial(n-i)//factorial(i))%p)*((factorial(n)//factorial(n-(K-A*i)//B)//factorial((K-A*i)//B))%p))%p
      ans=ans%p
print(ans)

### FIXED CODE ###

n,a,b,k=map(int,input().split())
p=998244353
def getinv(n):
  inv=[0]*(n+1)
  inv[1]=1
  for i in range(2,n+1):
    inv[i]=(-(p//i)*inv[p%i])%p
  return inv
def getnCr(n):
  inv=getinv(n)
  nCr=[0]*(n+1)
  nCr[0]=1
  for i in range(1,n+1):
    nCr[i]=(nCr[i-1]*(n-i+1)*inv[i])%p
  return nCr
def solve(n,a,b,k):
  ans=0
  nCr=getnCr(n)
  for i in range(n+1):
    if (k-a*i)<0 or (k-a*i)%b!=0:
      continue
    j=(k-a*i)//b
    if a*i+b*j==k and 0<=j<=n:
      ans+= nCr[i]*nCr[j]
      ans%=p
  return ans
print(solve(n,a,b,k))
import sys
input = sys.stdin.readline

import scipy.sparse
N = int(input())
lil = scipy.sparse.lil_matrix((N, N), dtype = int)
for i in range(N-1):
    a, b, c = (int(x) for x in input().split())
    lil[a-1, b-1] = c
lil2 = scipy.sparse.csgraph.dijkstra(lil,directed=False).astype(int)
Q, K = (int(x) for x in input().split())
for i in range(Q):
    x, y = (int(x) for x in input().split())
    print(lil2[K-1][x-1]+lil2[K-1][y-1])

### FIXED CODE ###

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

N = int(input())
connected = [[]for _ in range(N+1)]
for i in range(N-1):
    a, b, c = (int(x) for x in input().split())
    connected[a].append((b,c))
    connected[b].append((a,c))
Q, K = (int(x) for x in input().split())
distk = [-1] * (N+1)
d = deque([K])
distk[K] = 0
while d:
    temp = d.popleft()
    for vert, dist in connected[temp]:
        if distk[vert] == -1:
            d.append(vert)
            distk[vert] = distk[temp] + dist
for i in range(Q):
    x, y = (int(x) for x in input().split())
    print(distk[x]+distk[y])
K = int(input())
A = int(input())
B = int(input())
if B-A > K:
    print('OK')
else:
    print('NG')

### FIXED CODE ###

K = int(input())
k = K
A,B = map(int, input().split())
for i in range(1, B+1):
    k *= i
    if k >= A and k <= B:
        print('OK')
        a = True
        break
    else:
        k = K
        a = False
        continue
if a != True:
    print('NG')
N = int(input())
x = list(input())[::-1]

num = 0
pop_num = 0
for i in range(N):
    if x[i] == "1":
        num += 2 ** i
        pop_num += 1

def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c
x = x[::-1]
import sys
sys.setrecursionlimit(10**8)

def calc(i,depth,n):
    if depth == 0:
        if x[i] == "1":
            tmp = (num - 2 ** (N - i)) % (pop_num - 1)
            return calc(i,depth+1,tmp)
        else:
            tmp = (num + 2 ** (N - i)) % (pop_num + 1)
            return calc(i,depth+1,tmp)
    else:
        if n == 0: return depth
        return calc(i,depth+1, n % popcnt(n))
        

for i in range(N):
    print(calc(i,0,0))



### FIXED CODE ###

N = int(input())
x = list(input())[::-1]
num = 0
nump = 0
numm = 0
pop_num = 0
for i in range(N):
        if x[i] == "1":
            pop_num += 1
for i in range(N):
    if x[i] == "1":
        num += pow(2,i,pop_num)
        num %= pop_num 
        nump += pow(2,i,pop_num+1)
        nump %= pop_num  + 1
        if pop_num-1 != 0:
            numm += pow(2,i,pop_num - 1)
            numm %= pop_num - 1



def popcnt(n):
    c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555)
    c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333)
    c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f)
    c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff)
    c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff)
    c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff)
    return c

x = x[::-1]
def calc(i,depth,n):
    if depth == 0:
        if x[i] == "1":
            tmp = numm
            if pop_num - 1 != 0:
                tmp -= pow(2,N-i-1,pop_num-1)
                tmp %= (pop_num - 1)
            else:
                return 0
            return calc(i,depth+1,tmp)
        else:
            tmp = nump
            tmp += pow(2,N-i-1,pop_num+1)
            tmp %= (pop_num + 1)
            return calc(i,depth+1,tmp)
    else:
        if n == 0: return depth
        return calc(i,depth+1, n % popcnt(n))
        

for i in range(N):
    print(calc(i,0,0))
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for j in range(N)]

ans = 0
for elem in A:
  sum_A = 0
  for j in range(M):
    sum_A += elem[i] * B[i]
  if sum_A + C > 0:
    ans += 1
print(ans)
    
  

### FIXED CODE ###

N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for j in range(N)]

ans = 0
for elem in A:
  sum_A = 0
  for j in range(M):
    sum_A += elem[j] * B[j]
  if sum_A + C > 0:
    ans += 1
print(ans)
#!/usr/bin/python


def datasets():
    s = raw_input().strip()
    yield s
    
def main():
    for s in datasets():
        import s.lower()
        
if __name__ == '__main__':
    main()

### FIXED CODE ###

#!/usr/bin/python


def datasets():
    s = raw_input().strip()
    yield s
    
def main():
    for s in datasets():
        print s.upper()
        
if __name__ == '__main__':
    main()
C,D=input().split('')
C=int(C)
D=int(D)

numb=4*C
if D>numb:
    print("No.")
else:
    print("Yes.")


### FIXED CODE ###

#getting input from user
#cranes and turtle already give the information
#condition yes or no 
X,Y= map(int,input().split())
cranes= 2 # assign 2 to cranes
turtles= 4 # assign 4 to turtle
ans="No"
for i in range(X+1): 
    b=X-i
    if cranes*i + turtles*b == Y:
        ans = "Yes"
print(ans)

# Time complixity O(X)
A,B= map(int, input().split())

#隠される範囲
C = (B*2)
D = A-C

if D = 0:
    print(0)
else:
    print(D) 

### FIXED CODE ###

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

#隠される範囲
B_2 = B*2

if A - B_2 >= 0:
    print(A - B_2)
else:
    print(0)
N = input()
S = 0
for n in N:
  S += int(n)
N = int(N)
print("Yes" if N%S == 0 else "No")


### FIXED CODE ###

S = input()
number = 0
for i in range(len(S)):
    if S[i] == "+":
        number += 1
    else:
        number -= 1
print(number)
import sys
input = sys.stdin.buffer.readline
n,ma,mb=map(int,input().split())
ABC=[list(map(int,input().split())) for _ in range(n)]
infi=10**15
dp=[[[infi]*(401) for _ in range(401)]for _ in range(41)]
dp[0][0][0]=0
for i in range(n):
    a,b,c=ABC[i]
    for j in range(401-a):
        for k in range(401-b):
            ni=i+1
            dp[ni][j][k]=min(dp[ni][j][k], dp[i][j][k])
            dp[ni][nj][nk]=min(dp[i][j][k]+c,dp[ni][nj][nk])

ans=infi
for i in range(1,401):
    if ma*i>400:
        break
    if mb*i>400:
        break    
    ans=min(ans, dp[n][ma*i][mb*i])
print(ans if ans!=infi else -1)

### FIXED CODE ###

import sys
input = sys.stdin.buffer.readline
n,ma,mb=map(int,input().split())
ABC=[list(map(int,input().split())) for _ in range(n)]
infi=10**15
dp=[[[infi]*(401) for _ in range(401)]for _ in range(41)]
dp[0][0][0]=0
for i in range(n):
    a,b,c=ABC[i]
    for j in range(401-a):
        for k in range(401-b):
            ni=i+1
            nj=j+a
            nk=k+b
            dp[ni][j][k]=min(dp[ni][j][k], dp[i][j][k])
            dp[ni][nj][nk]=min(dp[i][j][k]+c,dp[ni][nj][nk])

ans=infi
for i in range(1,401):
    if ma*i>400:
        break
    if mb*i>400:
        break    
    ans=min(ans, dp[n][ma*i][mb*i])
print(ans if ans!=infi else -1)
from collections import defaultdict, deque, Counter
from math import sqrt
def inpl(): return list(map(int, input().split()))

N = int(input())
A = inpl()
S = []
x = 0
for i in range(N):
    x ^= A[i]
    S.append(x)
if S[-1] != 0:
    print(2**(S.count(S[-1])-1))
else:
    raise

### FIXED CODE ###

from collections import defaultdict
from math import sqrt
def inpl(): return list(map(int, input().split()))
MOD = 10**9 + 7
N = int(input())
S = []

x = 0
for a in map(int, input().split()):
    x ^= a
    S.append(x)

A = defaultdict(int)
B = defaultdict(int)
L = defaultdict(int)
Z = 0

if S[-1] != 0:
    sr = S[-1]
    a, b = 0, 0
    for s in S:
        if s == sr:
            b =  (b + a + 1)%MOD
        elif s == 0:
            a = (a + b)%MOD
    print(a+1)
else:
    for s in S:
        if s == 0:
            Z += 1
        else:
            A[s] = (A[s] + (Z - L[s])*B[s])%MOD
            B[s] = (A[s] + B[s] + 1)%MOD
            L[s] = Z
    print((sum(B.values()) + pow(2, Z-1, MOD))%MOD)
from operator import itemgetter

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

a = []
b = []

for i in range(M):
    ao,bo = map(int,input().split())
    a.append(ao)
    b.append(bo)

ab = sorted([(a[i],b[i]) for i in range(M)], key = itemgetter(1))

ans = 0
last = 0

for i in range(N):
    if last <= ab[i][0]:
        ans += 1
        last = ab[i][1]

print(ans)


### FIXED CODE ###

from operator import itemgetter

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

a = []
b = []

for i in range(M):
    ao,bo = map(int,input().split())
    a.append(ao)
    b.append(bo)

ab = sorted([(a[i],b[i]) for i in range(M)], key = itemgetter(1))

ans = 0
last = 0

for i in range(M):
    if last <= ab[i][0]:
        ans += 1
        last = ab[i][1]

print(ans)
count=0

n=int(input())
l=list(map(str,input()))
for i in range(n-3):
    if list[0]=='R':
        j=i+1
        while i+1<=j and j<=n-1:
            if l[j]=='R':
                j+=1
            else:
                k=j+1
                while j+1<=k and k<=n and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                    else:
                        k+=1
                j+=1
            i+=1
    if list[0]=='G':
        j=i+1
        while i+1<=j and j<=n-1:
            if l[j]=='G':
                j+=1
            else:
                k+=1
                while j+1<=k and k<=n and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                    else:
                        k+=1
                j+=1
            i+=1    
    if list[0]=='B':
        j+=1
        while i+1<=j and j<=n-1:
            if l[j]=='B':
                j+=1
            else:
                k+=1
                while j+1<=k and k<=n and k-j!=j-i:
                    if l[k]!=l[j]:
                        count+=1
                    else:
                        k+=1
                j+=1
            i+=1
print(count)

### FIXED CODE ###

n=int(input())
l=input()
a=l.count('R')
b=l.count('G')
c=l.count('B')
d=a*b*c
i=0
count=0
lis=list(l)
while i<=n-3:
    j=i+1
    while i+2*(j-i)<=n-1:
        if lis[i]!=lis[j] and lis[j]!=lis[i+2*(j-i)] and lis[i]!=lis[i+2*(j-i)]:
            count+=1
            j+=1
        else:
            j+=1
    i+=1
print(d-count)
a = int(input())
b = int(input())
c = int(input())
print(c,a,b)

### FIXED CODE ###

A,B,C= map(int,input().split())
print(C,A,B)
N = input()
ls = map(int, input().split())
tot = 1
for i in ls:
    tot = i*tot
    if tot > 10^18:
        break
    elif tot ==0:
        break
    
if i <= 10^18:
    print(tot)
else:
    print(-1)

### FIXED CODE ###

A, B = map(int, input().split())
print(A*B)
X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

import heapq

heap = []
heapq.heappush(heap, (-(A[0]+B[0]+C[0]), 0, 0, 0))
added = set([(0, 0, 0)])

for _ in range(K):
    p, i, j, k = heapq.heappop(heap)
    if (i+1, j, k) not in added and i+1<X:
        heapq.heappush(heap, -(A[i+1]+B[j]+C[k]), i+1, j, k)
        added.add((i+1, j, k))
    if (i, j+1, k) not in added and j+1<Y:
        heapq.heappush(heap, -(A[i]+B[j+1]+C[k]), i, k+1, j)
        added.add((i, j+1, k))
    if (i, j, k+1) not in added and k+1<Z:
        heapq.heappush(heap, -(A[i]+B[j]+[k]), i, j, k+1)
        added.add((i, j, k+1))
    print(-p)

### FIXED CODE ###

import heapq
 
X, Y, Z, K = map(int, input().split())
A = sorted([int(i) for i in input().split()], reverse=True)
B = sorted([int(i) for i in input().split()], reverse=True)
C = sorted([int(i) for i in input().split()], reverse=True)
 
heap = []
heapq.heappush(heap, (-(A[0] + B[0] + C[0]), 0, 0, 0))
added = set([(0, 0, 0)])
for _ in range(K):
    p, i, j, k = heapq.heappop(heap)
    if (i + 1, j, k) not in added and i + 1 < X:
        heapq.heappush(heap, (-(A[i + 1] + B[j] + C[k]), i + 1, j, k))
        added.add((i + 1, j, k))
    if (i, j + 1, k) not in added and j + 1 < Y:
        heapq.heappush(heap, (-(A[i] + B[j + 1] + C[k]), i, j + 1, k))
        added.add((i, j + 1, k))
    if (i, j, k + 1) not in added and k + 1 < Z:
        heapq.heappush(heap, (-(A[i] + B[j] + C[k + 1]), i, j, k + 1))
        added.add((i, j, k + 1))
    print(-p)
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a+1):
  A=i*500
  for j in　range(b+1):
    B=j*100
    for k in range(c+1):
      C=k*50
      
      if A+B+C=x:
        ans+=1
print(ans)


### FIXED CODE ###

a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=0
for i in range(a+1):
  A=i*500
  for j in range(b+1):
    B=j*100
    for k in range(c+1):
      C=k*50
      
      if A+B+C==x:
        ans+=1
print(ans)
a=list(map(int(input().split()))
print(a[0]-a[1]+1)

### FIXED CODE ###

a=list(map(int,input().split()))
print(a[0]-a[1]+1)
X = int(input())
flag = True
num = 31
lst = []
i = 2
while i <= 10:
    while flag:
        if num**i <= X:
            z = num**i
            lst.append(z)
            break
        elif num == 0:
            break
        else:
            num -= 1
    num= 31
    i += 1
print(max(lst))

### FIXED CODE ###

l = list(map(int, input().split()))
a = l[0]
b = l[1]
c = l[2]
d = l[3]
if abs( c - a ) <= d:
    print("Yes")
elif abs(c - b) <= d:
    if abs(b-a) <= d:
        print("Yes")
    else:
        print("No")
else:
    print("No")
N, W = map(int, input().split())
p = []
for it in test[1:]:
    p.append(list(map(int,input().split())))
    
import numpy as np
dp = np.zeros((N+1,W+1), dtype=np.int64)

i = 0
for w, v in p:
    i += 1
    for w_limit in range(1, W+1):
        if w_limit < w:
            dp[i,w_limit]=dp[i-1,w_limit]
            continue
        if (dp[i-1, w_limit-w] + v) > dp[i-1, w_limit]:
            dp[i, w_limit] = dp[i-1, w_limit-w] + v
        else:
            dp[i,w_limit]=dp[i-1,w_limit]
print(dp.max())

### FIXED CODE ###

N, W = map(int, input().split())
p = []
for it in range(N):
    p.append(list(map(int,input().split())))
    
dp = [[0 for i in range(W+1)] for j in range(N+1)]
i = 0
for w, v in p:
    i += 1
    for w_limit in range(1, W+1):
        if w_limit < w:
            dp[i][w_limit]=dp[i-1][w_limit]
            continue
        if (dp[i-1][w_limit-w] + v) > dp[i-1][w_limit]:
            dp[i][w_limit] = dp[i-1][w_limit-w] + v
        else:
            dp[i][w_limit]=dp[i-1][w_limit]
print(max(max(dp)))
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

def lcm_list(li):
    if len(li) == 1:
        return li[0]

    elif len(li) == 2:
        return lcm(li[0], li[1])

    else:
        li = [lcm(li[0], li[1])] + li[2:]
        return lcm_list(li)

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


i = max(lcm_list(a) - 1, 1)
print(sum([i % j for j in a]))

### FIXED CODE ###

import sys
sys.setrecursionlimit(30000)

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

def lcm_list(li):
    if len(li) == 2:
        return lcm(li[0], li[1])

    else:
        li = [lcm(li[0], li[1])] + li[2:]
        return lcm_list(li)

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


i = max(lcm_list(a) - 1, 1)
print(sum([i % j for j in a]))
s = input()
cnt = 0
l =[]
for i in range(3):
    if s[i] == "R":
        cnt += 1
    else:
        l.append(cnt)
        cnt = 0

print(max(l))
    

### FIXED CODE ###

s = input()
cnt = 0
l =[]
for i in range(3):
    if s[i] == "R":
        cnt += 1
    else:
        l.append(cnt)
        cnt = 0

l.append(cnt)

print(max(l))
a = input()
b = input()
c = a%500
if b >= c:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

a = int(input())
b = int(input())
if a%500 <= b:
  print("Yes")
else:
  print("No")
a, b = raw_input()
return 'Yay!' if a <= 8 and b <= 8 else ':('

### FIXED CODE ###

a, b = map(int, raw_input().split(' '))
print 'Yay!' if a <= 8 and b <= 8 else ':('
a=int(input())
b=[int(input()) for i in range(a)]
b.sort()
c=sum(b)
if c%10!==0:
  print(c)
else:
  while c%10==0:
    for k in range(a):
      c=c-b[k]
  print(c)

### FIXED CODE ###

a=int(input())
b=[int(input()) for i in range(a)]
b.sort()
c=sum(b)
d=0
if c%10!=0:
  print(c)
else:
  for i in range(a):
    if b[i]%10!=0:
      c=c-b[i]
      print(c)
      break
  if sum(b)==c:
    print(0)
def main():
    s = input()
    if s = 'ABC':
        print('ARC')
    else:
        print('ARC')


if __name__ == "__main__":
    main()


### FIXED CODE ###


def main():
    s = input()
    if s == 'ABC':
        print('ARC')
    else:
        print('ABC')


if __name__ == "__main__":
    main()
a,b,c=map(int,input().split())
if c-a-b<=0:
	print("No")
else:
  	p=(a*b)**(1/2)
	if 2*p<(c-a-b):
    	print("Yes")
    else:
    	print("No")

### FIXED CODE ###

a,b,c=map(int,input().split())
if c-a-b<=0:
	print("No")
else:
	if 4*a*b<(c-a-b)**2:
		print("Yes")
	else:
		print("No")
def cost( i,k,j ):
  return m[i][k] + m[k+1][j] + p[i][0] * p[k][1] * p[j][1]
 
n = input()
M = []
m = [ [ 0 for i in range(n) ] for j in range(n) ]
for i in range(n):
  M.append( map ( int , raw_input().split() ) )

M_long = len(M)
for x in range( 2,M_long+1 ):
  for i in range( 0,M_long-x+1 ):
    j = i + x - 1
    m[i][j] = min( cost( i,k,j ) for k in range( i,j ) )
 
print m[0][M_long-1]

### FIXED CODE ###

def cost( i,k,j ):
  return m[i][k] + m[k+1][j] + M[i][0] * M[k][1] * M[j][1]
 
n = input()
M = []
m = [[ 0 for i in range(n) ] for j in range(n) ]
for i in range(n):
  M.append( map (int, raw_input().split() ) )
 
M_long = len(M)
for l in range( 2,M_long+1 ):
  for i in range( 0,M_long-l+1 ):
    j = i+l-1
    m[i][j] = min( cost( i,k,j ) for k in range( i,j ) )
 
print m[0][M_long-1]
N = int(input())
D = list(map(int, input().split()))

waru = 998244353

dic = {}
dic2 = {}

for i in range(1, N+1):
    dic[i] = D[i-1]

for number, distance in dic.items():
    if distance in dic2:
        dic2[distance] = dic2[distance] + 1
    else:
        dic2[distance] = 1

if 0 in dic2:
    pass
else:
    print(0)
    exit(0)

l = []

for i in range(1, len(dic2.items()) -1):
    l.append(dic2[i] ** dic2[i+1])

#print(l)

r = 1
for x in l:
    r *= x
d, m = divmod(r, waru)
print(m)

### FIXED CODE ###

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

if D[0] != 0:
    print(0)
    exit(0)

waru = 998244353

dic = {}
dic2 = {}

for i in range(1, N+1):
    dic[i] = D[i-1]

for number, distance in dic.items():
    if distance in dic2:
        dic2[distance] = dic2[distance] + 1
    else:
        dic2[distance] = 1

if 0 in dic2:
    if dic2[0] >= 2:
        print(0)
        exit(0)

l = []

for i in range(1, len(dic2.items()) - 1):
    if i in dic2 and (i+1) in dic2:
        l.append(dic2[i] ** dic2[i+1])
    else:
        print(0)
        exit(0)

r = 1
for x in l:
    r *= x

d, m = divmod(r, waru)
print(m)
N = int(input())
L = input().split()
L.sort()
c = 0
for a in range(N):
    if a == 0:
        c = c + float(L[0])*pow(0.5, N - 1)
    else:
        c = c + float(L[a])*pow(0.5, N - a)
print(c)

### FIXED CODE ###

a = int(input())
s = input()
if a >= 3200:
    print(s)
else:
    print("red")
N,M=map(int,input().split())
A=[input()for i in range(N)]
B=[input()for i in range(M)]
b=''
a='no'
for i in range(M):
    b+=B[i]
print(b)
for i in range(N-M+1):
    if B[0]in A[i] and B[1] in A[i+1]:
        for j in range(N-M+1):
            a=''
            for k in range(M):
                a+=A[i+k][j:j+M]
            if a==b:
                print("Yes")
                exit()
print("No") 


### FIXED CODE ###

N,M=map(int,input().split())
A=[input()for i in range(N)]
B=[input()for i in range(M)]
b=''
a='no'
for i in range(M):
    b+=B[i]
for i in range(N-M+1):
    if B[0]in A[i] :
        for j in range(N-M+1):
            a=''
            for k in range(M):
                a+=A[i+k][j:j+M]
            if a==b:
                print("Yes")
                exit()
print("No")
n = int(input())
if n < 1000:
  print('ABC')
else:
  print('ABD')

### FIXED CODE ###

a,b = map(int, input().split())
print((b-a)*(b-a-1)//2 - a)
n = int(input())
A = sorted(list(map(int, input().split())))
B = sorted(list(map(int, input().split())))
C = sorted(list(map(int, input().split())))

import bisect

ans = 0
for b in B:
    a = bisect.bisect_left(A,b)
    c = n - bisect.bisect_right(C,b)
    ans += a*c

print(ans)


### FIXED CODE ###

c = [input() for _ in range(2)]
if c[0][0] == c[1][2] and c[0][1] == c[1][1] and c[0][2] == c[1][0]:
    print("YES")
else:
    print("NO")
n=map(int,input())
sun_m=0
for i in range(n+1):
  sum_n+=i
print(sum_n)

### FIXED CODE ###

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