Harryxun/stf_run huggingface dataset:
N = int(input())
count = {}
for x in map(int, input().split()):
    count[x] = count.get(x, 0) + 1

a = sorted(count.values())
sums = a[:]
n = len(a)
for i in range(1, n):
    sums[i] += sums[i-1]
    
def check(k, x):
    pos = bisect.bisect_right(a, x)
    return (sums[pos-1] if pos-1 >= 0 else 0) + x * (n - pos) >= k * x

x = 0
res = []
for k in range(N, 0, -1):
    while check(k, x+1):
        x += 1
    res.append(x)
    
for x in res[::-1]:
    print(x)

### FIXED CODE ###

import bisect
N = int(input())
count = {}
for x in map(int, input().split()):
    count[x] = count.get(x, 0) + 1

a = sorted(count.values())
sums = a[:]
n = len(a)
for i in range(1, n):
    sums[i] += sums[i-1]
    
def check(k, x):
    pos = bisect.bisect_right(a, x)
    if pos == 0:
        return x * n >= k * x
    return sums[pos-1]+ x * (n - pos) >= k * x

x = 0
res = []
for k in range(N, 0, -1):
    while check(k, x+1):
        x += 1
    res.append(x)
    
for x in res[::-1]:
    print(x)
N_A_B = list(map(int, input().split()))
ball = ""
for i in range(10**100):
  ball += "A" * N_A_B[1]
  ball += "B" * N_A_B[2]
  if (len(ball) > N_A_B[0]):
    break

print(ball[:N_A_B[0]].count("A"))


### FIXED CODE ###

NAB = list(map(int, input().split()))
N = NAB[0]
A = NAB[1]
B = NAB[2]
ans = ( N//(A+B)) * A

if N%(A+B) <= A:
  ans += N%(A+B)
else:
  ans += A

print(ans)
S = input()

li = S.split()
if ((li[0] == li[1] and li[2] ==li[3]) or (li[0] == li[2] and li[1] == li[3])
    or (li[0] ==li[3] and li[1] == li[2]):
    print('Yes')
else:
    print('No')

### FIXED CODE ###

S = input()

if (S[0] == S[1] and S[1] != S[2] and S[2] ==S[3]):
    print('Yes')
elif (S[0] == S[2] and S[2] != S[1] and S[1] == S[3]):
    print('Yes')
elif (S[0] == S[3] and S[3] != S[1] and S[1] == S[2]):
    print('Yes')
else:
    print('No')
a=list(input())
b=list(input())
d=""
for i in range(0,len(b)):
    c=a[i]+b[i]
    d=d+c
    if len(b)+1 == len(a):
        d = d+ a[len(a)]
print(d)

### FIXED CODE ###

a=list(input())
b=list(input())
d=""
for i in range(0,len(b)):
    c=a[i]+b[i]
    d=d+c

if len(b)+1 == len(a):
    d = d+ a[len(a)-1]

print(d)
n = int(input())
coord = []

for i in range(n):
    x, y, h = map(int, input().split())
    coord.append([h, x, y])

flag = False

for cx in range(0, 101):
    for cy in range(0, 101):
        flag = True

        H = coord[0][0] + abs(coord[0][1] - cx) + abs(coord[0][2] - cy)

        for i in range(1, n):
            if coord[i][0] > 0 and H != coord[i][0] + abs(coord[i][1] - cx) + abs(
                coord[i][2] - cy
            ):
                flag = False

            if coord[i][0] == 0 and H > abs(coord[i][1] - cx) + abs(coord[i][2] - cy):
                flag = False

        if flag is True:
            res_x = cx
            res_y = cy
            res_h = H

print(res_x, res_y, res_h)


### FIXED CODE ###

n = int(input())
coord = []

for i in range(n):
    x, y, h = map(int, input().split())
    coord.append([h, x, y])
    if h > 0:
        x0, y0, h0 = x, y, h

flag = False


for cx in range(0, 101):
    for cy in range(0, 101):
        flag = True

        H = h0 + abs(x0 - cx) + abs(y0 - cy)

        for i in range(n):
            if coord[i][0] != max(H - abs(coord[i][1] - cx) - abs(coord[i][2] - cy), 0):
                flag = False
                break

        if flag is True:
            res_x = cx
            res_y = cy
            res_h = H

print(res_x, res_y, res_h)
N = int(input())
A = list(map(int, input().split()))
n = max(A)
dp = [True for i in range(n+1)]
p = 2
while (p * p <= n): 
  # If prime[p] is not changed, then it is a prime 
  if (prime[p] == True): 
    # Update all multiples of p 
    for i in range(p * p, n+1, p): 
      prime[i] = False
      p += 1
ans = 0
for num in A:
  if dp[num]:
    ans += 1
print(ans)

### FIXED CODE ###

from collections import Counter
def D():
    N = int(input())
    A = list(map(int, input().split()))
    nums = Counter(A)
    if 1 in nums:
        if nums[1] > 1:
            print(0)
            return
        else:
            print(1)
            return
    n = max(A)
    dp = [True for i in range(n+1)]
    p = 2
    while (p <= n): 
        if (p in nums and dp[p] == True): 
            for i in range(p*2, n+1, p): 
                # print(i)
                dp[i] = False
        p += 1
    ans = 0
    for num in nums:
        if nums[num] == 1 and dp[num]:
            # print(num)
            ans += 1
    print(ans)

D()
import sys
import os

def file_input():
    f = open('../Beginner_Contest_165/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    # input()
    A,B,N=map(int, input().split())

    max=0
    # for x in range(N+1):
    #     # ans=int(A*x/B)-A*int(x/B)
    #     min,_=math.modf(x/B)
    #     # ans=int(A*min)
    #     # print(min)
    #     if x==0:
    #         max=min
    #     elif min > max:
    #         max=min
    #     else:
    #         break

    max=0
    max_x=0
    reg=[False]*B

    for x in range(N+1):
        rem = x%B
        if reg[rem]:
            break
        else:
            reg[rem]=True
        if rem > max:
            max=rem
            max_x=x

    # min,_=math.modf(max_x/B)

    print(int(A*max_x/B)-A*int(max_x/B))

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
import os

def file_input():
    f = open('../Beginner_Contest_165/input.txt', 'r')
    sys.stdin = f

def main():
   # file_input()
    # input()
    A,B,N=map(int, input().split())

    max=0
    # for x in range(N+1):
    #     # ans=int(A*x/B)-A*int(x/B)
    #     min,_=math.modf(x/B)
    #     # ans=int(A*min)
    #     # print(min)
    #     if x==0:
    #         max=min
    #     elif min > max:
    #         max=min
    #     else:
    #         break

    # max=0
    # max_x=0
    # first=0
    #
    # for x in range(N+1):
    #     rem = x%B
    #     if x == 0:
    #         first=rem
    #     elif rem == first:
    #         break
    #     if rem > max:
    #         max=rem
    #         max_x=x

    if N<B:
        max_x=N
    else:
        max_x=B-1

    # min,_=math.modf(max_x/B)

    print(int(A*max_x/B)-A*int(max_x/B))

if __name__ == '__main__':
    main()
N=int(input())
A=list(map(int,input().split()))
ans=0

for i in range(0,N):
  for j in range(i,N):
    ans = max(abs(i-j))
    
print(ans)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
ans=0

for i in range(0,N):
  for j in range(i,N):
    ans = max(abs(A[i]-A[j]),ans)
    
print(ans)
s=input()
t=input()
count=0
for i in s:
    if s[i] != t[i]:
        count += 1
print(count)

### FIXED CODE ###

s=input()
t=input()
length=len(s)
count=0
for i in range(length):
    if s[i] != t[i]:
        count += 1
print(count)
n = int(input())
data = list(map(int, input().split()))
data_d = data.sort(reverse = True)
a = sum(data_d[::2])
b = sum(data_d[1::2])
print(a - b)

### FIXED CODE ###

n = int(input())
a = list(map(int, input().split()))
b = a.sort(reverse = True)
print(sum(a[::2])-sum(a[1::2]))
S= input()
days = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
for i in days:
    if S==days[0]:
        print(0)
    elif S==days[i]:
        print(7-i)


### FIXED CODE ###

S= input()
days = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"]
for i in range(7):
    if S==days[i]:
        a=7-i
print(a)
N = list(input())

for i in N：
    if i == "7"
     print("Yes")
     break
    
else：
    print("No")

### FIXED CODE ###

N = list(input())

for i in N:
    if i == "7":
        print("Yes")
        break
    
else:
    print("No")
import collections
n=int(input())

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

a=collections.Counter(A)

X=sorted(a.items(), key=lambda x:x[0])

K=[]
V=[]

RES=[]
for i in range(len(X)):
    K.append(X[i][0])
    V.append(X[i][1])
    
for j in range(1,len(X)-1):
    res=V[j]
    if K[j]-1==K[j-1]:
        res+=V[j-1]
    if K[j]+1==K[j+1]:
        res+=V[j+1]
    RES.append(res)

print(max(RES))

### FIXED CODE ###

import collections
n=int(input())

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

a=collections.Counter(A)

X=sorted(a.items(), key=lambda x:x[0])

K=[]
V=[]

RES=[]
for i in range(len(X)):
    K.append(X[i][0])
    V.append(X[i][1])

if len(X)>=3:
    for j in range(1,len(X)-1):
        res=V[j]
        if K[j]-1==K[j-1]:
            res+=V[j-1]
        if K[j]+1==K[j+1]:
            res+=V[j+1]
        RES.append(res)
elif len(X)==2:
    if K[0]+1==K[1]:
        RES.append(V[0]+V[1])
    else:
        RES.append(max(V))
else:
    RES.append(V[0])        

print(max(RES))
n = int(input())
ans = 0
if n <= 1000:
	for i in range(n):
		ans += i
else:
	for j in range(500500,n):
		ans += i
print(ans)

### FIXED CODE ###

n = int(input())
print(n*(n-1)//2)
while True:
    n,w=map(int,raw_input().split())
    if n==w==0:break
    L=[0]*(n+1)
    for i in range(n):
        v=input()
        L[v/w]+=1
    maxh=max(L)
    r=n-1
    while r>0 and L[r]==0:
        r-=1
    ink=0.01
    for i in range(r+1):
        ink+=float(r-i)/r*float(L[i])/maxh
    print ink

### FIXED CODE ###

while True:
    n,w=map(int,raw_input().split())
    if n==w==0:break
    L=[0]*(w+1)
    for i in range(n):
        v=input()
        L[v/w]+=1
    maxh=max(L)
    r=w
    while r>0 and L[r]==0:
        r-=1
    ink=0.01
    for i in range(r+1):
        if r<>0:
            ink+=float(r-i)/r*float(L[i])/maxh
        else:
            ink+=L[i]
    print ink
N=input()
N=int(N)
M=input()
M=int(M)

sum=0
for num in range(M):
	a=input()
	a=int(a)
	sum=sum+a
	
nokori=N-sum	
if nokori>=0:
	print(nokori)
	
else:
	print(-1)

### FIXED CODE ###

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

sum=0
a=list(map(int,input().split()))
for num in range(M):
	sum=sum+a[num]
	
nokori=N-sum	
if nokori>=0:
	print(nokori)
	
else:
	print(-1)
a=input()
t=-1
flag="False"
for i in range(n-1):
  if a[i]==a[i+1]:
    flag="True1"
    t=i
    break
  if i!=n-2:
    if a[i]==a[i+2]:
      flag="True2"
      t=i
      break
if flag=="False":
  print("{} {}".format(-1,-1))
elif flag=="True1":
  print("{} {}".format(t+1,t+2))
else flag=="True2":
  print("{} {}".format(t+1,t+2))

### FIXED CODE ###

a=input()
t=-1
flag="False"
for i in range(len(a)-1):
  if a[i]==a[i+1]:
    flag="True1"
    t=i
    break
  if i!=len(a)-2:
    if a[i]==a[i+2]:
      flag="True2"
      t=i
      break
if flag=="False":
  print("{} {}".format(-1,-1))
elif flag=="True1":
  print("{} {}".format(t+1,t+2))
else:
  print("{} {}".format(t+1,t+3))
from fractions import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
n=int(input())
s=1
for i in range(n):
    t=int(input())
    s=lcm(a,t)

### FIXED CODE ###

from fractions import gcd
a=1
for _ in[0]*int(input()):
    t=int(input())
    a*=t//gcd(a,t)
print(a)
N=input()
if N[2]==2 and N[2]==4 and N[2]==5 and N[2]==7 and N[2]==9:
    print('hon')
elif N[2]==0 and N[2]==1 and N[2]==6 and N[2]==8:
    print('pon')
else:
    print('bon')


### FIXED CODE ###

N=input()
B=0
B=len(N)
B=B-1
#print(B,N)
if N[B]=='2' or N[B]=='4' or N[B]=='5' or N[B]=='7' or N[B]=='9':
    print('hon')
elif N[B]=='0' or N[B]=='1' or N[B]=='6' or N[B]=='8':
    print('pon')
else:
    print('bon')
s=[int(0) for i in range(26)]
while 1:
    x=[i for i in input()]
    if x==EOF:
        break
    for i in range(len(x)):
        if 97<=ord(x[i].lower())<=122:
            s[ord(x[i].lower())-97]=s[ord(x[i].lower())-97]+1
for i in range(26):
    print(chr(97+i),":",s[i])

### FIXED CODE ###

s=[int(0) for i in range(26)]
while True:
    try:
        x=input()
        for i in range(len(list(x))):
            if 97<=ord(list(x)[i].lower())<=122:
                s[ord(list(x)[i].lower())-97]=s[ord(list(x)[i].lower())-97]+1
    except EOFError:
        break
for i in range(26):
    print(chr(97+i),":",s[i])
from numpy import gcd

n, x0 = map(int, input().split())
x = list(map(int, input().split())) + [x0]

x = list(set(x))
x.sort()
if len(x) >= 3:
    diff_x = [x[i+1] - x[i] for i in range(n-1)]
    ans = diff_x[0]
    for dx in diff_x[1:]:
        ans = int(gcd(ans, dx))
elif len(x) == 2:
    ans = x[1] - x[0]
else:
    ans = 0

print(ans)

### FIXED CODE ###

def gcd(a, b):
    m, n = max(a,b), min(a,b)
    while n != 0:
        m, n = n, m%n
    return m

n, x0 = map(int, input().split())
x = list(map(int, input().split())) + [x0]

x = list(set(x))
x.sort()
if len(x) >= 3:
    diff_x = [x[i+1] - x[i] for i in range(n)]
    ans = diff_x[0]
    for dx in diff_x[1:]:
        ans = int(gcd(ans, dx))
elif len(x) == 2:
    ans = x[1] - x[0]


print(ans)
N = int(input())
Llist = list(map(int, input().split()))
 
sum = 0
for i in Llist:
  if i != max(Llist):
    sum += i
 
if max(Llist) <= sum:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

x,t = map(int, input().split())
print("{}".format(float(x)/t))
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
point = 0

for i in range(N):
  point += B[A[i]]
  if i>0 and A[i] = A[i-1]:
    point += C[A[i-1]]
print(point)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
point = 0

for i in range(N):
    point += B[A[i]-1]
    if i>0 and A[i]-1 == A[i-1]:
        point += C[A[i-1]-1]
print(point)
n = int(input())
f = False
for i in range(int(n/4)):
    for j in range((n/7)):
      if 4*i + 7*j == n:
        f = True
if f:
  print('Yes')
else:
  print('No')

### FIXED CODE ###

n = int(input())
ans = 'No'
for i in range(n):
    for j in range(n):
        if 7*i + 4*j == n:
            ans = 'Yes'
print(ans)
x=input().split()
y=set(x)
print(y[x.count(y[0])-1])

### FIXED CODE ###

x=input().split()
y=list(set(x))
print(y[x.count(y[0])-1])
h = int(input())

def dev(n):
    if n == 1:
        retuen 1
    else:
        retuen 1 + dev(n//2) * 2

print(dev(h))

### FIXED CODE ###

h = int(input())

def dev_(n):
    if n == 1:
        return 1
    else:
        return 1 + dev_(n//2) * 2

print(dev_(h))
A,B,C,D = input()
S = (A+B+C+D)
S1 = []
if A == B == C== D:
    print('No')
    exit()
for i in S:
    if i.strip(A) !='':
        S1.append(i.strip(A))
if S1[0] == S1[1] and len(S1) == 2 and len(S2) == 2:
    print("Yes")
else :
    print("No")


### FIXED CODE ###

A,B,C,D = input()
S = (A+B+C+D)
S1 = []
if A == B == C== D:
    print('No')
    exit()
for i in S:
    if i.strip(A) !='':
        S1.append(i.strip(A))
if len(S1) == 2:
        if S1[0] == S1[1]:
            print("Yes")
        else:
            print("No")
else :
    print("No")
# B - Shift only
# https://atcoder.jp/contests/abc081/tasks/abc081_b

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

count= 0

while all(a % 2 == 0 for num in nums):
    num = [(num/2) for num in nums]
    count +=  1

print(count)

### FIXED CODE ###

N = int(input())

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

i = 0

while 1 != 0:
    new = [(num/2) for num in nums if (num%2) == 0]

    if len(new) != N:
        print(i)
        exit()
    else:
        i += 1
        nums = new
from itertools import groupby
H, W = map(int, input().split())
if H%2==1:
    assert False
S = ["" for _ in range(W)]
T = []
for _ in range(H):
    s = input()
    T.append(s)
    for i, c in enumerate(s):
        S[i] += c
T = [sorted(t) for t in T]
S = [sorted(s) for s in S]
T.sort()
S.sort()
cnt = 0
for _, g in groupby(T):
    if len(list(g))%2:
        cnt += 1
if H%2 < cnt:
    print("NO")
    exit()
cnt = 0
for _, g in groupby(S):
    if len(list(g))%2:
        cnt += 1
if W%2 < cnt:
    print("NO")
    exit()
print("YES")


### FIXED CODE ###

# この解法は嘘を含む

from itertools import groupby
H, W = map(int, input().split())
S_ = ["" for _ in range(W)]
T_ = []
for _ in range(H):
    s = input()
    T_.append(s)
    for i, c in enumerate(s):
        S_[i] += c
T = [sorted(t) for t in T_]
S = [sorted(s) for s in S_]
cnt = 0
for _, g in groupby(sorted(T)):
    if len(list(g))%2:
        cnt += 1
if H%2 < cnt:
    print("NO")
    exit()
cnt = 0
for _, g in groupby(sorted(S)):
    if len(list(g))%2:
        cnt += 1
if W%2 < cnt:
    print("NO")
    exit()
if W%2 or H%2:
    print("YES")
    exit()
T1 = []
T2 = []
for i, (_, t) in enumerate(sorted(zip(T, T_))):
    if i%2:
        T1.append(t)
    else:
        T2.append(t)
T_p = T1 + T2[::-1]
S_pp = ["" for _ in range(W)]
for t in T_p:
    for i, c in enumerate(t):
        S_pp[i] += c
S1 = []
S2 = []
for i, (_, s) in enumerate(sorted(zip(S, S_pp))):
    if i%2:
        S1.append(s)
    else:
        S2.append(s)
S_p = S1 + S2[::-1]
for s1, s2 in zip(S_p, S_p[::-1]):
    for c1, c2 in zip(s1, s2[::-1]):
        if c1!=c2:
            print("NO")
            exit()
print("YES")
h,w=map(int,input().split())
field=[]
for i in range(h):
    field.append(list(map(int,input().split())))
opr=0
ans=[]
for j in range(h):
    for k in range(w):
        if j%2==0:
            if field[j][k]%2==1 and k!=w-1:
                field[j][k]-=1
                field[j][k+1]+=1
                opr+=1
                ans.append([j+1,k+1,j+1,k+2])
            elif field[j][k]%2==1 and k==w-1: 
                field[j][k]-=1
                field[j+1][k]+=1
                opr+=1
                ans.append([j+1,k+1,j+2,k+1]) 
        else:
            if field[j][-(k+1)]%2==1 and k!=w-1:
                field[j][-(k+1)]-=1
                field[j][-(k+2)]+=1
                opr+=1
                ans.append([j+1,w-k,j+1,w-k-1])
            elif field[j][k]%2==1 and k==w-1: 
                field[j][-(k+1)]-=1
                field[j+1][-(k+1)]+=1
                opr+=1
                ans.append([j+1,w-k,j+2,w-k])
print(opr)
for l in range(len(ans)):
    print(ans[l][0],ans[l][1],ans[l][2],ans[l][3])

### FIXED CODE ###

h,w=map(int,input().split())
field=[]
for i in range(h):
    field.append(list(map(int,input().split())))
opr=0
ans=[]
for j in range(h):
    for k in range(w):
          if field[j][k]%2==1 and k!=w-1:
              field[j][k]-=1
              field[j][k+1]+=1
              opr+=1
              ans.append([j+1,k+1,j+1,k+2])
          elif field[j][k]%2==1 and k==w-1 and j<h-1: 
              field[j][k]-=1
              field[j+1][k]+=1
              opr+=1
              ans.append([j+1,k+1,j+2,k+1]) 
   
print(opr)
for l in range(len(ans)):
    print(ans[l][0],ans[l][1],ans[l][2],ans[l][3])
l = map(int, input().split())

ab = l[0] - l[1]
cab = l[2] - ab

if cab < 0:
  print(0)
else:
  print(cab)

### FIXED CODE ###

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

ab = a - b
cab = c - ab
 
if cab < 0:
  print(0)
else:
  print(cab)
N = int(input())
HP_list = [int(i) for i in input().split()]
while len(set(HP_list))>1:
    for i in range(0, len(set(HP_list))):
        min_HP = min(HP_list)
        if HP_list[i] > min_HP:
            HP_list[i] = HP_list%min_HP
            if HP_list[i]==0:
                HP_list[i] += min_HP
print(list(set(HP_list))[0])

### FIXED CODE ###

import numpy as np
N = int(input())
HPs = np.array([int(i) for i in input().split()])
np.sort(HPs)
while len(HPs) > 1:
    HPs[1:] %= HPs[0]
    HPs[HPs==0] = HPs[0]
    HPs=np.unique(HPs)
print(HPs[0])
t = int(input())
for i in range(t):
    able = "Yes"
    a,b,c,d = map(int, input().split())
    if a - b < 0:
        able = "No"
    else:
        x = c+(a-c)%b
        if x <= c:
            x+=d
        for i in range(1500):
            x-=b
            if x >= 0:
                if x <= c:
                    x+=d
            else:
                able = "No"
                break
    print(able)

### FIXED CODE ###

n = int(input())
a= list(input().split())
res = 0
for i in range(n-1):
    if a[i] == a[i+1]:
        a[i+1]=10001
        res +=1
print(res)
a, b, x = map(int, input().split())
print('YES' if a <= x <= a + b)

### FIXED CODE ###

a, b, x = map(int, input().split())
print('YES' if a <= x <= a + b else 'NO')
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,a,b=map(int,input().split())

    if(a+b>n+1):
        print(-1)
        return
    if(a*b<n):
        print(-1)
        return

    # a*b=n のとき
    A=[None]*(a*b)
    for i in range(a):
        for j in range(b):
            A[i*b+j]=(i+1)*b-j

    d=a*b-n
    m=0
    for i in range(1,a):
        k=min(b-1,d)
        d-=k
        m+=k
        for j in range(i*b,(i+1)*b):
            if(j>=(i+1)*b-k): A[j]=None
            else: A[j]-=m

    ans=[a for a in A if(a is not None)]
    print(*ans)
resolve()

### FIXED CODE ###

import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,a,b=map(int,input().split())
    if(a+b>n+1):
        print(-1)
        return
    if(a*b<n):
        print(-1)
        return

    ans=list(range(b,0,-1))
    now=b
    d=a*b-n
    for _ in range(a-1):
        k=min(d,b-1)
        d-=k
        next=now+(b-k)
        for i in range(next,now,-1):
            ans.append(i)
        now=next

    print(*ans)
resolve()
x = input()
n = len(x)
ans = "NO"

def f(i):
    if n==i:
        global ans
        ans = "YES"
    else:
        if x[i:i+5] == "dream":
            f(i+5)
        if x[i:i+7] == "dreamer":
            f(i+7)
        if x[i:i+5] == "erase":
            f(i+5)
        if x[i:i+6] == "eraser":
            f(i+6)
f(0)
print(ans)

### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)
x = input()
n = len(x)
ans = "NO"

def f(i):
    if n==i:
        global ans
        ans = "YES"
    else:
        if x[i:i+5] == "dream":
            f(i+5)
        if x[i:i+7] == "dreamer":
            f(i+7)
        if x[i:i+5] == "erase":
            f(i+5)
        if x[i:i+6] == "eraser":
            f(i+6)
f(0)
print(ans)
# -*- coding: utf-8 -*-

# input
S = input()
# S = "abcdefghijklmnopqrstuvwzyx"
# S = "atcoder"

s = list(S)
a = []
for i in range(len(s)):
    a.append(ord(s[i]))

t = [chr(i) for i in range(97, 97+26)]
b = [i for i in range(97, 97+26)]


# function
def func(s_):
    ss_ = []
    for i in range(len(s_)):
        ss_.append(chr(s_[i]))
    ss_ = ''.join(ss_)
    return ss_


# solve
if (len(s) < 26):
    for i in range(len(s)):
        b.remove(a[i])
    a.append(min(b))
    print(func(a))

if (len(s) == 26):
    for i in reversed(range(len(s))):
        if (a[i] < a[i-1]):
            if (i == 1):
                print(-1)
            else:
                continue
        else:
            a = a[0:i]
            # ここから26文字未満の場合とほとんど同じ
            for i in range(len(a)):
                b.remove(a[i])
            a.pop()
            a.append(min(b))
            print(func(a))
            break


### FIXED CODE ###

# -*- coding: utf-8 -*-
import bisect

# input
S = input()
# S = "abcdefghijklmnopqrstuvwzyx"
# S = "atcoder"
# S = "qpwoeirutyalskdjfhgzmxnvcb"

s = list(S)
a = []
for i in range(len(s)):
    a.append(ord(s[i]))

t = [chr(i) for i in range(97, 97+26)]
b = [i for i in range(97, 97+26)]


# function
def func(s_):
    ss_ = []
    for i in range(len(s_)):
        ss_.append(chr(s_[i]))
    ss_ = ''.join(ss_)
    return ss_


# solve
if (len(s) < 26):
    for i in range(len(s)):
        b.remove(a[i])
    a.append(min(b))
    print(func(a))

if (len(s) == 26):
    for i in reversed(range(len(s))):
        if (a[i] < a[i-1]):
            if (i == 1):
                print(-1)
                break
            else:
                continue
        else:
            c = a[0:i]
            d = a[i:len(a)]
            d = sorted(d)
            # a[i-1]よりも大きくて最も小さいものを探す
            num = c.pop()
            ind = bisect.bisect_left(d, num)
            c.append(d[ind])
            print(func(c))
            break