peterverebics/CodeNet_Python_428 huggingface dataset:
# Judge status: Accepted
S = input()
T = input()
length = len(T)
results = []
for i in range(len(S)-length+1):
    flag = True
    for s, t in zip(S[i:i+length], T):
        if s == "?":
            continue
        if s != t:
            flag = False
            break
    if flag:
        results.append(S[:i] + T + S[i+length:])

if len(results) == 0:
    print("UNRESTORABLE")
else:
    results = [res.replace("?", "a") for res in results]
    results.sort()
    print(results[0])
# Judge status: Accepted
n=int(input())
w=tuple(map(int,input().split()))
t=sum(w)
key = 0

while t > 0:
    prev = t
    t -= w[key]*2
    key += 1
    
print(min(abs(t), prev))
# Judge status: Wrong Answer
s = input()

s_cnt, t_cnt = 0, 0
ans = 0
for i in range(len(s)):
    if s[i] == "S":
        s_cnt += 1
    else:
        t_cnt += 1
        if i == len(s) - 1 or s[i + 1] == "S":
            ans += min(t_cnt, s_cnt)
            t_cnt = 0
            s_cnt = max(0, s_cnt - t_cnt)

print(len(s) - ans * 2)
# Judge status: Wrong Answer
n,m = map(int, input().split())
minn, maxn = 1, n
for i in range(m):
	l, r = map(int,input().split())
	minn, maxn = max(minn, l), min(maxn, r)
print(maxn-minn+1)
# Judge status: Wrong Answer
chk = input()

if str(chk)[-1] == '3':
  print('bon')
if str(chk)[-1] in ('0', '1', '6', '8'):
  print('pon')
else:
  print('hon')
# Judge status: Accepted
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if v <= w:
    print('NO')
else:
    if abs(a - b) /(v - w) <= t:
        print('YES')
    else:
        print('NO')
# Judge status: Wrong Answer
n,k,q=map(int,input().split())
life=[k-q]*n
for i in range(q):
    tem=int(input())
    life[tem-1]+=1
for j in life:
    print('YNEOS'[j<=0::2])
# Judge status: Accepted
k = int(input())
a,b = map(int, input().split())

flg = False
for i in range(a,b+1):
    if i%k == 0:
        flg = True
if flg:
    print('OK')
else:
    print('NG')
# Judge status: Accepted
import sys
input = sys.stdin.readline

H, N = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
dp = [10**14]*(H+1)
dp[0] = 0
for a, b in AB:
    for i in range(H+1):
        if i < a:
            if dp[i] > b:
                dp[i] = b
        else:
            if dp[i] > dp[i-a]+b:
                dp[i] = dp[i-a]+b
print(dp[H])
# Judge status: Wrong Answer
N = int(input())
A = int(input())

N //= 500
print("Yes" if N <= A else "No")
# Judge status: Wrong Answer
a,b=map(int,input().split())
for i in range(21):
	l=(b+1)*i
	if l>=a:
		print(i)
# Judge status: Accepted
t=int(input())
n=list(map(int,input().split()))
xor=0
for x in n:
  xor^=x
for x in n:
  print(x^xor,end=" ")
# Judge status: Wrong Answer
import bisect
n = int(input())
l_list = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(i+1 , n):
        ans += bisect.bisect_left(l_list,l_list[i] + l_list[j]) -j -1
        
print(ans)
# Judge status: Wrong Answer
a,b=map(int,input().split())
c=list(input())
if c[b-1]=='A':
  
  c[b-1]='a'
elif c[b-1]=='B':
  c[b-1]='b'
else:
  c[b-1]='c'
print(c)
# Judge status: Wrong Answer
N = int(input())
A = [int(input()) for i in range(N)]
B = 0
for i in A:
    if A.count(i)%2 == 1: 
        B += 1
    else:
        while i in A:A.remove(i)
print(B)
# Judge status: Wrong Answer
n,m=map(int,input().split())
l=list(map(int,input().split()))
s=sum(l)//(4*m)
c=0
for i in range(n):
    if(l[i]>=s):
        c=c+1
if(c>=m):
    print("Yes")
else:
    print("No")
# Judge status: Accepted
N=int(input())
abc=[[] for _ in range(N)]

for i in range(N):
    abc[i]=list(map(int,input().split()))

dp=[[0,0,0] for _ in range(N+1)]
for i in range(1,N+1):
    for j in range(3):#新しく選ぶもの
        for k in range(3):#選ぶもの
            if k!=j:
                dp[i][j]=max(dp[i][j] , dp[i-1][k]+abc[i-1][k])
                

print(max(dp[-1]))
# Judge status: Accepted
from collections import defaultdict
N, K = map(int, input().split())
nums = [int(i) for i in input().split()]

num_freq = defaultdict(int)
for num in nums:
    num_freq[num] += 1

_sorted_nums = [[i] * j for i,
                j in sorted(num_freq.items(), key=lambda x:x[1])]
sorted_nums = []
for i in _sorted_nums:
    sorted_nums += i

borders = []
for i in range(1, N):
    if sorted_nums[i-1] != sorted_nums[i]:
        borders.append(i)

if len(num_freq) <= K:
    print(0)
else:
    print(borders[-K])
# Judge status: Accepted
N = int(input())
X = [int(i) for i in input().split()]

indexes = [i for i in range(N)]
sorted_indexes = sorted(indexes, key=lambda i: X[i])

for i in range(N):

    if X[i] <= X[sorted_indexes[int(N / 2)-1]]:
        print(X[sorted_indexes[int(N / 2)]])
    else:
        print(X[sorted_indexes[int(N / 2)-1]])
# Judge status: Wrong Answer
d,t,s=map(int,input().split())
temp1=d//t
if temp1==s:
  print("YES")
else:
  print("NO")
# Judge status: Wrong Answer
input = raw_input
n = int(input())
nums = map(int, input().split(" "))

out = sum(nums) - min(nums)
print(out)
# Judge status: Wrong Answer
x = int(input())
if x == 1:
  print("1")
  exit()
  
ans = 0
for b in range(2,int(x**(1/2)+1)):
  for p in range(2,1000):
    tmp = pow(b,p)
    if tmp<=x:
      ans = max(ans,pow(b,p))
      break
      
print(ans)
# Judge status: Accepted
n=input()
k=len(n)
dp=[[0]*2 for _ in range(k)]
dp[0][0]=min(int(n[0]),11-int(n[0]))
dp[0][1]=min(int(n[0])+1,11-(int(n[0])+1))
for i in range(1,k):
  dig=int(n[i])
  dp[i][0]=min(dp[i-1][0]+dig,dp[i-1][1]+10-dig)
  dp[i][1]=min(dp[i-1][0]+dig+1,dp[i-1][1]+10-(dig+1))
print(dp[k-1][0])
# Judge status: Accepted
N, M = map(int, input().split())
ans = min(M//2, N)
M = M - 2*ans
ans += M//4 
print(ans)
# Judge status: Accepted
N,M = map(int,input().split())
if N==M:
    print("Yes")
else:
    print("No")
# Judge status: Accepted
import math
n = int(input())
print(math.factorial(n) % (10**9 + 7))
# Judge status: Accepted
k, n = map(int, input().split())
a = [int(x) for x in input().split()]

diff = [a[i + 1] - a[i] for i in range(n - 1)] + [k - a[-1] + a[0]]
ans = sum(diff) - max(diff)
print(ans)
# Judge status: Accepted
a=list(map(int,input().split()))

for num in range(len(a)):
    if a[num]==0:
        print(num+1)
# Judge status: Wrong Answer
import bisect

N, M, K = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arui = [0] * (N + 1)
brui = [0] * (M + 1)
for i in range(N):
    arui[i + 1] = a[i] + arui[i]
for i in range(M):
    brui[i + 1] = b[i] + brui[i]

ans = 0
for i in range(1, N + 1):
    if arui[i] > K:
        break
    bcnt = M
    while brui[bcnt] + arui[i] > K:
        bcnt -= 1
    ans = max(ans, i + bcnt)

print(ans)
# Judge status: Accepted
a, b = map(int,input().split())
print("Even" if a * b % 2 == 0 else "Odd")
# Judge status: Accepted
p, q, r = map(int, input().split())

print(min(min(p+q, q+r), r+p))
# Judge status: Accepted
n = int(input())
S = [0]*n
for i in range(n):
    S[i] = int(input())

r = sum(S)
S.sort()
for i in range(n):
    if r%10 != 0:
        break
    if r%10 == 0 and S[i]%10!=0:
        r -= S[i]
        break
    if i==n-1:
        r = 0
print(r)
# Judge status: Accepted
import sys

sys.setrecursionlimit(10 ** 9)

asc2en = lambda x: chr(x + 97)
N = int(input())


def rec(N):
    if (N - 1) // 26:
        return rec((N - 1) // 26) + asc2en((N - 1) % 26)
    return asc2en((N - 1) % 26)


print(rec(N))
# Judge status: Accepted
N,M = map(int,input().split())
PY = [[int(i) for i in input().split()]+[j] for j in range(M)]

dic = {}
PY.sort(key = lambda x:x[1])
ken = [0 for i in range(N)]
for k,value,s in PY:
    ken[k-1] += 1
    s1 = str(k).zfill(6)
    s2 = str(ken[k-1])
    s2 = s2.zfill(6)
    dic[s] = s1+s2

ans = sorted(dic.items(),key=lambda x:x[0])

for i,j in ans:
    print(j)
# Judge status: Accepted
n, k = map(int, input().split())
A = list(map(int, input().split()))


def judge(length):
    cnt = 0
    for a in A:
        cnt += a // length
        if a % length == 0:  # ちょうど割り切れるときは切る回数が一回少なくて済む
            cnt -= 1
    return cnt <= k


ng, ok = 0, max(A)
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if judge(mid):
        ok = mid
    else:
        ng = mid

print(ok)
# Judge status: Accepted
N = int(input())
a = list(map(int, input().split()))
 
i = 0
odd = 0
while odd == 0:
    for n in range(N):
        if a[n] % 2 == 0:
            a[n] /= 2
        else:
            odd = 1
            break
    if odd == 0:
        i += 1
print(i)
# Judge status: Accepted
from sys import exit
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if w >= v:
    print("NO")
    exit()

time = abs(a - b) / (v - w)
if time > t:
    print("NO")
else:
    print("YES")
# Judge status: Accepted
As=input().split()

count5=0
count7=0

for A in As:
    if A=="5":
        count5+=1
    elif A=="7":
        count7+=1

if count5==2 and count7==1:
    print("YES")
else:
    print("NO")
# Judge status: Wrong Answer
text=input('現在の気温')
if text.isdigit():
  temperature=int(text)
  if temperature<30:
    print('No')
  elif temperature>=30:
    print('Yes')
# Judge status: Wrong Answer
s = input()
l = len(s)
ans = 0
for i in range(l):
  for j in range(i+1, l+1):
    a =int(s[i:j]) % 10**9+7 
    if a % 2019 % 10**9+7 == 0:
      ans +=1
print(ans)
# Judge status: Accepted
S = input()
if S == "ARC":
    print("ABC")
elif S =="ABC":
    print("ARC")
# Judge status: Accepted
N = int(input())
a_list = []
b_list = []
for i in range(N):
    A, B = map(int, input().split())
    a_list.append(A)
    b_list.append(B)

a_list.sort()
b_list.sort()

a_m = a_list[N // 2 - 1] + a_list[N // 2] if N % 2 == 0 else a_list[(N + 1) // 2 - 1]
b_m = b_list[N // 2 - 1] + b_list[N // 2] if N % 2 == 0 else b_list[(N + 1) // 2 - 1]
a_m /= 2
b_m /= 2

print(int((b_m - a_m) / 0.5) + 1)
# Judge status: Accepted
n=int(input())
A = [list(map(str,input().split())) for i in range(n)]
A_s = sorted(A, key=lambda x: int(x[1]), reverse=True)
A_ss = sorted(A_s, key=lambda x: x[0], reverse=False)
for i in range(n):
    print(A.index( A_ss[i])+1)
# Judge status: Accepted
def find(s):
  ans=0
  for i in s:
    if i=="R":
      ans+=1
    elif i=="S" and ans>0:
      return ans
  return ans
s=input()
print(find(s))
# Judge status: Accepted
N = int(input())
X = list(map(int, input().split()))
HP = set()
for p in  range(100):
    p += 1
    A = 0
    for i in range(N):
        A += (X[i] - p)**2
    HP.add(A)
print(min(HP))
# Judge status: Accepted
a = int(input())
b = int(input())

ans = 0

if a == 1:
    if b == 2:
        ans = 3
    else:
        ans = 2
elif a == 2:
    if b == 1:
        ans = 3
    else:
        ans = 1
else:
    if b == 1:
        ans = 2
    else:
        ans = 1

print(ans)
# Judge status: Wrong Answer
n = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))

ans = 0
for i in range(n):
  ans = sum(A1[:i+1]) + sum(A2[i:])
print(ans)
# Judge status: Accepted
N = int(input())
W = [int(x) for x in input().split()]
sumW = sum(W)
s = 0
ans = 100 * N
for i in range(N):
    s += W[i]
    ans = min(ans, abs(sumW - 2 * s))

print(ans)
# Judge status: Accepted
W, H, N = map(int, input().split())

sum = W*H

X1 = [0]
X2 = [W]
Y1 = [0]
Y2 = [H]
for i in range(N):
    x,y,a = map(int, input().split())
    if a == 1:
        X1.append(x)
    elif a == 2:
        X2.append(x)
    elif a == 3:
        Y1.append(y)
    else:
        Y2.append(y)

left = max(X1)
right = min(X2)
bottom = max(Y1)
top = min(Y2)

if left >= right or bottom >= top:
    print(0)
else :
    print((right-left)*(top-bottom))
# Judge status: Accepted
n=int(input())
a=list(map(int,input().split()))
b=[0]+list(map(int,input().split()))
c=[0]+list(map(int,input().split()))

cnt=0
before=0

for i in range(n):
    cnt+=b[a[i]]
    if a[i]==before+1:
        cnt+=c[before]
    before=a[i]
print(cnt)
# Judge status: Accepted
n = int(input())
s = input()
x = 0
maxVal = 0
for letter in s:
    if letter == "D":
        x -= 1
    elif letter == "I":
        x += 1
    maxVal = max(x,maxVal)
print(maxVal)
# Judge status: Wrong Answer
n=int(input())
S=input()

L,R=0,0
l,r=0,0

for i in S:
    if "(":l +=1
    else:l -=1;L=min(L,l)

for i in S[::-1]:
    if ")":r +=1
    else:r -=1;R=min(R,r)

print("("*-L+S+")"*-R)
# Judge status: Wrong Answer
def Good_Sequence(n , al):

    count = {}
    ans = 0

    for i in al:
        if i in count:
            count[i] += 1
        else:
            count[i] = 1

    for i in count.keys():
        key = int(i)
        value = int(count[i])
        if key != value:
            ans += value if value < key else key - value

    return ans

def main():
    n = int(input())
    al = list(map(int , input().split()))
    print(Good_Sequence(n , al))

if __name__ == '__main__':
    main()
# Judge status: Accepted
N = int(input())
k = 1
while (k*(k+1))//2<N:
    k += 1
A = [i for i in range(1,k+1)]
if N==(k*(k+1))//2:
    for a in A:
        print(a)
else:
    m = (k*(k+1))//2-N
    for a in A:
        if a!=m:
            print(a)
# Judge status: Accepted
N = int(input())
S = list(map(str, input().rstrip()))

ans = 0

for i in range(1, N):
    ans = max(ans, len(set(S[:i]) & set(S[i:])))

print(ans)
# Judge status: Accepted
n = int(input())
A, B, C = [], [], []
for i in range(n):
    a, b, c = map(int, input().split())
    A.append(a); B.append(b); C.append(c)

dp = [[0] * 3 for _ in range(n+1)]

for i in range(n):
    dp[i+1][0] = max(dp[i+1][0], max(dp[i][1], dp[i][2])+A[i])
    dp[i+1][1] = max(dp[i+1][1], max(dp[i][0], dp[i][2])+B[i])
    dp[i+1][2] = max(dp[i+1][2], max(dp[i][1], dp[i][0])+C[i])
print(max(dp[n]))
# Judge status: Wrong Answer
D,N = map(int,input().split())

if D==0 and N ==100:
    ans = 100**D*N+1
else:
    ans = 100**D*N

print(ans)
# Judge status: Accepted
num = list(map(int, input().split()))
num.sort()

x = num[2] * 3 - sum(num)

if x%2 == 0:
  ans = int(x/2)
else:
  ans = int(x//2 + 2)

print(ans)
# Judge status: Accepted
s = int(input())
a = (s-1)//10**9+1; b = 10**9-(s-1)%10**9-1
print(0, 0, 1, a, 10**9, b)
# Judge status: Wrong Answer
n=int(input())
x=[]
for i in range(n):
  x.append(list(map(int, input().split())))
a=2*(10**9)
b=0

for j in range(n):
  if sum(x[j])<a:
    a=sum(x[j])
    c=j
  if sum(x[j])>b:
    b=sum(x[j])
    d=j
if c==d:
  print(0)
else:
  print(x[d][0]-x[c][0]+x[d][1]-x[c][1])
# Judge status: Accepted
# coding: utf-8
# Your code here!
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=[0]*m
y=[0]*m
c=[0]*m
d=[]
for i in range(m):
 x[i],y[i],c[i]=map(int,input().split())
 d.append(a[x[i]-1]+b[y[i]-1]-c[i])
print(min(min(d),min(a)+min(b)))
# Judge status: Accepted
h,w=map(int,input().split());print([0--h*w//2,1][h<2 or w<2])
# Judge status: Accepted
a, b, c, d = map(int, input().split())

import fractions
#import math
from functools import reduce
def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)
  #return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

l = lcm_base(c, d)

i = b//c-(a-1)//c
j = b//d-(a-1)//d
k = b//l-(a-1)//l
#print(i, j, k)
ans = b-a+1-(i+j-k)
print(ans)
# Judge status: Accepted
N=int(input())
List = list(map(int, input().split()))
sumS = 0
for i in range(N):
  sumS +=List[i]
trial = sumS // N
mid = 0
res = 10000000
for i in range(N):
  trial += i
  mid = 0 
  for j in range(N):
    mid += (trial - List[j])**2
  res = min(res, mid)
print(res)
# Judge status: Accepted
def resolve():
    K = int(input())
    N = 7
    c = 1
    for i in range(10**6):
        if N % K == 0:
            print(c)
            break
        else:
            N = N * 10 + 7
            N %= K
            c += 1
    else:
        print(-1)
resolve()
# Judge status: Wrong Answer
N, A, B, C, D = map(int, input().split())
s = list(input())
flag = False

if C > D:
    s[D-1] = '#'
    s = ''.join(s)
    if "..." in s[B-1:D]:
        flag = True
else:
    s = ''.join(s)

if "##" in s:
    print("No")
else:
    if not flag:
        print("No")
    else:
        print("Yes")
# Judge status: Accepted
N = int(input())
S = input()

x = 0
m = 0
for i in range(N):
  if S[i] == "I": x += 1
  else: x -= 1
  if m < x:
    m = x
print(m)
# Judge status: Wrong Answer
n=int(input())
a=list(map(int,input().split()))
if a[0]:exit(print(-1))
b=[1]
for i in range(1,n+1):
  b.append(b[-1]*2-a[i])
b[-1]=a[-1]
for i in range(n,0,-1):
  b[i-1]=min(b[i-1],b[i])
  b[i-1]+=a[i-1]
  if not(b[i-1]-a[i-1]<=b[i]<=2*(b[i-1]-a[i-1])):exit(print(-1))
print(sum(b))
# Judge status: Accepted
import sys

if __name__ == "__main__":
 
    N = int(input())
 
    P = list(map(int,input().split()))

    if(0 in P):
        print(0)
    else:
        P.sort()

        mult = 1
        for i in P:
            mult *= i 
            if (mult > 10 ** 18):
                print(-1)
                sys.exit()

        print(mult)
# Judge status: Wrong Answer
#!/usr/bin/env python
import math

a, b, x = map(int, input().split())

if a%x == 0:
    if b%x == 0:
        if b//x - a//x != 0:
            ans = b//x - a//x + 1 
            print(ans)
            exit()
        else:
            ans = b//x - a//x
            print(ans)
            exit()
ans = b//x - a//x
print(ans)
# Judge status: Accepted
N = int(input())
sum = 0

for i in range(N+1):
    if i % 15 == 0:
        pass
    elif i % 3 == 0:
        pass
    elif i % 5 == 0:
        pass
    else:
        sum = sum + i

print(sum)
# Judge status: Accepted
s = input()
s1 = s[:len(s)//2]
s2 = s[len(s)//2+1:]
print("Yes" if s==s[::-1] and s1==s1[::-1] and s2==s2[::-1] else "No")
# Judge status: Wrong Answer
#Tenka1 Programmer Beginner Contest 2019 a
a,b,c=map(int,input().split())
if a<c and c<b:
    print("Yes")
else:
    print("No")
# Judge status: Wrong Answer
def main():
    S = input()
    k = int(input())
    ans = []
    for s in S:
        if (r := 123 - ord(s)) <= k:
            ans.append('a')
            k -= r
        else:
            ans.append(s)
    if k > 0:
        k %= 26
        ans[-1] = chr(a if (a := ord(ans[-1]) + k) <= 122 else a - 26)
    print(''.join(ans))

if __name__ == '__main__':
    main()
# Judge status: Wrong Answer
d=int(input())
print("Christmas"+"Eve"*(25-d))
# Judge status: Wrong Answer
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N - 1)]


for i in range(N):
    t = 0

    for c, s, f in CSF[i:]:
        # 待ち時間
        if t < s:
            t = s
        else:
            t = ((t - s) // f) * f + s
        # i -> i+1に移動
        t += c

    print(t)
# Judge status: Accepted
N, M = map(int,input().split())
if N>1 and M>1:
  print(N*M-(N*2 + (M-2)*2))
elif N==1 and M>1:
  print(N*M-2)
elif M==1 and N>1:
  print(N*M-2)
else:
  print(1)
# Judge status: Accepted
d,t,s=map(int,input().split())
if s*t>=d:
  print("Yes")
else:
  print("No")
# Judge status: Wrong Answer
N = int(input())
print(1000 - (N % 1000))
# Judge status: Accepted
D,N=list(map(int,input().split()))
if D==0:
    if N==100:
        print(101)
        exit()
    print(N)
elif D==1:
    if N==100:
        print(100*101)
        exit()
    print(100*N)
else:
    if N==100:
        print(100*100*101)
        exit()
    print(100*100*N)
# Judge status: Accepted
s = input()
n=int(s[0])
s = input().split()
d={}
dc={}
summ=0
for i in s:
    if i not in d:
        d[i]=1
    else:
        d[i]+=1
for i in d:
    n = d[i]
    if n>1:
        e=n*(n-1)/2
        summ+=e
        dc[i]=e
    else:
        dc[i]=0
for i in s:
    n = d[i]-1
    e = n*(n-1)/2
    print(int(summ-dc[i]+e))
# Judge status: Accepted
n = int(raw_input())
ais = [int(raw_input()) for _ in range(n)]
tails = []
import bisect
for a in ais:
	if not(tails) or (tails[-1] >= a):
		tails.append(a)
	else:
		# maintain a decreaing tails
		986643321
		lo,hi = 0, len(tails) - 1
		while(lo<hi):
			med= (lo + hi)/2
			if tails[med] < a:
				hi = med
			else:
				lo = med + 1
		tails[lo] = a
print len(tails)
# Judge status: Wrong Answer
a, b = map(str, input().split())
anser = ""

if a > b:
    for i in range(0, int(a) + 1):
        anser = b * i
if a == b:
    for i in range(0, int(a) + 1):
        anser = b * i
if a < b:
    for i in range(0, int(b) + 1):
        anser = b * i
print(anser)
# Judge status: Wrong Answer
d = int(input())
print('christmas' + ' Eve' * (25 - d))
# Judge status: Accepted
def main():
    w = input()
    A = [0]*26
    for char in w:
        A[ord(char) - ord('a')] += 1
    for a in A:
        if a%2 != 0:
            print("No")
            return
    print("Yes")
    return

main()
# Judge status: Accepted
n = int(input())
towns = []
total = 0
for i in range(n):
    town = list(map(int,input().split()))
    towns.append(town)
                
for i in range(n):
    for j in range(n):
        total += ((towns[i][0] - towns[j][0])**2 + (towns[i][1] - towns[j][1])**2)**(1/2) / n

print(total)
# Judge status: Accepted
X, Y, Z = map(int, input().split())
mylist=[]
for i in range(X):
    if (Y*i)+(Z*(i+1)) <= X:
        mylist.append(1)
    else:
        pass
print(len(mylist)-1)
# Judge status: Wrong Answer
n=int(input())

ans=0
lastk=n
for i in range(1,n+1):
    k=n//i
    if i>k:
        break
    ans+=k*(k+1)//2*i
    ans+=i*(i-1)//2*(lastk+k+1)*(lastk-k)//2
    lastk=k

print(ans)
# Judge status: Wrong Answer
X,Y = map(int,input().split())
print(X + Y/2)
# Judge status: Accepted
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

ans = 'No'
for i in range(N-M+1):
    for j in range(N-M+1):
        C = [A[k][i:i+M] for k in range(j, j+M)]
        if B == C:
            ans = 'Yes'
print(ans)
# Judge status: Accepted
N, x = [int(i) for i in input().split(" ")]
lst = [int(i) for i in input().split(" ")]
 
lst.sort()
cnt = 0
 
for i in range(0,N-1):
  if x >= lst[i]:
    x -= lst[i]
    cnt += 1
  else:
    break

if x == lst[N-1]:
    cnt +=1
    
print(cnt)
# Judge status: Accepted
n = int(input())
d = list(map(int,input().split()))
d.sort()
if d[int(n/2)] == d[int(n/2)-1]:
  ans = 0
else:
  ans = d[int(n/2)] - d[int(n/2)-1]
print(ans)
# Judge status: Accepted
N, Q = map(int, input().split())
S = input()

ans = [0] * N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        ans[i+1] += (ans[i] + 1)
    else:
        ans[i+1] = ans[i]

for _ in range(Q):
    l, r = map(int, input().split())
    print(ans[r-1] - ans[l-1])
# Judge status: Wrong Answer
x = int(input())
ans = 0
for i in range(1,x+1):
    for j in range(2,int(i**0.5)+2):
        if i**(1/j) % 1 == 0:
            ans = i
print(ans)
# Judge status: Accepted
S=input()
S2=S[:(len(S))//2]
while len(S)>=2:
    S=S[:-2]
    S2=S2[:-1]
    if S==S2+S2:
        print(len(S))
        exit()
# Judge status: Accepted
S = input()

now = int(S[5:7]+S[8:10])
if now <= 430:
    print("Heisei")
else:
    print("TBD")
# Judge status: Wrong Answer
n = int(input())

ans = 0
for a in range(1,int(n**(1/2))):
  tmp = 0
  if n%a == 0:
    tmp += ((n//a)-1-a)*2
    tmp += 1
  else:
    tmp += (n//a-a)*2
    tmp += 1
  #print(tmp)
  ans += tmp
print(ans)
# Judge status: Accepted
N = input()

if '7' in N:
  print('Yes')
else:
  print('No')
# Judge status: Wrong Answer
s=input()
ans=0
a=0
b=0
for i in range(len(s)):
    if s[i]=="T":
        a+=1
    else:
        break
for i in range(len(s)):
    if s[-i-1]=="S":
        b+=1
    else:
        break
print(a+b)
# Judge status: Wrong Answer
import sys

(x, n) = list(map(int, input().split()))
arr = list(map(int, input().split()))

if(len(arr) == 0):
    print(x)
    sys.exit()

if(x in arr):
    print(x)
    sys.exit()

i = 1
while True:
    if(not (x - i in arr)):
        print(x - i)
        sys.exit()
    
    if(not (x + i in arr)):
        print(x + i)
        sys.exit()
    i += 1
# Judge status: Accepted
from itertools import accumulate
from operator import add
N = int(input())
S = input()
E = list(accumulate("E"==s for s in "W"+S[:0:-1]))[::-1]
W = list(accumulate("W"==s for s in "E"+S[:-1]))
print(min(map(add, E, W)))
# Judge status: Wrong Answer
def resolve():
	s = input()
	w = ['dream', 'dreamer', 'erase', 'eraser']
	h = dict()
	for i in range(len(w)):
		h[w[i][::-1]] = True
	s = s[::-1]
	c = ''
	for i in s:
		c += i
		if h.get(c):
			c = ''
	if not len(c):
		print('YES')
	else:
		print('NO')
resolve()