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

# encoding: "utf-8"

from collections import defaultdict

# class Stdin:
#     @staticmethod
#     def read_line(converter=str):
#         return [converter(x) for x in input().split()]
    
#     @staticmethod
#     def read_lines(n, converter=str):
#         result = list()
#         for _ in range(n):
#             result.append(Stdin.read_line(converter))
#         return result
    
#     @staticmethod
#     def convert(data, converter):
#         assert(len(data) == len(converter))
#         return tuple(map(lambda x, f: f(x), data, converter))

#     @staticmethod
#     def convert_lines(datas, n, converter):
#         return [converter(data, n, converter) for data in datas]


def first_count_and_pop(xs):
    cnt = 0
    fst = xs[0]
    # cnt = xs.count(fst)
    for x in xs:
        if x != fst:
            break
        cnt += 1
    return (cnt, xs[cnt:])    
    

def main():
    _ = input()
    # xs = Stdin.read_line(converter=int)
    xs = [int(x) for x in input().split()]
    xs.sort()
    ys = defaultdict(int)
    while True:
        key = xs[0]
        cnt, xs = first_count_and_pop(xs)
        ys[key] += cnt
        ys[key-1] += cnt
        ys[key+1] += cnt
        if xs == []:
            break

    print(max(ys.values()))

# def main_():
#     input()
#     xs = Stdin.read_line(converter=int)
#     xs.sort()
#     counts = list()
#     for i in range(100000):
#         if not xs:
#             counts.extend([0] * (100000 - len(counts)))
#             break     
#         elif i == xs[0]:
#             cnt, xs = first_count_and_pop(xs)
#             counts.append(cnt)
#         else:
#             counts.append(0)
#     m = 0
#     for i in range(0, 100000):
#         if i == 0:
#             temp = counts[i] + counts[i+1]
#         elif i == 100000 - 1:
#             temp = counts[i-1] + counts[i]
#         else:
#             temp = counts[i-1] + counts[i] + counts[i+1]
#         if m < temp:
#             m = temp
#     print(m)

if __name__ == "__main__":
    main()

### FIXED CODE ###

input()
a_list = [int(s) for s in input().split()]

count = [0]*100002

for a in a_list:
    count[a] += 1
    count[a+1] += 1
    count[a+2] += 1
    
print(max(count))
### BUGGY CODE ###

S = input()
count = 0
dic = {}
ans = [0 for i in range(len(S))]
for i in range(len(S)):
  pi= -1
  ppi = -1
  ori = i
  while not ppi==i:
    ppi = pi
    pi = i
    if S[i] == 'R':
      i +=1
    else:
      i -=1
  if (ppi-ori)%2==0:
    dic[ori]=ppi
  else:
    dic[ori]=pi
for k in dic.keys():
  ind = dic[k]
  ans[ind]+=1
A = [str(i) for i in ans]
print(' '.join(A))

### FIXED CODE ###

S = input()
count = 0
dic = {}
ans = [0 for i in range(len(S))]
ind = []
for i in range(len(S)-1):
  if S[i]=='R' and S[i+1]=='L':
    ind += [i]
j = 0
k = 0
for i in range(len(S)):
  s = S[i]
  if s=='R':
    while i>ind[j]:
      j+=1
    if (ind[j]-i)%2==0:
      ans[ind[j]]+=1
    else:
      ans[ind[j]+1]+=1
  if s=='L':
    while ind[k]<i:
      k +=1
      if k==len(ind):
        break
    k -= 1
    if (ind[k]-i)%2==0:
      ans[ind[k]]+=1
    else:
      ans[ind[k]+1]+=1
A = [str(i) for i in  ans]
print(' '.join(A))
### BUGGY CODE ###

from scipy.sparse.csgraph import floyd_warshall
import itertools


def warshal_floyd(d):
    # d[i][j] := iからjへの最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    # "今現在求まっているiからjへの最短距離"と"今現在求まっているiからkへの最短距離 + 今現在求まっているkからjへの最短距離 の和"を比較する
    return d


N, M, R = map(int, input().split())  # N個の町, M本の道, R個の町を訪れることになった
town = list(map(lambda x: int(x)-1, input().split()))
distant = [[float('inf')]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    distant[a][b] = c
    distant[b][a] = c
for i in range(N):
    distant[i][i] = 0

warshal_floyd(distant)
# print(distant)  # Rは最大8だから全てを試しても大丈夫
ans = 10**9
for x in itertools.permutations(town):
    x = list(x)
    now = x[0]
    tmp = 0
    for i in range(1, len(x)):
        tmp += distant[now][x[i]]
        now = x[i]
    ans = min(ans, tmp)
print(ans)


### FIXED CODE ###

# from scipy.sparse.csgraph import floyd_warshall
import itertools


def warshal_floyd(d):
    # d[i][j] := iからjへの最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    # "今現在求まっているiからjへの最短距離"と"今現在求まっているiからkへの最短距離 + 今現在求まっているkからjへの最短距離 の和"を比較する
    return d


N, M, R = map(int, input().split())  # N個の町, M本の道, R個の町を訪れることになった
town = list(map(lambda x: int(x)-1, input().split()))
distant = [[float('inf')]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    distant[a][b] = c
    distant[b][a] = c
for i in range(N):
    distant[i][i] = 0

warshal_floyd(distant)
# print(distant)  # Rは最大8だから全てを試しても大丈夫
ans = 10**9
for x in itertools.permutations(town):
    x = list(x)
    now = x[0]
    tmp = 0
    for i in range(1, len(x)):
        tmp += distant[now][x[i]]
        now = x[i]
    ans = min(ans, tmp)
print(ans)
### BUGGY CODE ###

n,a,b = map(int,input().split())
sums = 0

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

for i in range(n+1):
    if i == a or i == b or i == 0:continue
    sums += cmb(n,i)
if sums >= (10**9 + 7):
    sums %= (10**9 + 7)
print(sums)

### FIXED CODE ###

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

mod = 10 ** 9 + 7
k = max(a,b)
com = [1]

for i in range(1,k+1):
    com.append((com[i-1]*(n-i+1)*pow(i,mod-2,mod))%mod)

print((pow(2,n,mod)-1-com[a]-com[b])%mod)
### BUGGY CODE ###

from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1

INF = 1e10
maze = []

dh = [-1,0,1,0]
dw = [0,1,0,-1]

for i in range(H):
    tmp = list(input())
    maze.append(tmp)

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

l = deque()
l.appendleft((Ch, Cw))
reached[Ch][Cw] = 0
while l:
    h, w = l.popleft()
    d = reached[h][w]
    for i in range(4):
        nh = h + dh[i]
        nw = w + dw[i]
        if 0 <= nh <= H-1 and 0 <= nw <= W-1 and maze[nh][nw] != "#" and reached[nh][nw] > d:
            reached[nh][nw] = d
            l.appendleft((nh, nw))
    for i in range(-2, 3):
        for j in range(-2, 3):
            nh = h + i
            nw = w + j
            if 0 <= nh <= H-1 and 0 <= nw <= W-1 and maze[nh][nw] != "#" and reached[nh][nw] > d:
                reached[nh][nw] = d + 1
                l.append((nh, nw))

ans = reached[Dh][Dw]
if ans != INF:
    print(ans)
else:
    print(-1)

    

### FIXED CODE ###

from collections import deque

H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
Ch -= 1
Cw -= 1
Dh -= 1
Dw -= 1

INF = 1e10
maze = []

dh = [-1,0,1,0]
dw = [0,1,0,-1]

for i in range(H):
    tmp = list(input())
    maze.append(tmp)

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

l = deque()
l.appendleft((Ch, Cw))
reached[Ch][Cw] = 0
while l:
    h, w = l.popleft()
    d = reached[h][w]
    for i in range(4):
        nh = h + dh[i]
        nw = w + dw[i]
        if not (0 <= nh <= H-1 and 0 <= nw <= W-1):
            continue
        if not maze[nh][nw] != "#":
            continue
        if not reached[nh][nw] > d:
            continue
        reached[nh][nw] = d
        l.appendleft((nh, nw))
    for i in range(-2, 3):
        for j in range(-2, 3):
            nh = h + i
            nw = w + j
            if not (0 <= nh <= H-1 and 0 <= nw <= W-1):
                continue
            if not maze[nh][nw] != "#":
                continue
            if not reached[nh][nw] > d + 1:
                continue
            reached[nh][nw] = d + 1
            l.append((nh, nw))

ans = reached[Dh][Dw]
if ans != INF:
    print(ans)
else:
    print(-1)
### BUGGY CODE ###

S = input()
N = len(S)
 
for i in range(N):
    S = S.replace('01', '').replace('10', '')
 
print(N - len(S))

### FIXED CODE ###

S = input()
N = len(S)
A = 0

for i in range(N):
    if S[i] == '1':
        A = A + 1

print(min(N - A, A)*2)
### BUGGY CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from functools import lru_cache

PRIME = 10 ** 9 + 7


@lru_cache(maxsize=None)
def digitmod13(y):
    if y == 0:
        return 1
    elif y == 1:
        return 10 % 13
    elif y % 2 == 0:
        return digitmod13(y // 2) ** 2 % 13
    else:
        return digitmod13(y // 2) ** 2 * 10 % 13


def main():
    S = input()
    N = len(S)
    dp = [[0 for _ in range(13)] for _ in range(N)]
    S = S[::-1]
    
    # init
    first = S[0]
    if first == '?':
        for k in range(10):
            dp[0][k] = 1
    else:
        first = int(first)
        dp[0][first] = 1
    
    # dp
    for i in range(1, N):
        c = S[i]
        if c == '?':
            for d in range(13):
                for k in range(10):
                    dp[i][(d + k * digitmod13(i)) % 13] += dp[i - 1][d]
                    dp[i][(d + k * digitmod13(i)) % 13] %= PRIME
        else:
            c = int(c)
            for d in range(13):
                dp[i][(d + c * digitmod13(i)) % 13] += dp[i - 1][d]
                dp[i][(d + c * digitmod13(i)) % 13] %= PRIME
    
    print(dp[N - 1][5] % PRIME)


if __name__ == "__main__":
    main()


### FIXED CODE ###

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from functools import lru_cache

PRIME = 10 ** 9 + 7


@lru_cache(maxsize=None)
def digitmod13(y):
    if y == 0:
        return 1
    elif y == 1:
        return 10 % 13
    elif y % 2 == 0:
        return digitmod13(y // 2) ** 2 % 13
    else:
        return digitmod13(y // 2) ** 2 * 10 % 13


def main():
    S = input()
    N = len(S)
    dp = [[0 for _ in range(13)] for _ in range(N)]
    S = S[::-1]
    
    # init
    first = S[0]
    if first == '?':
        for k in range(10):
            dp[0][k] = 1
    else:
        first = int(first)
        dp[0][first] = 1
    
    # prepare table
    table = [[[(i + (j * k)) % 13 for k in range(13)] for j in range(10)] for i in range(13)]
    
    # dp
    for i in range(1, N):
        c = S[i]
        if c == '?':
            for d in range(13):
                for k in range(10):
                    mod = table[d][k][digitmod13(i)]
                    dp[i][mod] += dp[i - 1][d]
                    dp[i][mod] %= PRIME
        else:
            c = int(c)
            for d in range(13):
                mod = table[d][c][digitmod13(i)]
                dp[i][mod] += dp[i - 1][d]
                dp[i][mod] %= PRIME
    
    print(dp[N - 1][5] % PRIME)


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

from collections import deque
H,W,K,*L = open(0).read().split()
H,W,K = map(int, (H,W,K))
q = deque([])
step = [(-1,0),(1,0),(0,-1),(0,1)]
for i in range(H):
  flag = False
  for j in range(W):
    if L[i][j]=='S':
      q.append((i,j,0))
      flag = True
      break
  if flag:
    break
dist = [[10**10]*W for i in range(H)]
dist[i][j] = 0
while q:
  a,b,c = q.popleft()
  dist[a][b] = c
  if c+1>K:
    continue
  for dx,dy in step:
    n = a+dx
    m = b+dy
    if not(-1<n<H and -1<m<W):
      continue
    if dist[n][m]<c+1:
      continue
    if L[n][m]=='.':
      q.append((n,m,c+1))
      
ans = 10**10
for i in range(H):
  for j in range(W):
    if dist[i][j]==10**10:
      continue
    x = min(i,H-i-1,j,W-j-1)
    cnt = 1+(x+K-1)//K
    ans = min(cnt,ans)
print(ans)

### FIXED CODE ###

from collections import deque
H,W,K,*L = open(0).read().split()
L = [list(a) for a in L]
H,W,K = map(int, (H,W,K))
q = deque([])
step = [(-1,0),(1,0),(0,-1),(0,1)]
for i,a in enumerate(L):
  if 'S' in a:
    q = deque([(0,i,a.index('S'))])
    break
ans = 10**10
while q:
  c,a,b = q.popleft()
  x = min(a,H-a-1,b,W-b-1)
  cnt = 1+(x+K-1)//K
  ans = min(cnt,ans)
  if c+1>K:
    continue
  for dx,dy in step:
    n = a+dx
    m = b+dy
    if not(-1<n<H and -1<m<W):
      continue
    if L[n][m]=='.':
      L[n][m]='#'
      q.append((c+1,n,m))
print(ans)
### BUGGY CODE ###

import fractions
def main():
    N=int(input())
    a=list(map(int,input().split()))
    mod=10**9+7
    c=a[0]
    for i in range(1, N):
        c=c*a[i]//fractions.gcd(c,a[i])
    b=0
    for k in a:
        b+=c//k
        b%=mod
    print(b)
main()

### FIXED CODE ###

from fractions import gcd
def main():
    N=int(input())
    A=list(map(int,input().split()))
    mod=10**9+7
    b=0
    c=1
    for a in A:
        c=c*a//gcd(c,a)
    c%=mod
    for a in A:
        b+=c*pow(a,mod-2,mod)
    print(b%mod)
if __name__=="__main__":
    main()
### BUGGY CODE ###

import bisect
 
 
N = int(input())
 
lis = []
 
A1 = int(input())
 
 
lis.append(A1)
 
 
for i in range(N-1):
 
    A = int(input())
 
    flag = True
    ins = bisect.bisect_left(lis,A)
 
    if ins == 0:
        lis.insert(0,A)
 
    if lis[ins-1] < A:
        lis[ins-1] = A
 
"""
    for l in lis:
 
 
 
        if l < A:
            l = A
            flag = False
            lis.sort()
            maxi = max(maxi , i)
            break
 
    if flag:
        lis.append(A)
"""
 
#print (lis)
print (len(lis))


### FIXED CODE ###

import bisect

N = int(input())

A = []

for i in range(N):

    a = int(input())
    A.append(a)

A.reverse()

seq = [float("-inf")]

for i in A:

    ind = bisect.bisect_right(seq,i)

    if ind == len(seq):
        seq.append(i)
    else:
        seq[ind] = i

print (len(seq)-1)
### BUGGY CODE ###

ans = 0
n, m =map(int,input().split())
s = list(map(int,input().split()))
a = [list(map(int, input().split())) for _ in range(m)]
for i in range(1,n+1):
  l = []
  for _ in range(m):
    if i in a[_]:
      l += a[_]
      l.remove(i)
  for _ in range(len(l)):
    l[_] = s[l[_]-1]
  if not l:
    l.append(0)
  if s[i-1] > max(l):
    ans += 1
print(ans)

### FIXED CODE ###

n, m =map(int,input().split())
s = list(map(int,input().split()))
t = [0]*n #展望台が良いと0
for __ in range(m):
  a, b =map(int,input().split())
  if s[a-1] >= s[b-1]:
    t[b-1] += 1
  if s[a-1] <= s[b-1]:
    t[a-1] += 1
print(t.count(0))
### BUGGY CODE ###

import sys
from collections import defaultdict


def dfs(root, links):
    status = {}
    topological = []
    q = [(r, 0, 1) for r in root]
    while q:
        node = q.pop()
        if node[1] == 0:
            v, _, d = node
            q.append((v, 1))
            status[v] = 1
            d += 1
            for u in links[v]:
                if u in status:
                    if status[u] == 1:
                        return False
                else:
                    q.append((u, 0, d))
        else:
            v = node[0]
            status[v] = 2
            topological.append(v)
    topological.reverse()
    return topological


n = int(input())
links = defaultdict(set)
may_root = set()
in_cnt = defaultdict(lambda: 0)
for i, line in enumerate(sys.stdin):
    aaa = list(map(int, line.split()))
    j = aaa[0] - 1
    a, b = (i, j) if i < j else (j, i)
    prev = a * 1000 + b
    may_root.add(prev)

    for j in aaa[1:]:
        j -= 1
        a, b = (i, j) if i < j else (j, i)
        key = a * 1000 + b
        links[prev].add(key)
        in_cnt[key] += 1
        prev = key
may_root = {r for r in may_root if in_cnt[r] == 0}

if not may_root:
    print(-1)
    exit()

topological = dfs(may_root, links)
if topological == False:
    print(-1)
    exit()

ans = 0
depth = defaultdict(lambda: 1)
for v in topological:
    d = depth[v] + 1
    for u in links[v]:
        depth[u] = max(depth[u], d)

print(max(depth.values()))


### FIXED CODE ###

import sys
from collections import defaultdict


def dfs(root, links):
    status = {}
    topological = []
    q = [(r, 0, 1) for r in root]
    while q:
        node = q.pop()
        if node[1] == 0:
            v, _, d = node
            q.append((v, 1))
            status[v] = 1
            d += 1
            for u in links[v]:
                if u in status:
                    if status[u] == 1:
                        return False
                else:
                    q.append((u, 0, d))
        else:
            v = node[0]
            status[v] = 2
            topological.append(v)
    topological.reverse()
    return topological


n = int(input())
links = defaultdict(set)
may_root = set()
lines = sys.stdin.readlines()
matches = []
for i in range(n):
    line = lines[i]
    aaa = list(map(int, line.split()))
    match_order = []
    for j in aaa:
        j -= 1
        a, b = (i, j) if i < j else (j, i)
        key = a * n + b
        match_order.append(key)
    matches.append(match_order)
    may_root.add(match_order[0])

for i in range(n):
    kkk = matches[i]
    prev = kkk[0]

    for key in kkk[1:]:
        links[prev].add(key)
        may_root.discard(key)
        prev = key

if not may_root:
    print(-1)
    exit()

topological = dfs(may_root, links)
if topological == False:
    print(-1)
    exit()

ans = 0
depth = defaultdict(lambda: 1)
for v in topological:
    d = depth[v] + 1
    for u in links[v]:
        depth[u] = max(depth[u], d)

print(max(depth.values()))
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
R=[tuple(map(int,input().split())) for i in range(M)]

E=[set() for i in range(N)]

for x,y in R:
    E[x-1].add(y-1)

DP=[1<<60]*N
DP[N-1]=0

for i in range(N-2,-1,-1):
    score=0
    for x in E[i]:
        score+=1+DP[x]

    DP[i]=score/len(E[i])
        
ANS=DP[0]

for i in range(N-2):
    rem=-1
    remsc=0
    for j in E[i]:
        if DP[j]>remsc:
            rem=j
            remsc=DP[j]

    if remsc==0:
        continue

    E[i].remove(rem)

    NDP=[1<<60]*N
    NDP[N-1]=0

    for l in range(N-2,-1,-1):
        
        score=0
        
        if len(E[l])==0:
            continue
        
        for x in E[l]:
            score+=1+NDP[x]

        NDP[l]=score/len(E[l])

    #print(i,rem,E,NDP)

    ANS=min(ANS,NDP[0])
    E[i].add(rem)

print(ANS)

### FIXED CODE ###

import sys
input = sys.stdin.readline

N,M=map(int,input().split())
R=[tuple(map(int,input().split())) for i in range(M)]

E=[set() for i in range(N)]

for x,y in R:
    E[x-1].add(y-1)

DP=[M]*N
DP[N-1]=0

for i in range(N-2,-1,-1):
    score=0
    for x in E[i]:
        score+=1+DP[x]

    DP[i]=score/len(E[i])
        
ANS=DP[0]

for i in range(N-2):
    rem=-1
    remsc=0
    for j in E[i]:
        if DP[j]>remsc:
            rem=j
            remsc=DP[j]

    if remsc==0:
        continue

    E[i].remove(rem)

    NDP=[M]*N
    NDP[N-1]=0

    for l in range(N-2,-1,-1):
        
        score=0
        
        if len(E[l])==0:
            continue
        
        for x in E[l]:
            score+=1+NDP[x]

        NDP[l]=score/len(E[l])

    #print(i,rem,E,NDP)

    ANS=min(ANS,NDP[0])
    E[i].add(rem)

print(ANS)
### BUGGY CODE ###

from collections import deque
N = int(input())
a = list(map(int, input().split()))
b = deque()
ans = 0

for i in range(N):
  t = N-1-i
  s = 0
  while t < N:
    if t+1 in b:
      s += 1
    t += N-i
  if (a[N-1-i]+s) % 2 == 1:
    b.appendleft(N-i)
    ans += 1
    
print(ans)
print(' '.join(map(str, b)))

### FIXED CODE ###

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

b = [0] * N
for i in range(N):
  tmp = 0
  n = N-i
  for j in range(n*2-1, N, n):
    if b[j] == 1:
      tmp += 1
  if a[n-1] != tmp%2:
    b[n-1] = 1

ans = []
for i in range(N):
  if b[i] == 1:
    ans.append(i+1)
if ans != []:
  print(len(ans))
  print(*ans)
else:
  print(0)
### BUGGY CODE ###

print(sum([i for i in range(1, int(input()))]))

### FIXED CODE ###

N = int(input())

if N % 2 == 0:
    print((N-1)*N//2)
else:
    print(N*(N-1)//2)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

n,q = map(int,input().split())
s = input()
lr = []
for i in range(0,q):
    lr.append(input().split())
map(int,lr)

ei = []
for index, item in enumerate(s):
    if index == n - 1:
        break
    if s[index] == "A" and s[index + 1] == "C":
        ei.append(index)

for i in range(0,q):
    sum = 0
    for j in range(int(lr[i][0])-1,int(lr[i][1])):
        if j in ei:
            sum += 1
    if int(lr[i][1])-1 in ei:
        sum -= 1
    print(sum)


### FIXED CODE ###

# -*- coding: utf-8 -*-

n, q = map(int,input().split())
s = list(input())
l = [0] * q
r = [0] * q
for i in range(q):
    l[i],r[i] = map(int,input().split())

aclist = []

cnt = 0
for i in range(n):
    if s[i-1] == "A" and s[i] == "C":
        cnt += 1
        aclist.append(cnt)
    else:
        aclist.append(cnt)

for i in range(q):
    print(aclist[r[i]-1] - aclist[l[i]-1])
### BUGGY CODE ###

# import bisect
from collections import Counter, deque
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# from operator import xor
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

    def main():
        S=str(input())
        d=deque(['dream','dreamer','erase','eraser'])
        long=5

        while long<len(S)*2:
            dd = d.popleft()
            long=len(dd)
            if dd==S:
                return 'YES'

            else:
                d.extend([dd+'dream',dd+'dreamer',dd+'erase',dd+'eraser'])

        return 'NO'
    print(main())





resolve()

### FIXED CODE ###

def resolve():

    S=str(input())[::-1]
    flag='YES'
    i=0

    while i<len(S):
        if S[i:i+5]=='maerd' or S[i:i+5]=='esare':
            i+=5
            continue
        if S[i:i+6]=='resare':
            i+=6
            continue
        if S[i:i+7]=='remaerd':
            i+=7
        else:
            flag='NO'
            break

    print(flag)









resolve()
### BUGGY CODE ###

n,m = map(int,input().split())
br = [list(map(int,input().split())) for i in range(m)]
ans = [(n*(n-1))//2]
member = [[i] for i in range(n)]

def search_member(br_i, member):
     flag = 0
     br_mem_num =[]
     mem_1 = br_i[0] - 1
     mem_2 = br_i[1] - 1
     for i in range(len(member)):
          if mem_1 in member[i]:
               br_mem_num.append(i)
               flag += 1
          if mem_2 in member[i]:
               br_mem_num.append(i)
               flag += 1
          if flag == 2:
               break
     return br_mem_num
     
def change_member(br_mem_num, member):
     mem1_num = br_mem_num[0]
     mem2_num = br_mem_num[1]
     member[mem1_num] += member[mem2_num]
     member[mem2_num] = []

for i in range(m-1,-1,-1):
     br_i = br[i]
     br_mem_num = search_member(br_i, member)
     if br_mem_num[0] != br_mem_num[1]:
          len_1, len_2 = len(member[br_mem_num[0]]), len(member[br_mem_num[1]])
          ans.append(ans[-1] - (len_1*len_2))
          change_member(br_mem_num, member)
     else:
          ans.append(ans[-1])

for i in range(m-1,-1,-1):
     print(ans[i])

### FIXED CODE ###

#https://atcoder.jp/contests/abc120/submissions/4458925
(N,M) = map(int,input().split())
A = [0]*M
B = [0]*M
for i in range(M):
    (A[i], B[i]) = map(int,input().split())
    A[i] -= 1
    B[i] -= 1
 
parent = [-1]*N
depth = [0] * N
 
def boss(n):
    d = 0
    while parent[n] >= 0:
        n = parent[n]
        d += 1
    return n,d
 
P = [1]*N
S = (N*(N-1))//2
 
ans = [0] * M
ans[M-1] = S
 
for i in range(M-1):
    j = M-1-i
    bA, dA = boss(A[j])
    bB, dB = boss(B[j])
    if bA != bB:
        if depth[bA] < depth[bB]:
            (bA, bB) = (bB, bA)
        parent[bB] = bA
        S -= P[bA]*P[bB]
        P[bA] = P[bA] + P[bB]
        P[bB] = 0
        depth[bA] = max(depth[bA],depth[bB]+1)
    ans[j-1] = S
 
for i in range(M):
    print(ans[i])